| 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" |
| 11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 12 #include "base/synchronization/waitable_event.h" |
| 12 #include "chrome/browser/content_settings/host_content_settings_map.h" | 13 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 13 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 14 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" | 15 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" |
| 15 #include "chrome/browser/infobars/infobar.h" | 16 #include "chrome/browser/infobars/infobar.h" |
| 16 #include "chrome/browser/infobars/infobar_tab_helper.h" | 17 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 17 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 18 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 19 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" | 20 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 geolocation_permission_context_; | 134 geolocation_permission_context_; |
| 134 ClosedDelegateTracker closed_delegate_tracker_; | 135 ClosedDelegateTracker closed_delegate_tracker_; |
| 135 ScopedVector<TabContentsWrapper> extra_tabs_; | 136 ScopedVector<TabContentsWrapper> extra_tabs_; |
| 136 | 137 |
| 137 private: | 138 private: |
| 138 // TabContentsWrapperTestHarness: | 139 // TabContentsWrapperTestHarness: |
| 139 virtual void SetUp() OVERRIDE; | 140 virtual void SetUp() OVERRIDE; |
| 140 virtual void TearDown() OVERRIDE; | 141 virtual void TearDown() OVERRIDE; |
| 141 | 142 |
| 142 content::TestBrowserThread ui_thread_; | 143 content::TestBrowserThread ui_thread_; |
| 144 content::TestBrowserThread db_thread_; |
| 143 | 145 |
| 144 // A map between renderer child id and a pair represending the bridge id and | 146 // A map between renderer child id and a pair represending the bridge id and |
| 145 // whether the requested permission was allowed. | 147 // whether the requested permission was allowed. |
| 146 base::hash_map<int, std::pair<int, bool> > responses_; | 148 base::hash_map<int, std::pair<int, bool> > responses_; |
| 147 }; | 149 }; |
| 148 | 150 |
| 149 GeolocationPermissionContextTests::GeolocationPermissionContextTests() | 151 GeolocationPermissionContextTests::GeolocationPermissionContextTests() |
| 150 : TabContentsWrapperTestHarness(), | 152 : TabContentsWrapperTestHarness(), |
| 151 ui_thread_(BrowserThread::UI, MessageLoop::current()) { | 153 ui_thread_(BrowserThread::UI, MessageLoop::current()), |
| 154 db_thread_(BrowserThread::DB) { |
| 152 } | 155 } |
| 153 | 156 |
| 154 GeolocationPermissionContextTests::~GeolocationPermissionContextTests() { | 157 GeolocationPermissionContextTests::~GeolocationPermissionContextTests() { |
| 155 } | 158 } |
| 156 | 159 |
| 157 void GeolocationPermissionContextTests::RequestGeolocationPermission( | 160 void GeolocationPermissionContextTests::RequestGeolocationPermission( |
| 158 int render_process_id, | 161 int render_process_id, |
| 159 int render_view_id, | 162 int render_view_id, |
| 160 int bridge_id, | 163 int bridge_id, |
| 161 const GURL& requesting_frame) { | 164 const GURL& requesting_frame) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin())); | 224 EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin())); |
| 222 EXPECT_EQ(0U, state_map.count(requesting_frame)); | 225 EXPECT_EQ(0U, state_map.count(requesting_frame)); |
| 223 GeolocationSettingsState::StateMap::const_iterator settings = | 226 GeolocationSettingsState::StateMap::const_iterator settings = |
| 224 state_map.find(requesting_frame.GetOrigin()); | 227 state_map.find(requesting_frame.GetOrigin()); |
| 225 ASSERT_FALSE(settings == state_map.end()) | 228 ASSERT_FALSE(settings == state_map.end()) |
| 226 << "geolocation state not found " << requesting_frame; | 229 << "geolocation state not found " << requesting_frame; |
| 227 EXPECT_EQ(expected_content_setting, settings->second); | 230 EXPECT_EQ(expected_content_setting, settings->second); |
| 228 } | 231 } |
| 229 | 232 |
| 230 void GeolocationPermissionContextTests::SetUp() { | 233 void GeolocationPermissionContextTests::SetUp() { |
| 234 db_thread_.Start(); |
| 231 TabContentsWrapperTestHarness::SetUp(); | 235 TabContentsWrapperTestHarness::SetUp(); |
| 232 geolocation_permission_context_ = | 236 geolocation_permission_context_ = |
| 233 new ChromeGeolocationPermissionContext(profile()); | 237 new ChromeGeolocationPermissionContext(profile()); |
| 234 } | 238 } |
| 235 | 239 |
| 236 void GeolocationPermissionContextTests::TearDown() { | 240 void GeolocationPermissionContextTests::TearDown() { |
| 237 extra_tabs_.reset(); | 241 extra_tabs_.reset(); |
| 238 TabContentsWrapperTestHarness::TearDown(); | 242 TabContentsWrapperTestHarness::TearDown(); |
| 243 // Schedule another task on the DB thread to notify us that it's safe to |
| 244 // carry on with the test. |
| 245 base::WaitableEvent done(false, false); |
| 246 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 247 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
| 248 done.Wait(); |
| 249 db_thread_.Stop(); |
| 239 } | 250 } |
| 240 | 251 |
| 241 | 252 |
| 242 // Tests ---------------------------------------------------------------------- | 253 // Tests ---------------------------------------------------------------------- |
| 243 | 254 |
| 244 TEST_F(GeolocationPermissionContextTests, SinglePermission) { | 255 TEST_F(GeolocationPermissionContextTests, SinglePermission) { |
| 245 GURL requesting_frame("http://www.example.com/geolocation"); | 256 GURL requesting_frame("http://www.example.com/geolocation"); |
| 246 NavigateAndCommit(requesting_frame); | 257 NavigateAndCommit(requesting_frame); |
| 247 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); | 258 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); |
| 248 RequestGeolocationPermission( | 259 RequestGeolocationPermission( |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 ASSERT_FALSE(infobar_0->ShouldExpire(details)); | 603 ASSERT_FALSE(infobar_0->ShouldExpire(details)); |
| 593 // Commit the "GoBack()" above, and ensure the infobar is now expired. | 604 // Commit the "GoBack()" above, and ensure the infobar is now expired. |
| 594 WebContentsTester::For(contents())->CommitPendingNavigation(); | 605 WebContentsTester::For(contents())->CommitPendingNavigation(); |
| 595 details.entry = contents()->GetController().GetLastCommittedEntry(); | 606 details.entry = contents()->GetController().GetLastCommittedEntry(); |
| 596 ASSERT_TRUE(infobar_0->ShouldExpire(details)); | 607 ASSERT_TRUE(infobar_0->ShouldExpire(details)); |
| 597 | 608 |
| 598 // Delete the tab contents. | 609 // Delete the tab contents. |
| 599 DeleteContents(); | 610 DeleteContents(); |
| 600 infobar_0->InfoBarClosed(); | 611 infobar_0->InfoBarClosed(); |
| 601 } | 612 } |
| OLD | NEW |