Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Side by Side Diff: chrome/browser/content_settings/content_settings_policy_provider_unittest.cc

Issue 1086733002: Ensure tests have an active task runner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/content_settings/core/browser/content_settings_policy_provi der.h" 5 #include "components/content_settings/core/browser/content_settings_policy_provi der.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 "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "chrome/browser/content_settings/content_settings_mock_observer.h" 14 #include "chrome/browser/content_settings/content_settings_mock_observer.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
17 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
18 #include "chrome/test/base/testing_pref_service_syncable.h" 18 #include "chrome/test/base/testing_pref_service_syncable.h"
19 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
20 #include "components/content_settings/core/browser/content_settings_rule.h" 20 #include "components/content_settings/core/browser/content_settings_rule.h"
21 #include "components/content_settings/core/browser/content_settings_utils.h" 21 #include "components/content_settings/core/browser/content_settings_utils.h"
22 #include "components/content_settings/core/test/content_settings_test_utils.h" 22 #include "components/content_settings/core/test/content_settings_test_utils.h"
23 #include "content/public/test/test_browser_thread_bundle.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 #include "url/gurl.h" 25 #include "url/gurl.h"
25 26
26 using ::testing::_; 27 using ::testing::_;
27 28
28 namespace content_settings { 29 namespace content_settings {
29 30
30 typedef std::vector<Rule> Rules; 31 typedef std::vector<Rule> Rules;
31 32
32 TEST(PolicyProviderTest, DefaultGeolocationContentSetting) { 33 class PolicyProviderTest : public testing::Test {
34 content::TestBrowserThreadBundle thread_bundle_;
35 };
36
37 TEST_F(PolicyProviderTest, DefaultGeolocationContentSetting) {
33 TestingProfile profile; 38 TestingProfile profile;
34 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 39 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
35 PolicyProvider provider(prefs); 40 PolicyProvider provider(prefs);
36 41
37 Rules rules; 42 Rules rules;
38 43
39 scoped_ptr<RuleIterator> rule_iterator( 44 scoped_ptr<RuleIterator> rule_iterator(
40 provider.GetRuleIterator( 45 provider.GetRuleIterator(
41 CONTENT_SETTINGS_TYPE_GEOLOCATION, 46 CONTENT_SETTINGS_TYPE_GEOLOCATION,
42 std::string(), 47 std::string(),
(...skipping 13 matching lines...) Expand all
56 Rule rule = rule_iterator->Next(); 61 Rule rule = rule_iterator->Next();
57 EXPECT_FALSE(rule_iterator->HasNext()); 62 EXPECT_FALSE(rule_iterator->HasNext());
58 63
59 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern); 64 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern);
60 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern); 65 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern);
61 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get())); 66 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get()));
62 67
63 provider.ShutdownOnUIThread(); 68 provider.ShutdownOnUIThread();
64 } 69 }
65 70
66 TEST(PolicyProviderTest, ManagedDefaultContentSettings) { 71 TEST_F(PolicyProviderTest, ManagedDefaultContentSettings) {
67 TestingProfile profile; 72 TestingProfile profile;
68 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 73 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
69 PolicyProvider provider(prefs); 74 PolicyProvider provider(prefs);
70 75
71 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, 76 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting,
72 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 77 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
73 78
74 scoped_ptr<RuleIterator> rule_iterator( 79 scoped_ptr<RuleIterator> rule_iterator(
75 provider.GetRuleIterator( 80 provider.GetRuleIterator(
76 CONTENT_SETTINGS_TYPE_PLUGINS, 81 CONTENT_SETTINGS_TYPE_PLUGINS,
77 std::string(), 82 std::string(),
78 false)); 83 false));
79 EXPECT_TRUE(rule_iterator->HasNext()); 84 EXPECT_TRUE(rule_iterator->HasNext());
80 Rule rule = rule_iterator->Next(); 85 Rule rule = rule_iterator->Next();
81 EXPECT_FALSE(rule_iterator->HasNext()); 86 EXPECT_FALSE(rule_iterator->HasNext());
82 87
83 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern); 88 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern);
84 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern); 89 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern);
85 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get())); 90 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get()));
86 91
87 provider.ShutdownOnUIThread(); 92 provider.ShutdownOnUIThread();
88 } 93 }
89 94
90 // When a default-content-setting is set to a managed setting a 95 // When a default-content-setting is set to a managed setting a
91 // CONTENT_SETTINGS_CHANGED notification should be fired. The same should happen 96 // CONTENT_SETTINGS_CHANGED notification should be fired. The same should happen
92 // if the managed setting is removed. 97 // if the managed setting is removed.
93 TEST(PolicyProviderTest, ObserveManagedSettingsChange) { 98 TEST_F(PolicyProviderTest, ObserveManagedSettingsChange) {
94 TestingProfile profile; 99 TestingProfile profile;
95 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 100 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
96 PolicyProvider provider(prefs); 101 PolicyProvider provider(prefs);
97 102
98 MockObserver mock_observer; 103 MockObserver mock_observer;
99 EXPECT_CALL(mock_observer, 104 EXPECT_CALL(mock_observer,
100 OnContentSettingChanged(_, 105 OnContentSettingChanged(_,
101 _, 106 _,
102 CONTENT_SETTINGS_TYPE_DEFAULT, 107 CONTENT_SETTINGS_TYPE_DEFAULT,
103 "")); 108 ""));
104 provider.AddObserver(&mock_observer); 109 provider.AddObserver(&mock_observer);
105 110
106 // Set the managed default-content-setting. 111 // Set the managed default-content-setting.
107 prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting, 112 prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting,
108 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 113 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
109 ::testing::Mock::VerifyAndClearExpectations(&mock_observer); 114 ::testing::Mock::VerifyAndClearExpectations(&mock_observer);
110 EXPECT_CALL(mock_observer, 115 EXPECT_CALL(mock_observer,
111 OnContentSettingChanged(_, 116 OnContentSettingChanged(_,
112 _, 117 _,
113 CONTENT_SETTINGS_TYPE_DEFAULT, 118 CONTENT_SETTINGS_TYPE_DEFAULT,
114 "")); 119 ""));
115 // Remove the managed default-content-setting. 120 // Remove the managed default-content-setting.
116 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting); 121 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting);
117 provider.ShutdownOnUIThread(); 122 provider.ShutdownOnUIThread();
118 } 123 }
119 124
120 TEST(PolicyProviderTest, GettingManagedContentSettings) { 125 TEST_F(PolicyProviderTest, GettingManagedContentSettings) {
121 TestingProfile profile; 126 TestingProfile profile;
122 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 127 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
123 128
124 base::ListValue* value = new base::ListValue(); 129 base::ListValue* value = new base::ListValue();
125 value->Append(new base::StringValue("[*.]google.com")); 130 value->Append(new base::StringValue("[*.]google.com"));
126 prefs->SetManagedPref(prefs::kManagedImagesBlockedForUrls, 131 prefs->SetManagedPref(prefs::kManagedImagesBlockedForUrls,
127 value); 132 value);
128 133
129 PolicyProvider provider(prefs); 134 PolicyProvider provider(prefs);
130 135
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 GetContentSetting(&provider, 187 GetContentSetting(&provider,
183 youtube_url, 188 youtube_url,
184 youtube_url, 189 youtube_url,
185 CONTENT_SETTINGS_TYPE_COOKIES, 190 CONTENT_SETTINGS_TYPE_COOKIES,
186 std::string(), 191 std::string(),
187 false)); 192 false));
188 193
189 provider.ShutdownOnUIThread(); 194 provider.ShutdownOnUIThread();
190 } 195 }
191 196
192 TEST(PolicyProviderTest, ResourceIdentifier) { 197 TEST_F(PolicyProviderTest, ResourceIdentifier) {
193 TestingProfile profile; 198 TestingProfile profile;
194 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 199 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
195 200
196 base::ListValue* value = new base::ListValue(); 201 base::ListValue* value = new base::ListValue();
197 value->Append(new base::StringValue("[*.]google.com")); 202 value->Append(new base::StringValue("[*.]google.com"));
198 prefs->SetManagedPref(prefs::kManagedPluginsAllowedForUrls, 203 prefs->SetManagedPref(prefs::kManagedPluginsAllowedForUrls,
199 value); 204 value);
200 205
201 PolicyProvider provider(prefs); 206 PolicyProvider provider(prefs);
202 207
(...skipping 16 matching lines...) Expand all
219 false)); 224 false));
220 225
221 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 226 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
222 GetContentSetting( 227 GetContentSetting(
223 &provider, google_url, google_url, 228 &provider, google_url, google_url,
224 CONTENT_SETTINGS_TYPE_PLUGINS, "someplugin", false)); 229 CONTENT_SETTINGS_TYPE_PLUGINS, "someplugin", false));
225 230
226 provider.ShutdownOnUIThread(); 231 provider.ShutdownOnUIThread();
227 } 232 }
228 233
229 TEST(PolicyProviderTest, AutoSelectCertificateList) { 234 TEST_F(PolicyProviderTest, AutoSelectCertificateList) {
230 TestingProfile profile; 235 TestingProfile profile;
231 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 236 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
232 237
233 PolicyProvider provider(prefs); 238 PolicyProvider provider(prefs);
234 GURL google_url("https://mail.google.com"); 239 GURL google_url("https://mail.google.com");
235 // Tests the default setting for auto selecting certificates 240 // Tests the default setting for auto selecting certificates
236 EXPECT_EQ( 241 EXPECT_EQ(
237 NULL, 242 NULL,
238 GetContentSettingValue(&provider, 243 GetContentSettingValue(&provider,
239 google_url, 244 google_url,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 ASSERT_EQ(base::Value::TYPE_DICTIONARY, cert_filter->GetType()); 276 ASSERT_EQ(base::Value::TYPE_DICTIONARY, cert_filter->GetType());
272 base::DictionaryValue* dict_value = 277 base::DictionaryValue* dict_value =
273 static_cast<base::DictionaryValue*>(cert_filter.get()); 278 static_cast<base::DictionaryValue*>(cert_filter.get());
274 std::string actual_common_name; 279 std::string actual_common_name;
275 ASSERT_TRUE(dict_value->GetString("ISSUER.CN", &actual_common_name)); 280 ASSERT_TRUE(dict_value->GetString("ISSUER.CN", &actual_common_name));
276 EXPECT_EQ("issuer name", actual_common_name); 281 EXPECT_EQ("issuer name", actual_common_name);
277 provider.ShutdownOnUIThread(); 282 provider.ShutdownOnUIThread();
278 } 283 }
279 284
280 } // namespace content_settings 285 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698