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

Side by Side Diff: chrome/browser/content_settings/permission_context_base_unittest.cc

Issue 411503005: Change tests to prepare for turning on the permission bubble flag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/download/download_permission_request.cc » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/content_settings/permission_context_base.h" 5 #include "chrome/browser/content_settings/permission_context_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chrome/browser/content_settings/host_content_settings_map.h" 8 #include "chrome/browser/content_settings/host_content_settings_map.h"
9 #include "chrome/browser/content_settings/permission_queue_controller.h" 9 #include "chrome/browser/content_settings/permission_queue_controller.h"
10 #include "chrome/browser/content_settings/permission_request_id.h" 10 #include "chrome/browser/content_settings/permission_request_id.h"
11 #include "chrome/browser/infobars/infobar_service.h" 11 #include "chrome/browser/infobars/infobar_service.h"
12 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
12 #include "chrome/common/content_settings.h" 13 #include "chrome/common/content_settings.h"
13 #include "chrome/common/content_settings_types.h" 14 #include "chrome/common/content_settings_types.h"
14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
15 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
17 #include "content/public/test/mock_render_process_host.h" 18 #include "content/public/test/mock_render_process_host.h"
18 #include "content/public/test/web_contents_tester.h" 19 #include "content/public/test/web_contents_tester.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 class PermissionContextBaseTests : public ChromeRenderViewHostTestHarness { 22 class PermissionContextBaseTests : public ChromeRenderViewHostTestHarness {
22 protected: 23 protected:
23 PermissionContextBaseTests() {} 24 PermissionContextBaseTests() {}
24 virtual ~PermissionContextBaseTests() {} 25 virtual ~PermissionContextBaseTests() {}
25 26
27 // Accept or dismiss the permission bubble.
28 void RespondPermissionBubble(bool accept) {
29 PermissionBubbleManager* manager =
30 PermissionBubbleManager::FromWebContents(web_contents());
31 if (accept)
32 manager->Accept();
33 else
34 manager->Closing();
35 }
36
26 private: 37 private:
27 // ChromeRenderViewHostTestHarness: 38 // ChromeRenderViewHostTestHarness:
28 virtual void SetUp() OVERRIDE { 39 virtual void SetUp() OVERRIDE {
29 ChromeRenderViewHostTestHarness::SetUp(); 40 ChromeRenderViewHostTestHarness::SetUp();
30 InfoBarService::CreateForWebContents(web_contents()); 41 InfoBarService::CreateForWebContents(web_contents());
42 PermissionBubbleManager::CreateForWebContents(web_contents());
leng 2014/07/23 16:29:10 Is this a no-op for !PermissionBubbleManager::Enab
Greg Billock 2014/07/29 16:44:13 Not quite a no-op, but shouldn't interfere.
31 } 43 }
32 44
33 DISALLOW_COPY_AND_ASSIGN(PermissionContextBaseTests); 45 DISALLOW_COPY_AND_ASSIGN(PermissionContextBaseTests);
34 }; 46 };
35 47
36 class TestPermissionContext : public PermissionContextBase { 48 class TestPermissionContext : public PermissionContextBase {
37 public: 49 public:
38 TestPermissionContext(Profile* profile, 50 TestPermissionContext(Profile* profile,
39 const ContentSettingsType permission_type) 51 const ContentSettingsType permission_type)
40 : PermissionContextBase(profile, permission_type), 52 : PermissionContextBase(profile, permission_type),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 const PermissionRequestID id( 101 const PermissionRequestID id(
90 web_contents()->GetRenderProcessHost()->GetID(), 102 web_contents()->GetRenderProcessHost()->GetID(),
91 web_contents()->GetRenderViewHost()->GetRoutingID(), 103 web_contents()->GetRenderViewHost()->GetRoutingID(),
92 -1, GURL()); 104 -1, GURL());
93 permission_context.RequestPermission( 105 permission_context.RequestPermission(
94 web_contents(), 106 web_contents(),
95 id, url, true, 107 id, url, true,
96 base::Bind(&TestPermissionContext::TrackPermissionDecision, 108 base::Bind(&TestPermissionContext::TrackPermissionDecision,
97 base::Unretained(&permission_context))); 109 base::Unretained(&permission_context)));
98 110
99 permission_context.GetInfoBarController()->OnPermissionSet( 111 if (!PermissionBubbleManager::Enabled()) {
Miguel Garcia 2014/07/25 12:17:35 Can you create a Respond(bool value) method that
Greg Billock 2014/07/29 16:44:13 Done.
100 id, url, url, true, true); 112 permission_context.GetInfoBarController()->OnPermissionSet(
113 id, url, url, true, true);
114 } else {
115 RespondPermissionBubble(true);
116 }
101 EXPECT_TRUE(permission_context.permission_set()); 117 EXPECT_TRUE(permission_context.permission_set());
102 EXPECT_TRUE(permission_context.permission_granted()); 118 EXPECT_TRUE(permission_context.permission_granted());
103 EXPECT_TRUE(permission_context.tab_context_updated()); 119 EXPECT_TRUE(permission_context.tab_context_updated());
104 120
105 ContentSetting setting = 121 ContentSetting setting =
106 profile()->GetHostContentSettingsMap()->GetContentSetting( 122 profile()->GetHostContentSettingsMap()->GetContentSetting(
107 url.GetOrigin(), url.GetOrigin(), 123 url.GetOrigin(), url.GetOrigin(),
108 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string()); 124 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, std::string());
109 EXPECT_EQ(CONTENT_SETTING_ALLOW , setting); 125 EXPECT_EQ(CONTENT_SETTING_ALLOW , setting);
110 }; 126 };
111 127
112 // Simulates clicking Dismiss (X in the infobar. 128 // Simulates clicking Dismiss (X in the infobar.
113 // The permission should be denied but not saved for future use. 129 // The permission should be denied but not saved for future use.
114 TEST_F(PermissionContextBaseTests, TestAskAndDismiss) { 130 TEST_F(PermissionContextBaseTests, TestAskAndDismiss) {
115 TestPermissionContext permission_context(profile(), 131 TestPermissionContext permission_context(profile(),
116 CONTENT_SETTINGS_TYPE_MIDI_SYSEX); 132 CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
117 GURL url("http://www.google.es"); 133 GURL url("http://www.google.es");
118 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); 134 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url);
119 135
120 const PermissionRequestID id( 136 const PermissionRequestID id(
121 web_contents()->GetRenderProcessHost()->GetID(), 137 web_contents()->GetRenderProcessHost()->GetID(),
122 web_contents()->GetRenderViewHost()->GetRoutingID(), 138 web_contents()->GetRenderViewHost()->GetRoutingID(),
123 -1, GURL()); 139 -1, GURL());
124 permission_context.RequestPermission( 140 permission_context.RequestPermission(
125 web_contents(), 141 web_contents(),
126 id, url, true, 142 id, url, true,
127 base::Bind(&TestPermissionContext::TrackPermissionDecision, 143 base::Bind(&TestPermissionContext::TrackPermissionDecision,
128 base::Unretained(&permission_context))); 144 base::Unretained(&permission_context)));
129 145
130 permission_context.GetInfoBarController()->OnPermissionSet( 146 if (!PermissionBubbleManager::Enabled()) {
131 id, url, url, false, false); 147 permission_context.GetInfoBarController()->OnPermissionSet(
148 id, url, url, false, false);
149 } else {
150 RespondPermissionBubble(false);
151 }
132 EXPECT_TRUE(permission_context.permission_set()); 152 EXPECT_TRUE(permission_context.permission_set());
133 EXPECT_FALSE(permission_context.permission_granted()); 153 EXPECT_FALSE(permission_context.permission_granted());
134 EXPECT_TRUE(permission_context.tab_context_updated()); 154 EXPECT_TRUE(permission_context.tab_context_updated());
135 155
136 ContentSetting setting = 156 ContentSetting setting =
137 profile()->GetHostContentSettingsMap()->GetContentSetting( 157 profile()->GetHostContentSettingsMap()->GetContentSetting(
138 url.GetOrigin(), url.GetOrigin(), 158 url.GetOrigin(), url.GetOrigin(),
139 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string()); 159 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string());
140 EXPECT_EQ(CONTENT_SETTING_ASK , setting); 160 EXPECT_EQ(CONTENT_SETTING_ASK , setting);
141 }; 161 };
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_permission_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698