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/geolocation_permission_context.h" | 5 #include "chrome/browser/geolocation/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 "base/test/simple_test_clock.h" | 16 #include "base/test/simple_test_clock.h" |
17 #include "base/time/clock.h" | 17 #include "base/time/clock.h" |
18 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
19 #include "chrome/browser/content_settings/host_content_settings_map.h" | 19 #include "chrome/browser/content_settings/host_content_settings_map.h" |
20 #include "chrome/browser/content_settings/permission_request_id.h" | 20 #include "chrome/browser/content_settings/permission_request_id.h" |
21 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 21 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
22 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" | 22 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" |
23 #include "chrome/browser/infobars/infobar_service.h" | 23 #include "chrome/browser/infobars/infobar_service.h" |
24 #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" |
27 #include "components/infobars/core/confirm_infobar_delegate.h" | 26 #include "components/infobars/core/confirm_infobar_delegate.h" |
28 #include "components/infobars/core/infobar.h" | 27 #include "components/infobars/core/infobar.h" |
29 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
30 #include "content/public/browser/navigation_details.h" | 29 #include "content/public/browser/navigation_details.h" |
31 #include "content/public/browser/notification_registrar.h" | 30 #include "content/public/browser/notification_registrar.h" |
32 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
33 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
34 #include "content/public/test/mock_render_process_host.h" | 33 #include "content/public/test/mock_render_process_host.h" |
35 #include "content/public/test/test_renderer_host.h" | 34 #include "content/public/test/test_renderer_host.h" |
36 #include "content/public/test/web_contents_tester.h" | 35 #include "content/public/test/web_contents_tester.h" |
37 #include "extensions/browser/view_type_utils.h" | |
38 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
39 | 37 |
40 #if defined(OS_ANDROID) | 38 #if defined(OS_ANDROID) |
41 #include "base/prefs/pref_service.h" | 39 #include "base/prefs/pref_service.h" |
42 #include "chrome/browser/android/mock_google_location_settings_helper.h" | 40 #include "chrome/browser/android/mock_google_location_settings_helper.h" |
43 #include "chrome/common/pref_names.h" | 41 #include "chrome/common/pref_names.h" |
44 #endif | 42 #endif |
45 | 43 |
44 #if defined(ENABLE_EXTENSIONS) | |
Michael van Ouwerkerk
2014/07/30 10:58:33
I do appreciate fixing the unit test, but why not
| |
45 #include "extensions/browser/view_type_utils.h" | |
46 #endif | |
47 | |
46 using content::MockRenderProcessHost; | 48 using content::MockRenderProcessHost; |
47 | 49 |
48 | 50 |
49 // ClosedInfoBarTracker ------------------------------------------------------- | 51 // ClosedInfoBarTracker ------------------------------------------------------- |
50 | 52 |
51 // We need to track which infobars were closed. | 53 // We need to track which infobars were closed. |
52 class ClosedInfoBarTracker : public content::NotificationObserver { | 54 class ClosedInfoBarTracker : public content::NotificationObserver { |
53 public: | 55 public: |
54 ClosedInfoBarTracker(); | 56 ClosedInfoBarTracker(); |
55 virtual ~ClosedInfoBarTracker(); | 57 virtual ~ClosedInfoBarTracker(); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 | 216 |
215 void GeolocationPermissionContextTests::AddNewTab(const GURL& url) { | 217 void GeolocationPermissionContextTests::AddNewTab(const GURL& url) { |
216 content::WebContents* new_tab = content::WebContents::Create( | 218 content::WebContents* new_tab = content::WebContents::Create( |
217 content::WebContents::CreateParams(profile())); | 219 content::WebContents::CreateParams(profile())); |
218 new_tab->GetController().LoadURL( | 220 new_tab->GetController().LoadURL( |
219 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 221 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
220 content::RenderViewHostTester::For(new_tab->GetRenderViewHost())-> | 222 content::RenderViewHostTester::For(new_tab->GetRenderViewHost())-> |
221 SendNavigate(extra_tabs_.size() + 1, url); | 223 SendNavigate(extra_tabs_.size() + 1, url); |
222 | 224 |
223 // Set up required helpers, and make this be as "tabby" as the code requires. | 225 // Set up required helpers, and make this be as "tabby" as the code requires. |
226 #if defined(ENABLE_EXTENSIONS) | |
224 extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS); | 227 extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS); |
228 #endif | |
225 InfoBarService::CreateForWebContents(new_tab); | 229 InfoBarService::CreateForWebContents(new_tab); |
226 | 230 |
227 extra_tabs_.push_back(new_tab); | 231 extra_tabs_.push_back(new_tab); |
228 } | 232 } |
229 | 233 |
230 void GeolocationPermissionContextTests::CheckTabContentsState( | 234 void GeolocationPermissionContextTests::CheckTabContentsState( |
231 const GURL& requesting_frame, | 235 const GURL& requesting_frame, |
232 ContentSetting expected_content_setting) { | 236 ContentSetting expected_content_setting) { |
233 TabSpecificContentSettings* content_settings = | 237 TabSpecificContentSettings* content_settings = |
234 TabSpecificContentSettings::FromWebContents(web_contents()); | 238 TabSpecificContentSettings::FromWebContents(web_contents()); |
235 const ContentSettingsUsagesState::StateMap& state_map = | 239 const ContentSettingsUsagesState::StateMap& state_map = |
236 content_settings->geolocation_usages_state().state_map(); | 240 content_settings->geolocation_usages_state().state_map(); |
237 EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin())); | 241 EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin())); |
238 EXPECT_EQ(0U, state_map.count(requesting_frame)); | 242 EXPECT_EQ(0U, state_map.count(requesting_frame)); |
239 ContentSettingsUsagesState::StateMap::const_iterator settings = | 243 ContentSettingsUsagesState::StateMap::const_iterator settings = |
240 state_map.find(requesting_frame.GetOrigin()); | 244 state_map.find(requesting_frame.GetOrigin()); |
241 ASSERT_FALSE(settings == state_map.end()) | 245 ASSERT_FALSE(settings == state_map.end()) |
242 << "geolocation state not found " << requesting_frame; | 246 << "geolocation state not found " << requesting_frame; |
243 EXPECT_EQ(expected_content_setting, settings->second); | 247 EXPECT_EQ(expected_content_setting, settings->second); |
244 } | 248 } |
245 | 249 |
246 void GeolocationPermissionContextTests::SetUp() { | 250 void GeolocationPermissionContextTests::SetUp() { |
247 ChromeRenderViewHostTestHarness::SetUp(); | 251 ChromeRenderViewHostTestHarness::SetUp(); |
248 | 252 |
249 // Set up required helpers, and make this be as "tabby" as the code requires. | 253 // Set up required helpers, and make this be as "tabby" as the code requires. |
254 #if defined(ENABLE_EXTENSIONS) | |
250 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS); | 255 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS); |
256 #endif | |
251 InfoBarService::CreateForWebContents(web_contents()); | 257 InfoBarService::CreateForWebContents(web_contents()); |
252 TabSpecificContentSettings::CreateForWebContents(web_contents()); | 258 TabSpecificContentSettings::CreateForWebContents(web_contents()); |
253 #if defined(OS_ANDROID) | 259 #if defined(OS_ANDROID) |
254 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | 260 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); |
255 #endif | 261 #endif |
256 geolocation_permission_context_ = | 262 geolocation_permission_context_ = |
257 GeolocationPermissionContextFactory::GetForProfile(profile()); | 263 GeolocationPermissionContextFactory::GetForProfile(profile()); |
258 } | 264 } |
259 | 265 |
260 void GeolocationPermissionContextTests::TearDown() { | 266 void GeolocationPermissionContextTests::TearDown() { |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
827 // it is the embedder. | 833 // it is the embedder. |
828 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | 834 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
829 requesting_frame_0.GetOrigin(), | 835 requesting_frame_0.GetOrigin(), |
830 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 836 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
831 13); | 837 13); |
832 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 838 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
833 requesting_frame_0.GetOrigin(), | 839 requesting_frame_0.GetOrigin(), |
834 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 840 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
835 11); | 841 11); |
836 } | 842 } |
OLD | NEW |