OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "chrome/browser/content_settings/host_content_settings_map.h" | 12 #include "chrome/browser/content_settings/host_content_settings_map.h" |
13 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 13 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
14 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" | 14 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" |
15 #include "chrome/browser/infobars/infobar.h" | 15 #include "chrome/browser/infobars/infobar.h" |
16 #include "chrome/browser/infobars/infobar_tab_helper.h" | 16 #include "chrome/browser/infobars/infobar_tab_helper.h" |
17 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 17 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
19 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" |
20 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
21 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
22 #include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h
" | 22 #include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h
" |
23 #include "content/browser/geolocation/location_arbitrator.h" | 23 #include "content/browser/geolocation/location_arbitrator.h" |
24 #include "content/browser/geolocation/location_provider.h" | 24 #include "content/browser/geolocation/location_provider.h" |
25 #include "content/browser/geolocation/mock_location_provider.h" | 25 #include "content/browser/geolocation/mock_location_provider.h" |
26 #include "content/browser/renderer_host/mock_render_process_host.h" | 26 #include "content/browser/renderer_host/mock_render_process_host.h" |
| 27 #include "content/browser/tab_contents/navigation_details.h" |
27 #include "content/browser/tab_contents/test_tab_contents.h" | 28 #include "content/browser/tab_contents/test_tab_contents.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/test/test_browser_thread.h" | 31 #include "content/test/test_browser_thread.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
32 | 33 |
33 using content::BrowserThread; | 34 using content::BrowserThread; |
34 | 35 |
35 // ClosedDelegateTracker ------------------------------------------------------ | 36 // ClosedDelegateTracker ------------------------------------------------------ |
36 | 37 |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 // Ensure only one infobar is created. | 564 // Ensure only one infobar is created. |
564 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); | 565 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); |
565 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> | 566 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> |
566 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 567 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
567 ASSERT_TRUE(infobar_0); | 568 ASSERT_TRUE(infobar_0); |
568 | 569 |
569 // Delete the tab contents. | 570 // Delete the tab contents. |
570 DeleteContents(); | 571 DeleteContents(); |
571 infobar_0->InfoBarClosed(); | 572 infobar_0->InfoBarClosed(); |
572 } | 573 } |
| 574 |
| 575 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { |
| 576 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 577 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 578 NavigateAndCommit(requesting_frame_0); |
| 579 NavigateAndCommit(requesting_frame_1); |
| 580 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); |
| 581 // Go back: navigate to a pending entry before requesting geolocation |
| 582 // permission. |
| 583 contents()->controller().GoBack(); |
| 584 // Request permission for the committed frame (not the pending one). |
| 585 RequestGeolocationPermission( |
| 586 process_id(), render_id(), bridge_id(), requesting_frame_1); |
| 587 // Ensure the infobar is created. |
| 588 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); |
| 589 InfoBarDelegate* infobar_0 = infobar_tab_helper()->GetInfoBarDelegateAt(0); |
| 590 ASSERT_TRUE(infobar_0); |
| 591 // Ensure the infobar is not yet expired. |
| 592 content::LoadCommittedDetails details; |
| 593 details.entry = contents()->controller().GetLastCommittedEntry(); |
| 594 ASSERT_FALSE(infobar_0->ShouldExpire(details)); |
| 595 // Commit the "GoBack()" above, and ensure the infobar is now expired. |
| 596 contents()->CommitPendingNavigation(); |
| 597 details.entry = contents()->controller().GetLastCommittedEntry(); |
| 598 ASSERT_TRUE(infobar_0->ShouldExpire(details)); |
| 599 |
| 600 // Delete the tab contents. |
| 601 DeleteContents(); |
| 602 infobar_0->InfoBarClosed(); |
| 603 } |
OLD | NEW |