| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 geolocation_permission_context_; | 135 geolocation_permission_context_; |
| 135 ClosedDelegateTracker closed_delegate_tracker_; | 136 ClosedDelegateTracker closed_delegate_tracker_; |
| 136 ScopedVector<TabContentsWrapper> extra_tabs_; | 137 ScopedVector<TabContentsWrapper> extra_tabs_; |
| 137 | 138 |
| 138 private: | 139 private: |
| 139 // TabContentsWrapperTestHarness: | 140 // TabContentsWrapperTestHarness: |
| 140 virtual void SetUp() OVERRIDE; | 141 virtual void SetUp() OVERRIDE; |
| 141 virtual void TearDown() OVERRIDE; | 142 virtual void TearDown() OVERRIDE; |
| 142 | 143 |
| 143 content::TestBrowserThread ui_thread_; | 144 content::TestBrowserThread ui_thread_; |
| 145 content::TestBrowserThread db_thread_; |
| 144 content::MockGeolocation mock_geolocation_; | 146 content::MockGeolocation mock_geolocation_; |
| 145 | 147 |
| 146 // 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 |
| 147 // whether the requested permission was allowed. | 149 // whether the requested permission was allowed. |
| 148 base::hash_map<int, std::pair<int, bool> > responses_; | 150 base::hash_map<int, std::pair<int, bool> > responses_; |
| 149 }; | 151 }; |
| 150 | 152 |
| 151 GeolocationPermissionContextTests::GeolocationPermissionContextTests() | 153 GeolocationPermissionContextTests::GeolocationPermissionContextTests() |
| 152 : TabContentsWrapperTestHarness(), | 154 : TabContentsWrapperTestHarness(), |
| 153 ui_thread_(BrowserThread::UI, MessageLoop::current()) { | 155 ui_thread_(BrowserThread::UI, MessageLoop::current()), |
| 156 db_thread_(BrowserThread::DB) { |
| 154 } | 157 } |
| 155 | 158 |
| 156 GeolocationPermissionContextTests::~GeolocationPermissionContextTests() { | 159 GeolocationPermissionContextTests::~GeolocationPermissionContextTests() { |
| 157 } | 160 } |
| 158 | 161 |
| 159 void GeolocationPermissionContextTests::RequestGeolocationPermission( | 162 void GeolocationPermissionContextTests::RequestGeolocationPermission( |
| 160 int render_process_id, | 163 int render_process_id, |
| 161 int render_view_id, | 164 int render_view_id, |
| 162 int bridge_id, | 165 int bridge_id, |
| 163 const GURL& requesting_frame) { | 166 const GURL& requesting_frame) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin())); | 226 EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin())); |
| 224 EXPECT_EQ(0U, state_map.count(requesting_frame)); | 227 EXPECT_EQ(0U, state_map.count(requesting_frame)); |
| 225 GeolocationSettingsState::StateMap::const_iterator settings = | 228 GeolocationSettingsState::StateMap::const_iterator settings = |
| 226 state_map.find(requesting_frame.GetOrigin()); | 229 state_map.find(requesting_frame.GetOrigin()); |
| 227 ASSERT_FALSE(settings == state_map.end()) | 230 ASSERT_FALSE(settings == state_map.end()) |
| 228 << "geolocation state not found " << requesting_frame; | 231 << "geolocation state not found " << requesting_frame; |
| 229 EXPECT_EQ(expected_content_setting, settings->second); | 232 EXPECT_EQ(expected_content_setting, settings->second); |
| 230 } | 233 } |
| 231 | 234 |
| 232 void GeolocationPermissionContextTests::SetUp() { | 235 void GeolocationPermissionContextTests::SetUp() { |
| 236 db_thread_.Start(); |
| 233 TabContentsWrapperTestHarness::SetUp(); | 237 TabContentsWrapperTestHarness::SetUp(); |
| 234 mock_geolocation_.Setup(); | 238 mock_geolocation_.Setup(); |
| 235 geolocation_permission_context_ = | 239 geolocation_permission_context_ = |
| 236 new ChromeGeolocationPermissionContext(profile()); | 240 new ChromeGeolocationPermissionContext(profile()); |
| 237 } | 241 } |
| 238 | 242 |
| 239 void GeolocationPermissionContextTests::TearDown() { | 243 void GeolocationPermissionContextTests::TearDown() { |
| 240 extra_tabs_.reset(); | 244 extra_tabs_.reset(); |
| 241 mock_geolocation_.TearDown(); | 245 mock_geolocation_.TearDown(); |
| 242 TabContentsWrapperTestHarness::TearDown(); | 246 TabContentsWrapperTestHarness::TearDown(); |
| 247 // Schedule another task on the DB thread to notify us that it's safe to |
| 248 // carry on with the test. |
| 249 base::WaitableEvent done(false, false); |
| 250 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 251 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
| 252 done.Wait(); |
| 253 db_thread_.Stop(); |
| 243 } | 254 } |
| 244 | 255 |
| 245 | 256 |
| 246 // Tests ---------------------------------------------------------------------- | 257 // Tests ---------------------------------------------------------------------- |
| 247 | 258 |
| 248 TEST_F(GeolocationPermissionContextTests, SinglePermission) { | 259 TEST_F(GeolocationPermissionContextTests, SinglePermission) { |
| 249 GURL requesting_frame("http://www.example.com/geolocation"); | 260 GURL requesting_frame("http://www.example.com/geolocation"); |
| 250 NavigateAndCommit(requesting_frame); | 261 NavigateAndCommit(requesting_frame); |
| 251 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); | 262 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); |
| 252 RequestGeolocationPermission( | 263 RequestGeolocationPermission( |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 WebContentsTester::For(contents())->CommitPendingNavigation(); | 609 WebContentsTester::For(contents())->CommitPendingNavigation(); |
| 599 details.entry = contents()->GetController().GetLastCommittedEntry(); | 610 details.entry = contents()->GetController().GetLastCommittedEntry(); |
| 600 ASSERT_TRUE(infobar_0->ShouldExpire(details)); | 611 ASSERT_TRUE(infobar_0->ShouldExpire(details)); |
| 601 | 612 |
| 602 // Delete the tab contents. | 613 // Delete the tab contents. |
| 603 DeleteContents(); | 614 DeleteContents(); |
| 604 infobar_0->InfoBarClosed(); | 615 infobar_0->InfoBarClosed(); |
| 605 } | 616 } |
| 606 | 617 |
| 607 | 618 |
| OLD | NEW |