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

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

Issue 1337903002: permissions: remove PermissionQueueController and introduce PermissionInfoBarManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@callbacks-delegates
Patch Set: Just a rebase Created 5 years, 2 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
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/permissions/permission_context_base.h" 5 #include "chrome/browser/permissions/permission_context_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
10 #include "chrome/browser/infobars/infobar_service.h" 10 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/browser/permissions/permission_queue_controller.h" 11 #include "chrome/browser/permissions/permission_infobar_manager.h"
12 #include "chrome/browser/permissions/permission_request_id.h" 12 #include "chrome/browser/permissions/permission_request_id.h"
13 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 13 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
14 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
16 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
17 #include "components/content_settings/core/browser/host_content_settings_map.h" 17 #include "components/content_settings/core/browser/host_content_settings_map.h"
18 #include "components/content_settings/core/common/content_settings.h" 18 #include "components/content_settings/core/common/content_settings.h"
19 #include "components/content_settings/core/common/content_settings_types.h" 19 #include "components/content_settings/core/common/content_settings_types.h"
20 #include "content/public/browser/render_frame_host.h" 20 #include "content/public/browser/render_frame_host.h"
21 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
22 #include "content/public/test/mock_render_process_host.h" 22 #include "content/public/test/mock_render_process_host.h"
23 #include "content/public/test/web_contents_tester.h" 23 #include "content/public/test/web_contents_tester.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 25
26 class TestPermissionContext : public PermissionContextBase { 26 class TestPermissionContext : public PermissionContextBase {
27 public: 27 public:
28 TestPermissionContext(Profile* profile, 28 TestPermissionContext(Profile* profile,
29 const ContentSettingsType permission_type) 29 const ContentSettingsType permission_type)
30 : PermissionContextBase(profile, permission_type), 30 : PermissionContextBase(profile, permission_type),
31 permission_set_(false), 31 permission_set_(false),
32 permission_granted_(false), 32 permission_granted_(false),
33 tab_context_updated_(false) {} 33 tab_context_updated_(false) {}
34 34
35 ~TestPermissionContext() override {} 35 ~TestPermissionContext() override {}
36 36
37 PermissionQueueController* GetInfoBarController() {
38 return GetQueueController();
39 }
40
41 bool permission_granted() { 37 bool permission_granted() {
42 return permission_granted_; 38 return permission_granted_;
43 } 39 }
44 40
45 bool permission_set() { 41 bool permission_set() {
46 return permission_set_; 42 return permission_set_;
47 } 43 }
48 44
49 bool tab_context_updated() { 45 bool tab_context_updated() {
50 return tab_context_updated_; 46 return tab_context_updated_;
(...skipping 19 matching lines...) Expand all
70 bool permission_set_; 66 bool permission_set_;
71 bool permission_granted_; 67 bool permission_granted_;
72 bool tab_context_updated_; 68 bool tab_context_updated_;
73 }; 69 };
74 70
75 class PermissionContextBaseTests : public ChromeRenderViewHostTestHarness { 71 class PermissionContextBaseTests : public ChromeRenderViewHostTestHarness {
76 protected: 72 protected:
77 PermissionContextBaseTests() {} 73 PermissionContextBaseTests() {}
78 74
79 // Accept or dismiss the permission bubble or infobar. 75 // Accept or dismiss the permission bubble or infobar.
80 void RespondToPermission(TestPermissionContext* context, 76 void RespondToPermission(const PermissionRequestID& request,
81 const PermissionRequestID& id,
82 const GURL& url,
83 bool accept) { 77 bool accept) {
84 if (!PermissionBubbleManager::Enabled()) { 78 if (!PermissionBubbleManager::Enabled()) {
85 context->GetInfoBarController()->OnPermissionSet( 79 PermissionInfoBarManager* manager =
86 id, url, url, accept, accept); 80 PermissionInfoBarManager::FromWebContents(web_contents());
81 manager->CancelInfoBarRequest(request);
mlamouri (slow - plz ping) 2015/09/28 13:30:14 That sounds odd. You don't actually use |accept|.
Lalit Maganti 2015/09/28 15:32:38 I have no clue. Will look into it.
87 return; 82 return;
88 } 83 }
89 84
90 PermissionBubbleManager* manager = 85 PermissionBubbleManager* manager =
91 PermissionBubbleManager::FromWebContents(web_contents()); 86 PermissionBubbleManager::FromWebContents(web_contents());
92 if (accept) 87 if (accept)
93 manager->Accept(); 88 manager->Accept();
94 else 89 else
95 manager->Closing(); 90 manager->Closing();
96 } 91 }
97 92
98 void TestAskAndGrant_TestContent() { 93 void TestAskAndGrant_TestContent() {
99 TestPermissionContext permission_context( 94 TestPermissionContext permission_context(
100 profile(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 95 profile(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
101 GURL url("http://www.google.com"); 96 GURL url("http://www.google.com");
102 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); 97 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url);
103 98
104 const PermissionRequestID id( 99 const PermissionRequestID id(
105 web_contents()->GetRenderProcessHost()->GetID(), 100 web_contents()->GetRenderProcessHost()->GetID(),
106 web_contents()->GetMainFrame()->GetRoutingID(), 101 web_contents()->GetMainFrame()->GetRoutingID(),
107 -1); 102 -1);
108 permission_context.RequestPermission( 103 permission_context.RequestPermission(
109 web_contents(), 104 web_contents(),
110 id, url, true, 105 id, url, true,
111 base::Bind(&TestPermissionContext::TrackPermissionDecision, 106 base::Bind(&TestPermissionContext::TrackPermissionDecision,
112 base::Unretained(&permission_context))); 107 base::Unretained(&permission_context)));
113 108
114 RespondToPermission(&permission_context, id, url, true); 109 RespondToPermission(id, true);
115 EXPECT_TRUE(permission_context.permission_set()); 110 EXPECT_TRUE(permission_context.permission_set());
116 EXPECT_TRUE(permission_context.permission_granted()); 111 EXPECT_TRUE(permission_context.permission_granted());
117 EXPECT_TRUE(permission_context.tab_context_updated()); 112 EXPECT_TRUE(permission_context.tab_context_updated());
118 113
119 ContentSetting setting = 114 ContentSetting setting =
120 HostContentSettingsMapFactory::GetForProfile(profile()) 115 HostContentSettingsMapFactory::GetForProfile(profile())
121 ->GetContentSetting(url.GetOrigin(), 116 ->GetContentSetting(url.GetOrigin(),
122 url.GetOrigin(), 117 url.GetOrigin(),
123 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 118 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
124 std::string()); 119 std::string());
125 EXPECT_EQ(CONTENT_SETTING_ALLOW, setting); 120 EXPECT_EQ(CONTENT_SETTING_ALLOW, setting);
126 } 121 }
127 122
128 void TestAskAndDismiss_TestContent() { 123 void TestAskAndDismiss_TestContent() {
129 TestPermissionContext permission_context( 124 TestPermissionContext permission_context(
130 profile(), CONTENT_SETTINGS_TYPE_MIDI_SYSEX); 125 profile(), CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
131 GURL url("http://www.google.es"); 126 GURL url("http://www.google.es");
132 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); 127 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url);
133 128
134 const PermissionRequestID id( 129 const PermissionRequestID id(
135 web_contents()->GetRenderProcessHost()->GetID(), 130 web_contents()->GetRenderProcessHost()->GetID(),
136 web_contents()->GetMainFrame()->GetRoutingID(), 131 web_contents()->GetMainFrame()->GetRoutingID(),
137 -1); 132 -1);
138 permission_context.RequestPermission( 133 permission_context.RequestPermission(
139 web_contents(), 134 web_contents(),
140 id, url, true, 135 id, url, true,
141 base::Bind(&TestPermissionContext::TrackPermissionDecision, 136 base::Bind(&TestPermissionContext::TrackPermissionDecision,
142 base::Unretained(&permission_context))); 137 base::Unretained(&permission_context)));
143 138
144 RespondToPermission(&permission_context, id, url, false); 139 RespondToPermission(id, false);
145 EXPECT_TRUE(permission_context.permission_set()); 140 EXPECT_TRUE(permission_context.permission_set());
146 EXPECT_FALSE(permission_context.permission_granted()); 141 EXPECT_FALSE(permission_context.permission_granted());
147 EXPECT_TRUE(permission_context.tab_context_updated()); 142 EXPECT_TRUE(permission_context.tab_context_updated());
148 143
149 ContentSetting setting = 144 ContentSetting setting =
150 HostContentSettingsMapFactory::GetForProfile(profile()) 145 HostContentSettingsMapFactory::GetForProfile(profile())
151 ->GetContentSetting(url.GetOrigin(), 146 ->GetContentSetting(url.GetOrigin(),
152 url.GetOrigin(), 147 url.GetOrigin(),
153 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, 148 CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
154 std::string()); 149 std::string());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 const PermissionRequestID id( 188 const PermissionRequestID id(
194 web_contents()->GetRenderProcessHost()->GetID(), 189 web_contents()->GetRenderProcessHost()->GetID(),
195 web_contents()->GetMainFrame()->GetRoutingID(), 190 web_contents()->GetMainFrame()->GetRoutingID(),
196 -1); 191 -1);
197 permission_context.RequestPermission( 192 permission_context.RequestPermission(
198 web_contents(), 193 web_contents(),
199 id, url, true, 194 id, url, true,
200 base::Bind(&TestPermissionContext::TrackPermissionDecision, 195 base::Bind(&TestPermissionContext::TrackPermissionDecision,
201 base::Unretained(&permission_context))); 196 base::Unretained(&permission_context)));
202 197
203 RespondToPermission(&permission_context, id, url, true); 198 RespondToPermission(id, true);
204 EXPECT_TRUE(permission_context.permission_set()); 199 EXPECT_TRUE(permission_context.permission_set());
205 EXPECT_TRUE(permission_context.permission_granted()); 200 EXPECT_TRUE(permission_context.permission_granted());
206 EXPECT_TRUE(permission_context.tab_context_updated()); 201 EXPECT_TRUE(permission_context.tab_context_updated());
207 202
208 ContentSetting setting = 203 ContentSetting setting =
209 HostContentSettingsMapFactory::GetForProfile(profile()) 204 HostContentSettingsMapFactory::GetForProfile(profile())
210 ->GetContentSetting(url.GetOrigin(), 205 ->GetContentSetting(url.GetOrigin(),
211 url.GetOrigin(), 206 url.GetOrigin(),
212 type, 207 type,
213 std::string()); 208 std::string());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 #if defined(ENABLE_NOTIFICATIONS) 285 #if defined(ENABLE_NOTIFICATIONS)
291 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 286 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
292 CONTENT_SETTING_ASK); 287 CONTENT_SETTING_ASK);
293 #endif 288 #endif
294 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, 289 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
295 CONTENT_SETTING_ASK); 290 CONTENT_SETTING_ASK);
296 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 291 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
297 CONTENT_SETTING_ASK); 292 CONTENT_SETTING_ASK);
298 } 293 }
299 #endif 294 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698