| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/test/simple_test_clock.h" | 12 #include "base/test/simple_test_clock.h" |
| 13 #include "base/time/clock.h" | 13 #include "base/time/clock.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 15 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_commands.h" | 19 #include "chrome/browser/ui/browser_commands.h" |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 21 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| 21 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/test/base/in_process_browser_test.h" | 24 #include "chrome/test/base/in_process_browser_test.h" |
| 24 #include "chrome/test/base/ui_test_utils.h" | 25 #include "chrome/test/base/ui_test_utils.h" |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 | 472 |
| 472 // Checks bubble is not needed in a second tab. | 473 // Checks bubble is not needed in a second tab. |
| 473 ASSERT_TRUE(Initialize(INITIALIZATION_NEWTAB)); | 474 ASSERT_TRUE(Initialize(INITIALIZATION_NEWTAB)); |
| 474 SetFrameHost(""); | 475 SetFrameHost(""); |
| 475 RequestPermissionAndObserve(false); | 476 RequestPermissionAndObserve(false); |
| 476 CheckGeoposition(fake_latitude(), fake_longitude()); | 477 CheckGeoposition(fake_latitude(), fake_longitude()); |
| 477 } | 478 } |
| 478 | 479 |
| 479 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptForDeniedOrigin) { | 480 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptForDeniedOrigin) { |
| 480 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 481 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| 481 current_browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | 482 HostContentSettingsMapFactory::GetForProfile(current_browser()->profile()) |
| 482 ContentSettingsPattern::FromURLNoWildcard(current_url()), | 483 ->SetContentSetting( |
| 483 ContentSettingsPattern::FromURLNoWildcard(current_url()), | 484 ContentSettingsPattern::FromURLNoWildcard(current_url()), |
| 484 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), CONTENT_SETTING_BLOCK); | 485 ContentSettingsPattern::FromURLNoWildcard(current_url()), |
| 486 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 487 std::string(), |
| 488 CONTENT_SETTING_BLOCK); |
| 485 | 489 |
| 486 // Check that the bubble wasn't shown but we get an error for this origin. | 490 // Check that the bubble wasn't shown but we get an error for this origin. |
| 487 SetFrameHost(""); | 491 SetFrameHost(""); |
| 488 RequestPermissionAndObserve(false); | 492 RequestPermissionAndObserve(false); |
| 489 CheckStringValueFromJavascript("1", "geoGetLastError()"); | 493 CheckStringValueFromJavascript("1", "geoGetLastError()"); |
| 490 | 494 |
| 491 // Checks prompt will not be created a second tab. | 495 // Checks prompt will not be created a second tab. |
| 492 ASSERT_TRUE(Initialize(INITIALIZATION_NEWTAB)); | 496 ASSERT_TRUE(Initialize(INITIALIZATION_NEWTAB)); |
| 493 SetFrameHost(""); | 497 SetFrameHost(""); |
| 494 RequestPermissionAndObserve(false); | 498 RequestPermissionAndObserve(false); |
| 495 CheckStringValueFromJavascript("1", "geoGetLastError()"); | 499 CheckStringValueFromJavascript("1", "geoGetLastError()"); |
| 496 } | 500 } |
| 497 | 501 |
| 498 #if defined(OS_LINUX) | 502 #if defined(OS_LINUX) |
| 499 // http://crbug.com/527437 | 503 // http://crbug.com/527437 |
| 500 #define MAYBE_NoPromptForAllowedOrigin DISABLED_NoPromptForAllowedOrigin | 504 #define MAYBE_NoPromptForAllowedOrigin DISABLED_NoPromptForAllowedOrigin |
| 501 #else | 505 #else |
| 502 #define MAYBE_NoPromptForAllowedOrigin NoPromptForAllowedOrigin | 506 #define MAYBE_NoPromptForAllowedOrigin NoPromptForAllowedOrigin |
| 503 #endif | 507 #endif |
| 504 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoPromptForAllowedOrigin) { | 508 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoPromptForAllowedOrigin) { |
| 505 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 509 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| 506 current_browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | 510 HostContentSettingsMapFactory::GetForProfile(current_browser()->profile()) |
| 507 ContentSettingsPattern::FromURLNoWildcard(current_url()), | 511 ->SetContentSetting( |
| 508 ContentSettingsPattern::FromURLNoWildcard(current_url()), | 512 ContentSettingsPattern::FromURLNoWildcard(current_url()), |
| 509 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), CONTENT_SETTING_ALLOW); | 513 ContentSettingsPattern::FromURLNoWildcard(current_url()), |
| 514 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 515 std::string(), |
| 516 CONTENT_SETTING_ALLOW); |
| 510 // Checks no prompt will be created and there's no error callback. | 517 // Checks no prompt will be created and there's no error callback. |
| 511 SetFrameHost(""); | 518 SetFrameHost(""); |
| 512 RequestPermissionAndObserve(false); | 519 RequestPermissionAndObserve(false); |
| 513 CheckGeoposition(fake_latitude(), fake_longitude()); | 520 CheckGeoposition(fake_latitude(), fake_longitude()); |
| 514 } | 521 } |
| 515 | 522 |
| 516 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptForOffTheRecord) { | 523 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptForOffTheRecord) { |
| 517 // Check prompt will be created and persisted for regular profile. | 524 // Check prompt will be created and persisted for regular profile. |
| 518 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 525 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| 519 SetFrameHost(""); | 526 SetFrameHost(""); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 | 738 |
| 732 #if defined(OS_LINUX) | 739 #if defined(OS_LINUX) |
| 733 // http://crbug.com/527437 | 740 // http://crbug.com/527437 |
| 734 #define MAYBE_LastUsageUpdated DISABLED_LastUsageUpdated | 741 #define MAYBE_LastUsageUpdated DISABLED_LastUsageUpdated |
| 735 #else | 742 #else |
| 736 #define MAYBE_LastUsageUpdated LastUsageUpdated | 743 #define MAYBE_LastUsageUpdated LastUsageUpdated |
| 737 #endif | 744 #endif |
| 738 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_LastUsageUpdated) { | 745 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_LastUsageUpdated) { |
| 739 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | 746 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| 740 base::SimpleTestClock* clock_ = new base::SimpleTestClock(); | 747 base::SimpleTestClock* clock_ = new base::SimpleTestClock(); |
| 741 current_browser() | 748 HostContentSettingsMapFactory::GetForProfile(current_browser()->profile()) |
| 742 ->profile() | |
| 743 ->GetHostContentSettingsMap() | |
| 744 ->SetPrefClockForTesting(scoped_ptr<base::Clock>(clock_)); | 749 ->SetPrefClockForTesting(scoped_ptr<base::Clock>(clock_)); |
| 745 clock_->SetNow(base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(10)); | 750 clock_->SetNow(base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(10)); |
| 746 | 751 |
| 747 // Setting the permission should trigger the last usage. | 752 // Setting the permission should trigger the last usage. |
| 748 current_browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | 753 HostContentSettingsMapFactory::GetForProfile(current_browser()->profile()) |
| 749 ContentSettingsPattern::FromURLNoWildcard(current_url()), | 754 ->SetContentSetting( |
| 750 ContentSettingsPattern::FromURLNoWildcard(current_url()), | 755 ContentSettingsPattern::FromURLNoWildcard(current_url()), |
| 751 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 756 ContentSettingsPattern::FromURLNoWildcard(current_url()), |
| 752 std::string(), | 757 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 753 CONTENT_SETTING_ALLOW); | 758 std::string(), |
| 759 CONTENT_SETTING_ALLOW); |
| 754 | 760 |
| 755 // Permission has been used at the starting time. | 761 // Permission has been used at the starting time. |
| 756 EXPECT_EQ(current_browser() | 762 EXPECT_EQ(HostContentSettingsMapFactory::GetForProfile( |
| 757 ->profile() | 763 current_browser()->profile())->GetLastUsage( |
| 758 ->GetHostContentSettingsMap() | 764 current_url().GetOrigin(), |
| 759 ->GetLastUsage(current_url().GetOrigin(), | 765 current_url().GetOrigin(), |
| 760 current_url().GetOrigin(), | 766 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 10); |
| 761 CONTENT_SETTINGS_TYPE_GEOLOCATION) | |
| 762 .ToDoubleT(), | |
| 763 10); | |
| 764 | 767 |
| 765 clock_->Advance(base::TimeDelta::FromSeconds(3)); | 768 clock_->Advance(base::TimeDelta::FromSeconds(3)); |
| 766 | 769 |
| 767 // Watching should trigger the last usage update. | 770 // Watching should trigger the last usage update. |
| 768 SetFrameHost(""); | 771 SetFrameHost(""); |
| 769 RequestPermissionAndObserve(false); | 772 RequestPermissionAndObserve(false); |
| 770 CheckGeoposition(fake_latitude(), fake_longitude()); | 773 CheckGeoposition(fake_latitude(), fake_longitude()); |
| 771 | 774 |
| 772 // Last usage has been updated. | 775 // Last usage has been updated. |
| 773 EXPECT_EQ(current_browser() | 776 EXPECT_EQ(HostContentSettingsMapFactory::GetForProfile( |
| 774 ->profile() | 777 current_browser()->profile())->GetLastUsage( |
| 775 ->GetHostContentSettingsMap() | 778 current_url().GetOrigin(), |
| 776 ->GetLastUsage(current_url().GetOrigin(), | 779 current_url().GetOrigin(), |
| 777 current_url().GetOrigin(), | 780 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 13); |
| 778 CONTENT_SETTINGS_TYPE_GEOLOCATION) | |
| 779 .ToDoubleT(), | |
| 780 13); | |
| 781 } | 781 } |
| OLD | NEW |