| 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" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/test/simple_test_clock.h" | 14 #include "base/test/simple_test_clock.h" |
| 15 #include "base/time/clock.h" | 15 #include "base/time/clock.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
| 18 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 18 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 19 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 19 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/browser_commands.h" | 22 #include "chrome/browser/ui/browser_commands.h" |
| 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 24 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 24 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| 25 #include "chrome/test/base/in_process_browser_test.h" | 25 #include "chrome/test/base/in_process_browser_test.h" |
| 26 #include "chrome/test/base/ui_test_utils.h" | 26 #include "chrome/test/base/ui_test_utils.h" |
| 27 #include "components/content_settings/core/browser/content_settings_usages_state
.h" | 27 #include "components/content_settings/core/browser/content_settings_usages_state
.h" |
| 28 #include "components/content_settings/core/browser/host_content_settings_map.h" | 28 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 29 #include "components/content_settings/core/common/content_settings_pattern.h" | |
| 30 #include "content/public/browser/navigation_controller.h" | 29 #include "content/public/browser/navigation_controller.h" |
| 31 #include "content/public/browser/notification_details.h" | 30 #include "content/public/browser/notification_details.h" |
| 32 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
| 33 #include "content/public/browser/render_frame_host.h" | 32 #include "content/public/browser/render_frame_host.h" |
| 34 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
| 35 #include "content/public/common/geoposition.h" | 34 #include "content/public/common/geoposition.h" |
| 36 #include "content/public/test/browser_test_utils.h" | 35 #include "content/public/test/browser_test_utils.h" |
| 37 #include "net/test/embedded_test_server/embedded_test_server.h" | 36 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 38 | 37 |
| 39 namespace { | 38 namespace { |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 ASSERT_TRUE(WatchPositionAndGrantPermission()); | 470 ASSERT_TRUE(WatchPositionAndGrantPermission()); |
| 472 | 471 |
| 473 // Checks bubble is not needed in a second tab. | 472 // Checks bubble is not needed in a second tab. |
| 474 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_NEWTAB)); | 473 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_NEWTAB)); |
| 475 WatchPositionAndObservePermissionBubble(false); | 474 WatchPositionAndObservePermissionBubble(false); |
| 476 ExpectPosition(fake_latitude(), fake_longitude()); | 475 ExpectPosition(fake_latitude(), fake_longitude()); |
| 477 } | 476 } |
| 478 | 477 |
| 479 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptForDeniedOrigin) { | 478 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptForDeniedOrigin) { |
| 480 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 479 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| 481 GetHostContentSettingsMap()->SetContentSetting( | 480 GetHostContentSettingsMap()->SetContentSettingDefaultScope( |
| 482 ContentSettingsPattern::FromURLNoWildcard(current_url()), | 481 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 483 ContentSettingsPattern::FromURLNoWildcard(current_url()), | 482 std::string(), CONTENT_SETTING_BLOCK); |
| 484 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), CONTENT_SETTING_BLOCK); | |
| 485 | 483 |
| 486 // Check that the bubble wasn't shown but we get an error for this origin. | 484 // Check that the bubble wasn't shown but we get an error for this origin. |
| 487 WatchPositionAndObservePermissionBubble(false); | 485 WatchPositionAndObservePermissionBubble(false); |
| 488 ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()"); | 486 ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()"); |
| 489 | 487 |
| 490 // Checks prompt will not be created a second tab. | 488 // Checks prompt will not be created a second tab. |
| 491 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_NEWTAB)); | 489 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_NEWTAB)); |
| 492 WatchPositionAndObservePermissionBubble(false); | 490 WatchPositionAndObservePermissionBubble(false); |
| 493 ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()"); | 491 ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()"); |
| 494 } | 492 } |
| 495 | 493 |
| 496 #if defined(OS_LINUX) | 494 #if defined(OS_LINUX) |
| 497 // http://crbug.com/527437 | 495 // http://crbug.com/527437 |
| 498 #define MAYBE_NoPromptForAllowedOrigin DISABLED_NoPromptForAllowedOrigin | 496 #define MAYBE_NoPromptForAllowedOrigin DISABLED_NoPromptForAllowedOrigin |
| 499 #else | 497 #else |
| 500 #define MAYBE_NoPromptForAllowedOrigin NoPromptForAllowedOrigin | 498 #define MAYBE_NoPromptForAllowedOrigin NoPromptForAllowedOrigin |
| 501 #endif | 499 #endif |
| 502 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoPromptForAllowedOrigin) { | 500 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoPromptForAllowedOrigin) { |
| 503 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 501 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| 504 GetHostContentSettingsMap()->SetContentSetting( | 502 GetHostContentSettingsMap()->SetContentSettingDefaultScope( |
| 505 ContentSettingsPattern::FromURLNoWildcard(current_url()), | 503 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 506 ContentSettingsPattern::FromURLNoWildcard(current_url()), | 504 std::string(), CONTENT_SETTING_ALLOW); |
| 507 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), CONTENT_SETTING_ALLOW); | |
| 508 // The bubble is not shown, there is no error, and the position gets to the | 505 // The bubble is not shown, there is no error, and the position gets to the |
| 509 // script. | 506 // script. |
| 510 WatchPositionAndObservePermissionBubble(false); | 507 WatchPositionAndObservePermissionBubble(false); |
| 511 ExpectPosition(fake_latitude(), fake_longitude()); | 508 ExpectPosition(fake_latitude(), fake_longitude()); |
| 512 } | 509 } |
| 513 | 510 |
| 514 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptForOffTheRecord) { | 511 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptForOffTheRecord) { |
| 515 // For a regular profile the user is prompted, and when granted the position | 512 // For a regular profile the user is prompted, and when granted the position |
| 516 // gets to the script. | 513 // gets to the script. |
| 517 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 514 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 #define MAYBE_LastUsageUpdated LastUsageUpdated | 735 #define MAYBE_LastUsageUpdated LastUsageUpdated |
| 739 #endif | 736 #endif |
| 740 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_LastUsageUpdated) { | 737 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_LastUsageUpdated) { |
| 741 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 738 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
| 742 base::SimpleTestClock* clock_ = new base::SimpleTestClock(); | 739 base::SimpleTestClock* clock_ = new base::SimpleTestClock(); |
| 743 GetHostContentSettingsMap()->SetPrefClockForTesting( | 740 GetHostContentSettingsMap()->SetPrefClockForTesting( |
| 744 scoped_ptr<base::Clock>(clock_)); | 741 scoped_ptr<base::Clock>(clock_)); |
| 745 clock_->SetNow(base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(10)); | 742 clock_->SetNow(base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(10)); |
| 746 | 743 |
| 747 // Setting the permission should trigger the last usage. | 744 // Setting the permission should trigger the last usage. |
| 748 GetHostContentSettingsMap()->SetContentSetting( | 745 GetHostContentSettingsMap()->SetContentSettingDefaultScope( |
| 749 ContentSettingsPattern::FromURLNoWildcard(current_url()), | 746 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 750 ContentSettingsPattern::FromURLNoWildcard(current_url()), | 747 std::string(), CONTENT_SETTING_ALLOW); |
| 751 CONTENT_SETTINGS_TYPE_GEOLOCATION, | |
| 752 std::string(), | |
| 753 CONTENT_SETTING_ALLOW); | |
| 754 | 748 |
| 755 // Permission has been used at the starting time. | 749 // Permission has been used at the starting time. |
| 756 EXPECT_EQ(GetHostContentSettingsMap()->GetLastUsage( | 750 EXPECT_EQ(GetHostContentSettingsMap()->GetLastUsage( |
| 757 current_url().GetOrigin(), | 751 current_url().GetOrigin(), |
| 758 current_url().GetOrigin(), | 752 current_url().GetOrigin(), |
| 759 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 10); | 753 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 10); |
| 760 | 754 |
| 761 clock_->Advance(base::TimeDelta::FromSeconds(3)); | 755 clock_->Advance(base::TimeDelta::FromSeconds(3)); |
| 762 | 756 |
| 763 // Calling watchPosition should trigger the last usage update. | 757 // Calling watchPosition should trigger the last usage update. |
| 764 WatchPositionAndObservePermissionBubble(false); | 758 WatchPositionAndObservePermissionBubble(false); |
| 765 ExpectPosition(fake_latitude(), fake_longitude()); | 759 ExpectPosition(fake_latitude(), fake_longitude()); |
| 766 | 760 |
| 767 // Last usage has been updated. | 761 // Last usage has been updated. |
| 768 EXPECT_EQ(GetHostContentSettingsMap()->GetLastUsage( | 762 EXPECT_EQ(GetHostContentSettingsMap()->GetLastUsage( |
| 769 current_url().GetOrigin(), | 763 current_url().GetOrigin(), |
| 770 current_url().GetOrigin(), | 764 current_url().GetOrigin(), |
| 771 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 13); | 765 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 13); |
| 772 } | 766 } |
| OLD | NEW |