Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: chrome/browser/geolocation/geolocation_permission_context_unittest.cc

Issue 815343005: Clean up geolocation code now that it's all upstream. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: renamed IsSystemLocationEnabled -> IsLocationEnabled Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 21 matching lines...) Expand all
32 #include "content/public/browser/notification_service.h" 32 #include "content/public/browser/notification_service.h"
33 #include "content/public/browser/web_contents.h" 33 #include "content/public/browser/web_contents.h"
34 #include "content/public/test/mock_render_process_host.h" 34 #include "content/public/test/mock_render_process_host.h"
35 #include "content/public/test/test_renderer_host.h" 35 #include "content/public/test/test_renderer_host.h"
36 #include "content/public/test/test_utils.h" 36 #include "content/public/test/test_utils.h"
37 #include "content/public/test/web_contents_tester.h" 37 #include "content/public/test/web_contents_tester.h"
38 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
39 39
40 #if defined(OS_ANDROID) 40 #if defined(OS_ANDROID)
41 #include "base/prefs/pref_service.h" 41 #include "base/prefs/pref_service.h"
42 #include "chrome/browser/android/mock_google_location_settings_helper.h" 42 #include "chrome/browser/android/mock_location_settings.h"
43 #include "chrome/browser/geolocation/geolocation_permission_context_android.h" 43 #include "chrome/browser/geolocation/geolocation_permission_context_android.h"
44 #endif 44 #endif
45 45
46 #if defined(ENABLE_EXTENSIONS) 46 #if defined(ENABLE_EXTENSIONS)
47 #include "extensions/browser/view_type_utils.h" 47 #include "extensions/browser/view_type_utils.h"
48 #endif 48 #endif
49 49
50 using content::MockRenderProcessHost; 50 using content::MockRenderProcessHost;
51 51
52 52
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 242
243 // Set up required helpers, and make this be as "tabby" as the code requires. 243 // Set up required helpers, and make this be as "tabby" as the code requires.
244 #if defined(ENABLE_EXTENSIONS) 244 #if defined(ENABLE_EXTENSIONS)
245 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS); 245 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS);
246 #endif 246 #endif
247 InfoBarService::CreateForWebContents(web_contents()); 247 InfoBarService::CreateForWebContents(web_contents());
248 TabSpecificContentSettings::CreateForWebContents(web_contents()); 248 TabSpecificContentSettings::CreateForWebContents(web_contents());
249 geolocation_permission_context_ = 249 geolocation_permission_context_ =
250 GeolocationPermissionContextFactory::GetForProfile(profile()); 250 GeolocationPermissionContextFactory::GetForProfile(profile());
251 #if defined(OS_ANDROID) 251 #if defined(OS_ANDROID)
252 scoped_ptr<GoogleLocationSettingsHelper> helper(
253 new MockGoogleLocationSettingsHelper());
254 static_cast<GeolocationPermissionContextAndroid*>( 252 static_cast<GeolocationPermissionContextAndroid*>(
255 geolocation_permission_context_)-> 253 geolocation_permission_context_)
256 SetGoogleLocationSettingsHelperForTesting(helper.Pass()); 254 ->SetLocationSettingsForTesting(
257 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); 255 scoped_ptr<LocationSettings>(new MockLocationSettings()));
256 MockLocationSettings::SetLocationStatus(true, true);
258 #endif 257 #endif
259 } 258 }
260 259
261 void GeolocationPermissionContextTests::TearDown() { 260 void GeolocationPermissionContextTests::TearDown() {
262 extra_tabs_.clear(); 261 extra_tabs_.clear();
263 ChromeRenderViewHostTestHarness::TearDown(); 262 ChromeRenderViewHostTestHarness::TearDown();
264 } 263 }
265 264
266 // Tests ---------------------------------------------------------------------- 265 // Tests ----------------------------------------------------------------------
267 266
(...skipping 10 matching lines...) Expand all
278 infobar_delegate->Cancel(); 277 infobar_delegate->Cancel();
279 infobar_service()->RemoveInfoBar(infobar); 278 infobar_service()->RemoveInfoBar(infobar);
280 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 279 EXPECT_EQ(1U, closed_infobar_tracker_.size());
281 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); 280 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
282 } 281 }
283 282
284 #if defined(OS_ANDROID) 283 #if defined(OS_ANDROID)
285 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { 284 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) {
286 GURL requesting_frame("http://www.example.com/geolocation"); 285 GURL requesting_frame("http://www.example.com/geolocation");
287 NavigateAndCommit(requesting_frame); 286 NavigateAndCommit(requesting_frame);
288 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); 287 MockLocationSettings::SetLocationStatus(true, true);
289 EXPECT_EQ(0U, infobar_service()->infobar_count()); 288 EXPECT_EQ(0U, infobar_service()->infobar_count());
290 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 289 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
291 EXPECT_EQ(1U, infobar_service()->infobar_count()); 290 EXPECT_EQ(1U, infobar_service()->infobar_count());
292 ConfirmInfoBarDelegate* infobar_delegate_0 = 291 ConfirmInfoBarDelegate* infobar_delegate_0 =
293 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 292 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
294 ASSERT_TRUE(infobar_delegate_0); 293 ASSERT_TRUE(infobar_delegate_0);
295 base::string16 text_0 = infobar_delegate_0->GetButtonLabel( 294 base::string16 text_0 = infobar_delegate_0->GetButtonLabel(
296 ConfirmInfoBarDelegate::BUTTON_OK); 295 ConfirmInfoBarDelegate::BUTTON_OK);
297 296
298 Reload(); 297 Reload();
299 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); 298 MockLocationSettings::SetLocationStatus(true, false);
300 EXPECT_EQ(0U, infobar_service()->infobar_count()); 299 EXPECT_EQ(0U, infobar_service()->infobar_count());
301 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 300 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
302 EXPECT_EQ(0U, infobar_service()->infobar_count()); 301 EXPECT_EQ(0U, infobar_service()->infobar_count());
303 } 302 }
304 303
305 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { 304 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) {
306 GURL requesting_frame("http://www.example.com/geolocation"); 305 GURL requesting_frame("http://www.example.com/geolocation");
307 NavigateAndCommit(requesting_frame); 306 NavigateAndCommit(requesting_frame);
308 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); 307 MockLocationSettings::SetLocationStatus(true, true);
309 EXPECT_EQ(0U, infobar_service()->infobar_count()); 308 EXPECT_EQ(0U, infobar_service()->infobar_count());
310 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 309 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
311 EXPECT_EQ(1U, infobar_service()->infobar_count()); 310 EXPECT_EQ(1U, infobar_service()->infobar_count());
312 ConfirmInfoBarDelegate* infobar_delegate = 311 ConfirmInfoBarDelegate* infobar_delegate =
313 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 312 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
314 ASSERT_TRUE(infobar_delegate); 313 ASSERT_TRUE(infobar_delegate);
315 infobar_delegate->Accept(); 314 infobar_delegate->Accept();
316 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); 315 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
317 CheckPermissionMessageSent(0, true); 316 CheckPermissionMessageSent(0, true);
318 } 317 }
319 318
320 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { 319 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) {
321 GURL requesting_frame("http://www.example.com/geolocation"); 320 GURL requesting_frame("http://www.example.com/geolocation");
322 NavigateAndCommit(requesting_frame); 321 NavigateAndCommit(requesting_frame);
323 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); 322 MockLocationSettings::SetLocationStatus(true, false);
324 EXPECT_EQ(0U, infobar_service()->infobar_count()); 323 EXPECT_EQ(0U, infobar_service()->infobar_count());
325 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 324 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
326 EXPECT_EQ(0U, infobar_service()->infobar_count()); 325 EXPECT_EQ(0U, infobar_service()->infobar_count());
327 } 326 }
328 #endif 327 #endif
329 328
330 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { 329 TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
331 GURL requesting_frame_0("http://www.example.com/geolocation"); 330 GURL requesting_frame_0("http://www.example.com/geolocation");
332 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 331 GURL requesting_frame_1("http://www.example-2.com/geolocation");
333 EXPECT_EQ(CONTENT_SETTING_ASK, 332 EXPECT_EQ(CONTENT_SETTING_ASK,
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 // it is the embedder. 779 // it is the embedder.
781 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), 780 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
782 requesting_frame_0.GetOrigin(), 781 requesting_frame_0.GetOrigin(),
783 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 782 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
784 13); 783 13);
785 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), 784 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
786 requesting_frame_0.GetOrigin(), 785 requesting_frame_0.GetOrigin(),
787 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 786 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
788 11); 787 11);
789 } 788 }
OLDNEW
« no previous file with comments | « chrome/browser/geolocation/geolocation_permission_context_android.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698