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