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

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

Issue 2338173002: Improve permission persistence tests. (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « no previous file | chrome/browser/permissions/permission_context_base_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 const std::string& function); 247 const std::string& function);
248 248
249 // Sets a new (second) position and runs all callbacks currently registered 249 // Sets a new (second) position and runs all callbacks currently registered
250 // with the Geolocation system. Returns |true| if the new position is updated 250 // with the Geolocation system. Returns |true| if the new position is updated
251 // successfully in JavaScript. 251 // successfully in JavaScript.
252 bool SetPositionAndWaitUntilUpdated(double latitude, double longitude); 252 bool SetPositionAndWaitUntilUpdated(double latitude, double longitude);
253 253
254 // Convenience method to look up the number of queued permission requests. 254 // Convenience method to look up the number of queued permission requests.
255 int GetRequestQueueSize(PermissionRequestManager* manager); 255 int GetRequestQueueSize(PermissionRequestManager* manager);
256 256
257 // Toggle whether the prompt decision should be persisted.
258 void TogglePersist(bool persist);
259
257 private: 260 private:
258 // Calls watchPosition() in JavaScript and accepts or denies the resulting 261 // Calls watchPosition() in JavaScript and accepts or denies the resulting
259 // permission request. Returns the JavaScript response. 262 // permission request. Returns the JavaScript response.
260 std::string WatchPositionAndRespondToPermissionRequest( 263 std::string WatchPositionAndRespondToPermissionRequest(
261 PermissionRequestManager::AutoResponseType request_response); 264 PermissionRequestManager::AutoResponseType request_response);
262 265
263 // The current Browser as set in Initialize. May be for an incognito profile. 266 // The current Browser as set in Initialize. May be for an incognito profile.
264 Browser* current_browser_ = nullptr; 267 Browser* current_browser_ = nullptr;
265 268
266 // The path element of a URL referencing the html content for this test. 269 // The path element of a URL referencing the html content for this test.
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 std::string result = 425 std::string result =
423 RunScript(render_frame_host_, "checkIfGeopositionUpdated()"); 426 RunScript(render_frame_host_, "checkIfGeopositionUpdated()");
424 return result == "geoposition-updated"; 427 return result == "geoposition-updated";
425 } 428 }
426 429
427 int GeolocationBrowserTest::GetRequestQueueSize( 430 int GeolocationBrowserTest::GetRequestQueueSize(
428 PermissionRequestManager* manager) { 431 PermissionRequestManager* manager) {
429 return static_cast<int>(manager->requests_.size()); 432 return static_cast<int>(manager->requests_.size());
430 } 433 }
431 434
435 void GeolocationBrowserTest::TogglePersist(bool persist) {
436 content::WebContents* web_contents =
437 current_browser()->tab_strip_model()->GetActiveWebContents();
438 PermissionRequestManager::FromWebContents(web_contents)
439 ->TogglePersist(persist);
440 }
441
432 // Tests ---------------------------------------------------------------------- 442 // Tests ----------------------------------------------------------------------
433 443
434 #if defined(OS_LINUX) 444 #if defined(OS_LINUX)
435 // http://crbug.com/527437 445 // http://crbug.com/527437
436 #define MAYBE_DisplaysPrompt DISABLED_DisplaysPrompt 446 #define MAYBE_DisplaysPrompt DISABLED_DisplaysPrompt
437 #else 447 #else
438 #define MAYBE_DisplaysPrompt DisplaysPrompt 448 #define MAYBE_DisplaysPrompt DisplaysPrompt
439 #endif 449 #endif
440 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_DisplaysPrompt) { 450 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_DisplaysPrompt) {
441 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); 451 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT));
442 ASSERT_TRUE(WatchPositionAndGrantPermission()); 452 ASSERT_TRUE(WatchPositionAndGrantPermission());
453
454 EXPECT_EQ(CONTENT_SETTING_ALLOW,
455 GetHostContentSettingsMap()->GetContentSetting(
456 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION,
457 std::string()));
raymes 2016/09/15 05:16:08 Maybe we could do WatchPositionAndObservePermissio
dominickn 2016/09/15 05:40:29 Done.
443 } 458 }
444 459
445 #if defined(OS_LINUX) 460 #if defined(OS_LINUX)
446 // http://crbug.com/527437 461 // http://crbug.com/527437
447 #define MAYBE_Geoposition DISABLED_Geoposition 462 #define MAYBE_Geoposition DISABLED_Geoposition
448 #else 463 #else
449 #define MAYBE_Geoposition Geoposition 464 #define MAYBE_Geoposition Geoposition
450 #endif 465 #endif
451 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_Geoposition) { 466 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_Geoposition) {
452 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); 467 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT));
453 ASSERT_TRUE(WatchPositionAndGrantPermission()); 468 ASSERT_TRUE(WatchPositionAndGrantPermission());
454 ExpectPosition(fake_latitude(), fake_longitude()); 469 ExpectPosition(fake_latitude(), fake_longitude());
455 } 470 }
456 471
457 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, ErrorOnPermissionDenied) { 472 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, ErrorOnPermissionDenied) {
458 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); 473 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT));
459 EXPECT_TRUE(WatchPositionAndDenyPermission()); 474 EXPECT_TRUE(WatchPositionAndDenyPermission());
460 ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()"); 475 ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()");
476
477 EXPECT_EQ(CONTENT_SETTING_BLOCK,
478 GetHostContentSettingsMap()->GetContentSetting(
479 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION,
480 std::string()));
raymes 2016/09/15 05:16:08 Same with this (see below)
dominickn 2016/09/15 05:40:29 Done.
461 } 481 }
462 482
463 #if defined(OS_LINUX) 483 #if defined(OS_LINUX)
464 // http://crbug.com/527437 484 // http://crbug.com/527437
465 #define MAYBE_NoPromptForSecondTab DISABLED_NoPromptForSecondTab 485 #define MAYBE_NoPromptForSecondTab DISABLED_NoPromptForSecondTab
466 #else 486 #else
467 #define MAYBE_NoPromptForSecondTab NoPromptForSecondTab 487 #define MAYBE_NoPromptForSecondTab NoPromptForSecondTab
468 #endif 488 #endif
469 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoPromptForSecondTab) { 489 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoPromptForSecondTab) {
470 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); 490 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT));
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 ASSERT_TRUE(WatchPositionAndGrantPermission()); 553 ASSERT_TRUE(WatchPositionAndGrantPermission());
534 ExpectPosition(fake_latitude(), fake_longitude()); 554 ExpectPosition(fake_latitude(), fake_longitude());
535 555
536 // The regular profile knows nothing of what happened in incognito. It is 556 // The regular profile knows nothing of what happened in incognito. It is
537 // prompted and when granted the position gets to the script. 557 // prompted and when granted the position gets to the script.
538 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); 558 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT));
539 ASSERT_TRUE(WatchPositionAndGrantPermission()); 559 ASSERT_TRUE(WatchPositionAndGrantPermission());
540 ExpectPosition(fake_latitude(), fake_longitude()); 560 ExpectPosition(fake_latitude(), fake_longitude());
541 } 561 }
542 562
563 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TogglePersistGranted) {
564 // Initialize and turn persistence off.
565 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT));
566 TogglePersist(false);
567
568 ASSERT_TRUE(WatchPositionAndGrantPermission());
569 EXPECT_EQ(CONTENT_SETTING_ASK,
570 GetHostContentSettingsMap()->GetContentSetting(
571 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION,
572 std::string()));
raymes 2016/09/15 05:16:08 Can we do WatchPositionAndObservePermissionRequest
dominickn 2016/09/15 05:40:29 Done.
573 }
574
575 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TogglePersistBlocked) {
576 // Initialize and turn persistence off.
577 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT));
578 TogglePersist(false);
579
580 ASSERT_TRUE(WatchPositionAndDenyPermission());
581 EXPECT_EQ(CONTENT_SETTING_ASK,
582 GetHostContentSettingsMap()->GetContentSetting(
583 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION,
584 std::string()));
raymes 2016/09/15 05:16:08 Same here.
dominickn 2016/09/15 05:40:29 Done.
585 }
586
543 #if defined(OS_LINUX) 587 #if defined(OS_LINUX)
544 // http://crbug.com/527437 588 // http://crbug.com/527437
545 #define MAYBE_IFramesWithFreshPosition DISABLED_IFramesWithFreshPosition 589 #define MAYBE_IFramesWithFreshPosition DISABLED_IFramesWithFreshPosition
546 #else 590 #else
547 #define MAYBE_IFramesWithFreshPosition IFramesWithFreshPosition 591 #define MAYBE_IFramesWithFreshPosition IFramesWithFreshPosition
548 #endif 592 #endif
549 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_IFramesWithFreshPosition) { 593 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_IFramesWithFreshPosition) {
550 set_html_for_tests("/geolocation/two_iframes.html"); 594 set_html_for_tests("/geolocation/two_iframes.html");
551 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); 595 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT));
552 LoadIFrames(); 596 LoadIFrames();
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 // Calling watchPosition should trigger the last usage update. 802 // Calling watchPosition should trigger the last usage update.
759 WatchPositionAndObservePermissionRequest(false); 803 WatchPositionAndObservePermissionRequest(false);
760 ExpectPosition(fake_latitude(), fake_longitude()); 804 ExpectPosition(fake_latitude(), fake_longitude());
761 805
762 // Last usage has been updated. 806 // Last usage has been updated.
763 EXPECT_EQ(GetHostContentSettingsMap()->GetLastUsage( 807 EXPECT_EQ(GetHostContentSettingsMap()->GetLastUsage(
764 current_url().GetOrigin(), 808 current_url().GetOrigin(),
765 current_url().GetOrigin(), 809 current_url().GetOrigin(),
766 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 13); 810 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 13);
767 } 811 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/permissions/permission_context_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698