| 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 <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 Loading... |
| 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 Loading... |
| 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())); |
| 458 |
| 459 // Ensure a second request doesn't create a prompt in this tab. |
| 460 WatchPositionAndObservePermissionRequest(false); |
| 443 } | 461 } |
| 444 | 462 |
| 445 #if defined(OS_LINUX) | 463 #if defined(OS_LINUX) |
| 446 // http://crbug.com/527437 | 464 // http://crbug.com/527437 |
| 447 #define MAYBE_Geoposition DISABLED_Geoposition | 465 #define MAYBE_Geoposition DISABLED_Geoposition |
| 448 #else | 466 #else |
| 449 #define MAYBE_Geoposition Geoposition | 467 #define MAYBE_Geoposition Geoposition |
| 450 #endif | 468 #endif |
| 451 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_Geoposition) { | 469 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_Geoposition) { |
| 452 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 470 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| 453 ASSERT_TRUE(WatchPositionAndGrantPermission()); | 471 ASSERT_TRUE(WatchPositionAndGrantPermission()); |
| 454 ExpectPosition(fake_latitude(), fake_longitude()); | 472 ExpectPosition(fake_latitude(), fake_longitude()); |
| 455 } | 473 } |
| 456 | 474 |
| 457 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, ErrorOnPermissionDenied) { | 475 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, ErrorOnPermissionDenied) { |
| 458 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 476 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| 459 EXPECT_TRUE(WatchPositionAndDenyPermission()); | 477 EXPECT_TRUE(WatchPositionAndDenyPermission()); |
| 460 ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()"); | 478 ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()"); |
| 479 |
| 480 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 481 GetHostContentSettingsMap()->GetContentSetting( |
| 482 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 483 std::string())); |
| 484 |
| 485 // Ensure a second request doesn't create a prompt in this tab. |
| 486 WatchPositionAndObservePermissionRequest(false); |
| 461 } | 487 } |
| 462 | 488 |
| 463 #if defined(OS_LINUX) | 489 #if defined(OS_LINUX) |
| 464 // http://crbug.com/527437 | 490 // http://crbug.com/527437 |
| 465 #define MAYBE_NoPromptForSecondTab DISABLED_NoPromptForSecondTab | 491 #define MAYBE_NoPromptForSecondTab DISABLED_NoPromptForSecondTab |
| 466 #else | 492 #else |
| 467 #define MAYBE_NoPromptForSecondTab NoPromptForSecondTab | 493 #define MAYBE_NoPromptForSecondTab NoPromptForSecondTab |
| 468 #endif | 494 #endif |
| 469 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoPromptForSecondTab) { | 495 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoPromptForSecondTab) { |
| 470 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 496 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 ASSERT_TRUE(WatchPositionAndGrantPermission()); | 559 ASSERT_TRUE(WatchPositionAndGrantPermission()); |
| 534 ExpectPosition(fake_latitude(), fake_longitude()); | 560 ExpectPosition(fake_latitude(), fake_longitude()); |
| 535 | 561 |
| 536 // The regular profile knows nothing of what happened in incognito. It is | 562 // The regular profile knows nothing of what happened in incognito. It is |
| 537 // prompted and when granted the position gets to the script. | 563 // prompted and when granted the position gets to the script. |
| 538 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 564 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| 539 ASSERT_TRUE(WatchPositionAndGrantPermission()); | 565 ASSERT_TRUE(WatchPositionAndGrantPermission()); |
| 540 ExpectPosition(fake_latitude(), fake_longitude()); | 566 ExpectPosition(fake_latitude(), fake_longitude()); |
| 541 } | 567 } |
| 542 | 568 |
| 569 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TogglePersistGranted) { |
| 570 // Initialize and turn persistence off. |
| 571 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| 572 TogglePersist(false); |
| 573 |
| 574 ASSERT_TRUE(WatchPositionAndGrantPermission()); |
| 575 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 576 GetHostContentSettingsMap()->GetContentSetting( |
| 577 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 578 std::string())); |
| 579 |
| 580 // Expect the grant to be remembered at the blink layer, so a second request |
| 581 // on this page doesn't create a request. |
| 582 WatchPositionAndObservePermissionRequest(false); |
| 583 |
| 584 // Navigate and ensure that a prompt is shown when we request again. |
| 585 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| 586 WatchPositionAndObservePermissionRequest(true); |
| 587 } |
| 588 |
| 589 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TogglePersistBlocked) { |
| 590 // Initialize and turn persistence off. |
| 591 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| 592 TogglePersist(false); |
| 593 |
| 594 ASSERT_TRUE(WatchPositionAndDenyPermission()); |
| 595 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 596 GetHostContentSettingsMap()->GetContentSetting( |
| 597 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 598 std::string())); |
| 599 |
| 600 // Expect the block to be remembered at the blink layer, so a second request |
| 601 // on this page doesn't create a request. |
| 602 WatchPositionAndObservePermissionRequest(false); |
| 603 |
| 604 // Navigate and ensure that a prompt is shown when we request again. |
| 605 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| 606 WatchPositionAndObservePermissionRequest(true); |
| 607 } |
| 608 |
| 543 #if defined(OS_LINUX) | 609 #if defined(OS_LINUX) |
| 544 // http://crbug.com/527437 | 610 // http://crbug.com/527437 |
| 545 #define MAYBE_IFramesWithFreshPosition DISABLED_IFramesWithFreshPosition | 611 #define MAYBE_IFramesWithFreshPosition DISABLED_IFramesWithFreshPosition |
| 546 #else | 612 #else |
| 547 #define MAYBE_IFramesWithFreshPosition IFramesWithFreshPosition | 613 #define MAYBE_IFramesWithFreshPosition IFramesWithFreshPosition |
| 548 #endif | 614 #endif |
| 549 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_IFramesWithFreshPosition) { | 615 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_IFramesWithFreshPosition) { |
| 550 set_html_for_tests("/geolocation/two_iframes.html"); | 616 set_html_for_tests("/geolocation/two_iframes.html"); |
| 551 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 617 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| 552 LoadIFrames(); | 618 LoadIFrames(); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 // Calling watchPosition should trigger the last usage update. | 824 // Calling watchPosition should trigger the last usage update. |
| 759 WatchPositionAndObservePermissionRequest(false); | 825 WatchPositionAndObservePermissionRequest(false); |
| 760 ExpectPosition(fake_latitude(), fake_longitude()); | 826 ExpectPosition(fake_latitude(), fake_longitude()); |
| 761 | 827 |
| 762 // Last usage has been updated. | 828 // Last usage has been updated. |
| 763 EXPECT_EQ(GetHostContentSettingsMap()->GetLastUsage( | 829 EXPECT_EQ(GetHostContentSettingsMap()->GetLastUsage( |
| 764 current_url().GetOrigin(), | 830 current_url().GetOrigin(), |
| 765 current_url().GetOrigin(), | 831 current_url().GetOrigin(), |
| 766 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 13); | 832 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 13); |
| 767 } | 833 } |
| OLD | NEW |