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

Side by Side Diff: chrome/browser/geolocation/geolocation_permission_context_unittest.cc

Issue 787033004: Update geolocation permission tests for the permission bubble (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes for timvolodine Created 6 years 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 (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 "chrome/browser/geolocation/geolocation_permission_context.h" 5 #include "chrome/browser/geolocation/geolocation_permission_context.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h"
12 #include "base/containers/hash_tables.h" 13 #include "base/containers/hash_tables.h"
13 #include "base/id_map.h" 14 #include "base/id_map.h"
14 #include "base/memory/scoped_vector.h" 15 #include "base/memory/scoped_vector.h"
15 #include "base/synchronization/waitable_event.h" 16 #include "base/synchronization/waitable_event.h"
16 #include "base/test/simple_test_clock.h" 17 #include "base/test/simple_test_clock.h"
17 #include "base/time/clock.h" 18 #include "base/time/clock.h"
18 #include "chrome/browser/chrome_notification_types.h" 19 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 20 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
20 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" 21 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h"
21 #include "chrome/browser/infobars/infobar_service.h" 22 #include "chrome/browser/infobars/infobar_service.h"
23 #include "chrome/browser/ui/website_settings/mock_permission_bubble_view.h"
24 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
25 #include "chrome/browser/ui/website_settings/permission_bubble_request.h"
26 #include "chrome/common/chrome_switches.h"
22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 27 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
23 #include "chrome/test/base/testing_profile.h" 28 #include "chrome/test/base/testing_profile.h"
24 #include "components/content_settings/core/browser/host_content_settings_map.h" 29 #include "components/content_settings/core/browser/host_content_settings_map.h"
25 #include "components/content_settings/core/common/permission_request_id.h" 30 #include "components/content_settings/core/common/permission_request_id.h"
26 #include "components/infobars/core/confirm_infobar_delegate.h" 31 #include "components/infobars/core/confirm_infobar_delegate.h"
27 #include "components/infobars/core/infobar.h" 32 #include "components/infobars/core/infobar.h"
28 #include "content/public/browser/browser_thread.h" 33 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/navigation_details.h" 34 #include "content/public/browser/navigation_details.h"
30 #include "content/public/browser/notification_observer.h" 35 #include "content/public/browser/notification_observer.h"
31 #include "content/public/browser/notification_registrar.h" 36 #include "content/public/browser/notification_registrar.h"
32 #include "content/public/browser/notification_service.h" 37 #include "content/public/browser/notification_service.h"
33 #include "content/public/browser/web_contents.h" 38 #include "content/public/browser/web_contents.h"
34 #include "content/public/test/mock_render_process_host.h" 39 #include "content/public/test/mock_render_process_host.h"
35 #include "content/public/test/test_renderer_host.h" 40 #include "content/public/test/test_renderer_host.h"
36 #include "content/public/test/test_utils.h" 41 #include "content/public/test/test_utils.h"
37 #include "content/public/test/web_contents_tester.h" 42 #include "content/public/test/web_contents_tester.h"
38 #include "testing/gtest/include/gtest/gtest.h" 43 #include "testing/gtest/include/gtest/gtest.h"
39 44
40 #if defined(OS_ANDROID) 45 #if defined(OS_ANDROID)
41 #include "base/prefs/pref_service.h" 46 #include "base/prefs/pref_service.h"
42 #include "chrome/browser/android/mock_google_location_settings_helper.h" 47 #include "chrome/browser/android/mock_google_location_settings_helper.h"
43 #endif 48 #endif
44 49
45 #if defined(ENABLE_EXTENSIONS) 50 #if defined(ENABLE_EXTENSIONS)
46 #include "extensions/browser/view_type_utils.h" 51 #include "extensions/browser/view_type_utils.h"
47 #endif 52 #endif
48 53
49 using content::MockRenderProcessHost; 54 using content::MockRenderProcessHost;
50 55
51
52 // ClosedInfoBarTracker ------------------------------------------------------- 56 // ClosedInfoBarTracker -------------------------------------------------------
53 57
54 // We need to track which infobars were closed. 58 // We need to track which infobars were closed.
55 class ClosedInfoBarTracker : public content::NotificationObserver { 59 class ClosedInfoBarTracker : public content::NotificationObserver {
56 public: 60 public:
57 ClosedInfoBarTracker(); 61 ClosedInfoBarTracker();
58 ~ClosedInfoBarTracker() override; 62 ~ClosedInfoBarTracker() override;
59 63
60 // content::NotificationObserver: 64 // content::NotificationObserver:
61 void Observe(int type, 65 void Observe(int type,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 PermissionRequestID RequestIDForTab(int tab, int bridge_id); 116 PermissionRequestID RequestIDForTab(int tab, int bridge_id);
113 InfoBarService* infobar_service() { 117 InfoBarService* infobar_service() {
114 return InfoBarService::FromWebContents(web_contents()); 118 return InfoBarService::FromWebContents(web_contents());
115 } 119 }
116 InfoBarService* infobar_service_for_tab(int tab) { 120 InfoBarService* infobar_service_for_tab(int tab) {
117 return InfoBarService::FromWebContents(extra_tabs_[tab]); 121 return InfoBarService::FromWebContents(extra_tabs_[tab]);
118 } 122 }
119 123
120 void RequestGeolocationPermission(content::WebContents* web_contents, 124 void RequestGeolocationPermission(content::WebContents* web_contents,
121 const PermissionRequestID& id, 125 const PermissionRequestID& id,
122 const GURL& requesting_frame); 126 const GURL& requesting_frame,
123 127 bool user_gesture);
124 void PermissionResponse(const PermissionRequestID& id, 128 void PermissionResponse(const PermissionRequestID& id,
125 bool allowed); 129 bool allowed);
126 void CheckPermissionMessageSent(int bridge_id, bool allowed); 130 void CheckPermissionMessageSent(int bridge_id, bool allowed);
127 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); 131 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed);
128 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, 132 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process,
129 int bridge_id, 133 int bridge_id,
130 bool allowed); 134 bool allowed);
131 void AddNewTab(const GURL& url); 135 void AddNewTab(const GURL& url);
132 void CheckTabContentsState(const GURL& requesting_frame, 136 void CheckTabContentsState(const GURL& requesting_frame,
133 ContentSetting expected_content_setting); 137 ContentSetting expected_content_setting);
138 base::string16 GetFirstRequestText(PermissionBubbleManager* manager);
139 size_t GetBubblesQueueSize(PermissionBubbleManager* manager);
140 void AcceptBubble(PermissionBubbleManager* manager);
141 void DenyBubble(PermissionBubbleManager* manager);
142 void CloseBubble(PermissionBubbleManager* manager);
143 void BubbleManagerDocumentLoadCompleted();
144 void BubbleManagerDocumentLoadCompleted(content::WebContents* web_contents);
145 ContentSetting GetGeolocationContentSetting(GURL frame_0, GURL frame_1);
134 146
135 // owned by the browser context 147 // owned by the browser context
136 GeolocationPermissionContext* geolocation_permission_context_; 148 GeolocationPermissionContext* geolocation_permission_context_;
137 ClosedInfoBarTracker closed_infobar_tracker_; 149 ClosedInfoBarTracker closed_infobar_tracker_;
150 MockPermissionBubbleView bubble_view_;
138 ScopedVector<content::WebContents> extra_tabs_; 151 ScopedVector<content::WebContents> extra_tabs_;
139 152
140 // A map between renderer child id and a pair represending the bridge id and 153 // A map between renderer child id and a pair represending the bridge id and
141 // whether the requested permission was allowed. 154 // whether the requested permission was allowed.
142 base::hash_map<int, std::pair<int, bool> > responses_; 155 base::hash_map<int, std::pair<int, bool> > responses_;
143 }; 156 };
144 157
145 PermissionRequestID GeolocationPermissionContextTests::RequestID( 158 PermissionRequestID GeolocationPermissionContextTests::RequestID(
146 int bridge_id) { 159 int bridge_id) {
147 return PermissionRequestID( 160 return PermissionRequestID(
148 web_contents()->GetRenderProcessHost()->GetID(), 161 web_contents()->GetRenderProcessHost()->GetID(),
149 web_contents()->GetRenderViewHost()->GetRoutingID(), 162 web_contents()->GetRenderViewHost()->GetRoutingID(),
150 bridge_id, 163 bridge_id,
151 GURL()); 164 GURL());
152 } 165 }
153 166
154 PermissionRequestID GeolocationPermissionContextTests::RequestIDForTab( 167 PermissionRequestID GeolocationPermissionContextTests::RequestIDForTab(
155 int tab, 168 int tab,
156 int bridge_id) { 169 int bridge_id) {
157 return PermissionRequestID( 170 return PermissionRequestID(
158 extra_tabs_[tab]->GetRenderProcessHost()->GetID(), 171 extra_tabs_[tab]->GetRenderProcessHost()->GetID(),
159 extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(), 172 extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(),
160 bridge_id, 173 bridge_id,
161 GURL()); 174 GURL());
162 } 175 }
163 176
164 void GeolocationPermissionContextTests::RequestGeolocationPermission( 177 void GeolocationPermissionContextTests::RequestGeolocationPermission(
165 content::WebContents* web_contents, 178 content::WebContents* web_contents,
166 const PermissionRequestID& id, 179 const PermissionRequestID& id,
167 const GURL& requesting_frame) { 180 const GURL& requesting_frame,
181 bool user_gesture) {
168 geolocation_permission_context_->RequestPermission( 182 geolocation_permission_context_->RequestPermission(
169 web_contents, id, requesting_frame, false, 183 web_contents, id, requesting_frame, user_gesture,
170 base::Bind(&GeolocationPermissionContextTests::PermissionResponse, 184 base::Bind(&GeolocationPermissionContextTests::PermissionResponse,
171 base::Unretained(this), id)); 185 base::Unretained(this), id));
172 content::RunAllBlockingPoolTasksUntilIdle(); 186 content::RunAllBlockingPoolTasksUntilIdle();
173 } 187 }
174 188
175 void GeolocationPermissionContextTests::PermissionResponse( 189 void GeolocationPermissionContextTests::PermissionResponse(
176 const PermissionRequestID& id, 190 const PermissionRequestID& id,
177 bool allowed) { 191 bool allowed) {
178 responses_[id.render_process_id()] = std::make_pair(id.bridge_id(), allowed); 192 responses_[id.render_process_id()] = std::make_pair(id.bridge_id(), allowed);
179 } 193 }
180 194
181 void GeolocationPermissionContextTests::CheckPermissionMessageSent( 195 void GeolocationPermissionContextTests::CheckPermissionMessageSent(
182 int bridge_id, 196 int bridge_id,
(...skipping 26 matching lines...) Expand all
209 new_tab->GetController().LoadURL( 223 new_tab->GetController().LoadURL(
210 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 224 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
211 content::RenderFrameHostTester::For(new_tab->GetMainFrame()) 225 content::RenderFrameHostTester::For(new_tab->GetMainFrame())
212 ->SendNavigate(extra_tabs_.size() + 1, url); 226 ->SendNavigate(extra_tabs_.size() + 1, url);
213 227
214 // Set up required helpers, and make this be as "tabby" as the code requires. 228 // Set up required helpers, and make this be as "tabby" as the code requires.
215 #if defined(ENABLE_EXTENSIONS) 229 #if defined(ENABLE_EXTENSIONS)
216 extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS); 230 extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS);
217 #endif 231 #endif
218 InfoBarService::CreateForWebContents(new_tab); 232 InfoBarService::CreateForWebContents(new_tab);
233 PermissionBubbleManager::CreateForWebContents(new_tab);
234 PermissionBubbleManager::FromWebContents(new_tab)->SetView(
235 &bubble_view_);
219 236
220 extra_tabs_.push_back(new_tab); 237 extra_tabs_.push_back(new_tab);
221 } 238 }
222 239
223 void GeolocationPermissionContextTests::CheckTabContentsState( 240 void GeolocationPermissionContextTests::CheckTabContentsState(
224 const GURL& requesting_frame, 241 const GURL& requesting_frame,
225 ContentSetting expected_content_setting) { 242 ContentSetting expected_content_setting) {
226 TabSpecificContentSettings* content_settings = 243 TabSpecificContentSettings* content_settings =
227 TabSpecificContentSettings::FromWebContents(web_contents()); 244 TabSpecificContentSettings::FromWebContents(web_contents());
228 const ContentSettingsUsagesState::StateMap& state_map = 245 const ContentSettingsUsagesState::StateMap& state_map =
(...skipping 14 matching lines...) Expand all
243 #if defined(ENABLE_EXTENSIONS) 260 #if defined(ENABLE_EXTENSIONS)
244 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS); 261 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS);
245 #endif 262 #endif
246 InfoBarService::CreateForWebContents(web_contents()); 263 InfoBarService::CreateForWebContents(web_contents());
247 TabSpecificContentSettings::CreateForWebContents(web_contents()); 264 TabSpecificContentSettings::CreateForWebContents(web_contents());
248 #if defined(OS_ANDROID) 265 #if defined(OS_ANDROID)
249 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); 266 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true);
250 #endif 267 #endif
251 geolocation_permission_context_ = 268 geolocation_permission_context_ =
252 GeolocationPermissionContextFactory::GetForProfile(profile()); 269 GeolocationPermissionContextFactory::GetForProfile(profile());
270 PermissionBubbleManager::CreateForWebContents(web_contents());
271 PermissionBubbleManager::FromWebContents(web_contents())->SetView(
272 &bubble_view_);
253 } 273 }
254 274
255 void GeolocationPermissionContextTests::TearDown() { 275 void GeolocationPermissionContextTests::TearDown() {
256 extra_tabs_.clear(); 276 extra_tabs_.clear();
257 ChromeRenderViewHostTestHarness::TearDown(); 277 ChromeRenderViewHostTestHarness::TearDown();
258 } 278 }
259 279
280 base::string16 GeolocationPermissionContextTests::GetFirstRequestText(
281 PermissionBubbleManager* manager) {
282 return manager->requests_.front()->GetMessageText();
283 }
284
285 size_t GeolocationPermissionContextTests::GetBubblesQueueSize(
286 PermissionBubbleManager* manager) {
287 return manager->requests_.size();
288 }
289
290 void GeolocationPermissionContextTests::AcceptBubble(
291 PermissionBubbleManager* manager) {
292 manager->Accept();
293 }
294
295 void GeolocationPermissionContextTests::DenyBubble(
296 PermissionBubbleManager* manager) {
297 manager->Deny();
298 }
299
300 void GeolocationPermissionContextTests::CloseBubble(
301 PermissionBubbleManager* manager) {
302 manager->Closing();
303 }
304
305 void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted() {
306 GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted(
307 web_contents());
308 }
309
310 void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted(
311 content::WebContents* web_contents) {
312 PermissionBubbleManager::FromWebContents(web_contents)->
313 DocumentOnLoadCompletedInMainFrame();
314 }
315
316 ContentSetting GeolocationPermissionContextTests::GetGeolocationContentSetting(
317 GURL frame_0, GURL frame_1) {
318 return profile()->GetHostContentSettingsMap()->GetContentSetting(
319 frame_0, frame_1, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string());
320 }
321
322 // Needed to parameterize the tests for both infobars & permission bubbles.
323 class GeolocationPermissionContextParamTests :
324 public GeolocationPermissionContextTests,
325 public ::testing::WithParamInterface<bool> {
326 protected:
327 GeolocationPermissionContextParamTests() {}
328 ~GeolocationPermissionContextParamTests() override {}
329
330 bool BubbleEnabled() const {
331 return GetParam();
332 }
333
334 void SetUp() override {
335 GeolocationPermissionContextTests::SetUp();
336 #if !defined(OS_ANDROID)
337 if (BubbleEnabled()) {
338 base::CommandLine::ForCurrentProcess()->AppendSwitch(
339 switches::kEnablePermissionsBubbles);
340 EXPECT_TRUE(PermissionBubbleManager::Enabled());
341 } else {
342 base::CommandLine::ForCurrentProcess()->AppendSwitch(
343 switches::kDisablePermissionsBubbles);
344 EXPECT_FALSE(PermissionBubbleManager::Enabled());
345 }
346 #endif
347 }
348
349 size_t GetNumberOfPrompts() {
350 if (BubbleEnabled()) {
351 PermissionBubbleManager* manager =
352 PermissionBubbleManager::FromWebContents(web_contents());
353 return GetBubblesQueueSize(manager);
354 } else {
355 return infobar_service()->infobar_count();
356 }
357 }
358
359 void AcceptPrompt() {
360 if (BubbleEnabled()) {
361 PermissionBubbleManager* manager =
362 PermissionBubbleManager::FromWebContents(web_contents());
363 AcceptBubble(manager);
364 } else {
365 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
366 ConfirmInfoBarDelegate* infobar_delegate =
367 infobar->delegate()->AsConfirmInfoBarDelegate();
368 infobar_delegate->Accept();
369 }
370 }
371
372 base::string16 GetPromptText() {
373 if (BubbleEnabled()) {
374 PermissionBubbleManager* manager =
375 PermissionBubbleManager::FromWebContents(web_contents());
376 return GetFirstRequestText(manager);
377 }
378 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
379 ConfirmInfoBarDelegate* infobar_delegate =
380 infobar->delegate()->AsConfirmInfoBarDelegate();
381 return infobar_delegate->GetMessageText();
382 }
383 private:
384 DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContextParamTests);
385 };
386
260 // Tests ---------------------------------------------------------------------- 387 // Tests ----------------------------------------------------------------------
261 388
262 TEST_F(GeolocationPermissionContextTests, SinglePermission) { 389 TEST_P(GeolocationPermissionContextParamTests, SinglePermissionInfobar) {
390 if (BubbleEnabled()) return;
391
263 GURL requesting_frame("http://www.example.com/geolocation"); 392 GURL requesting_frame("http://www.example.com/geolocation");
264 NavigateAndCommit(requesting_frame); 393 NavigateAndCommit(requesting_frame);
265 EXPECT_EQ(0U, infobar_service()->infobar_count()); 394 EXPECT_EQ(0U, infobar_service()->infobar_count());
266 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 395 RequestGeolocationPermission(
396 web_contents(), RequestID(0), requesting_frame, true);
267 ASSERT_EQ(1U, infobar_service()->infobar_count()); 397 ASSERT_EQ(1U, infobar_service()->infobar_count());
268 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 398 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
269 ConfirmInfoBarDelegate* infobar_delegate = 399 ConfirmInfoBarDelegate* infobar_delegate =
270 infobar->delegate()->AsConfirmInfoBarDelegate(); 400 infobar->delegate()->AsConfirmInfoBarDelegate();
271 ASSERT_TRUE(infobar_delegate); 401 ASSERT_TRUE(infobar_delegate);
272 infobar_delegate->Cancel(); 402 infobar_delegate->Cancel();
273 infobar_service()->RemoveInfoBar(infobar); 403 infobar_service()->RemoveInfoBar(infobar);
274 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 404 EXPECT_EQ(1U, closed_infobar_tracker_.size());
275 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); 405 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
276 } 406 }
277 407
278 #if defined(OS_ANDROID) 408 TEST_P(GeolocationPermissionContextParamTests, SinglePermissionBubble) {
279 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { 409 if (!BubbleEnabled()) return;
410
280 GURL requesting_frame("http://www.example.com/geolocation"); 411 GURL requesting_frame("http://www.example.com/geolocation");
281 NavigateAndCommit(requesting_frame); 412 NavigateAndCommit(requesting_frame);
282 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); 413 BubbleManagerDocumentLoadCompleted();
283 EXPECT_EQ(0U, infobar_service()->infobar_count()); 414
284 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 415 EXPECT_EQ(0U, GetNumberOfPrompts());
285 EXPECT_EQ(1U, infobar_service()->infobar_count()); 416 RequestGeolocationPermission(
286 ConfirmInfoBarDelegate* infobar_delegate_0 = 417 web_contents(), RequestID(0), requesting_frame, true);
287 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 418 ASSERT_EQ(1U, GetNumberOfPrompts());
288 ASSERT_TRUE(infobar_delegate_0); 419 }
289 base::string16 text_0 = infobar_delegate_0->GetButtonLabel( 420
290 ConfirmInfoBarDelegate::BUTTON_OK); 421 TEST_P(GeolocationPermissionContextParamTests, QueuedPermission) {
291
292 Reload();
293 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false);
294 EXPECT_EQ(0U, infobar_service()->infobar_count());
295 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
296 EXPECT_EQ(0U, infobar_service()->infobar_count());
297 }
298
299 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) {
300 GURL requesting_frame("http://www.example.com/geolocation");
301 NavigateAndCommit(requesting_frame);
302 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true);
303 EXPECT_EQ(0U, infobar_service()->infobar_count());
304 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
305 EXPECT_EQ(1U, infobar_service()->infobar_count());
306 ConfirmInfoBarDelegate* infobar_delegate =
307 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
308 ASSERT_TRUE(infobar_delegate);
309 infobar_delegate->Accept();
310 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
311 CheckPermissionMessageSent(0, true);
312 }
313
314 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) {
315 GURL requesting_frame("http://www.example.com/geolocation");
316 NavigateAndCommit(requesting_frame);
317 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false);
318 EXPECT_EQ(0U, infobar_service()->infobar_count());
319 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
320 EXPECT_EQ(0U, infobar_service()->infobar_count());
321 }
322 #endif
323
324 TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
325 GURL requesting_frame_0("http://www.example.com/geolocation"); 422 GURL requesting_frame_0("http://www.example.com/geolocation");
326 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 423 GURL requesting_frame_1("http://www.example-2.com/geolocation");
327 EXPECT_EQ(CONTENT_SETTING_ASK, 424 EXPECT_EQ(
328 profile()->GetHostContentSettingsMap()->GetContentSetting( 425 CONTENT_SETTING_ASK,
329 requesting_frame_0, requesting_frame_0, 426 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_1));
330 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 427 EXPECT_EQ(
331 EXPECT_EQ(CONTENT_SETTING_ASK, 428 CONTENT_SETTING_ASK,
332 profile()->GetHostContentSettingsMap()->GetContentSetting( 429 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_1));
333 requesting_frame_1, requesting_frame_0,
334 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
335 430
336 NavigateAndCommit(requesting_frame_0); 431 NavigateAndCommit(requesting_frame_0);
337 EXPECT_EQ(0U, infobar_service()->infobar_count()); 432 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
433
434 // Check that no permission requests have happened yet.
435 EXPECT_EQ(0U, GetNumberOfPrompts());
436
338 // Request permission for two frames. 437 // Request permission for two frames.
339 RequestGeolocationPermission( 438 RequestGeolocationPermission(
340 web_contents(), RequestID(0), requesting_frame_0); 439 web_contents(), RequestID(0), requesting_frame_0, BubbleEnabled());
341 RequestGeolocationPermission( 440 RequestGeolocationPermission(
342 web_contents(), RequestID(1), requesting_frame_1); 441 web_contents(), RequestID(1), requesting_frame_1, BubbleEnabled());
442
343 // Ensure only one infobar is created. 443 // Ensure only one infobar is created.
timvolodine 2014/12/19 19:47:03 nit: infobar -> prompt
felt 2015/01/30 00:59:20 Done.
344 ASSERT_EQ(1U, infobar_service()->infobar_count()); 444 ASSERT_EQ(1U, GetNumberOfPrompts());
345 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); 445 base::string16 text_0 = GetPromptText();
346 ConfirmInfoBarDelegate* infobar_delegate_0 =
347 infobar_0->delegate()->AsConfirmInfoBarDelegate();
348 ASSERT_TRUE(infobar_delegate_0);
349 base::string16 text_0 = infobar_delegate_0->GetMessageText();
350 446
351 // Accept the first frame. 447 // Accept the first frame.
352 infobar_delegate_0->Accept(); 448 AcceptPrompt();
353 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); 449 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
354 CheckPermissionMessageSent(0, true); 450 CheckPermissionMessageSent(0, true);
355 451 if (!BubbleEnabled()) {
356 infobar_service()->RemoveInfoBar(infobar_0); 452 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0);
357 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 453 infobar_service()->RemoveInfoBar(infobar_0);
358 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); 454 EXPECT_EQ(1U, closed_infobar_tracker_.size());
359 closed_infobar_tracker_.Clear(); 455 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0));
360 // Now we should have a new infobar for the second frame. 456 closed_infobar_tracker_.Clear();
361 ASSERT_EQ(1U, infobar_service()->infobar_count()); 457 }
362 458
363 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); 459 // Now we should have a new request for the second frame.
364 ConfirmInfoBarDelegate* infobar_delegate_1 = 460 ASSERT_EQ(1U, GetNumberOfPrompts());
365 infobar_1->delegate()->AsConfirmInfoBarDelegate(); 461 base::string16 text_1 = GetPromptText();
366 ASSERT_TRUE(infobar_delegate_1); 462
367 base::string16 text_1 = infobar_delegate_1->GetMessageText(); 463 // Check that the messages differ.
368 EXPECT_NE(text_0, text_1); 464 EXPECT_NE(text_0, text_1);
369 465
370 // Cancel (block) this frame. 466 // Cancel (block) this frame.
371 infobar_delegate_1->Cancel(); 467 if (BubbleEnabled()) {
468 PermissionBubbleManager* manager =
469 PermissionBubbleManager::FromWebContents(web_contents());
470 DenyBubble(manager);
471 } else {
472 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0);
473 infobar_1->delegate()->AsConfirmInfoBarDelegate()->Cancel();
474 }
372 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); 475 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK);
373 CheckPermissionMessageSent(1, false); 476 CheckPermissionMessageSent(1, false);
374 infobar_service()->RemoveInfoBar(infobar_1); 477
375 EXPECT_EQ(1U, closed_infobar_tracker_.size());
376 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
377 EXPECT_EQ(0U, infobar_service()->infobar_count());
378 // Ensure the persisted permissions are ok. 478 // Ensure the persisted permissions are ok.
379 EXPECT_EQ(CONTENT_SETTING_ALLOW, 479 EXPECT_EQ(
380 profile()->GetHostContentSettingsMap()->GetContentSetting( 480 CONTENT_SETTING_ALLOW,
381 requesting_frame_0, requesting_frame_0, 481 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0));
382 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 482 EXPECT_EQ(
383 483 CONTENT_SETTING_BLOCK,
384 EXPECT_EQ(CONTENT_SETTING_BLOCK, 484 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0));
385 profile()->GetHostContentSettingsMap()->GetContentSetting( 485 }
386 requesting_frame_1, requesting_frame_0, 486
387 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 487 TEST_P(GeolocationPermissionContextParamTests, HashIsIgnored) {
388 }
389
390 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) {
391 GURL url_a("http://www.example.com/geolocation#a"); 488 GURL url_a("http://www.example.com/geolocation#a");
392 GURL url_b("http://www.example.com/geolocation#b"); 489 GURL url_b("http://www.example.com/geolocation#b");
393 490
394 // Navigate to the first url and check permission is requested. 491 // Navigate to the first url.
395 NavigateAndCommit(url_a); 492 NavigateAndCommit(url_a);
396 EXPECT_EQ(0U, infobar_service()->infobar_count()); 493 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
397 RequestGeolocationPermission(web_contents(), RequestID(0), url_a); 494
398 ASSERT_EQ(1U, infobar_service()->infobar_count()); 495 // Check permission is requested.
399 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 496 ASSERT_EQ(0U, GetNumberOfPrompts());
400 ConfirmInfoBarDelegate* infobar_delegate = 497 RequestGeolocationPermission(
401 infobar->delegate()->AsConfirmInfoBarDelegate(); 498 web_contents(), RequestID(0), url_a, BubbleEnabled());
402 ASSERT_TRUE(infobar_delegate); 499 ASSERT_EQ(1U, GetNumberOfPrompts());
403 500
404 // Change the hash, we'll still be on the same page. 501 // Change the hash, we'll still be on the same page.
405 NavigateAndCommit(url_b); 502 NavigateAndCommit(url_b);
503 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
406 504
407 // Accept. 505 // Accept.
408 infobar_delegate->Accept(); 506 AcceptPrompt();
409 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); 507 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW);
410 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); 508 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW);
411 CheckPermissionMessageSent(0, true); 509 CheckPermissionMessageSent(0, true);
412 510
413 // Cleanup. 511 // Cleanup.
414 infobar_service()->RemoveInfoBar(infobar); 512 if (!BubbleEnabled()) {
415 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 513 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
416 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); 514 infobar_service()->RemoveInfoBar(infobar);
417 } 515 EXPECT_EQ(1U, closed_infobar_tracker_.size());
418 516 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
419 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { 517 }
518 }
519
520 TEST_P(GeolocationPermissionContextParamTests, PermissionForFileScheme) {
521 // TODO(felt): The bubble is rejecting file:// permission requests.
522 // Fix and enable this test. crbug.com/444047
523 if (BubbleEnabled()) return;
524
420 GURL requesting_frame("file://example/geolocation.html"); 525 GURL requesting_frame("file://example/geolocation.html");
421 NavigateAndCommit(requesting_frame); 526 NavigateAndCommit(requesting_frame);
422 EXPECT_EQ(0U, infobar_service()->infobar_count()); 527 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
423 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 528
424 EXPECT_EQ(1U, infobar_service()->infobar_count()); 529 // Check permission is requested.
425 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 530 ASSERT_EQ(0U, GetNumberOfPrompts());
426 ConfirmInfoBarDelegate* infobar_delegate = 531 RequestGeolocationPermission(
427 infobar->delegate()->AsConfirmInfoBarDelegate(); 532 web_contents(), RequestID(0), requesting_frame, BubbleEnabled());
428 ASSERT_TRUE(infobar_delegate); 533 ASSERT_EQ(1U, GetNumberOfPrompts());
534
429 // Accept the frame. 535 // Accept the frame.
430 infobar_delegate->Accept(); 536 AcceptPrompt();
431 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); 537 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
432 CheckPermissionMessageSent(0, true); 538 CheckPermissionMessageSent(0, true);
433 infobar_service()->RemoveInfoBar(infobar);
434 539
435 // Make sure the setting is not stored. 540 // Make sure the setting is not stored.
436 EXPECT_EQ(CONTENT_SETTING_ASK, 541 EXPECT_EQ(
437 profile()->GetHostContentSettingsMap()->GetContentSetting( 542 CONTENT_SETTING_ASK,
438 requesting_frame, 543 GetGeolocationContentSetting(requesting_frame, requesting_frame));
439 requesting_frame, 544 }
440 CONTENT_SETTINGS_TYPE_GEOLOCATION, 545
441 std::string())); 546 TEST_P(GeolocationPermissionContextParamTests,
442 } 547 CancelGeolocationPermissionRequest) {
443 548 GURL frame_0("http://www.example.com/geolocation");
444 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { 549 GURL frame_1("http://www.example-2.com/geolocation");
445 GURL requesting_frame_0("http://www.example.com/geolocation"); 550 EXPECT_EQ(
446 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 551 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_0, frame_0));
447 EXPECT_EQ(CONTENT_SETTING_ASK, 552 EXPECT_EQ(
448 profile()->GetHostContentSettingsMap()->GetContentSetting( 553 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_1, frame_0));
449 requesting_frame_0, requesting_frame_0, 554
450 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 555 NavigateAndCommit(frame_0);
451 556 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
452 EXPECT_EQ(CONTENT_SETTING_ASK, 557
453 profile()->GetHostContentSettingsMap()->GetContentSetting( 558 ASSERT_EQ(0U, GetNumberOfPrompts());
454 requesting_frame_1, requesting_frame_0,
455 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
456
457 NavigateAndCommit(requesting_frame_0);
458 EXPECT_EQ(0U, infobar_service()->infobar_count());
459 559
460 // Request permission for two frames. 560 // Request permission for two frames.
461 RequestGeolocationPermission( 561 RequestGeolocationPermission(
462 web_contents(), RequestID(0), requesting_frame_0); 562 web_contents(), RequestID(0), frame_0, BubbleEnabled());
463 RequestGeolocationPermission( 563 RequestGeolocationPermission(
464 web_contents(), RequestID(1), requesting_frame_1); 564 web_contents(), RequestID(1), frame_1, BubbleEnabled());
465 ASSERT_EQ(1U, infobar_service()->infobar_count()); 565 ASSERT_EQ(1U, GetNumberOfPrompts());
466 566
467 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); 567 // Get the first permission request text.
468 ConfirmInfoBarDelegate* infobar_delegate_0 = 568 ASSERT_EQ(1U, GetNumberOfPrompts());
469 infobar_0->delegate()->AsConfirmInfoBarDelegate(); 569 base::string16 text_0 = GetPromptText();
470 ASSERT_TRUE(infobar_delegate_0); 570 ASSERT_FALSE(text_0.empty());
471 base::string16 text_0 = infobar_delegate_0->GetMessageText(); 571
472 572 // Simulate frame 0 going away; the request should be removed.
473 // Simulate the frame going away, ensure the infobar for this frame 573 if (BubbleEnabled()) {
474 // is removed and the next pending infobar is created. 574 PermissionBubbleManager* manager =
475 geolocation_permission_context_->CancelPermissionRequest(web_contents(), 575 PermissionBubbleManager::FromWebContents(web_contents());
476 RequestID(0)); 576 CloseBubble(manager);
477 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 577 } else {
478 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); 578 geolocation_permission_context_->CancelPermissionRequest(web_contents(),
479 closed_infobar_tracker_.Clear(); 579 RequestID(0));
480 ASSERT_EQ(1U, infobar_service()->infobar_count()); 580 ASSERT_EQ(1U, infobar_service()->infobar_count());
481 581 }
482 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); 582
483 ConfirmInfoBarDelegate* infobar_delegate_1 = 583 // Check that the next pending request is created correctly.
484 infobar_1->delegate()->AsConfirmInfoBarDelegate(); 584 base::string16 text_1 = GetPromptText();;
485 ASSERT_TRUE(infobar_delegate_1);
486 base::string16 text_1 = infobar_delegate_1->GetMessageText();
487 EXPECT_NE(text_0, text_1); 585 EXPECT_NE(text_0, text_1);
488 586
489 // Allow this frame. 587 // Allow this frame and check that it worked.
490 infobar_delegate_1->Accept(); 588 AcceptPrompt();
491 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); 589 CheckTabContentsState(frame_1, CONTENT_SETTING_ALLOW);
492 CheckPermissionMessageSent(1, true); 590 CheckPermissionMessageSent(1, true);
493 infobar_service()->RemoveInfoBar(infobar_1); 591
494 EXPECT_EQ(1U, closed_infobar_tracker_.size());
495 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
496 EXPECT_EQ(0U, infobar_service()->infobar_count());
497 // Ensure the persisted permissions are ok. 592 // Ensure the persisted permissions are ok.
498 EXPECT_EQ(CONTENT_SETTING_ASK, 593 EXPECT_EQ(
499 profile()->GetHostContentSettingsMap()->GetContentSetting( 594 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_0, frame_0));
500 requesting_frame_0, requesting_frame_0, 595 EXPECT_EQ(
501 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 596 CONTENT_SETTING_ALLOW, GetGeolocationContentSetting(frame_1, frame_0));
502 597 }
503 EXPECT_EQ(CONTENT_SETTING_ALLOW, 598
504 profile()->GetHostContentSettingsMap()->GetContentSetting( 599 TEST_P(GeolocationPermissionContextParamTests, InvalidURL) {
505 requesting_frame_1, requesting_frame_0, 600 // Navigate to the first url.
506 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
507 }
508
509 TEST_F(GeolocationPermissionContextTests, InvalidURL) {
510 GURL invalid_embedder("about:blank"); 601 GURL invalid_embedder("about:blank");
511 GURL requesting_frame; 602 GURL requesting_frame;
512 NavigateAndCommit(invalid_embedder); 603 NavigateAndCommit(invalid_embedder);
513 EXPECT_EQ(0U, infobar_service()->infobar_count()); 604 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
514 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 605
515 EXPECT_EQ(0U, infobar_service()->infobar_count()); 606 // Nothing should be displayed.
607 EXPECT_EQ(0U, GetNumberOfPrompts());
608 RequestGeolocationPermission(
609 web_contents(), RequestID(0), requesting_frame, BubbleEnabled());
610 EXPECT_EQ(0U, GetNumberOfPrompts());
516 CheckPermissionMessageSent(0, false); 611 CheckPermissionMessageSent(0, false);
517 } 612 }
518 613
519 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { 614 TEST_P(GeolocationPermissionContextParamTests, SameOriginMultipleTabs) {
520 GURL url_a("http://www.example.com/geolocation"); 615 GURL url_a("http://www.example.com/geolocation");
521 GURL url_b("http://www.example-2.com/geolocation"); 616 GURL url_b("http://www.example-2.com/geolocation");
522 NavigateAndCommit(url_a); 617 NavigateAndCommit(url_a); // Tab A0
523 AddNewTab(url_b); 618 AddNewTab(url_b); // Tab B (extra_tabs_[0])
524 AddNewTab(url_a); 619 AddNewTab(url_a); // Tab A1 (extra_tabs_[1])
525 620 if (BubbleEnabled()) {
526 EXPECT_EQ(0U, infobar_service()->infobar_count()); 621 BubbleManagerDocumentLoadCompleted();
527 RequestGeolocationPermission(web_contents(), RequestID(0), url_a); 622 BubbleManagerDocumentLoadCompleted(extra_tabs_[0]);
528 ASSERT_EQ(1U, infobar_service()->infobar_count()); 623 BubbleManagerDocumentLoadCompleted(extra_tabs_[1]);
529 624 }
530 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 0), url_b); 625 PermissionBubbleManager* manager_a0 =
531 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 626 PermissionBubbleManager::FromWebContents(web_contents());
532 627 PermissionBubbleManager* manager_b =
533 RequestGeolocationPermission(extra_tabs_[1], RequestIDForTab(1, 0), url_a); 628 PermissionBubbleManager::FromWebContents(extra_tabs_[0]);
534 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); 629 PermissionBubbleManager* manager_a1 =
535 630 PermissionBubbleManager::FromWebContents(extra_tabs_[1]);
536 infobars::InfoBar* removed_infobar = 631
537 infobar_service_for_tab(1)->infobar_at(0); 632 // Request permission in all three tabs.
538 633 RequestGeolocationPermission(
539 // Accept the first tab. 634 web_contents(), RequestID(0), url_a, BubbleEnabled());
540 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); 635 RequestGeolocationPermission(
541 ConfirmInfoBarDelegate* infobar_delegate_0 = 636 extra_tabs_[0], RequestIDForTab(0, 0), url_b, BubbleEnabled());
542 infobar_0->delegate()->AsConfirmInfoBarDelegate(); 637 RequestGeolocationPermission(
543 ASSERT_TRUE(infobar_delegate_0); 638 extra_tabs_[1], RequestIDForTab(1, 0), url_a, BubbleEnabled());
544 infobar_delegate_0->Accept(); 639 ASSERT_EQ(1U, GetNumberOfPrompts()); // For A0.
640 if (BubbleEnabled()) {
641 ASSERT_EQ(1U, GetBubblesQueueSize(manager_b));
642 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1));
643 } else {
644 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
645 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count());
646 }
647
648 // Accept the permission in tab A0.
649 if (BubbleEnabled()) {
650 AcceptBubble(manager_a0);
651 } else {
652 infobars::InfoBar* infobar_a0 = infobar_service()->infobar_at(0);
653 ConfirmInfoBarDelegate* infobar_delegate_a0 =
654 infobar_a0->delegate()->AsConfirmInfoBarDelegate();
655 ASSERT_TRUE(infobar_delegate_a0);
656 infobar_delegate_a0->Accept();
657 infobar_service()->RemoveInfoBar(infobar_a0);
658 EXPECT_EQ(2U, closed_infobar_tracker_.size());
659 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a0));
660 }
545 CheckPermissionMessageSent(0, true); 661 CheckPermissionMessageSent(0, true);
546 infobar_service()->RemoveInfoBar(infobar_0); 662
547 EXPECT_EQ(2U, closed_infobar_tracker_.size()); 663 // Because they're the same origin, this will cause tab A1's infobar to
548 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); 664 // disappear. It does not cause the bubble to disappear: crbug.com/443013.
549 // Now the infobar for the tab with the same origin should have gone. 665 // TODO(felt): Update this test when the bubble's behavior is changed.
550 EXPECT_EQ(0U, infobar_service_for_tab(1)->infobar_count()); 666 if (BubbleEnabled())
551 CheckPermissionMessageSentForTab(1, 0, true); 667 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1));
552 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); 668 else
553 closed_infobar_tracker_.Clear(); 669 CheckPermissionMessageSentForTab(1, 0, true);
554 670
555 // But the other tab should still have the info bar... 671 // Either way, tab B should still have a pending permission request.
556 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 672 if (BubbleEnabled())
557 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); 673 ASSERT_EQ(1U, GetBubblesQueueSize(manager_b));
558 ConfirmInfoBarDelegate* infobar_delegate_1 = 674 else
559 infobar_1->delegate()->AsConfirmInfoBarDelegate(); 675 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
560 ASSERT_TRUE(infobar_delegate_1); 676 }
561 infobar_delegate_1->Cancel(); 677
562 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); 678 TEST_P(GeolocationPermissionContextParamTests, QueuedOriginMultipleTabs) {
563 EXPECT_EQ(1U, closed_infobar_tracker_.size());
564 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
565 }
566
567 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
568 GURL url_a("http://www.example.com/geolocation"); 679 GURL url_a("http://www.example.com/geolocation");
569 GURL url_b("http://www.example-2.com/geolocation"); 680 GURL url_b("http://www.example-2.com/geolocation");
570 NavigateAndCommit(url_a); 681 NavigateAndCommit(url_a); // Tab A0.
571 AddNewTab(url_a); 682 AddNewTab(url_a); // Tab A1.
572 683 if (BubbleEnabled()) {
573 EXPECT_EQ(0U, infobar_service()->infobar_count()); 684 BubbleManagerDocumentLoadCompleted();
574 RequestGeolocationPermission(web_contents(), RequestID(0), url_a); 685 BubbleManagerDocumentLoadCompleted(extra_tabs_[0]);
575 ASSERT_EQ(1U, infobar_service()->infobar_count()); 686 }
576 687 PermissionBubbleManager* manager_a0 =
577 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 0), url_a); 688 PermissionBubbleManager::FromWebContents(web_contents());
578 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 689 PermissionBubbleManager* manager_a1 =
579 690 PermissionBubbleManager::FromWebContents(extra_tabs_[0]);
580 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 1), url_b); 691 infobars::InfoBar* infobar_a0;
581 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 692
582 693 // Request permission in both tabs; the extra tab will have two permission
583 infobars::InfoBar* removed_infobar = infobar_service()->infobar_at(0); 694 // requests from two origins.
584 695 RequestGeolocationPermission(
585 // Accept the second tab. 696 web_contents(), RequestID(0), url_a, BubbleEnabled());
586 infobars::InfoBar* infobar_0 = infobar_service_for_tab(0)->infobar_at(0); 697 RequestGeolocationPermission(
587 ConfirmInfoBarDelegate* infobar_delegate_0 = 698 extra_tabs_[0], RequestIDForTab(0, 0), url_a, BubbleEnabled());
588 infobar_0->delegate()->AsConfirmInfoBarDelegate(); 699 RequestGeolocationPermission(
589 ASSERT_TRUE(infobar_delegate_0); 700 extra_tabs_[0], RequestIDForTab(0, 1), url_b, BubbleEnabled());
590 infobar_delegate_0->Accept(); 701 if (BubbleEnabled()) {
702 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a0));
703 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1));
704 } else {
705 ASSERT_EQ(1U, infobar_service()->infobar_count());
706 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
707 infobar_a0 = infobar_service()->infobar_at(0); // Save for later.
708 }
709
710 // Accept the first request in tab A1.
711 if (BubbleEnabled()) {
712 AcceptBubble(manager_a1);
713 } else {
714 infobars::InfoBar* infobar_a1 = infobar_service_for_tab(0)->infobar_at(0);
715 ConfirmInfoBarDelegate* infobar_delegate_a1 =
716 infobar_a1->delegate()->AsConfirmInfoBarDelegate();
717 ASSERT_TRUE(infobar_delegate_a1);
718 infobar_delegate_a1->Accept();
719 infobar_service_for_tab(0)->RemoveInfoBar(infobar_a1);
720 EXPECT_EQ(2U, closed_infobar_tracker_.size());
721 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a1));
722 }
591 CheckPermissionMessageSentForTab(0, 0, true); 723 CheckPermissionMessageSentForTab(0, 0, true);
592 infobar_service_for_tab(0)->RemoveInfoBar(infobar_0); 724
593 EXPECT_EQ(2U, closed_infobar_tracker_.size()); 725 // Because they're the same origin, this will cause tab A0's infobar to
594 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); 726 // disappear. It does not cause the bubble to disappear: crbug.com/443013.
595 // Now the infobar for the tab with the same origin should have gone. 727 // TODO(felt): Update this test when the bubble's behavior is changed.
596 EXPECT_EQ(0U, infobar_service()->infobar_count()); 728 if (BubbleEnabled()) {
597 CheckPermissionMessageSent(0, true); 729 EXPECT_EQ(1U, GetBubblesQueueSize(manager_a0));
598 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); 730 } else {
599 closed_infobar_tracker_.Clear(); 731 EXPECT_EQ(0U, infobar_service()->infobar_count());
600 732 CheckPermissionMessageSent(0, true);
601 // And we should have the queued infobar displayed now. 733 }
602 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 734
603 735 // The second request should now be visible in tab A1.
604 // Accept the second infobar. 736 if (BubbleEnabled())
605 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); 737 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1));
606 ConfirmInfoBarDelegate* infobar_delegate_1 = 738 else
607 infobar_1->delegate()->AsConfirmInfoBarDelegate(); 739 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
608 ASSERT_TRUE(infobar_delegate_1); 740
609 infobar_delegate_1->Accept(); 741 // Accept the second request and check that it's gone.
742 if (BubbleEnabled()) {
743 AcceptBubble(manager_a1);
744 EXPECT_EQ(0U, GetBubblesQueueSize(manager_a1));
745 } else {
746 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0);
747 ConfirmInfoBarDelegate* infobar_delegate_1 =
748 infobar_1->delegate()->AsConfirmInfoBarDelegate();
749 ASSERT_TRUE(infobar_delegate_1);
750 infobar_delegate_1->Accept();
751 }
610 CheckPermissionMessageSentForTab(0, 1, true); 752 CheckPermissionMessageSentForTab(0, 1, true);
611 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); 753 }
612 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 754
613 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); 755 TEST_P(GeolocationPermissionContextParamTests, TabDestroyed) {
614 }
615
616 TEST_F(GeolocationPermissionContextTests, TabDestroyed) {
617 GURL requesting_frame_0("http://www.example.com/geolocation"); 756 GURL requesting_frame_0("http://www.example.com/geolocation");
618 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 757 GURL requesting_frame_1("http://www.example-2.com/geolocation");
619 EXPECT_EQ(CONTENT_SETTING_ASK, 758 EXPECT_EQ(
620 profile()->GetHostContentSettingsMap()->GetContentSetting( 759 CONTENT_SETTING_ASK,
621 requesting_frame_0, requesting_frame_0, 760 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0));
622 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 761 EXPECT_EQ(
623 762 CONTENT_SETTING_ASK,
624 EXPECT_EQ(CONTENT_SETTING_ASK, 763 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0));
625 profile()->GetHostContentSettingsMap()->GetContentSetting(
626 requesting_frame_1, requesting_frame_0,
627 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
628 764
629 NavigateAndCommit(requesting_frame_0); 765 NavigateAndCommit(requesting_frame_0);
630 EXPECT_EQ(0U, infobar_service()->infobar_count()); 766 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
767
768 ASSERT_EQ(0U, GetNumberOfPrompts());
769
631 // Request permission for two frames. 770 // Request permission for two frames.
632 RequestGeolocationPermission( 771 RequestGeolocationPermission(
633 web_contents(), RequestID(0), requesting_frame_0); 772 web_contents(), RequestID(0), requesting_frame_0, false);
634 RequestGeolocationPermission( 773 RequestGeolocationPermission(
635 web_contents(), RequestID(1), requesting_frame_1); 774 web_contents(), RequestID(1), requesting_frame_1, false);
636 // Ensure only one infobar is created. 775
637 ASSERT_EQ(1U, infobar_service()->infobar_count()); 776 // Ensure only one infobar/bubble is created.
638 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 777 ASSERT_EQ(1U, GetNumberOfPrompts());
639 778
640 // Delete the tab contents. 779 // Delete the tab contents and check that the infobar was removed.
641 DeleteContents(); 780 if (!BubbleEnabled()) {
642 781 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
643 // During contents destruction, the infobar will have been closed, and the 782 DeleteContents();
644 // pending request should have been cleared without an infobar being created. 783 ASSERT_EQ(1U, closed_infobar_tracker_.size());
645 ASSERT_EQ(1U, closed_infobar_tracker_.size()); 784 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar));
646 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); 785 }
647 } 786
648 787 // The content settings should not have changed.
649 TEST_F(GeolocationPermissionContextTests, LastUsageAudited) { 788 EXPECT_EQ(
789 CONTENT_SETTING_ASK,
790 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0));
791 EXPECT_EQ(
792 CONTENT_SETTING_ASK,
793 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0));
794 }
795
796 TEST_P(GeolocationPermissionContextParamTests, LastUsageAudited) {
650 GURL requesting_frame("http://www.example.com/geolocation"); 797 GURL requesting_frame("http://www.example.com/geolocation");
651 NavigateAndCommit(requesting_frame); 798 NavigateAndCommit(requesting_frame);
799 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
652 800
653 base::SimpleTestClock* test_clock = new base::SimpleTestClock; 801 base::SimpleTestClock* test_clock = new base::SimpleTestClock;
654 test_clock->SetNow(base::Time::UnixEpoch() + 802 test_clock->SetNow(base::Time::UnixEpoch() +
655 base::TimeDelta::FromSeconds(10)); 803 base::TimeDelta::FromSeconds(10));
656 804
657 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); 805 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap();
658 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); 806 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock));
659 807
660 // The permission shouldn't have been used yet. 808 // The permission shouldn't have been used yet.
661 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), 809 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(),
662 requesting_frame.GetOrigin(), 810 requesting_frame.GetOrigin(),
663 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 811 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
664 0); 812 0);
665 813 ASSERT_EQ(0U, GetNumberOfPrompts());
666 EXPECT_EQ(0U, infobar_service()->infobar_count()); 814 RequestGeolocationPermission(
667 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 815 web_contents(), RequestID(0), requesting_frame, false);
668 ASSERT_EQ(1U, infobar_service()->infobar_count()); 816 ASSERT_EQ(1U, GetNumberOfPrompts());
669 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 817 AcceptPrompt();
670 ConfirmInfoBarDelegate* infobar_delegate =
671 infobar->delegate()->AsConfirmInfoBarDelegate();
672 ASSERT_TRUE(infobar_delegate);
673 infobar_delegate->Accept();
674 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); 818 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
675 CheckPermissionMessageSent(0, true); 819 CheckPermissionMessageSent(0, true);
676 820
677 // Permission has been used at the starting time. 821 // Permission has been used at the starting time.
678 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), 822 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(),
679 requesting_frame.GetOrigin(), 823 requesting_frame.GetOrigin(),
680 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 824 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
681 10); 825 10);
682 826
683 test_clock->Advance(base::TimeDelta::FromSeconds(3)); 827 test_clock->Advance(base::TimeDelta::FromSeconds(3));
684 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 828 RequestGeolocationPermission(
829 web_contents(), RequestID(0), requesting_frame, false);
685 830
686 // Permission has been used three seconds later. 831 // Permission has been used three seconds later.
687 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), 832 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(),
688 requesting_frame.GetOrigin(), 833 requesting_frame.GetOrigin(),
689 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 834 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
690 13); 835 13);
691 } 836 }
692 837
693 TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) { 838 TEST_P(GeolocationPermissionContextParamTests, LastUsageAuditedMultipleFrames) {
694 base::SimpleTestClock* test_clock = new base::SimpleTestClock; 839 base::SimpleTestClock* test_clock = new base::SimpleTestClock;
695 test_clock->SetNow(base::Time::UnixEpoch() + 840 test_clock->SetNow(base::Time::UnixEpoch() +
696 base::TimeDelta::FromSeconds(10)); 841 base::TimeDelta::FromSeconds(10));
697 842
698 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); 843 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap();
699 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); 844 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock));
700 845
701 GURL requesting_frame_0("http://www.example.com/geolocation"); 846 GURL requesting_frame_0("http://www.example.com/geolocation");
702 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 847 GURL requesting_frame_1("http://www.example-2.com/geolocation");
703 848
704 // The permission shouldn't have been used yet. 849 // The permission shouldn't have been used yet.
705 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), 850 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
706 requesting_frame_0.GetOrigin(), 851 requesting_frame_0.GetOrigin(),
707 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 852 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
708 0); 853 0);
709 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), 854 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
710 requesting_frame_0.GetOrigin(), 855 requesting_frame_0.GetOrigin(),
711 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 856 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
712 0); 857 0);
713 858
714 NavigateAndCommit(requesting_frame_0); 859 NavigateAndCommit(requesting_frame_0);
715 EXPECT_EQ(0U, infobar_service()->infobar_count()); 860 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
861
862 EXPECT_EQ(0U, GetNumberOfPrompts());
716 863
717 // Request permission for two frames. 864 // Request permission for two frames.
718 RequestGeolocationPermission( 865 RequestGeolocationPermission(
719 web_contents(), RequestID(0), requesting_frame_0); 866 web_contents(), RequestID(0), requesting_frame_0, false);
720 RequestGeolocationPermission( 867 RequestGeolocationPermission(
721 web_contents(), RequestID(1), requesting_frame_1); 868 web_contents(), RequestID(1), requesting_frame_1, false);
722 869
723 // Ensure only one infobar is created. 870 // Ensure only one request is created.
724 ASSERT_EQ(1U, infobar_service()->infobar_count()); 871 ASSERT_EQ(1U, GetNumberOfPrompts());
725 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0);
726 ConfirmInfoBarDelegate* infobar_delegate_0 =
727 infobar_0->delegate()->AsConfirmInfoBarDelegate();
728 872
729 // Accept the first frame. 873 // Accept the first frame.
730 infobar_delegate_0->Accept(); 874 AcceptPrompt();
875 if (!BubbleEnabled())
876 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0));
731 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); 877 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
732 CheckPermissionMessageSent(0, true); 878 CheckPermissionMessageSent(0, true);
733 infobar_service()->RemoveInfoBar(infobar_0);
734 879
735 // Verify that accepting the first didn't accept because it's embedder 880 // Verify that accepting the first didn't accept because it's embedded
736 // in the other. 881 // in the other.
737 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), 882 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
738 requesting_frame_0.GetOrigin(), 883 requesting_frame_0.GetOrigin(),
739 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 884 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
740 10); 885 10);
741 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), 886 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
742 requesting_frame_0.GetOrigin(), 887 requesting_frame_0.GetOrigin(),
743 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 888 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
744 0); 889 0);
745 890
746 ASSERT_EQ(1U, infobar_service()->infobar_count()); 891 ASSERT_EQ(1U, GetNumberOfPrompts());
747 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0);
748 ConfirmInfoBarDelegate* infobar_delegate_1 =
749 infobar_1->delegate()->AsConfirmInfoBarDelegate();
750 892
751 test_clock->Advance(base::TimeDelta::FromSeconds(1)); 893 test_clock->Advance(base::TimeDelta::FromSeconds(1));
752 894
753 // Allow the second frame. 895 // Allow the second frame.
754 infobar_delegate_1->Accept(); 896 AcceptPrompt();
755 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); 897 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW);
756 CheckPermissionMessageSent(1, true); 898 CheckPermissionMessageSent(1, true);
757 infobar_service()->RemoveInfoBar(infobar_1); 899 if (!BubbleEnabled())
900 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0));
758 901
759 // Verify that the times are different. 902 // Verify that the times are different.
760 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), 903 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
761 requesting_frame_0.GetOrigin(), 904 requesting_frame_0.GetOrigin(),
762 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 905 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
763 10); 906 10);
764 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), 907 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
765 requesting_frame_0.GetOrigin(), 908 requesting_frame_0.GetOrigin(),
766 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 909 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
767 11); 910 11);
768 911
769 test_clock->Advance(base::TimeDelta::FromSeconds(2)); 912 test_clock->Advance(base::TimeDelta::FromSeconds(2));
770 RequestGeolocationPermission( 913 RequestGeolocationPermission(
771 web_contents(), RequestID(0), requesting_frame_0); 914 web_contents(), RequestID(0), requesting_frame_0, false);
772 915
773 // Verify that requesting permission in one frame doesn't update other where 916 // Verify that requesting permission in one frame doesn't update other where
774 // it is the embedder. 917 // it is the embedder.
775 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), 918 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
776 requesting_frame_0.GetOrigin(), 919 requesting_frame_0.GetOrigin(),
777 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 920 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
778 13); 921 13);
779 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), 922 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
780 requesting_frame_0.GetOrigin(), 923 requesting_frame_0.GetOrigin(),
781 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 924 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
782 11); 925 11);
783 } 926 }
927
928 INSTANTIATE_TEST_CASE_P(GeolocationPermissionContextTestsWithAndWithoutBubbles,
929 GeolocationPermissionContextParamTests,
930 ::testing::Values(false, true));
931
932 // Infobar-only tests ----------------------------------------------------------
933 // Android doesn't support permission bubbles.
934
935 #if defined(OS_ANDROID)
936 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) {
937 EXPECT_FALSE(PermissionBubbleManager::Enabled());
938 GURL requesting_frame("http://www.example.com/geolocation");
939 NavigateAndCommit(requesting_frame);
940 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true);
941 EXPECT_EQ(0U, infobar_service()->infobar_count());
942 RequestGeolocationPermission(
943 web_contents(), RequestID(0), requesting_frame, true);
944 EXPECT_EQ(1U, infobar_service()->infobar_count());
945 ConfirmInfoBarDelegate* infobar_delegate_0 =
946 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
947 ASSERT_TRUE(infobar_delegate_0);
948 base::string16 text_0 = infobar_delegate_0->GetButtonLabel(
949 ConfirmInfoBarDelegate::BUTTON_OK);
950
951 Reload();
952 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false);
953 EXPECT_EQ(0U, infobar_service()->infobar_count());
954 RequestGeolocationPermission(
955 web_contents(), RequestID(0), requesting_frame, true);
956 EXPECT_EQ(0U, infobar_service()->infobar_count());
957 }
958
959 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) {
960 EXPECT_FALSE(PermissionBubbleManager::Enabled());
961 GURL requesting_frame("http://www.example.com/geolocation");
962 NavigateAndCommit(requesting_frame);
963 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true);
964 EXPECT_EQ(0U, infobar_service()->infobar_count());
965 RequestGeolocationPermission(
966 web_contents(), RequestID(0), requesting_frame, true);
967 EXPECT_EQ(1U, infobar_service()->infobar_count());
968 ConfirmInfoBarDelegate* infobar_delegate =
969 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
970 ASSERT_TRUE(infobar_delegate);
971 infobar_delegate->Accept();
972 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
973 CheckPermissionMessageSent(0, true);
974 }
975
976 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) {
977 EXPECT_FALSE(PermissionBubbleManager::Enabled());
978 GURL requesting_frame("http://www.example.com/geolocation");
979 NavigateAndCommit(requesting_frame);
980 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false);
981 EXPECT_EQ(0U, infobar_service()->infobar_count());
982 RequestGeolocationPermission(
983 web_contents(), RequestID(0), requesting_frame, true);
984 EXPECT_EQ(0U, infobar_service()->infobar_count());
985 }
986 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698