Index: chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc |
diff --git a/chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc b/chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3de56f18d3d2e8ea3375d7668136cc0b7fcfcca3 |
--- /dev/null |
+++ b/chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc |
@@ -0,0 +1,269 @@ |
+// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/geolocation/geolocation_content_settings_map.h" |
+ |
+#include "chrome/test/testing_profile.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+ |
+namespace { |
+ |
+class GeolocationContentSettingsMapTests : public testing::Test { |
+ public: |
+ GeolocationContentSettingsMapTests() |
+ : ui_thread_(ChromeThread::UI, &message_loop_) { |
Peter Kasting
2010/03/18 20:59:20
Nit: This still needs to be indented 4 rather than
|
+ } |
+ |
+ protected: |
+ MessageLoop message_loop_; |
+ ChromeThread ui_thread_; |
+}; |
+ |
+TEST_F(GeolocationContentSettingsMapTests, DefaultValues) { |
+ TestingProfile profile; |
+ GeolocationContentSettingsMap* geolocation_content_settings_map = |
+ profile.GetGeolocationContentSettingsMap(); |
+ |
+ // Check setting defaults. |
+ EXPECT_EQ(CONTENT_SETTING_ASK, |
+ geolocation_content_settings_map->GetDefaultContentSetting()); |
+ geolocation_content_settings_map->SetDefaultContentSetting( |
+ CONTENT_SETTING_BLOCK); |
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, |
+ geolocation_content_settings_map->GetDefaultContentSetting()); |
+} |
+ |
+TEST_F(GeolocationContentSettingsMapTests, Embedder) { |
+ TestingProfile profile; |
+ GeolocationContentSettingsMap* geolocation_content_settings_map = |
+ profile.GetGeolocationContentSettingsMap(); |
+ GURL embedder_0("http://www.toplevel0.com/foo/bar"); |
+ GURL origin_0(embedder_0); |
+ EXPECT_EQ(CONTENT_SETTING_ASK, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_0, origin_0)); |
+ // Now set the permission for origin_0. |
+ geolocation_content_settings_map->SetContentSetting( |
+ embedder_0, origin_0, CONTENT_SETTING_ALLOW); |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_0, origin_0)); |
+ |
+ GURL origin_1("http://www.frame0.com/foo/bar"); |
+ EXPECT_EQ(CONTENT_SETTING_ASK, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_0, origin_1)); |
+ // Now set the permission for only the origin_1. |
+ geolocation_content_settings_map->SetContentSetting( |
+ embedder_0, origin_1, CONTENT_SETTING_ALLOW); |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_0, origin_0)); |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_0, origin_1)); |
+ // Block only origin_1. |
+ geolocation_content_settings_map->SetContentSetting( |
+ embedder_0, origin_1, CONTENT_SETTING_BLOCK); |
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_0, origin_1)); |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_0, origin_0)); |
+} |
+ |
+TEST_F(GeolocationContentSettingsMapTests, MultipleEmbeddersAndOrigins) { |
+ TestingProfile profile; |
+ GeolocationContentSettingsMap* geolocation_content_settings_map = |
+ profile.GetGeolocationContentSettingsMap(); |
+ GURL embedder_0("http://www.toplevel0.com/foo/bar"); |
+ GURL origin_0("http://www.iframe0.com/foo/bar"); |
+ GURL origin_1("http://www.iframe1.co.uk/bar/foo"); |
+ EXPECT_EQ(CONTENT_SETTING_ASK, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_0, origin_0)); |
+ EXPECT_EQ(CONTENT_SETTING_ASK, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_0, origin_1)); |
+ // Now set the permission for only one origin. |
+ geolocation_content_settings_map->SetContentSetting( |
+ embedder_0, origin_0, CONTENT_SETTING_ALLOW); |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_0, origin_0)); |
+ EXPECT_EQ(CONTENT_SETTING_ASK, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_0, origin_1)); |
+ // Set the permission for the other origin. |
+ geolocation_content_settings_map->SetContentSetting( |
+ embedder_0, origin_1, CONTENT_SETTING_ALLOW); |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_0, origin_1)); |
+ // Check they're not allowed on a different embedder. |
+ GURL embedder_1("http://www.toplevel1.com/foo/bar"); |
+ EXPECT_EQ(CONTENT_SETTING_ASK, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_1, origin_0)); |
+ EXPECT_EQ(CONTENT_SETTING_ASK, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_1, origin_1)); |
+ // Check all settings are valid. |
+ GeolocationContentSettingsMap::RequestingOriginSettings |
+ requesting_origin_settings = |
+ geolocation_content_settings_map->requesting_origin_settings(); |
+ EXPECT_EQ(0U, requesting_origin_settings.count(origin_0)); |
+ EXPECT_EQ(1U, requesting_origin_settings.count(origin_0.GetOrigin())); |
+ GeolocationContentSettingsMap::EmbedderSettings embedder_settings = |
+ requesting_origin_settings[origin_0.GetOrigin()]; |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ embedder_settings[embedder_0.GetOrigin()]); |
+ |
+ EXPECT_EQ(0U, requesting_origin_settings.count(origin_1)); |
+ EXPECT_EQ(1U, requesting_origin_settings.count(origin_1.GetOrigin())); |
+ embedder_settings = |
+ requesting_origin_settings[origin_1.GetOrigin()]; |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, embedder_settings[embedder_0.GetOrigin()]); |
+ // Block origin_1 on the first embedder and add it to the second. |
+ geolocation_content_settings_map->SetContentSetting( |
+ embedder_0, origin_1, CONTENT_SETTING_BLOCK); |
+ geolocation_content_settings_map->SetContentSetting( |
+ embedder_1, origin_1, CONTENT_SETTING_ALLOW); |
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, |
+ geolocation_content_settings_map->GetContentSetting(embedder_0, |
+ origin_1)); |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ geolocation_content_settings_map->GetContentSetting(embedder_1, |
+ origin_1)); |
+} |
+ |
+TEST_F(GeolocationContentSettingsMapTests, SetContentSettingDefault) { |
+ TestingProfile profile; |
+ GeolocationContentSettingsMap* geolocation_content_settings_map = |
+ profile.GetGeolocationContentSettingsMap(); |
+ GURL embedder_0("http://www.toplevel0.com/foo/bar"); |
+ GURL origin_0(embedder_0); |
+ geolocation_content_settings_map->SetContentSetting( |
+ embedder_0, origin_0, CONTENT_SETTING_ALLOW); |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_0, origin_0)); |
+ // Set to CONTENT_SETTING_DEFAULT and check the actual value has changed. |
+ geolocation_content_settings_map->SetContentSetting( |
+ embedder_0, origin_0, CONTENT_SETTING_DEFAULT); |
+ EXPECT_EQ(CONTENT_SETTING_ASK, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_0, origin_0)); |
+} |
+ |
+TEST_F(GeolocationContentSettingsMapTests, Reset) { |
+ TestingProfile profile; |
+ GeolocationContentSettingsMap* geolocation_content_settings_map = |
+ profile.GetGeolocationContentSettingsMap(); |
+ GURL embedder_0("http://www.toplevel0.com/foo/bar"); |
+ GURL origin_0("http://www.iframe0.com/foo/bar"); |
+ geolocation_content_settings_map->SetContentSetting( |
+ embedder_0, origin_0, CONTENT_SETTING_ALLOW); |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_0, origin_0)); |
+ GeolocationContentSettingsMap::RequestingOriginSettings |
+ requesting_origin_settings = |
+ geolocation_content_settings_map->requesting_origin_settings(); |
+ EXPECT_EQ(1U, requesting_origin_settings.size()); |
+ |
+ // Set to CONTENT_SETTING_DEFAULT and check the actual value has changed. |
+ geolocation_content_settings_map->SetContentSetting( |
+ embedder_0, origin_0, CONTENT_SETTING_DEFAULT); |
+ EXPECT_EQ(CONTENT_SETTING_ASK, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_0, origin_0)); |
+ requesting_origin_settings = |
+ geolocation_content_settings_map->requesting_origin_settings(); |
+ EXPECT_TRUE(requesting_origin_settings.empty()); |
+} |
+ |
+TEST_F(GeolocationContentSettingsMapTests, ClearsWhenSettingBackToDefault) { |
+ TestingProfile profile; |
+ GeolocationContentSettingsMap* geolocation_content_settings_map = |
+ profile.GetGeolocationContentSettingsMap(); |
+ GURL embedder_0("http://www.toplevel0.com/foo/bar"); |
+ GURL origin_0("http://www.iframe0.com/foo/bar"); |
+ GURL origin_1("http://www.iframe1.com/foo/bar"); |
+ geolocation_content_settings_map->SetContentSetting( |
+ embedder_0, origin_0, CONTENT_SETTING_ALLOW); |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_0, origin_0)); |
+ GeolocationContentSettingsMap::RequestingOriginSettings |
+ requesting_origin_settings = |
+ geolocation_content_settings_map->requesting_origin_settings(); |
+ EXPECT_EQ(1U, requesting_origin_settings.size()); |
+ |
+ geolocation_content_settings_map->SetContentSetting( |
+ embedder_0, origin_1, CONTENT_SETTING_ALLOW); |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_0, origin_1)); |
+ requesting_origin_settings = |
+ geolocation_content_settings_map->requesting_origin_settings(); |
+ EXPECT_EQ(2U, requesting_origin_settings.size()); |
+ EXPECT_EQ(1U, requesting_origin_settings[origin_0.GetOrigin()].size()); |
+ EXPECT_EQ(1U, requesting_origin_settings[origin_1.GetOrigin()].size()); |
+ |
+ // Set to default. |
+ geolocation_content_settings_map->SetContentSetting( |
+ embedder_0, origin_0, CONTENT_SETTING_DEFAULT); |
+ requesting_origin_settings = |
+ geolocation_content_settings_map->requesting_origin_settings(); |
+ EXPECT_EQ(1U, requesting_origin_settings.size()); |
+ |
+ geolocation_content_settings_map->SetContentSetting( |
+ embedder_0, origin_1, CONTENT_SETTING_DEFAULT); |
+ requesting_origin_settings = |
+ geolocation_content_settings_map->requesting_origin_settings(); |
+ EXPECT_TRUE(requesting_origin_settings.empty()); |
+} |
+ |
+TEST_F(GeolocationContentSettingsMapTests, WildCardForEmptyEmbedder) { |
+ TestingProfile profile; |
+ GeolocationContentSettingsMap* geolocation_content_settings_map = |
+ profile.GetGeolocationContentSettingsMap(); |
+ GURL empty_embedder; |
+ GURL embedder_0("http://www.toplevel0.com/foo/bar"); |
+ GURL other_embedder("http://www.toplevel1.com/foo/bar"); |
+ GURL origin_0("http://www.iframe0.com/foo/bar"); |
+ geolocation_content_settings_map->SetContentSetting( |
+ embedder_0, origin_0, CONTENT_SETTING_BLOCK); |
+ geolocation_content_settings_map->SetContentSetting( |
+ empty_embedder, origin_0, CONTENT_SETTING_ALLOW); |
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_0, origin_0)); |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ geolocation_content_settings_map->GetContentSetting( |
+ empty_embedder, origin_0)); |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ geolocation_content_settings_map->GetContentSetting( |
+ other_embedder, origin_0)); |
+ |
+ // Change the wildcard behavior. |
+ geolocation_content_settings_map->SetContentSetting( |
+ embedder_0, origin_0, CONTENT_SETTING_ALLOW); |
+ geolocation_content_settings_map->SetContentSetting( |
+ empty_embedder, origin_0, CONTENT_SETTING_BLOCK); |
+ EXPECT_EQ(CONTENT_SETTING_ALLOW, |
+ geolocation_content_settings_map->GetContentSetting( |
+ embedder_0, origin_0)); |
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, |
+ geolocation_content_settings_map->GetContentSetting( |
+ empty_embedder, origin_0)); |
+ EXPECT_EQ(CONTENT_SETTING_BLOCK, |
+ geolocation_content_settings_map->GetContentSetting( |
+ other_embedder, origin_0)); |
+} |
+ |
+} // namespace |