OLD | NEW |
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" | |
23 #include "chrome/browser/infobars/infobar_service.h" | 22 #include "chrome/browser/infobars/infobar_service.h" |
24 #include "chrome/browser/infobars/infobar_service.h" | 23 #include "chrome/browser/infobars/infobar_service.h" |
25 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 24 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
26 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
| 26 #include "components/infobars/core/infobar.h" |
27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
28 #include "content/public/browser/navigation_details.h" | 28 #include "content/public/browser/navigation_details.h" |
29 #include "content/public/browser/notification_registrar.h" | 29 #include "content/public/browser/notification_registrar.h" |
30 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
31 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
32 #include "content/public/test/mock_render_process_host.h" | 32 #include "content/public/test/mock_render_process_host.h" |
33 #include "content/public/test/test_renderer_host.h" | 33 #include "content/public/test/test_renderer_host.h" |
34 #include "content/public/test/web_contents_tester.h" | 34 #include "content/public/test/web_contents_tester.h" |
35 #include "extensions/browser/view_type_utils.h" | 35 #include "extensions/browser/view_type_utils.h" |
36 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 15 matching lines...) Expand all Loading... |
52 ClosedInfoBarTracker(); | 52 ClosedInfoBarTracker(); |
53 virtual ~ClosedInfoBarTracker(); | 53 virtual ~ClosedInfoBarTracker(); |
54 | 54 |
55 // content::NotificationObserver: | 55 // content::NotificationObserver: |
56 virtual void Observe(int type, | 56 virtual void Observe(int type, |
57 const content::NotificationSource& source, | 57 const content::NotificationSource& source, |
58 const content::NotificationDetails& details) OVERRIDE; | 58 const content::NotificationDetails& details) OVERRIDE; |
59 | 59 |
60 size_t size() const { return removed_infobars_.size(); } | 60 size_t size() const { return removed_infobars_.size(); } |
61 | 61 |
62 bool Contains(InfoBar* infobar) const; | 62 bool Contains(infobars::InfoBar* infobar) const; |
63 void Clear(); | 63 void Clear(); |
64 | 64 |
65 private: | 65 private: |
66 FRIEND_TEST_ALL_PREFIXES(GeolocationPermissionContextTests, TabDestroyed); | 66 FRIEND_TEST_ALL_PREFIXES(GeolocationPermissionContextTests, TabDestroyed); |
67 content::NotificationRegistrar registrar_; | 67 content::NotificationRegistrar registrar_; |
68 std::set<InfoBar*> removed_infobars_; | 68 std::set<infobars::InfoBar*> removed_infobars_; |
69 }; | 69 }; |
70 | 70 |
71 ClosedInfoBarTracker::ClosedInfoBarTracker() { | 71 ClosedInfoBarTracker::ClosedInfoBarTracker() { |
72 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 72 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
73 content::NotificationService::AllSources()); | 73 content::NotificationService::AllSources()); |
74 } | 74 } |
75 | 75 |
76 ClosedInfoBarTracker::~ClosedInfoBarTracker() { | 76 ClosedInfoBarTracker::~ClosedInfoBarTracker() { |
77 } | 77 } |
78 | 78 |
79 void ClosedInfoBarTracker::Observe( | 79 void ClosedInfoBarTracker::Observe( |
80 int type, | 80 int type, |
81 const content::NotificationSource& source, | 81 const content::NotificationSource& source, |
82 const content::NotificationDetails& details) { | 82 const content::NotificationDetails& details) { |
83 DCHECK(type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED); | 83 DCHECK(type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED); |
84 removed_infobars_.insert( | 84 removed_infobars_.insert( |
85 content::Details<InfoBar::RemovedDetails>(details)->first); | 85 content::Details<infobars::InfoBar::RemovedDetails>(details)->first); |
86 } | 86 } |
87 | 87 |
88 bool ClosedInfoBarTracker::Contains(InfoBar* infobar) const { | 88 bool ClosedInfoBarTracker::Contains(infobars::InfoBar* infobar) const { |
89 return removed_infobars_.count(infobar) != 0; | 89 return removed_infobars_.count(infobar) != 0; |
90 } | 90 } |
91 | 91 |
92 void ClosedInfoBarTracker::Clear() { | 92 void ClosedInfoBarTracker::Clear() { |
93 removed_infobars_.clear(); | 93 removed_infobars_.clear(); |
94 } | 94 } |
95 | 95 |
96 | 96 |
97 // GeolocationPermissionContextTests ------------------------------------------ | 97 // GeolocationPermissionContextTests ------------------------------------------ |
98 | 98 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 } | 258 } |
259 | 259 |
260 // Tests ---------------------------------------------------------------------- | 260 // Tests ---------------------------------------------------------------------- |
261 | 261 |
262 TEST_F(GeolocationPermissionContextTests, SinglePermission) { | 262 TEST_F(GeolocationPermissionContextTests, SinglePermission) { |
263 GURL requesting_frame("http://www.example.com/geolocation"); | 263 GURL requesting_frame("http://www.example.com/geolocation"); |
264 NavigateAndCommit(requesting_frame); | 264 NavigateAndCommit(requesting_frame); |
265 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 265 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
266 RequestGeolocationPermission(RequestID(0), requesting_frame); | 266 RequestGeolocationPermission(RequestID(0), requesting_frame); |
267 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 267 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
268 InfoBar* infobar = infobar_service()->infobar_at(0); | 268 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
269 ConfirmInfoBarDelegate* infobar_delegate = | 269 ConfirmInfoBarDelegate* infobar_delegate = |
270 infobar->delegate()->AsConfirmInfoBarDelegate(); | 270 infobar->delegate()->AsConfirmInfoBarDelegate(); |
271 ASSERT_TRUE(infobar_delegate); | 271 ASSERT_TRUE(infobar_delegate); |
272 infobar_delegate->Cancel(); | 272 infobar_delegate->Cancel(); |
273 infobar_service()->RemoveInfoBar(infobar); | 273 infobar_service()->RemoveInfoBar(infobar); |
274 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 274 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
275 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 275 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
276 } | 276 } |
277 | 277 |
278 #if defined(OS_ANDROID) | 278 #if defined(OS_ANDROID) |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 requesting_frame_1, requesting_frame_0, | 351 requesting_frame_1, requesting_frame_0, |
352 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 352 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
353 | 353 |
354 NavigateAndCommit(requesting_frame_0); | 354 NavigateAndCommit(requesting_frame_0); |
355 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 355 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
356 // Request permission for two frames. | 356 // Request permission for two frames. |
357 RequestGeolocationPermission(RequestID(0), requesting_frame_0); | 357 RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
358 RequestGeolocationPermission(RequestID(1), requesting_frame_1); | 358 RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
359 // Ensure only one infobar is created. | 359 // Ensure only one infobar is created. |
360 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 360 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
361 InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 361 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); |
362 ConfirmInfoBarDelegate* infobar_delegate_0 = | 362 ConfirmInfoBarDelegate* infobar_delegate_0 = |
363 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 363 infobar_0->delegate()->AsConfirmInfoBarDelegate(); |
364 ASSERT_TRUE(infobar_delegate_0); | 364 ASSERT_TRUE(infobar_delegate_0); |
365 base::string16 text_0 = infobar_delegate_0->GetMessageText(); | 365 base::string16 text_0 = infobar_delegate_0->GetMessageText(); |
366 | 366 |
367 // Accept the first frame. | 367 // Accept the first frame. |
368 infobar_delegate_0->Accept(); | 368 infobar_delegate_0->Accept(); |
369 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); | 369 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
370 CheckPermissionMessageSent(0, true); | 370 CheckPermissionMessageSent(0, true); |
371 | 371 |
372 infobar_service()->RemoveInfoBar(infobar_0); | 372 infobar_service()->RemoveInfoBar(infobar_0); |
373 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 373 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
374 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 374 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); |
375 closed_infobar_tracker_.Clear(); | 375 closed_infobar_tracker_.Clear(); |
376 // Now we should have a new infobar for the second frame. | 376 // Now we should have a new infobar for the second frame. |
377 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 377 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
378 | 378 |
379 InfoBar* infobar_1 = infobar_service()->infobar_at(0); | 379 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); |
380 ConfirmInfoBarDelegate* infobar_delegate_1 = | 380 ConfirmInfoBarDelegate* infobar_delegate_1 = |
381 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 381 infobar_1->delegate()->AsConfirmInfoBarDelegate(); |
382 ASSERT_TRUE(infobar_delegate_1); | 382 ASSERT_TRUE(infobar_delegate_1); |
383 base::string16 text_1 = infobar_delegate_1->GetMessageText(); | 383 base::string16 text_1 = infobar_delegate_1->GetMessageText(); |
384 EXPECT_NE(text_0, text_1); | 384 EXPECT_NE(text_0, text_1); |
385 | 385 |
386 // Cancel (block) this frame. | 386 // Cancel (block) this frame. |
387 infobar_delegate_1->Cancel(); | 387 infobar_delegate_1->Cancel(); |
388 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); | 388 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); |
389 CheckPermissionMessageSent(1, false); | 389 CheckPermissionMessageSent(1, false); |
(...skipping 15 matching lines...) Expand all Loading... |
405 | 405 |
406 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { | 406 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { |
407 GURL url_a("http://www.example.com/geolocation#a"); | 407 GURL url_a("http://www.example.com/geolocation#a"); |
408 GURL url_b("http://www.example.com/geolocation#b"); | 408 GURL url_b("http://www.example.com/geolocation#b"); |
409 | 409 |
410 // Navigate to the first url and check permission is requested. | 410 // Navigate to the first url and check permission is requested. |
411 NavigateAndCommit(url_a); | 411 NavigateAndCommit(url_a); |
412 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 412 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
413 RequestGeolocationPermission(RequestID(0), url_a); | 413 RequestGeolocationPermission(RequestID(0), url_a); |
414 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 414 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
415 InfoBar* infobar = infobar_service()->infobar_at(0); | 415 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
416 ConfirmInfoBarDelegate* infobar_delegate = | 416 ConfirmInfoBarDelegate* infobar_delegate = |
417 infobar->delegate()->AsConfirmInfoBarDelegate(); | 417 infobar->delegate()->AsConfirmInfoBarDelegate(); |
418 ASSERT_TRUE(infobar_delegate); | 418 ASSERT_TRUE(infobar_delegate); |
419 | 419 |
420 // Change the hash, we'll still be on the same page. | 420 // Change the hash, we'll still be on the same page. |
421 NavigateAndCommit(url_b); | 421 NavigateAndCommit(url_b); |
422 | 422 |
423 // Accept. | 423 // Accept. |
424 infobar_delegate->Accept(); | 424 infobar_delegate->Accept(); |
425 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); | 425 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); |
426 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); | 426 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); |
427 CheckPermissionMessageSent(0, true); | 427 CheckPermissionMessageSent(0, true); |
428 | 428 |
429 // Cleanup. | 429 // Cleanup. |
430 infobar_service()->RemoveInfoBar(infobar); | 430 infobar_service()->RemoveInfoBar(infobar); |
431 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 431 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
432 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 432 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
433 } | 433 } |
434 | 434 |
435 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { | 435 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { |
436 GURL requesting_frame("file://example/geolocation.html"); | 436 GURL requesting_frame("file://example/geolocation.html"); |
437 NavigateAndCommit(requesting_frame); | 437 NavigateAndCommit(requesting_frame); |
438 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 438 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
439 RequestGeolocationPermission(RequestID(0), requesting_frame); | 439 RequestGeolocationPermission(RequestID(0), requesting_frame); |
440 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 440 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
441 InfoBar* infobar = infobar_service()->infobar_at(0); | 441 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
442 ConfirmInfoBarDelegate* infobar_delegate = | 442 ConfirmInfoBarDelegate* infobar_delegate = |
443 infobar->delegate()->AsConfirmInfoBarDelegate(); | 443 infobar->delegate()->AsConfirmInfoBarDelegate(); |
444 ASSERT_TRUE(infobar_delegate); | 444 ASSERT_TRUE(infobar_delegate); |
445 // Accept the frame. | 445 // Accept the frame. |
446 infobar_delegate->Accept(); | 446 infobar_delegate->Accept(); |
447 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 447 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
448 CheckPermissionMessageSent(0, true); | 448 CheckPermissionMessageSent(0, true); |
449 infobar_service()->RemoveInfoBar(infobar); | 449 infobar_service()->RemoveInfoBar(infobar); |
450 | 450 |
451 // Make sure the setting is not stored. | 451 // Make sure the setting is not stored. |
(...skipping 18 matching lines...) Expand all Loading... |
470 requesting_frame_1, requesting_frame_0, | 470 requesting_frame_1, requesting_frame_0, |
471 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 471 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
472 | 472 |
473 NavigateAndCommit(requesting_frame_0); | 473 NavigateAndCommit(requesting_frame_0); |
474 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 474 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
475 // Request permission for two frames. | 475 // Request permission for two frames. |
476 RequestGeolocationPermission(RequestID(0), requesting_frame_0); | 476 RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
477 RequestGeolocationPermission(RequestID(1), requesting_frame_1); | 477 RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
478 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 478 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
479 | 479 |
480 InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 480 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); |
481 ConfirmInfoBarDelegate* infobar_delegate_0 = | 481 ConfirmInfoBarDelegate* infobar_delegate_0 = |
482 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 482 infobar_0->delegate()->AsConfirmInfoBarDelegate(); |
483 ASSERT_TRUE(infobar_delegate_0); | 483 ASSERT_TRUE(infobar_delegate_0); |
484 base::string16 text_0 = infobar_delegate_0->GetMessageText(); | 484 base::string16 text_0 = infobar_delegate_0->GetMessageText(); |
485 | 485 |
486 // Simulate the frame going away, ensure the infobar for this frame | 486 // Simulate the frame going away, ensure the infobar for this frame |
487 // is removed and the next pending infobar is created. | 487 // is removed and the next pending infobar is created. |
488 CancelGeolocationPermissionRequest(RequestID(0), requesting_frame_0); | 488 CancelGeolocationPermissionRequest(RequestID(0), requesting_frame_0); |
489 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 489 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
490 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 490 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); |
491 closed_infobar_tracker_.Clear(); | 491 closed_infobar_tracker_.Clear(); |
492 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 492 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
493 | 493 |
494 InfoBar* infobar_1 = infobar_service()->infobar_at(0); | 494 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); |
495 ConfirmInfoBarDelegate* infobar_delegate_1 = | 495 ConfirmInfoBarDelegate* infobar_delegate_1 = |
496 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 496 infobar_1->delegate()->AsConfirmInfoBarDelegate(); |
497 ASSERT_TRUE(infobar_delegate_1); | 497 ASSERT_TRUE(infobar_delegate_1); |
498 base::string16 text_1 = infobar_delegate_1->GetMessageText(); | 498 base::string16 text_1 = infobar_delegate_1->GetMessageText(); |
499 EXPECT_NE(text_0, text_1); | 499 EXPECT_NE(text_0, text_1); |
500 | 500 |
501 // Allow this frame. | 501 // Allow this frame. |
502 infobar_delegate_1->Accept(); | 502 infobar_delegate_1->Accept(); |
503 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); | 503 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); |
504 CheckPermissionMessageSent(1, true); | 504 CheckPermissionMessageSent(1, true); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 538 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
539 RequestGeolocationPermission(RequestID(0), url_a); | 539 RequestGeolocationPermission(RequestID(0), url_a); |
540 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 540 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
541 | 541 |
542 RequestGeolocationPermission(RequestIDForTab(0, 0), url_b); | 542 RequestGeolocationPermission(RequestIDForTab(0, 0), url_b); |
543 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 543 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
544 | 544 |
545 RequestGeolocationPermission(RequestIDForTab(1, 0), url_a); | 545 RequestGeolocationPermission(RequestIDForTab(1, 0), url_a); |
546 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); | 546 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); |
547 | 547 |
548 InfoBar* removed_infobar = infobar_service_for_tab(1)->infobar_at(0); | 548 infobars::InfoBar* removed_infobar = |
| 549 infobar_service_for_tab(1)->infobar_at(0); |
549 | 550 |
550 // Accept the first tab. | 551 // Accept the first tab. |
551 InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 552 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); |
552 ConfirmInfoBarDelegate* infobar_delegate_0 = | 553 ConfirmInfoBarDelegate* infobar_delegate_0 = |
553 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 554 infobar_0->delegate()->AsConfirmInfoBarDelegate(); |
554 ASSERT_TRUE(infobar_delegate_0); | 555 ASSERT_TRUE(infobar_delegate_0); |
555 infobar_delegate_0->Accept(); | 556 infobar_delegate_0->Accept(); |
556 CheckPermissionMessageSent(0, true); | 557 CheckPermissionMessageSent(0, true); |
557 infobar_service()->RemoveInfoBar(infobar_0); | 558 infobar_service()->RemoveInfoBar(infobar_0); |
558 EXPECT_EQ(2U, closed_infobar_tracker_.size()); | 559 EXPECT_EQ(2U, closed_infobar_tracker_.size()); |
559 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 560 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); |
560 // Now the infobar for the tab with the same origin should have gone. | 561 // Now the infobar for the tab with the same origin should have gone. |
561 EXPECT_EQ(0U, infobar_service_for_tab(1)->infobar_count()); | 562 EXPECT_EQ(0U, infobar_service_for_tab(1)->infobar_count()); |
562 CheckPermissionMessageSentForTab(1, 0, true); | 563 CheckPermissionMessageSentForTab(1, 0, true); |
563 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); | 564 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); |
564 closed_infobar_tracker_.Clear(); | 565 closed_infobar_tracker_.Clear(); |
565 | 566 |
566 // But the other tab should still have the info bar... | 567 // But the other tab should still have the info bar... |
567 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 568 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
568 InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); | 569 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); |
569 ConfirmInfoBarDelegate* infobar_delegate_1 = | 570 ConfirmInfoBarDelegate* infobar_delegate_1 = |
570 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 571 infobar_1->delegate()->AsConfirmInfoBarDelegate(); |
571 ASSERT_TRUE(infobar_delegate_1); | 572 ASSERT_TRUE(infobar_delegate_1); |
572 infobar_delegate_1->Cancel(); | 573 infobar_delegate_1->Cancel(); |
573 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); | 574 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); |
574 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 575 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
575 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | 576 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); |
576 } | 577 } |
577 | 578 |
578 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { | 579 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { |
579 GURL url_a("http://www.example.com/geolocation"); | 580 GURL url_a("http://www.example.com/geolocation"); |
580 GURL url_b("http://www.example-2.com/geolocation"); | 581 GURL url_b("http://www.example-2.com/geolocation"); |
581 NavigateAndCommit(url_a); | 582 NavigateAndCommit(url_a); |
582 AddNewTab(url_a); | 583 AddNewTab(url_a); |
583 | 584 |
584 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 585 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
585 RequestGeolocationPermission(RequestID(0), url_a); | 586 RequestGeolocationPermission(RequestID(0), url_a); |
586 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 587 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
587 | 588 |
588 RequestGeolocationPermission(RequestIDForTab(0, 0), url_a); | 589 RequestGeolocationPermission(RequestIDForTab(0, 0), url_a); |
589 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 590 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
590 | 591 |
591 RequestGeolocationPermission(RequestIDForTab(0, 1), url_b); | 592 RequestGeolocationPermission(RequestIDForTab(0, 1), url_b); |
592 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 593 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
593 | 594 |
594 InfoBar* removed_infobar = infobar_service()->infobar_at(0); | 595 infobars::InfoBar* removed_infobar = infobar_service()->infobar_at(0); |
595 | 596 |
596 // Accept the second tab. | 597 // Accept the second tab. |
597 InfoBar* infobar_0 = infobar_service_for_tab(0)->infobar_at(0); | 598 infobars::InfoBar* infobar_0 = infobar_service_for_tab(0)->infobar_at(0); |
598 ConfirmInfoBarDelegate* infobar_delegate_0 = | 599 ConfirmInfoBarDelegate* infobar_delegate_0 = |
599 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 600 infobar_0->delegate()->AsConfirmInfoBarDelegate(); |
600 ASSERT_TRUE(infobar_delegate_0); | 601 ASSERT_TRUE(infobar_delegate_0); |
601 infobar_delegate_0->Accept(); | 602 infobar_delegate_0->Accept(); |
602 CheckPermissionMessageSentForTab(0, 0, true); | 603 CheckPermissionMessageSentForTab(0, 0, true); |
603 infobar_service_for_tab(0)->RemoveInfoBar(infobar_0); | 604 infobar_service_for_tab(0)->RemoveInfoBar(infobar_0); |
604 EXPECT_EQ(2U, closed_infobar_tracker_.size()); | 605 EXPECT_EQ(2U, closed_infobar_tracker_.size()); |
605 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 606 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); |
606 // Now the infobar for the tab with the same origin should have gone. | 607 // Now the infobar for the tab with the same origin should have gone. |
607 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 608 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
608 CheckPermissionMessageSent(0, true); | 609 CheckPermissionMessageSent(0, true); |
609 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); | 610 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); |
610 closed_infobar_tracker_.Clear(); | 611 closed_infobar_tracker_.Clear(); |
611 | 612 |
612 // And we should have the queued infobar displayed now. | 613 // And we should have the queued infobar displayed now. |
613 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 614 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
614 | 615 |
615 // Accept the second infobar. | 616 // Accept the second infobar. |
616 InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); | 617 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); |
617 ConfirmInfoBarDelegate* infobar_delegate_1 = | 618 ConfirmInfoBarDelegate* infobar_delegate_1 = |
618 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 619 infobar_1->delegate()->AsConfirmInfoBarDelegate(); |
619 ASSERT_TRUE(infobar_delegate_1); | 620 ASSERT_TRUE(infobar_delegate_1); |
620 infobar_delegate_1->Accept(); | 621 infobar_delegate_1->Accept(); |
621 CheckPermissionMessageSentForTab(0, 1, true); | 622 CheckPermissionMessageSentForTab(0, 1, true); |
622 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); | 623 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); |
623 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 624 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
624 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | 625 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); |
625 } | 626 } |
626 | 627 |
(...skipping 10 matching lines...) Expand all Loading... |
637 requesting_frame_1, requesting_frame_0, | 638 requesting_frame_1, requesting_frame_0, |
638 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 639 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
639 | 640 |
640 NavigateAndCommit(requesting_frame_0); | 641 NavigateAndCommit(requesting_frame_0); |
641 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 642 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
642 // Request permission for two frames. | 643 // Request permission for two frames. |
643 RequestGeolocationPermission(RequestID(0), requesting_frame_0); | 644 RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
644 RequestGeolocationPermission(RequestID(1), requesting_frame_1); | 645 RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
645 // Ensure only one infobar is created. | 646 // Ensure only one infobar is created. |
646 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 647 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
647 InfoBar* infobar = infobar_service()->infobar_at(0); | 648 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
648 | 649 |
649 // Delete the tab contents. | 650 // Delete the tab contents. |
650 DeleteContents(); | 651 DeleteContents(); |
651 | 652 |
652 // During contents destruction, the infobar will have been closed, and the | 653 // During contents destruction, the infobar will have been closed, and the |
653 // pending request should have been cleared without an infobar being created. | 654 // pending request should have been cleared without an infobar being created. |
654 ASSERT_EQ(1U, closed_infobar_tracker_.size()); | 655 ASSERT_EQ(1U, closed_infobar_tracker_.size()); |
655 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 656 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
656 } | 657 } |
657 | 658 |
658 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { | 659 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { |
659 GURL requesting_frame_0("http://www.example.com/geolocation"); | 660 GURL requesting_frame_0("http://www.example.com/geolocation"); |
660 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 661 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
661 NavigateAndCommit(requesting_frame_0); | 662 NavigateAndCommit(requesting_frame_0); |
662 NavigateAndCommit(requesting_frame_1); | 663 NavigateAndCommit(requesting_frame_1); |
663 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 664 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
664 // Go back: navigate to a pending entry before requesting geolocation | 665 // Go back: navigate to a pending entry before requesting geolocation |
665 // permission. | 666 // permission. |
666 web_contents()->GetController().GoBack(); | 667 web_contents()->GetController().GoBack(); |
667 // Request permission for the committed frame (not the pending one). | 668 // Request permission for the committed frame (not the pending one). |
668 RequestGeolocationPermission(RequestID(0), requesting_frame_1); | 669 RequestGeolocationPermission(RequestID(0), requesting_frame_1); |
669 // Ensure the infobar is created. | 670 // Ensure the infobar is created. |
670 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 671 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
671 InfoBarDelegate* infobar_delegate = | 672 infobars::InfoBarDelegate* infobar_delegate = |
672 infobar_service()->infobar_at(0)->delegate(); | 673 infobar_service()->infobar_at(0)->delegate(); |
673 ASSERT_TRUE(infobar_delegate); | 674 ASSERT_TRUE(infobar_delegate); |
674 // Ensure the infobar wouldn't expire for a navigation to the committed entry. | 675 // Ensure the infobar wouldn't expire for a navigation to the committed entry. |
675 content::LoadCommittedDetails details; | 676 content::LoadCommittedDetails details; |
676 details.entry = web_contents()->GetController().GetLastCommittedEntry(); | 677 details.entry = web_contents()->GetController().GetLastCommittedEntry(); |
677 EXPECT_FALSE(infobar_delegate->ShouldExpire( | 678 EXPECT_FALSE(infobar_delegate->ShouldExpire( |
678 InfoBarService::NavigationDetailsFromLoadCommittedDetails(details))); | 679 InfoBarService::NavigationDetailsFromLoadCommittedDetails(details))); |
679 // Ensure the infobar will expire when we commit the pending navigation. | 680 // Ensure the infobar will expire when we commit the pending navigation. |
680 details.entry = web_contents()->GetController().GetActiveEntry(); | 681 details.entry = web_contents()->GetController().GetActiveEntry(); |
681 EXPECT_TRUE(infobar_delegate->ShouldExpire( | 682 EXPECT_TRUE(infobar_delegate->ShouldExpire( |
682 InfoBarService::NavigationDetailsFromLoadCommittedDetails(details))); | 683 InfoBarService::NavigationDetailsFromLoadCommittedDetails(details))); |
683 | 684 |
684 // Delete the tab contents. | 685 // Delete the tab contents. |
685 DeleteContents(); | 686 DeleteContents(); |
686 } | 687 } |
OLD | NEW |