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 "chrome/browser/plugins/plugin_prefs.h" | 5 #include "chrome/browser/plugins/plugin_prefs.h" |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
15 #include "content/public/browser/plugin_service.h" | 15 #include "content/public/browser/plugin_service.h" |
16 #include "content/public/test/test_browser_thread.h" | 16 #include "content/public/test/test_browser_thread.h" |
17 #include "content/public/test/test_utils.h" | |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "webkit/plugins/npapi/mock_plugin_list.h" | |
19 #include "webkit/plugins/webplugininfo.h" | 19 #include "webkit/plugins/webplugininfo.h" |
20 | 20 |
21 using content::BrowserThread; | 21 using content::BrowserThread; |
22 using content::PluginService; | 22 using content::PluginService; |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 void CanEnablePluginCallback(const base::Closure& quit_closure, | 26 void CanEnablePluginCallback(const base::Closure& quit_closure, |
27 bool expected_can_change, | 27 bool expected_can_change, |
28 bool did_change) { | 28 bool did_change) { |
(...skipping 10 matching lines...) Expand all Loading... | |
39 path = path.Append(chrome::kPepperFlashPluginFilename); | 39 path = path.Append(chrome::kPepperFlashPluginFilename); |
40 return path; | 40 return path; |
41 } | 41 } |
42 | 42 |
43 base::FilePath GetBundledPepperFlashPath() { | 43 base::FilePath GetBundledPepperFlashPath() { |
44 base::FilePath path; | 44 base::FilePath path; |
45 EXPECT_TRUE(PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN, &path)); | 45 EXPECT_TRUE(PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN, &path)); |
46 return path; | 46 return path; |
47 } | 47 } |
48 | 48 |
49 void GotPlugins(const base::Closure& quit_closure, | |
50 const std::vector<webkit::WebPluginInfo>& plugins) { | |
51 quit_closure.Run(); | |
52 } | |
53 | |
49 } // namespace | 54 } // namespace |
50 | 55 |
51 class PluginPrefsTest : public ::testing::Test { | 56 class PluginPrefsTest : public ::testing::Test { |
52 public: | 57 public: |
53 virtual void SetUp() OVERRIDE { | 58 virtual void SetUp() OVERRIDE { |
54 plugin_prefs_ = new PluginPrefs(); | 59 plugin_prefs_ = new PluginPrefs(); |
55 } | 60 } |
56 | 61 |
57 void SetPolicyEnforcedPluginPatterns( | 62 void SetPolicyEnforcedPluginPatterns( |
58 const std::set<string16>& disabled, | 63 const std::set<string16>& disabled, |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 plugin_prefs_->PolicyStatusForPlugin(kGoogleMars)); | 180 plugin_prefs_->PolicyStatusForPlugin(kGoogleMars)); |
176 EXPECT_EQ(PluginPrefs::POLICY_DISABLED, | 181 EXPECT_EQ(PluginPrefs::POLICY_DISABLED, |
177 plugin_prefs_->PolicyStatusForPlugin(k42)); | 182 plugin_prefs_->PolicyStatusForPlugin(k42)); |
178 } | 183 } |
179 | 184 |
180 TEST_F(PluginPrefsTest, UnifiedPepperFlashState) { | 185 TEST_F(PluginPrefsTest, UnifiedPepperFlashState) { |
181 base::ShadowingAtExitManager at_exit_manager_; // Destroys the PluginService. | 186 base::ShadowingAtExitManager at_exit_manager_; // Destroys the PluginService. |
182 | 187 |
183 base::MessageLoop message_loop; | 188 base::MessageLoop message_loop; |
184 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 189 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
185 webkit::npapi::MockPluginList plugin_list; | |
186 PluginService::GetInstance()->SetPluginListForTesting(&plugin_list); | |
187 PluginService::GetInstance()->Init(); | 190 PluginService::GetInstance()->Init(); |
191 PluginService::GetInstance()->DisablePluginsDiscoveryForTesting(); | |
188 | 192 |
189 string16 component_updated_plugin_name( | 193 string16 component_updated_plugin_name( |
190 ASCIIToUTF16("Component-updated Pepper Flash")); | 194 ASCIIToUTF16("Component-updated Pepper Flash")); |
191 webkit::WebPluginInfo component_updated_plugin_1( | 195 webkit::WebPluginInfo component_updated_plugin_1( |
192 component_updated_plugin_name, | 196 component_updated_plugin_name, |
193 GetComponentUpdatedPepperFlashPath(FILE_PATH_LITERAL("11.3.31.227")), | 197 GetComponentUpdatedPepperFlashPath(FILE_PATH_LITERAL("11.3.31.227")), |
194 ASCIIToUTF16("11.3.31.227"), | 198 ASCIIToUTF16("11.3.31.227"), |
195 ASCIIToUTF16("")); | 199 ASCIIToUTF16("")); |
196 webkit::WebPluginInfo component_updated_plugin_2( | 200 webkit::WebPluginInfo component_updated_plugin_2( |
197 component_updated_plugin_name, | 201 component_updated_plugin_name, |
198 GetComponentUpdatedPepperFlashPath(FILE_PATH_LITERAL("11.3.31.228")), | 202 GetComponentUpdatedPepperFlashPath(FILE_PATH_LITERAL("11.3.31.228")), |
199 ASCIIToUTF16("11.3.31.228"), | 203 ASCIIToUTF16("11.3.31.228"), |
200 ASCIIToUTF16("")); | 204 ASCIIToUTF16("")); |
201 webkit::WebPluginInfo bundled_plugin(ASCIIToUTF16("Pepper Flash"), | 205 webkit::WebPluginInfo bundled_plugin(ASCIIToUTF16("Pepper Flash"), |
202 GetBundledPepperFlashPath(), | 206 GetBundledPepperFlashPath(), |
203 ASCIIToUTF16("11.3.31.229"), | 207 ASCIIToUTF16("11.3.31.229"), |
204 ASCIIToUTF16("")); | 208 ASCIIToUTF16("")); |
205 | 209 |
206 plugin_list.AddPluginToLoad(component_updated_plugin_1); | 210 PluginService::GetInstance()->RegisterInternalPlugin( |
207 plugin_list.AddPluginToLoad(component_updated_plugin_2); | 211 component_updated_plugin_1, false); |
208 plugin_list.AddPluginToLoad(bundled_plugin); | 212 PluginService::GetInstance()->RegisterInternalPlugin( |
213 component_updated_plugin_2, false); | |
214 PluginService::GetInstance()->RegisterInternalPlugin(bundled_plugin, false); | |
215 | |
216 scoped_refptr<content::MessageLoopRunner> runner = | |
scottmg
2013/07/18 00:33:09
was this previously a bug?
jam
2013/07/18 00:36:35
When MockPlugin was used, plugins were available i
| |
217 new content::MessageLoopRunner; | |
218 PluginService::GetInstance()->GetPlugins( | |
219 base::Bind(&GotPlugins, runner->QuitClosure())); | |
220 runner->Run(); | |
209 | 221 |
210 // Set the state of any of the three plugins will affect the others. | 222 // Set the state of any of the three plugins will affect the others. |
211 EnablePluginSynchronously(true, component_updated_plugin_1.path, true); | 223 EnablePluginSynchronously(true, component_updated_plugin_1.path, true); |
212 EXPECT_TRUE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_1)); | 224 EXPECT_TRUE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_1)); |
213 EXPECT_TRUE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_2)); | 225 EXPECT_TRUE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_2)); |
214 EXPECT_TRUE(plugin_prefs_->IsPluginEnabled(bundled_plugin)); | 226 EXPECT_TRUE(plugin_prefs_->IsPluginEnabled(bundled_plugin)); |
215 | 227 |
216 EnablePluginSynchronously(false, bundled_plugin.path, true); | 228 EnablePluginSynchronously(false, bundled_plugin.path, true); |
217 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_1)); | 229 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_1)); |
218 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_2)); | 230 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_2)); |
(...skipping 23 matching lines...) Expand all Loading... | |
242 // they are not restricted by any policy. | 254 // they are not restricted by any policy. |
243 EnablePluginSynchronously(true, component_updated_plugin_1.path, false); | 255 EnablePluginSynchronously(true, component_updated_plugin_1.path, false); |
244 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_1)); | 256 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_1)); |
245 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_2)); | 257 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_2)); |
246 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(bundled_plugin)); | 258 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(bundled_plugin)); |
247 | 259 |
248 EnablePluginSynchronously(true, bundled_plugin.path, true); | 260 EnablePluginSynchronously(true, bundled_plugin.path, true); |
249 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_1)); | 261 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_1)); |
250 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_2)); | 262 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_2)); |
251 EXPECT_TRUE(plugin_prefs_->IsPluginEnabled(bundled_plugin)); | 263 EXPECT_TRUE(plugin_prefs_->IsPluginEnabled(bundled_plugin)); |
252 | |
253 PluginService::GetInstance()->SetPluginListForTesting(NULL); | |
254 } | 264 } |
OLD | NEW |