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

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

Issue 190063006: Infobar Componentization Proof of Concept (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor fixes Created 6 years, 9 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 (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/chrome_geolocation_permission_context.h" 5 #include "chrome/browser/geolocation/chrome_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/containers/hash_tables.h" 12 #include "base/containers/hash_tables.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
16 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/content_settings/host_content_settings_map.h" 17 #include "chrome/browser/content_settings/host_content_settings_map.h"
18 #include "chrome/browser/content_settings/permission_request_id.h" 18 #include "chrome/browser/content_settings/permission_request_id.h"
19 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 19 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
20 #include "chrome/browser/geolocation/chrome_geolocation_permission_context_facto ry.h" 20 #include "chrome/browser/geolocation/chrome_geolocation_permission_context_facto ry.h"
21 #include "chrome/browser/infobars/confirm_infobar_delegate.h" 21 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
22 #include "chrome/browser/infobars/infobar.h" 22 #include "chrome/browser/infobars/infobar.h"
23 #include "chrome/browser/infobars/infobar_manager.h"
23 #include "chrome/browser/infobars/infobar_service.h" 24 #include "chrome/browser/infobars/infobar_service.h"
24 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 25 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
25 #include "chrome/test/base/testing_profile.h" 26 #include "chrome/test/base/testing_profile.h"
26 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/navigation_details.h" 28 #include "content/public/browser/navigation_details.h"
28 #include "content/public/browser/notification_registrar.h" 29 #include "content/public/browser/notification_registrar.h"
29 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
30 #include "content/public/browser/web_contents.h" 31 #include "content/public/browser/web_contents.h"
31 #include "content/public/test/mock_render_process_host.h" 32 #include "content/public/test/mock_render_process_host.h"
32 #include "content/public/test/test_renderer_host.h" 33 #include "content/public/test/test_renderer_host.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 98
98 class GeolocationPermissionContextTests 99 class GeolocationPermissionContextTests
99 : public ChromeRenderViewHostTestHarness { 100 : public ChromeRenderViewHostTestHarness {
100 protected: 101 protected:
101 // ChromeRenderViewHostTestHarness: 102 // ChromeRenderViewHostTestHarness:
102 virtual void SetUp() OVERRIDE; 103 virtual void SetUp() OVERRIDE;
103 virtual void TearDown() OVERRIDE; 104 virtual void TearDown() OVERRIDE;
104 105
105 PermissionRequestID RequestID(int bridge_id); 106 PermissionRequestID RequestID(int bridge_id);
106 PermissionRequestID RequestIDForTab(int tab, int bridge_id); 107 PermissionRequestID RequestIDForTab(int tab, int bridge_id);
107 InfoBarService* infobar_service() { 108 InfoBarManager& infobar_manager() {
108 return InfoBarService::FromWebContents(web_contents()); 109 return InfoBarService::FromWebContents(web_contents())->infobar_manager();
109 } 110 }
110 InfoBarService* infobar_service_for_tab(int tab) { 111 InfoBarManager& infobar_manager_for_tab(int tab) {
111 return InfoBarService::FromWebContents(extra_tabs_[tab]); 112 return InfoBarService::FromWebContents(extra_tabs_[tab])->infobar_manager();
112 } 113 }
113
114 void RequestGeolocationPermission(const PermissionRequestID& id, 114 void RequestGeolocationPermission(const PermissionRequestID& id,
115 const GURL& requesting_frame); 115 const GURL& requesting_frame);
116 void CancelGeolocationPermissionRequest(const PermissionRequestID& id, 116 void CancelGeolocationPermissionRequest(const PermissionRequestID& id,
117 const GURL& requesting_frame); 117 const GURL& requesting_frame);
118 void PermissionResponse(const PermissionRequestID& id, 118 void PermissionResponse(const PermissionRequestID& id,
119 bool allowed); 119 bool allowed);
120 void CheckPermissionMessageSent(int bridge_id, bool allowed); 120 void CheckPermissionMessageSent(int bridge_id, bool allowed);
121 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); 121 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed);
122 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, 122 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process,
123 int bridge_id, 123 int bridge_id,
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 void GeolocationPermissionContextTests::TearDown() { 254 void GeolocationPermissionContextTests::TearDown() {
255 extra_tabs_.clear(); 255 extra_tabs_.clear();
256 ChromeRenderViewHostTestHarness::TearDown(); 256 ChromeRenderViewHostTestHarness::TearDown();
257 } 257 }
258 258
259 // Tests ---------------------------------------------------------------------- 259 // Tests ----------------------------------------------------------------------
260 260
261 TEST_F(GeolocationPermissionContextTests, SinglePermission) { 261 TEST_F(GeolocationPermissionContextTests, SinglePermission) {
262 GURL requesting_frame("http://www.example.com/geolocation"); 262 GURL requesting_frame("http://www.example.com/geolocation");
263 NavigateAndCommit(requesting_frame); 263 NavigateAndCommit(requesting_frame);
264 EXPECT_EQ(0U, infobar_service()->infobar_count()); 264 EXPECT_EQ(0U, infobar_manager().infobar_count());
265 RequestGeolocationPermission(RequestID(0), requesting_frame); 265 RequestGeolocationPermission(RequestID(0), requesting_frame);
266 ASSERT_EQ(1U, infobar_service()->infobar_count()); 266 ASSERT_EQ(1U, infobar_manager().infobar_count());
267 InfoBar* infobar = infobar_service()->infobar_at(0); 267 InfoBar* infobar = infobar_manager().infobar_at(0);
268 ConfirmInfoBarDelegate* infobar_delegate = 268 ConfirmInfoBarDelegate* infobar_delegate =
269 infobar->delegate()->AsConfirmInfoBarDelegate(); 269 infobar->delegate()->AsConfirmInfoBarDelegate();
270 ASSERT_TRUE(infobar_delegate); 270 ASSERT_TRUE(infobar_delegate);
271 infobar_delegate->Cancel(); 271 infobar_delegate->Cancel();
272 infobar_service()->RemoveInfoBar(infobar); 272 infobar_manager().RemoveInfoBar(infobar);
273 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 273 EXPECT_EQ(1U, closed_infobar_tracker_.size());
274 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); 274 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
275 } 275 }
276 276
277 #if defined(OS_ANDROID) 277 #if defined(OS_ANDROID)
278 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { 278 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) {
279 GURL requesting_frame("http://www.example.com/geolocation"); 279 GURL requesting_frame("http://www.example.com/geolocation");
280 NavigateAndCommit(requesting_frame); 280 NavigateAndCommit(requesting_frame);
281 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); 281 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true);
282 EXPECT_EQ(0U, infobar_service()->infobar_count()); 282 EXPECT_EQ(0U, infobar_manager().infobar_count());
283 RequestGeolocationPermission(RequestID(0), requesting_frame); 283 RequestGeolocationPermission(RequestID(0), requesting_frame);
284 EXPECT_EQ(1U, infobar_service()->infobar_count()); 284 EXPECT_EQ(1U, infobar_manager().infobar_count());
285 ConfirmInfoBarDelegate* infobar_delegate_0 = infobar_service()-> 285 ConfirmInfoBarDelegate* infobar_delegate_0 =
286 infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 286 infobar_manager().infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
287 ASSERT_TRUE(infobar_delegate_0); 287 ASSERT_TRUE(infobar_delegate_0);
288 base::string16 text_0 = infobar_delegate_0->GetButtonLabel( 288 base::string16 text_0 = infobar_delegate_0->GetButtonLabel(
289 ConfirmInfoBarDelegate::BUTTON_OK); 289 ConfirmInfoBarDelegate::BUTTON_OK);
290 290
291 NavigateAndCommit(requesting_frame); 291 NavigateAndCommit(requesting_frame);
292 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); 292 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false);
293 EXPECT_EQ(0U, infobar_service()->infobar_count()); 293 EXPECT_EQ(0U, infobar_manager().infobar_count());
294 RequestGeolocationPermission(RequestID(0), requesting_frame); 294 RequestGeolocationPermission(RequestID(0), requesting_frame);
295 EXPECT_EQ(1U, infobar_service()->infobar_count()); 295 EXPECT_EQ(1U, infobar_manager().infobar_count());
296 ConfirmInfoBarDelegate* infobar_delegate_1 = infobar_service()-> 296 ConfirmInfoBarDelegate* infobar_delegate_1 =
297 infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 297 infobar_manager().infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
298 ASSERT_TRUE(infobar_delegate_1); 298 ASSERT_TRUE(infobar_delegate_1);
299 base::string16 text_1 = infobar_delegate_1->GetButtonLabel( 299 base::string16 text_1 = infobar_delegate_1->GetButtonLabel(
300 ConfirmInfoBarDelegate::BUTTON_OK); 300 ConfirmInfoBarDelegate::BUTTON_OK);
301 EXPECT_NE(text_0, text_1); 301 EXPECT_NE(text_0, text_1);
302 302
303 NavigateAndCommit(requesting_frame); 303 NavigateAndCommit(requesting_frame);
304 MockGoogleLocationSettingsHelper::SetLocationStatus(false, false); 304 MockGoogleLocationSettingsHelper::SetLocationStatus(false, false);
305 EXPECT_EQ(0U, infobar_service()->infobar_count()); 305 EXPECT_EQ(0U, infobar_manager().infobar_count());
306 RequestGeolocationPermission(RequestID(0), requesting_frame); 306 RequestGeolocationPermission(RequestID(0), requesting_frame);
307 EXPECT_EQ(0U, infobar_service()->infobar_count()); 307 EXPECT_EQ(0U, infobar_manager().infobar_count());
308 } 308 }
309 309
310 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { 310 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) {
311 GURL requesting_frame("http://www.example.com/geolocation"); 311 GURL requesting_frame("http://www.example.com/geolocation");
312 NavigateAndCommit(requesting_frame); 312 NavigateAndCommit(requesting_frame);
313 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); 313 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true);
314 EXPECT_EQ(0U, infobar_service()->infobar_count()); 314 EXPECT_EQ(0U, infobar_manager().infobar_count());
315 RequestGeolocationPermission(RequestID(0), requesting_frame); 315 RequestGeolocationPermission(RequestID(0), requesting_frame);
316 EXPECT_EQ(1U, infobar_service()->infobar_count()); 316 EXPECT_EQ(1U, infobar_manager().infobar_count());
317 ConfirmInfoBarDelegate* infobar_delegate = infobar_service()-> 317 ConfirmInfoBarDelegate* infobar_delegate =
318 infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 318 infobar_manager().infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
319 ASSERT_TRUE(infobar_delegate); 319 ASSERT_TRUE(infobar_delegate);
320 infobar_delegate->Accept(); 320 infobar_delegate->Accept();
321 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); 321 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
322 CheckPermissionMessageSent(0, true); 322 CheckPermissionMessageSent(0, true);
323 } 323 }
324 324
325 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { 325 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) {
326 GURL requesting_frame("http://www.example.com/geolocation"); 326 GURL requesting_frame("http://www.example.com/geolocation");
327 NavigateAndCommit(requesting_frame); 327 NavigateAndCommit(requesting_frame);
328 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); 328 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false);
329 EXPECT_EQ(0U, infobar_service()->infobar_count()); 329 EXPECT_EQ(0U, infobar_manager().infobar_count());
330 RequestGeolocationPermission(RequestID(0), requesting_frame); 330 RequestGeolocationPermission(RequestID(0), requesting_frame);
331 EXPECT_EQ(1U, infobar_service()->infobar_count()); 331 EXPECT_EQ(1U, infobar_manager().infobar_count());
332 ConfirmInfoBarDelegate* infobar_delegate = infobar_service()-> 332 ConfirmInfoBarDelegate* infobar_delegate =
333 infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 333 infobar_manager().infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
334 ASSERT_TRUE(infobar_delegate); 334 ASSERT_TRUE(infobar_delegate);
335 infobar_delegate->Accept(); 335 infobar_delegate->Accept();
336 EXPECT_TRUE( 336 EXPECT_TRUE(
337 MockGoogleLocationSettingsHelper::WasGoogleLocationSettingsCalled()); 337 MockGoogleLocationSettingsHelper::WasGoogleLocationSettingsCalled());
338 } 338 }
339 #endif 339 #endif
340 340
341 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { 341 TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
342 GURL requesting_frame_0("http://www.example.com/geolocation"); 342 GURL requesting_frame_0("http://www.example.com/geolocation");
343 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 343 GURL requesting_frame_1("http://www.example-2.com/geolocation");
344 EXPECT_EQ(CONTENT_SETTING_ASK, 344 EXPECT_EQ(CONTENT_SETTING_ASK,
345 profile()->GetHostContentSettingsMap()->GetContentSetting( 345 profile()->GetHostContentSettingsMap()->GetContentSetting(
346 requesting_frame_0, requesting_frame_0, 346 requesting_frame_0, requesting_frame_0,
347 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 347 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
348 EXPECT_EQ(CONTENT_SETTING_ASK, 348 EXPECT_EQ(CONTENT_SETTING_ASK,
349 profile()->GetHostContentSettingsMap()->GetContentSetting( 349 profile()->GetHostContentSettingsMap()->GetContentSetting(
350 requesting_frame_1, requesting_frame_0, 350 requesting_frame_1, requesting_frame_0,
351 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 351 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
352 352
353 NavigateAndCommit(requesting_frame_0); 353 NavigateAndCommit(requesting_frame_0);
354 EXPECT_EQ(0U, infobar_service()->infobar_count()); 354 EXPECT_EQ(0U, infobar_manager().infobar_count());
355 // Request permission for two frames. 355 // Request permission for two frames.
356 RequestGeolocationPermission(RequestID(0), requesting_frame_0); 356 RequestGeolocationPermission(RequestID(0), requesting_frame_0);
357 RequestGeolocationPermission(RequestID(1), requesting_frame_1); 357 RequestGeolocationPermission(RequestID(1), requesting_frame_1);
358 // Ensure only one infobar is created. 358 // Ensure only one infobar is created.
359 ASSERT_EQ(1U, infobar_service()->infobar_count()); 359 ASSERT_EQ(1U, infobar_manager().infobar_count());
360 InfoBar* infobar_0 = infobar_service()->infobar_at(0); 360 InfoBar* infobar_0 = infobar_manager().infobar_at(0);
361 ConfirmInfoBarDelegate* infobar_delegate_0 = 361 ConfirmInfoBarDelegate* infobar_delegate_0 =
362 infobar_0->delegate()->AsConfirmInfoBarDelegate(); 362 infobar_0->delegate()->AsConfirmInfoBarDelegate();
363 ASSERT_TRUE(infobar_delegate_0); 363 ASSERT_TRUE(infobar_delegate_0);
364 base::string16 text_0 = infobar_delegate_0->GetMessageText(); 364 base::string16 text_0 = infobar_delegate_0->GetMessageText();
365 365
366 // Accept the first frame. 366 // Accept the first frame.
367 infobar_delegate_0->Accept(); 367 infobar_delegate_0->Accept();
368 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); 368 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
369 CheckPermissionMessageSent(0, true); 369 CheckPermissionMessageSent(0, true);
370 370
371 infobar_service()->RemoveInfoBar(infobar_0); 371 infobar_manager().RemoveInfoBar(infobar_0);
372 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 372 EXPECT_EQ(1U, closed_infobar_tracker_.size());
373 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); 373 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0));
374 closed_infobar_tracker_.Clear(); 374 closed_infobar_tracker_.Clear();
375 // Now we should have a new infobar for the second frame. 375 // Now we should have a new infobar for the second frame.
376 ASSERT_EQ(1U, infobar_service()->infobar_count()); 376 ASSERT_EQ(1U, infobar_manager().infobar_count());
377 377
378 InfoBar* infobar_1 = infobar_service()->infobar_at(0); 378 InfoBar* infobar_1 = infobar_manager().infobar_at(0);
379 ConfirmInfoBarDelegate* infobar_delegate_1 = 379 ConfirmInfoBarDelegate* infobar_delegate_1 =
380 infobar_1->delegate()->AsConfirmInfoBarDelegate(); 380 infobar_1->delegate()->AsConfirmInfoBarDelegate();
381 ASSERT_TRUE(infobar_delegate_1); 381 ASSERT_TRUE(infobar_delegate_1);
382 base::string16 text_1 = infobar_delegate_1->GetMessageText(); 382 base::string16 text_1 = infobar_delegate_1->GetMessageText();
383 EXPECT_NE(text_0, text_1); 383 EXPECT_NE(text_0, text_1);
384 384
385 // Cancel (block) this frame. 385 // Cancel (block) this frame.
386 infobar_delegate_1->Cancel(); 386 infobar_delegate_1->Cancel();
387 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); 387 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK);
388 CheckPermissionMessageSent(1, false); 388 CheckPermissionMessageSent(1, false);
389 infobar_service()->RemoveInfoBar(infobar_1); 389 infobar_manager().RemoveInfoBar(infobar_1);
390 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 390 EXPECT_EQ(1U, closed_infobar_tracker_.size());
391 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); 391 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
392 EXPECT_EQ(0U, infobar_service()->infobar_count()); 392 EXPECT_EQ(0U, infobar_manager().infobar_count());
393 // Ensure the persisted permissions are ok. 393 // Ensure the persisted permissions are ok.
394 EXPECT_EQ(CONTENT_SETTING_ALLOW, 394 EXPECT_EQ(CONTENT_SETTING_ALLOW,
395 profile()->GetHostContentSettingsMap()->GetContentSetting( 395 profile()->GetHostContentSettingsMap()->GetContentSetting(
396 requesting_frame_0, requesting_frame_0, 396 requesting_frame_0, requesting_frame_0,
397 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 397 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
398 398
399 EXPECT_EQ(CONTENT_SETTING_BLOCK, 399 EXPECT_EQ(CONTENT_SETTING_BLOCK,
400 profile()->GetHostContentSettingsMap()->GetContentSetting( 400 profile()->GetHostContentSettingsMap()->GetContentSetting(
401 requesting_frame_1, requesting_frame_0, 401 requesting_frame_1, requesting_frame_0,
402 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 402 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
403 } 403 }
404 404
405 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { 405 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) {
406 GURL url_a("http://www.example.com/geolocation#a"); 406 GURL url_a("http://www.example.com/geolocation#a");
407 GURL url_b("http://www.example.com/geolocation#b"); 407 GURL url_b("http://www.example.com/geolocation#b");
408 408
409 // Navigate to the first url and check permission is requested. 409 // Navigate to the first url and check permission is requested.
410 NavigateAndCommit(url_a); 410 NavigateAndCommit(url_a);
411 EXPECT_EQ(0U, infobar_service()->infobar_count()); 411 EXPECT_EQ(0U, infobar_manager().infobar_count());
412 RequestGeolocationPermission(RequestID(0), url_a); 412 RequestGeolocationPermission(RequestID(0), url_a);
413 ASSERT_EQ(1U, infobar_service()->infobar_count()); 413 ASSERT_EQ(1U, infobar_manager().infobar_count());
414 InfoBar* infobar = infobar_service()->infobar_at(0); 414 InfoBar* infobar = infobar_manager().infobar_at(0);
415 ConfirmInfoBarDelegate* infobar_delegate = 415 ConfirmInfoBarDelegate* infobar_delegate =
416 infobar->delegate()->AsConfirmInfoBarDelegate(); 416 infobar->delegate()->AsConfirmInfoBarDelegate();
417 ASSERT_TRUE(infobar_delegate); 417 ASSERT_TRUE(infobar_delegate);
418 418
419 // Change the hash, we'll still be on the same page. 419 // Change the hash, we'll still be on the same page.
420 NavigateAndCommit(url_b); 420 NavigateAndCommit(url_b);
421 421
422 // Accept. 422 // Accept.
423 infobar_delegate->Accept(); 423 infobar_delegate->Accept();
424 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); 424 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW);
425 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); 425 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW);
426 CheckPermissionMessageSent(0, true); 426 CheckPermissionMessageSent(0, true);
427 427
428 // Cleanup. 428 // Cleanup.
429 infobar_service()->RemoveInfoBar(infobar); 429 infobar_manager().RemoveInfoBar(infobar);
430 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 430 EXPECT_EQ(1U, closed_infobar_tracker_.size());
431 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); 431 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
432 } 432 }
433 433
434 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { 434 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) {
435 GURL requesting_frame("file://example/geolocation.html"); 435 GURL requesting_frame("file://example/geolocation.html");
436 NavigateAndCommit(requesting_frame); 436 NavigateAndCommit(requesting_frame);
437 EXPECT_EQ(0U, infobar_service()->infobar_count()); 437 EXPECT_EQ(0U, infobar_manager().infobar_count());
438 RequestGeolocationPermission(RequestID(0), requesting_frame); 438 RequestGeolocationPermission(RequestID(0), requesting_frame);
439 EXPECT_EQ(1U, infobar_service()->infobar_count()); 439 EXPECT_EQ(1U, infobar_manager().infobar_count());
440 InfoBar* infobar = infobar_service()->infobar_at(0); 440 InfoBar* infobar = infobar_manager().infobar_at(0);
441 ConfirmInfoBarDelegate* infobar_delegate = 441 ConfirmInfoBarDelegate* infobar_delegate =
442 infobar->delegate()->AsConfirmInfoBarDelegate(); 442 infobar->delegate()->AsConfirmInfoBarDelegate();
443 ASSERT_TRUE(infobar_delegate); 443 ASSERT_TRUE(infobar_delegate);
444 // Accept the frame. 444 // Accept the frame.
445 infobar_delegate->Accept(); 445 infobar_delegate->Accept();
446 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); 446 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
447 CheckPermissionMessageSent(0, true); 447 CheckPermissionMessageSent(0, true);
448 infobar_service()->RemoveInfoBar(infobar); 448 infobar_manager().RemoveInfoBar(infobar);
449 449
450 // Make sure the setting is not stored. 450 // Make sure the setting is not stored.
451 EXPECT_EQ(CONTENT_SETTING_ASK, 451 EXPECT_EQ(CONTENT_SETTING_ASK,
452 profile()->GetHostContentSettingsMap()->GetContentSetting( 452 profile()->GetHostContentSettingsMap()->GetContentSetting(
453 requesting_frame, 453 requesting_frame,
454 requesting_frame, 454 requesting_frame,
455 CONTENT_SETTINGS_TYPE_GEOLOCATION, 455 CONTENT_SETTINGS_TYPE_GEOLOCATION,
456 std::string())); 456 std::string()));
457 } 457 }
458 458
459 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { 459 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) {
460 GURL requesting_frame_0("http://www.example.com/geolocation"); 460 GURL requesting_frame_0("http://www.example.com/geolocation");
461 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 461 GURL requesting_frame_1("http://www.example-2.com/geolocation");
462 EXPECT_EQ(CONTENT_SETTING_ASK, 462 EXPECT_EQ(CONTENT_SETTING_ASK,
463 profile()->GetHostContentSettingsMap()->GetContentSetting( 463 profile()->GetHostContentSettingsMap()->GetContentSetting(
464 requesting_frame_0, requesting_frame_0, 464 requesting_frame_0, requesting_frame_0,
465 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 465 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
466 466
467 EXPECT_EQ(CONTENT_SETTING_ASK, 467 EXPECT_EQ(CONTENT_SETTING_ASK,
468 profile()->GetHostContentSettingsMap()->GetContentSetting( 468 profile()->GetHostContentSettingsMap()->GetContentSetting(
469 requesting_frame_1, requesting_frame_0, 469 requesting_frame_1, requesting_frame_0,
470 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 470 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
471 471
472 NavigateAndCommit(requesting_frame_0); 472 NavigateAndCommit(requesting_frame_0);
473 EXPECT_EQ(0U, infobar_service()->infobar_count()); 473 EXPECT_EQ(0U, infobar_manager().infobar_count());
474 // Request permission for two frames. 474 // Request permission for two frames.
475 RequestGeolocationPermission(RequestID(0), requesting_frame_0); 475 RequestGeolocationPermission(RequestID(0), requesting_frame_0);
476 RequestGeolocationPermission(RequestID(1), requesting_frame_1); 476 RequestGeolocationPermission(RequestID(1), requesting_frame_1);
477 ASSERT_EQ(1U, infobar_service()->infobar_count()); 477 ASSERT_EQ(1U, infobar_manager().infobar_count());
478 478
479 InfoBar* infobar_0 = infobar_service()->infobar_at(0); 479 InfoBar* infobar_0 = infobar_manager().infobar_at(0);
480 ConfirmInfoBarDelegate* infobar_delegate_0 = 480 ConfirmInfoBarDelegate* infobar_delegate_0 =
481 infobar_0->delegate()->AsConfirmInfoBarDelegate(); 481 infobar_0->delegate()->AsConfirmInfoBarDelegate();
482 ASSERT_TRUE(infobar_delegate_0); 482 ASSERT_TRUE(infobar_delegate_0);
483 base::string16 text_0 = infobar_delegate_0->GetMessageText(); 483 base::string16 text_0 = infobar_delegate_0->GetMessageText();
484 484
485 // Simulate the frame going away, ensure the infobar for this frame 485 // Simulate the frame going away, ensure the infobar for this frame
486 // is removed and the next pending infobar is created. 486 // is removed and the next pending infobar is created.
487 CancelGeolocationPermissionRequest(RequestID(0), requesting_frame_0); 487 CancelGeolocationPermissionRequest(RequestID(0), requesting_frame_0);
488 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 488 EXPECT_EQ(1U, closed_infobar_tracker_.size());
489 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); 489 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0));
490 closed_infobar_tracker_.Clear(); 490 closed_infobar_tracker_.Clear();
491 ASSERT_EQ(1U, infobar_service()->infobar_count()); 491 ASSERT_EQ(1U, infobar_manager().infobar_count());
492 492
493 InfoBar* infobar_1 = infobar_service()->infobar_at(0); 493 InfoBar* infobar_1 = infobar_manager().infobar_at(0);
494 ConfirmInfoBarDelegate* infobar_delegate_1 = 494 ConfirmInfoBarDelegate* infobar_delegate_1 =
495 infobar_1->delegate()->AsConfirmInfoBarDelegate(); 495 infobar_1->delegate()->AsConfirmInfoBarDelegate();
496 ASSERT_TRUE(infobar_delegate_1); 496 ASSERT_TRUE(infobar_delegate_1);
497 base::string16 text_1 = infobar_delegate_1->GetMessageText(); 497 base::string16 text_1 = infobar_delegate_1->GetMessageText();
498 EXPECT_NE(text_0, text_1); 498 EXPECT_NE(text_0, text_1);
499 499
500 // Allow this frame. 500 // Allow this frame.
501 infobar_delegate_1->Accept(); 501 infobar_delegate_1->Accept();
502 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); 502 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW);
503 CheckPermissionMessageSent(1, true); 503 CheckPermissionMessageSent(1, true);
504 infobar_service()->RemoveInfoBar(infobar_1); 504 infobar_manager().RemoveInfoBar(infobar_1);
505 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 505 EXPECT_EQ(1U, closed_infobar_tracker_.size());
506 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); 506 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
507 EXPECT_EQ(0U, infobar_service()->infobar_count()); 507 EXPECT_EQ(0U, infobar_manager().infobar_count());
508 // Ensure the persisted permissions are ok. 508 // Ensure the persisted permissions are ok.
509 EXPECT_EQ(CONTENT_SETTING_ASK, 509 EXPECT_EQ(CONTENT_SETTING_ASK,
510 profile()->GetHostContentSettingsMap()->GetContentSetting( 510 profile()->GetHostContentSettingsMap()->GetContentSetting(
511 requesting_frame_0, requesting_frame_0, 511 requesting_frame_0, requesting_frame_0,
512 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 512 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
513 513
514 EXPECT_EQ(CONTENT_SETTING_ALLOW, 514 EXPECT_EQ(CONTENT_SETTING_ALLOW,
515 profile()->GetHostContentSettingsMap()->GetContentSetting( 515 profile()->GetHostContentSettingsMap()->GetContentSetting(
516 requesting_frame_1, requesting_frame_0, 516 requesting_frame_1, requesting_frame_0,
517 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 517 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
518 } 518 }
519 519
520 TEST_F(GeolocationPermissionContextTests, InvalidURL) { 520 TEST_F(GeolocationPermissionContextTests, InvalidURL) {
521 GURL invalid_embedder("about:blank"); 521 GURL invalid_embedder("about:blank");
522 GURL requesting_frame; 522 GURL requesting_frame;
523 NavigateAndCommit(invalid_embedder); 523 NavigateAndCommit(invalid_embedder);
524 EXPECT_EQ(0U, infobar_service()->infobar_count()); 524 EXPECT_EQ(0U, infobar_manager().infobar_count());
525 RequestGeolocationPermission(RequestID(0), requesting_frame); 525 RequestGeolocationPermission(RequestID(0), requesting_frame);
526 EXPECT_EQ(0U, infobar_service()->infobar_count()); 526 EXPECT_EQ(0U, infobar_manager().infobar_count());
527 CheckPermissionMessageSent(0, false); 527 CheckPermissionMessageSent(0, false);
528 } 528 }
529 529
530 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { 530 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) {
531 GURL url_a("http://www.example.com/geolocation"); 531 GURL url_a("http://www.example.com/geolocation");
532 GURL url_b("http://www.example-2.com/geolocation"); 532 GURL url_b("http://www.example-2.com/geolocation");
533 NavigateAndCommit(url_a); 533 NavigateAndCommit(url_a);
534 AddNewTab(url_b); 534 AddNewTab(url_b);
535 AddNewTab(url_a); 535 AddNewTab(url_a);
536 536
537 EXPECT_EQ(0U, infobar_service()->infobar_count()); 537 EXPECT_EQ(0U, infobar_manager().infobar_count());
538 RequestGeolocationPermission(RequestID(0), url_a); 538 RequestGeolocationPermission(RequestID(0), url_a);
539 ASSERT_EQ(1U, infobar_service()->infobar_count()); 539 ASSERT_EQ(1U, infobar_manager().infobar_count());
540 540
541 RequestGeolocationPermission(RequestIDForTab(0, 0), url_b); 541 RequestGeolocationPermission(RequestIDForTab(0, 0), url_b);
542 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 542 EXPECT_EQ(1U, infobar_manager_for_tab(0).infobar_count());
543 543
544 RequestGeolocationPermission(RequestIDForTab(1, 0), url_a); 544 RequestGeolocationPermission(RequestIDForTab(1, 0), url_a);
545 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); 545 ASSERT_EQ(1U, infobar_manager_for_tab(1).infobar_count());
546 546
547 InfoBar* removed_infobar = infobar_service_for_tab(1)->infobar_at(0); 547 InfoBar* removed_infobar = infobar_manager_for_tab(1).infobar_at(0);
548 548
549 // Accept the first tab. 549 // Accept the first tab.
550 InfoBar* infobar_0 = infobar_service()->infobar_at(0); 550 InfoBar* infobar_0 = infobar_manager().infobar_at(0);
551 ConfirmInfoBarDelegate* infobar_delegate_0 = 551 ConfirmInfoBarDelegate* infobar_delegate_0 =
552 infobar_0->delegate()->AsConfirmInfoBarDelegate(); 552 infobar_0->delegate()->AsConfirmInfoBarDelegate();
553 ASSERT_TRUE(infobar_delegate_0); 553 ASSERT_TRUE(infobar_delegate_0);
554 infobar_delegate_0->Accept(); 554 infobar_delegate_0->Accept();
555 CheckPermissionMessageSent(0, true); 555 CheckPermissionMessageSent(0, true);
556 infobar_service()->RemoveInfoBar(infobar_0); 556 infobar_manager().RemoveInfoBar(infobar_0);
557 EXPECT_EQ(2U, closed_infobar_tracker_.size()); 557 EXPECT_EQ(2U, closed_infobar_tracker_.size());
558 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); 558 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0));
559 // Now the infobar for the tab with the same origin should have gone. 559 // Now the infobar for the tab with the same origin should have gone.
560 EXPECT_EQ(0U, infobar_service_for_tab(1)->infobar_count()); 560 EXPECT_EQ(0U, infobar_manager_for_tab(1).infobar_count());
561 CheckPermissionMessageSentForTab(1, 0, true); 561 CheckPermissionMessageSentForTab(1, 0, true);
562 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); 562 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar));
563 closed_infobar_tracker_.Clear(); 563 closed_infobar_tracker_.Clear();
564 564
565 // But the other tab should still have the info bar... 565 // But the other tab should still have the info bar...
566 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 566 ASSERT_EQ(1U, infobar_manager_for_tab(0).infobar_count());
567 InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); 567 InfoBar* infobar_1 = infobar_manager_for_tab(0).infobar_at(0);
568 ConfirmInfoBarDelegate* infobar_delegate_1 = 568 ConfirmInfoBarDelegate* infobar_delegate_1 =
569 infobar_1->delegate()->AsConfirmInfoBarDelegate(); 569 infobar_1->delegate()->AsConfirmInfoBarDelegate();
570 ASSERT_TRUE(infobar_delegate_1); 570 ASSERT_TRUE(infobar_delegate_1);
571 infobar_delegate_1->Cancel(); 571 infobar_delegate_1->Cancel();
572 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); 572 infobar_manager_for_tab(0).RemoveInfoBar(infobar_1);
573 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 573 EXPECT_EQ(1U, closed_infobar_tracker_.size());
574 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); 574 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
575 } 575 }
576 576
577 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { 577 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
578 GURL url_a("http://www.example.com/geolocation"); 578 GURL url_a("http://www.example.com/geolocation");
579 GURL url_b("http://www.example-2.com/geolocation"); 579 GURL url_b("http://www.example-2.com/geolocation");
580 NavigateAndCommit(url_a); 580 NavigateAndCommit(url_a);
581 AddNewTab(url_a); 581 AddNewTab(url_a);
582 582
583 EXPECT_EQ(0U, infobar_service()->infobar_count()); 583 EXPECT_EQ(0U, infobar_manager().infobar_count());
584 RequestGeolocationPermission(RequestID(0), url_a); 584 RequestGeolocationPermission(RequestID(0), url_a);
585 ASSERT_EQ(1U, infobar_service()->infobar_count()); 585 ASSERT_EQ(1U, infobar_manager().infobar_count());
586 586
587 RequestGeolocationPermission(RequestIDForTab(0, 0), url_a); 587 RequestGeolocationPermission(RequestIDForTab(0, 0), url_a);
588 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 588 EXPECT_EQ(1U, infobar_manager_for_tab(0).infobar_count());
589 589
590 RequestGeolocationPermission(RequestIDForTab(0, 1), url_b); 590 RequestGeolocationPermission(RequestIDForTab(0, 1), url_b);
591 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 591 ASSERT_EQ(1U, infobar_manager_for_tab(0).infobar_count());
592 592
593 InfoBar* removed_infobar = infobar_service()->infobar_at(0); 593 InfoBar* removed_infobar = infobar_manager().infobar_at(0);
594 594
595 // Accept the second tab. 595 // Accept the second tab.
596 InfoBar* infobar_0 = infobar_service_for_tab(0)->infobar_at(0); 596 InfoBar* infobar_0 = infobar_manager_for_tab(0).infobar_at(0);
597 ConfirmInfoBarDelegate* infobar_delegate_0 = 597 ConfirmInfoBarDelegate* infobar_delegate_0 =
598 infobar_0->delegate()->AsConfirmInfoBarDelegate(); 598 infobar_0->delegate()->AsConfirmInfoBarDelegate();
599 ASSERT_TRUE(infobar_delegate_0); 599 ASSERT_TRUE(infobar_delegate_0);
600 infobar_delegate_0->Accept(); 600 infobar_delegate_0->Accept();
601 CheckPermissionMessageSentForTab(0, 0, true); 601 CheckPermissionMessageSentForTab(0, 0, true);
602 infobar_service_for_tab(0)->RemoveInfoBar(infobar_0); 602 infobar_manager_for_tab(0).RemoveInfoBar(infobar_0);
603 EXPECT_EQ(2U, closed_infobar_tracker_.size()); 603 EXPECT_EQ(2U, closed_infobar_tracker_.size());
604 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); 604 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0));
605 // Now the infobar for the tab with the same origin should have gone. 605 // Now the infobar for the tab with the same origin should have gone.
606 EXPECT_EQ(0U, infobar_service()->infobar_count()); 606 EXPECT_EQ(0U, infobar_manager().infobar_count());
607 CheckPermissionMessageSent(0, true); 607 CheckPermissionMessageSent(0, true);
608 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); 608 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar));
609 closed_infobar_tracker_.Clear(); 609 closed_infobar_tracker_.Clear();
610 610
611 // And we should have the queued infobar displayed now. 611 // And we should have the queued infobar displayed now.
612 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 612 ASSERT_EQ(1U, infobar_manager_for_tab(0).infobar_count());
613 613
614 // Accept the second infobar. 614 // Accept the second infobar.
615 InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); 615 InfoBar* infobar_1 = infobar_manager_for_tab(0).infobar_at(0);
616 ConfirmInfoBarDelegate* infobar_delegate_1 = 616 ConfirmInfoBarDelegate* infobar_delegate_1 =
617 infobar_1->delegate()->AsConfirmInfoBarDelegate(); 617 infobar_1->delegate()->AsConfirmInfoBarDelegate();
618 ASSERT_TRUE(infobar_delegate_1); 618 ASSERT_TRUE(infobar_delegate_1);
619 infobar_delegate_1->Accept(); 619 infobar_delegate_1->Accept();
620 CheckPermissionMessageSentForTab(0, 1, true); 620 CheckPermissionMessageSentForTab(0, 1, true);
621 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); 621 infobar_manager_for_tab(0).RemoveInfoBar(infobar_1);
622 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 622 EXPECT_EQ(1U, closed_infobar_tracker_.size());
623 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); 623 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1));
624 } 624 }
625 625
626 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { 626 TEST_F(GeolocationPermissionContextTests, TabDestroyed) {
627 GURL requesting_frame_0("http://www.example.com/geolocation"); 627 GURL requesting_frame_0("http://www.example.com/geolocation");
628 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 628 GURL requesting_frame_1("http://www.example-2.com/geolocation");
629 EXPECT_EQ(CONTENT_SETTING_ASK, 629 EXPECT_EQ(CONTENT_SETTING_ASK,
630 profile()->GetHostContentSettingsMap()->GetContentSetting( 630 profile()->GetHostContentSettingsMap()->GetContentSetting(
631 requesting_frame_0, requesting_frame_0, 631 requesting_frame_0, requesting_frame_0,
632 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 632 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
633 633
634 EXPECT_EQ(CONTENT_SETTING_ASK, 634 EXPECT_EQ(CONTENT_SETTING_ASK,
635 profile()->GetHostContentSettingsMap()->GetContentSetting( 635 profile()->GetHostContentSettingsMap()->GetContentSetting(
636 requesting_frame_1, requesting_frame_0, 636 requesting_frame_1, requesting_frame_0,
637 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 637 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
638 638
639 NavigateAndCommit(requesting_frame_0); 639 NavigateAndCommit(requesting_frame_0);
640 EXPECT_EQ(0U, infobar_service()->infobar_count()); 640 EXPECT_EQ(0U, infobar_manager().infobar_count());
641 // Request permission for two frames. 641 // Request permission for two frames.
642 RequestGeolocationPermission(RequestID(0), requesting_frame_0); 642 RequestGeolocationPermission(RequestID(0), requesting_frame_0);
643 RequestGeolocationPermission(RequestID(1), requesting_frame_1); 643 RequestGeolocationPermission(RequestID(1), requesting_frame_1);
644 // Ensure only one infobar is created. 644 // Ensure only one infobar is created.
645 ASSERT_EQ(1U, infobar_service()->infobar_count()); 645 ASSERT_EQ(1U, infobar_manager().infobar_count());
646 InfoBar* infobar = infobar_service()->infobar_at(0); 646 InfoBar* infobar = infobar_manager().infobar_at(0);
647 647
648 // Delete the tab contents. 648 // Delete the tab contents.
649 DeleteContents(); 649 DeleteContents();
650 650
651 // During contents destruction, the infobar will have been closed, and the 651 // During contents destruction, the infobar will have been closed, and the
652 // pending request should have been cleared without an infobar being created. 652 // pending request should have been cleared without an infobar being created.
653 ASSERT_EQ(1U, closed_infobar_tracker_.size()); 653 ASSERT_EQ(1U, closed_infobar_tracker_.size());
654 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); 654 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar));
655 } 655 }
656 656
657 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { 657 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) {
658 GURL requesting_frame_0("http://www.example.com/geolocation"); 658 GURL requesting_frame_0("http://www.example.com/geolocation");
659 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 659 GURL requesting_frame_1("http://www.example-2.com/geolocation");
660 NavigateAndCommit(requesting_frame_0); 660 NavigateAndCommit(requesting_frame_0);
661 NavigateAndCommit(requesting_frame_1); 661 NavigateAndCommit(requesting_frame_1);
662 EXPECT_EQ(0U, infobar_service()->infobar_count()); 662 EXPECT_EQ(0U, infobar_manager().infobar_count());
663 // Go back: navigate to a pending entry before requesting geolocation 663 // Go back: navigate to a pending entry before requesting geolocation
664 // permission. 664 // permission.
665 web_contents()->GetController().GoBack(); 665 web_contents()->GetController().GoBack();
666 // Request permission for the committed frame (not the pending one). 666 // Request permission for the committed frame (not the pending one).
667 RequestGeolocationPermission(RequestID(0), requesting_frame_1); 667 RequestGeolocationPermission(RequestID(0), requesting_frame_1);
668 // Ensure the infobar is created. 668 // Ensure the infobar is created.
669 ASSERT_EQ(1U, infobar_service()->infobar_count()); 669 ASSERT_EQ(1U, infobar_manager().infobar_count());
670 InfoBarDelegate* infobar_delegate = 670 InfoBarDelegate* infobar_delegate =
671 infobar_service()->infobar_at(0)->delegate(); 671 infobar_manager().infobar_at(0)->delegate();
672 ASSERT_TRUE(infobar_delegate); 672 ASSERT_TRUE(infobar_delegate);
673 // Ensure the infobar wouldn't expire for a navigation to the committed entry. 673 // Ensure the infobar wouldn't expire for a navigation to the committed entry.
674 content::LoadCommittedDetails details; 674 content::LoadCommittedDetails load_details;
675 details.entry = web_contents()->GetController().GetLastCommittedEntry(); 675 load_details.entry = web_contents()->GetController().GetLastCommittedEntry();
676 EXPECT_FALSE(infobar_delegate->ShouldExpire(details)); 676 InfoBarDelegate::NavigationDetails navigation_details =
677 InfoBarService::NavigationDetailsFromLoadCommittedDetails(load_details);
678 EXPECT_FALSE(infobar_delegate->ShouldExpire(navigation_details));
677 // Ensure the infobar will expire when we commit the pending navigation. 679 // Ensure the infobar will expire when we commit the pending navigation.
678 details.entry = web_contents()->GetController().GetActiveEntry(); 680 load_details.entry = web_contents()->GetController().GetActiveEntry();
679 EXPECT_TRUE(infobar_delegate->ShouldExpire(details)); 681 navigation_details =
682 InfoBarService::NavigationDetailsFromLoadCommittedDetails(load_details);
683 EXPECT_TRUE(infobar_delegate->ShouldExpire(navigation_details));
680 684
681 // Delete the tab contents. 685 // Delete the tab contents.
682 DeleteContents(); 686 DeleteContents();
683 } 687 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698