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 <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" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 void CheckTabContentsState(const GURL& requesting_frame, | 132 void CheckTabContentsState(const GURL& requesting_frame, |
133 ContentSetting expected_content_setting); | 133 ContentSetting expected_content_setting); |
134 | 134 |
135 scoped_refptr<ChromeGeolocationPermissionContext> | 135 scoped_refptr<ChromeGeolocationPermissionContext> |
136 geolocation_permission_context_; | 136 geolocation_permission_context_; |
137 ClosedDelegateTracker closed_delegate_tracker_; | 137 ClosedDelegateTracker closed_delegate_tracker_; |
138 ScopedVector<TabContentsWrapper> extra_tabs_; | 138 ScopedVector<TabContentsWrapper> extra_tabs_; |
139 | 139 |
140 private: | 140 private: |
141 // TabContentsWrapperTestHarness: | 141 // TabContentsWrapperTestHarness: |
142 virtual void SetUp(); | 142 virtual void SetUp() OVERRIDE; |
143 virtual void TearDown(); | 143 virtual void TearDown() OVERRIDE; |
144 | 144 |
145 content::TestBrowserThread ui_thread_; | 145 content::TestBrowserThread ui_thread_; |
146 content::MockGeolocation mock_geolocation_; | 146 content::MockGeolocation mock_geolocation_; |
147 | 147 |
148 // A map between renderer child id and a pair represending the bridge id and | 148 // A map between renderer child id and a pair represending the bridge id and |
149 // whether the requested permission was allowed. | 149 // whether the requested permission was allowed. |
150 base::hash_map<int, std::pair<int, bool> > responses_; | 150 base::hash_map<int, std::pair<int, bool> > responses_; |
151 }; | 151 }; |
152 | 152 |
153 GeolocationPermissionContextTests::GeolocationPermissionContextTests() | 153 GeolocationPermissionContextTests::GeolocationPermissionContextTests() |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 } | 232 } |
233 | 233 |
234 void GeolocationPermissionContextTests::SetUp() { | 234 void GeolocationPermissionContextTests::SetUp() { |
235 TabContentsWrapperTestHarness::SetUp(); | 235 TabContentsWrapperTestHarness::SetUp(); |
236 mock_geolocation_.Setup(); | 236 mock_geolocation_.Setup(); |
237 geolocation_permission_context_ = | 237 geolocation_permission_context_ = |
238 new ChromeGeolocationPermissionContext(profile()); | 238 new ChromeGeolocationPermissionContext(profile()); |
239 } | 239 } |
240 | 240 |
241 void GeolocationPermissionContextTests::TearDown() { | 241 void GeolocationPermissionContextTests::TearDown() { |
| 242 extra_tabs_.reset(); |
242 mock_geolocation_.TearDown(); | 243 mock_geolocation_.TearDown(); |
243 TabContentsWrapperTestHarness::TearDown(); | 244 TabContentsWrapperTestHarness::TearDown(); |
244 } | 245 } |
245 | 246 |
246 | 247 |
247 // Tests ---------------------------------------------------------------------- | 248 // Tests ---------------------------------------------------------------------- |
248 | 249 |
249 TEST_F(GeolocationPermissionContextTests, SinglePermission) { | 250 TEST_F(GeolocationPermissionContextTests, SinglePermission) { |
250 GURL requesting_frame("http://www.example.com/geolocation"); | 251 GURL requesting_frame("http://www.example.com/geolocation"); |
251 NavigateAndCommit(requesting_frame); | 252 NavigateAndCommit(requesting_frame); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 | 465 |
465 // But the other tab should still have the info bar... | 466 // But the other tab should still have the info bar... |
466 ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); | 467 ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); |
467 ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()-> | 468 ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()-> |
468 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 469 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
469 infobar_1->Cancel(); | 470 infobar_1->Cancel(); |
470 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1); | 471 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1); |
471 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 472 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
472 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 473 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
473 infobar_1->InfoBarClosed(); | 474 infobar_1->InfoBarClosed(); |
474 | |
475 extra_tabs_.reset(); | |
476 } | 475 } |
477 | 476 |
478 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { | 477 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { |
479 GURL url_a("http://www.example.com/geolocation"); | 478 GURL url_a("http://www.example.com/geolocation"); |
480 GURL url_b("http://www.example-2.com/geolocation"); | 479 GURL url_b("http://www.example-2.com/geolocation"); |
481 NavigateAndCommit(url_a); | 480 NavigateAndCommit(url_a); |
482 AddNewTab(url_a); | 481 AddNewTab(url_a); |
483 | 482 |
484 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); | 483 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); |
485 RequestGeolocationPermission( | 484 RequestGeolocationPermission( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 // Accept the second infobar. | 520 // Accept the second infobar. |
522 ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()-> | 521 ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()-> |
523 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 522 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
524 ASSERT_TRUE(infobar_1); | 523 ASSERT_TRUE(infobar_1); |
525 infobar_1->Accept(); | 524 infobar_1->Accept(); |
526 CheckPermissionMessageSentForTab(0, bridge_id() + 1, true); | 525 CheckPermissionMessageSentForTab(0, bridge_id() + 1, true); |
527 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1); | 526 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1); |
528 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 527 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
529 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 528 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
530 infobar_1->InfoBarClosed(); | 529 infobar_1->InfoBarClosed(); |
531 | |
532 extra_tabs_.reset(); | |
533 } | 530 } |
534 | 531 |
535 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { | 532 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { |
536 GURL requesting_frame_0("http://www.example.com/geolocation"); | 533 GURL requesting_frame_0("http://www.example.com/geolocation"); |
537 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 534 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
538 EXPECT_EQ( | 535 EXPECT_EQ( |
539 CONTENT_SETTING_ASK, | 536 CONTENT_SETTING_ASK, |
540 profile()->GetHostContentSettingsMap()->GetContentSetting( | 537 profile()->GetHostContentSettingsMap()->GetContentSetting( |
541 requesting_frame_0, | 538 requesting_frame_0, |
542 requesting_frame_0, | 539 requesting_frame_0, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 ASSERT_FALSE(infobar_0->ShouldExpire(details)); | 588 ASSERT_FALSE(infobar_0->ShouldExpire(details)); |
592 // Commit the "GoBack()" above, and ensure the infobar is now expired. | 589 // Commit the "GoBack()" above, and ensure the infobar is now expired. |
593 contents()->CommitPendingNavigation(); | 590 contents()->CommitPendingNavigation(); |
594 details.entry = contents()->GetController().GetLastCommittedEntry(); | 591 details.entry = contents()->GetController().GetLastCommittedEntry(); |
595 ASSERT_TRUE(infobar_0->ShouldExpire(details)); | 592 ASSERT_TRUE(infobar_0->ShouldExpire(details)); |
596 | 593 |
597 // Delete the tab contents. | 594 // Delete the tab contents. |
598 DeleteContents(); | 595 DeleteContents(); |
599 infobar_0->InfoBarClosed(); | 596 infobar_0->InfoBarClosed(); |
600 } | 597 } |
OLD | NEW |