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/plugin_prefs.h" | 5 #include "chrome/browser/plugin_prefs.h" |
6 | 6 |
7 #include "base/at_exit.h" | |
8 #include "base/bind.h" | |
9 #include "base/message_loop.h" | |
7 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
8 #include "chrome/test/base/testing_browser_process.h" | 11 #include "chrome/test/base/testing_browser_process.h" |
9 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
10 #include "chrome/test/base/testing_profile_manager.h" | 13 #include "chrome/test/base/testing_profile_manager.h" |
14 #include "content/browser/plugin_service.h" | |
11 #include "content/test/test_browser_thread.h" | 15 #include "content/test/test_browser_thread.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "webkit/plugins/npapi/mock_plugin_list.cc" | 17 #include "webkit/plugins/npapi/mock_plugin_list.cc" |
14 #include "webkit/plugins/webplugininfo.h" | 18 #include "webkit/plugins/webplugininfo.h" |
15 | 19 |
16 using content::BrowserThread; | 20 using content::BrowserThread; |
17 | 21 |
18 class PluginPrefsTest : public ::testing::Test { | 22 class PluginPrefsTest : public ::testing::Test { |
19 public: | 23 public: |
20 virtual void SetUp() OVERRIDE { | 24 virtual void SetUp() OVERRIDE { |
21 plugin_prefs_ = new PluginPrefs(); | 25 plugin_prefs_ = new PluginPrefs(); |
22 } | 26 } |
23 | 27 |
24 void SetPolicyEnforcedPluginPatterns( | 28 void SetPolicyEnforcedPluginPatterns( |
25 const std::set<string16>& disabled, | 29 const std::set<string16>& disabled, |
26 const std::set<string16>& disabled_exceptions, | 30 const std::set<string16>& disabled_exceptions, |
27 const std::set<string16>& enabled) { | 31 const std::set<string16>& enabled) { |
28 plugin_prefs_->SetPolicyEnforcedPluginPatterns( | 32 plugin_prefs_->SetPolicyEnforcedPluginPatterns( |
29 disabled, disabled_exceptions, enabled); | 33 disabled, disabled_exceptions, enabled); |
30 } | 34 } |
31 | 35 |
32 protected: | 36 protected: |
37 base::ShadowingAtExitManager at_exit_manager_; // Destroys the PluginService. | |
Bernhard Bauer
2011/11/10 23:19:24
You could move this down to PluginPrefsTest.Disabl
Robert Sesek
2011/11/10 23:25:39
Done.
| |
38 | |
33 scoped_refptr<PluginPrefs> plugin_prefs_; | 39 scoped_refptr<PluginPrefs> plugin_prefs_; |
34 }; | 40 }; |
35 | 41 |
36 TEST_F(PluginPrefsTest, DisabledByPolicy) { | 42 TEST_F(PluginPrefsTest, DisabledByPolicy) { |
37 std::set<string16> disabled_plugins; | 43 std::set<string16> disabled_plugins; |
38 disabled_plugins.insert(ASCIIToUTF16("Disable this!")); | 44 disabled_plugins.insert(ASCIIToUTF16("Disable this!")); |
39 disabled_plugins.insert(ASCIIToUTF16("*Google*")); | 45 disabled_plugins.insert(ASCIIToUTF16("*Google*")); |
40 SetPolicyEnforcedPluginPatterns(disabled_plugins, | 46 SetPolicyEnforcedPluginPatterns(disabled_plugins, |
41 std::set<string16>(), | 47 std::set<string16>(), |
42 std::set<string16>()); | 48 std::set<string16>()); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 plugin_prefs_->PolicyStatusForPlugin(kGoogleMars)); | 137 plugin_prefs_->PolicyStatusForPlugin(kGoogleMars)); |
132 EXPECT_EQ(PluginPrefs::POLICY_DISABLED, | 138 EXPECT_EQ(PluginPrefs::POLICY_DISABLED, |
133 plugin_prefs_->PolicyStatusForPlugin(k42)); | 139 plugin_prefs_->PolicyStatusForPlugin(k42)); |
134 } | 140 } |
135 | 141 |
136 TEST_F(PluginPrefsTest, DisableGlobally) { | 142 TEST_F(PluginPrefsTest, DisableGlobally) { |
137 MessageLoop message_loop; | 143 MessageLoop message_loop; |
138 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 144 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
139 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); | 145 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); |
140 | 146 |
147 webkit::npapi::MockPluginList plugin_list(NULL, 0); | |
148 PluginService::GetInstance()->SetPluginListForTesting(&plugin_list); | |
149 PluginService::GetInstance()->Init(); | |
150 | |
141 TestingBrowserProcess* browser_process = | 151 TestingBrowserProcess* browser_process = |
142 static_cast<TestingBrowserProcess*>(g_browser_process); | 152 static_cast<TestingBrowserProcess*>(g_browser_process); |
143 TestingProfileManager profile_manager(browser_process); | 153 TestingProfileManager profile_manager(browser_process); |
144 ASSERT_TRUE(profile_manager.SetUp()); | 154 ASSERT_TRUE(profile_manager.SetUp()); |
145 | 155 |
146 TestingProfile* profile_1 = | 156 TestingProfile* profile_1 = |
147 profile_manager.CreateTestingProfile("Profile 1"); | 157 profile_manager.CreateTestingProfile("Profile 1"); |
148 PluginPrefs* plugin_prefs = PluginPrefs::GetForTestingProfile(profile_1); | 158 PluginPrefs* plugin_prefs = PluginPrefs::GetForTestingProfile(profile_1); |
149 ASSERT_TRUE(plugin_prefs); | 159 ASSERT_TRUE(plugin_prefs); |
160 plugin_prefs->SetPluginListForTesting(&plugin_list); | |
150 | 161 |
151 webkit::WebPluginInfo plugin(ASCIIToUTF16("Foo"), | 162 webkit::WebPluginInfo plugin(ASCIIToUTF16("Foo"), |
152 FilePath(FILE_PATH_LITERAL("/path/too/foo")), | 163 FilePath(FILE_PATH_LITERAL("/path/too/foo")), |
153 ASCIIToUTF16("1.0.0"), | 164 ASCIIToUTF16("1.0.0"), |
154 ASCIIToUTF16("Foo plug-in")); | 165 ASCIIToUTF16("Foo plug-in")); |
155 webkit::npapi::MockPluginList plugin_list(NULL, 0); | |
156 plugin_list.AddPluginToLoad(plugin); | 166 plugin_list.AddPluginToLoad(plugin); |
157 plugin_prefs->SetPluginListForTesting(&plugin_list); | |
158 EXPECT_TRUE(PluginPrefs::EnablePluginGlobally(false, plugin.path)); | 167 EXPECT_TRUE(PluginPrefs::EnablePluginGlobally(false, plugin.path)); |
159 | 168 |
169 message_loop.RunAllPending(); | |
170 | |
160 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(plugin)); | 171 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(plugin)); |
161 | 172 |
162 TestingProfile* profile_2 = | 173 TestingProfile* profile_2 = |
163 profile_manager.CreateTestingProfile("Profile 2"); | 174 profile_manager.CreateTestingProfile("Profile 2"); |
164 PluginPrefs* plugin_prefs_2 = PluginPrefs::GetForTestingProfile(profile_2); | 175 PluginPrefs* plugin_prefs_2 = PluginPrefs::GetForTestingProfile(profile_2); |
165 ASSERT_TRUE(plugin_prefs); | 176 ASSERT_TRUE(plugin_prefs); |
166 plugin_prefs_2->SetPluginListForTesting(&plugin_list); | 177 plugin_prefs_2->SetPluginListForTesting(&plugin_list); |
167 EXPECT_FALSE(plugin_prefs_2->IsPluginEnabled(plugin)); | 178 EXPECT_FALSE(plugin_prefs_2->IsPluginEnabled(plugin)); |
179 | |
180 profile_manager.DeleteTestingProfile("Profile 1"); | |
181 profile_manager.DeleteTestingProfile("Profile 2"); | |
168 } | 182 } |
OLD | NEW |