1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "base/command_line.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_commands.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "chrome/test/base/ui_test_utils.h"
16 #include "content/public/browser/dom_operation_notification_details.h"
17 #include "content/public/browser/render_frame_host.h"
18 #include "content/public/browser/web_contents.h"
19 #include "content/public/test/browser_test_utils.h"
20 #include "net/test/embedded_test_server/embedded_test_server.h"
22 class DurableStorageBrowserTest
: public InProcessBrowserTest
{
24 DurableStorageBrowserTest() = default;
25 ~DurableStorageBrowserTest() override
= default;
27 void SetUpCommandLine(base::CommandLine
*) override
;
28 void SetUpOnMainThread() override
;
31 content::RenderFrameHost
* GetRenderFrameHost() {
32 return browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame();
37 DISALLOW_COPY_AND_ASSIGN(DurableStorageBrowserTest
);
40 void DurableStorageBrowserTest::SetUpCommandLine(
41 base::CommandLine
* command_line
) {
42 command_line
->AppendSwitch(
43 switches::kEnableExperimentalWebPlatformFeatures
);
46 void DurableStorageBrowserTest::SetUpOnMainThread() {
47 if (embedded_test_server()->Started())
49 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
50 url_
= embedded_test_server()->GetURL("/durable/durability-permissions.html");
53 IN_PROC_BROWSER_TEST_F(DurableStorageBrowserTest
, DenyString
) {
54 ui_test_utils::NavigateToURL(browser(), url_
);
55 PermissionBubbleManager::FromWebContents(
56 browser()->tab_strip_model()->GetActiveWebContents())
57 ->set_auto_response_for_test(PermissionBubbleManager::DENY_ALL
);
58 bool default_box_is_persistent
;
59 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
60 GetRenderFrameHost(), "requestPermission()", &default_box_is_persistent
));
61 EXPECT_FALSE(default_box_is_persistent
);
62 std::string permission_string
;
63 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
64 GetRenderFrameHost(), "checkPermission()", &permission_string
));
65 EXPECT_EQ("denied", permission_string
);
68 IN_PROC_BROWSER_TEST_F(DurableStorageBrowserTest
, FirstTabSeesResult
) {
69 ui_test_utils::NavigateToURL(browser(), url_
);
70 std::string permission_string
;
71 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
72 GetRenderFrameHost(), "checkPermission()", &permission_string
));
73 EXPECT_EQ("default", permission_string
);
75 chrome::NewTab(browser());
76 ui_test_utils::NavigateToURL(browser(), url_
);
77 PermissionBubbleManager::FromWebContents(
78 browser()->tab_strip_model()->GetActiveWebContents())
79 ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL
);
80 bool default_box_is_persistent
= false;
81 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
82 GetRenderFrameHost(), "requestPermission()", &default_box_is_persistent
));
83 EXPECT_TRUE(default_box_is_persistent
);
85 browser()->tab_strip_model()->ActivateTabAt(0, false);
86 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
87 GetRenderFrameHost(), "checkPermission()", &permission_string
));
88 EXPECT_EQ("granted", permission_string
);