| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/content_settings/content_settings_policy_provider.h" | 5 #include "chrome/browser/content_settings/content_settings_policy_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/content_settings/content_settings_mock_observer.h" | 12 #include "chrome/browser/content_settings/content_settings_mock_observer.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 16 #include "chrome/test/base/testing_pref_service.h" | 17 #include "chrome/test/base/testing_pref_service.h" |
| 17 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 18 #include "content/browser/browser_thread.h" | 19 #include "content/browser/browser_thread.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 EXPECT_CALL(mock_observer, | 122 EXPECT_CALL(mock_observer, |
| 122 OnContentSettingChanged(_, | 123 OnContentSettingChanged(_, |
| 123 _, | 124 _, |
| 124 CONTENT_SETTINGS_TYPE_DEFAULT, | 125 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 125 "")); | 126 "")); |
| 126 // Remove the managed default-content-setting. | 127 // Remove the managed default-content-setting. |
| 127 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting); | 128 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting); |
| 128 provider.ShutdownOnUIThread(); | 129 provider.ShutdownOnUIThread(); |
| 129 } | 130 } |
| 130 | 131 |
| 131 TEST_F(PolicyDefaultProviderTest, AutoSelectCertificate) { | |
| 132 TestingProfile profile; | |
| 133 TestingPrefService* prefs = profile.GetTestingPrefService(); | |
| 134 PolicyDefaultProvider provider(prefs); | |
| 135 | |
| 136 EXPECT_EQ(CONTENT_SETTING_ASK, | |
| 137 provider.ProvideDefaultSetting( | |
| 138 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE)); | |
| 139 | |
| 140 provider.ShutdownOnUIThread(); | |
| 141 } | |
| 142 | |
| 143 class PolicyProviderTest : public testing::Test { | 132 class PolicyProviderTest : public testing::Test { |
| 144 public: | 133 public: |
| 145 PolicyProviderTest() | 134 PolicyProviderTest() |
| 146 : ui_thread_(BrowserThread::UI, &message_loop_) { | 135 : ui_thread_(BrowserThread::UI, &message_loop_) { |
| 147 } | 136 } |
| 148 | 137 |
| 149 protected: | 138 protected: |
| 150 // TODO(markusheintz): Check if it's possible to derive the provider class | 139 // TODO(markusheintz): Check if it's possible to derive the provider class |
| 151 // from NonThreadSafe and to use native thread identifiers instead of | 140 // from NonThreadSafe and to use native thread identifiers instead of |
| 152 // BrowserThread IDs. Then we could get rid of the message_loop and ui_thread | 141 // BrowserThread IDs. Then we could get rid of the message_loop and ui_thread |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 provider.ShutdownOnUIThread(); | 237 provider.ShutdownOnUIThread(); |
| 249 } | 238 } |
| 250 | 239 |
| 251 TEST_F(PolicyProviderTest, AutoSelectCertificateList) { | 240 TEST_F(PolicyProviderTest, AutoSelectCertificateList) { |
| 252 TestingProfile profile; | 241 TestingProfile profile; |
| 253 TestingPrefService* prefs = profile.GetTestingPrefService(); | 242 TestingPrefService* prefs = profile.GetTestingPrefService(); |
| 254 | 243 |
| 255 PolicyProvider provider(prefs, NULL); | 244 PolicyProvider provider(prefs, NULL); |
| 256 GURL google_url("https://mail.google.com"); | 245 GURL google_url("https://mail.google.com"); |
| 257 // Tests the default setting for auto selecting certificates | 246 // Tests the default setting for auto selecting certificates |
| 258 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 247 EXPECT_EQ(NULL, |
| 259 provider.GetContentSetting( | 248 provider.GetContentSettingValue( |
| 260 google_url, | 249 google_url, |
| 261 google_url, | 250 google_url, |
| 262 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, | 251 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, |
| 263 std::string())); | 252 std::string())); |
| 264 | 253 |
| 265 // Set the content settings pattern list for origins to auto select | 254 // Set the content settings pattern list for origins to auto select |
| 266 // certificates. | 255 // certificates. |
| 256 std::string pattern_str("\"pattern\":\"[*.]google.com\""); |
| 257 std::string filter_str("\"filter\":{\"ISSUER\":{\"CN\":\"issuer name\"}}"); |
| 267 ListValue* value = new ListValue(); | 258 ListValue* value = new ListValue(); |
| 268 value->Append(Value::CreateStringValue("[*.]google.com")); | 259 value->Append(Value::CreateStringValue( |
| 260 "{" + pattern_str + "," + filter_str + "}")); |
| 269 prefs->SetManagedPref(prefs::kManagedAutoSelectCertificateForUrls, | 261 prefs->SetManagedPref(prefs::kManagedAutoSelectCertificateForUrls, |
| 270 value); | 262 value); |
| 271 GURL youtube_url("https://www.youtube.com"); | 263 GURL youtube_url("https://www.youtube.com"); |
| 272 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 264 EXPECT_EQ(NULL, |
| 273 provider.GetContentSetting( | 265 provider.GetContentSettingValue( |
| 274 youtube_url, | 266 youtube_url, |
| 275 youtube_url, | 267 youtube_url, |
| 276 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, | 268 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, |
| 277 std::string())); | 269 std::string())); |
| 278 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 270 scoped_ptr<Value> cert_filter(provider.GetContentSettingValue( |
| 279 provider.GetContentSetting( | 271 google_url, |
| 280 google_url, | 272 google_url, |
| 281 google_url, | 273 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, |
| 282 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, | 274 std::string())); |
| 283 std::string())); | |
| 284 | 275 |
| 276 ASSERT_EQ(Value::TYPE_DICTIONARY, cert_filter->GetType()); |
| 277 DictionaryValue* dict_value = |
| 278 static_cast<DictionaryValue*>(cert_filter.get()); |
| 279 std::string actual_common_name; |
| 280 ASSERT_TRUE(dict_value->GetString("ISSUER.CN", &actual_common_name)); |
| 281 EXPECT_EQ("issuer name", actual_common_name); |
| 285 provider.ShutdownOnUIThread(); | 282 provider.ShutdownOnUIThread(); |
| 286 } | 283 } |
| 284 |
| 287 } // namespace content_settings | 285 } // namespace content_settings |
| OLD | NEW |