Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: chrome/browser/storage/durable_storage_browsertest.cc

Issue 1294913009: Durable Storage: Add "deny" test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change permission to is_persistent Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/data/durable/durability-permissions.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_commands.h" 10 #include "chrome/browser/ui/browser_commands.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 12 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "chrome/test/base/ui_test_utils.h" 15 #include "chrome/test/base/ui_test_utils.h"
16 #include "content/public/browser/dom_operation_notification_details.h" 16 #include "content/public/browser/dom_operation_notification_details.h"
17 #include "content/public/browser/render_frame_host.h" 17 #include "content/public/browser/render_frame_host.h"
18 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
19 #include "content/public/test/browser_test_utils.h" 19 #include "content/public/test/browser_test_utils.h"
20 #include "net/test/embedded_test_server/embedded_test_server.h" 20 #include "net/test/embedded_test_server/embedded_test_server.h"
21 21
22 class DurableStorageBrowserTest : public InProcessBrowserTest { 22 class DurableStorageBrowserTest : public InProcessBrowserTest {
23 public: 23 public:
24 DurableStorageBrowserTest(); 24 DurableStorageBrowserTest() = default;
25 ~DurableStorageBrowserTest() override; 25 ~DurableStorageBrowserTest() override = default;
26 26
27 void SetUpCommandLine(base::CommandLine*) override; 27 void SetUpCommandLine(base::CommandLine*) override;
28 void SetUpOnMainThread() override;
29
30 protected:
31 content::RenderFrameHost* GetRenderFrameHost() {
32 return browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame();
33 }
34 GURL url_;
28 35
29 private: 36 private:
30 DISALLOW_COPY_AND_ASSIGN(DurableStorageBrowserTest); 37 DISALLOW_COPY_AND_ASSIGN(DurableStorageBrowserTest);
31 }; 38 };
32 39
33 DurableStorageBrowserTest::DurableStorageBrowserTest() {}
34
35 DurableStorageBrowserTest::~DurableStorageBrowserTest() {}
36
37 void DurableStorageBrowserTest::SetUpCommandLine( 40 void DurableStorageBrowserTest::SetUpCommandLine(
38 base::CommandLine* command_line) { 41 base::CommandLine* command_line) {
39 command_line->AppendSwitch( 42 command_line->AppendSwitch(
40 switches::kEnableExperimentalWebPlatformFeatures); 43 switches::kEnableExperimentalWebPlatformFeatures);
41 } 44 }
42 45
43 // TODO(dgrogan): Reenable after https://codereview.chromium.org/1302643002 46 void DurableStorageBrowserTest::SetUpOnMainThread() {
44 // lands. 47 if (embedded_test_server()->Started())
45 IN_PROC_BROWSER_TEST_F(DurableStorageBrowserTest, FirstTabSeesResult) { 48 return;
46 EXPECT_TRUE(embedded_test_server()->Started() || 49 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
47 embedded_test_server()->InitializeAndWaitUntilReady()); 50 url_ = embedded_test_server()->GetURL("/durable/durability-permissions.html");
51 }
48 52
49 Browser* current_browser = browser(); 53 IN_PROC_BROWSER_TEST_F(DurableStorageBrowserTest, DenyString) {
50 54 ui_test_utils::NavigateToURL(browser(), url_);
51 const GURL& url = 55 PermissionBubbleManager::FromWebContents(
52 embedded_test_server()->GetURL("/durable/durability-window1.html"); 56 browser()->tab_strip_model()->GetActiveWebContents())
53 ui_test_utils::NavigateToURL(current_browser, url); 57 ->set_auto_response_for_test(PermissionBubbleManager::DENY_ALL);
54 content::RenderFrameHost* render_frame_host = 58 bool default_box_is_persistent;
55 current_browser->tab_strip_model() 59 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
56 ->GetActiveWebContents() 60 GetRenderFrameHost(), "requestPermission()", &default_box_is_persistent));
57 ->GetMainFrame(); 61 EXPECT_EQ(false, default_box_is_persistent);
58 std::string permission_string; 62 std::string permission_string;
59 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 63 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
60 render_frame_host, "checkPermission()", &permission_string)); 64 GetRenderFrameHost(), "checkPermission()", &permission_string));
65 EXPECT_EQ("denied", permission_string);
66 }
67
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));
61 EXPECT_EQ("default", permission_string); 73 EXPECT_EQ("default", permission_string);
62 74
63 chrome::NewTab(current_browser); 75 chrome::NewTab(browser());
64 const GURL& url2 = 76 ui_test_utils::NavigateToURL(browser(), url_);
65 embedded_test_server()->GetURL("/durable/durability-window2.html");
66 ui_test_utils::NavigateToURL(current_browser, url2);
67 render_frame_host = current_browser->tab_strip_model()
68 ->GetActiveWebContents()
69 ->GetMainFrame();
70 PermissionBubbleManager::FromWebContents( 77 PermissionBubbleManager::FromWebContents(
71 current_browser->tab_strip_model()->GetActiveWebContents()) 78 browser()->tab_strip_model()->GetActiveWebContents())
72 ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL); 79 ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL);
73 bool default_box_is_persistent = false; 80 bool default_box_is_persistent = false;
74 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 81 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
75 render_frame_host, "requestPermission()", &default_box_is_persistent)); 82 GetRenderFrameHost(), "requestPermission()", &default_box_is_persistent));
76 EXPECT_EQ(true, default_box_is_persistent); 83 EXPECT_EQ(true, default_box_is_persistent);
77 84
78 current_browser->tab_strip_model()->ActivateTabAt(0, false); 85 browser()->tab_strip_model()->ActivateTabAt(0, false);
79 render_frame_host = current_browser->tab_strip_model()
80 ->GetActiveWebContents()
81 ->GetMainFrame();
82 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 86 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
83 render_frame_host, "checkPermission()", &permission_string)); 87 GetRenderFrameHost(), "checkPermission()", &permission_string));
84 EXPECT_EQ("granted", permission_string); 88 EXPECT_EQ("granted", permission_string);
85 } 89 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/durable/durability-permissions.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698