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

Side by Side Diff: chrome/browser/plugins/plugin_prefs_unittest.cc

Issue 19706002: Remove plugin_list.h includes from chrome tests in preparation for moving webkit/plugins to content… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix posix tests Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
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/browser/render_process_host.h"
16 #include "content/public/test/test_browser_thread.h" 17 #include "content/public/test/test_browser_thread.h"
18 #include "content/public/test/test_utils.h"
17 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
18 #include "webkit/plugins/npapi/mock_plugin_list.h"
19 #include "webkit/plugins/webplugininfo.h" 20 #include "webkit/plugins/webplugininfo.h"
20 21
21 using content::BrowserThread; 22 using content::BrowserThread;
22 using content::PluginService; 23 using content::PluginService;
23 24
24 namespace { 25 namespace {
25 26
26 void CanEnablePluginCallback(const base::Closure& quit_closure, 27 void CanEnablePluginCallback(const base::Closure& quit_closure,
27 bool expected_can_change, 28 bool expected_can_change,
28 bool did_change) { 29 bool did_change) {
(...skipping 10 matching lines...) Expand all
39 path = path.Append(chrome::kPepperFlashPluginFilename); 40 path = path.Append(chrome::kPepperFlashPluginFilename);
40 return path; 41 return path;
41 } 42 }
42 43
43 base::FilePath GetBundledPepperFlashPath() { 44 base::FilePath GetBundledPepperFlashPath() {
44 base::FilePath path; 45 base::FilePath path;
45 EXPECT_TRUE(PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN, &path)); 46 EXPECT_TRUE(PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN, &path));
46 return path; 47 return path;
47 } 48 }
48 49
50 void GotPlugins(const base::Closure& quit_closure,
51 const std::vector<webkit::WebPluginInfo>& plugins) {
52 quit_closure.Run();
53 }
54
49 } // namespace 55 } // namespace
50 56
51 class PluginPrefsTest : public ::testing::Test { 57 class PluginPrefsTest : public ::testing::Test {
52 public: 58 public:
53 virtual void SetUp() OVERRIDE { 59 virtual void SetUp() OVERRIDE {
54 plugin_prefs_ = new PluginPrefs(); 60 plugin_prefs_ = new PluginPrefs();
55 } 61 }
56 62
57 void SetPolicyEnforcedPluginPatterns( 63 void SetPolicyEnforcedPluginPatterns(
58 const std::set<string16>& disabled, 64 const std::set<string16>& disabled,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 enabled_plugins); 176 enabled_plugins);
171 177
172 EXPECT_EQ(PluginPrefs::POLICY_ENABLED, 178 EXPECT_EQ(PluginPrefs::POLICY_ENABLED,
173 plugin_prefs_->PolicyStatusForPlugin(kGoogleEarth)); 179 plugin_prefs_->PolicyStatusForPlugin(kGoogleEarth));
174 EXPECT_EQ(PluginPrefs::NO_POLICY, 180 EXPECT_EQ(PluginPrefs::NO_POLICY,
175 plugin_prefs_->PolicyStatusForPlugin(kGoogleMars)); 181 plugin_prefs_->PolicyStatusForPlugin(kGoogleMars));
176 EXPECT_EQ(PluginPrefs::POLICY_DISABLED, 182 EXPECT_EQ(PluginPrefs::POLICY_DISABLED,
177 plugin_prefs_->PolicyStatusForPlugin(k42)); 183 plugin_prefs_->PolicyStatusForPlugin(k42));
178 } 184 }
179 185
186 // Linux Aura doesn't support NPAPI.
187 #if !(defined(OS_LINUX) && defined(USE_AURA))
188
180 TEST_F(PluginPrefsTest, UnifiedPepperFlashState) { 189 TEST_F(PluginPrefsTest, UnifiedPepperFlashState) {
181 base::ShadowingAtExitManager at_exit_manager_; // Destroys the PluginService. 190 base::ShadowingAtExitManager at_exit_manager_; // Destroys the PluginService.
182 191
183 base::MessageLoop message_loop; 192 base::MessageLoop message_loop;
184 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 193 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
185 webkit::npapi::MockPluginList plugin_list;
186 PluginService::GetInstance()->SetPluginListForTesting(&plugin_list);
187 PluginService::GetInstance()->Init(); 194 PluginService::GetInstance()->Init();
195 PluginService::GetInstance()->DisablePluginsDiscoveryForTesting();
188 196
189 string16 component_updated_plugin_name( 197 string16 component_updated_plugin_name(
190 ASCIIToUTF16("Component-updated Pepper Flash")); 198 ASCIIToUTF16("Component-updated Pepper Flash"));
191 webkit::WebPluginInfo component_updated_plugin_1( 199 webkit::WebPluginInfo component_updated_plugin_1(
192 component_updated_plugin_name, 200 component_updated_plugin_name,
193 GetComponentUpdatedPepperFlashPath(FILE_PATH_LITERAL("11.3.31.227")), 201 GetComponentUpdatedPepperFlashPath(FILE_PATH_LITERAL("11.3.31.227")),
194 ASCIIToUTF16("11.3.31.227"), 202 ASCIIToUTF16("11.3.31.227"),
195 ASCIIToUTF16("")); 203 ASCIIToUTF16(""));
196 webkit::WebPluginInfo component_updated_plugin_2( 204 webkit::WebPluginInfo component_updated_plugin_2(
197 component_updated_plugin_name, 205 component_updated_plugin_name,
198 GetComponentUpdatedPepperFlashPath(FILE_PATH_LITERAL("11.3.31.228")), 206 GetComponentUpdatedPepperFlashPath(FILE_PATH_LITERAL("11.3.31.228")),
199 ASCIIToUTF16("11.3.31.228"), 207 ASCIIToUTF16("11.3.31.228"),
200 ASCIIToUTF16("")); 208 ASCIIToUTF16(""));
201 webkit::WebPluginInfo bundled_plugin(ASCIIToUTF16("Pepper Flash"), 209 webkit::WebPluginInfo bundled_plugin(ASCIIToUTF16("Pepper Flash"),
202 GetBundledPepperFlashPath(), 210 GetBundledPepperFlashPath(),
203 ASCIIToUTF16("11.3.31.229"), 211 ASCIIToUTF16("11.3.31.229"),
204 ASCIIToUTF16("")); 212 ASCIIToUTF16(""));
205 213
206 plugin_list.AddPluginToLoad(component_updated_plugin_1); 214 PluginService::GetInstance()->RegisterInternalPlugin(
207 plugin_list.AddPluginToLoad(component_updated_plugin_2); 215 component_updated_plugin_1, false);
208 plugin_list.AddPluginToLoad(bundled_plugin); 216 PluginService::GetInstance()->RegisterInternalPlugin(
217 component_updated_plugin_2, false);
218 PluginService::GetInstance()->RegisterInternalPlugin(bundled_plugin, false);
219
220 #if !defined(OS_WIN)
221 // Can't go out of process in unit tests.
222 content::RenderProcessHost::SetRunRendererInProcess(true);
223 #endif
224 scoped_refptr<content::MessageLoopRunner> runner =
225 new content::MessageLoopRunner;
226 PluginService::GetInstance()->GetPlugins(
227 base::Bind(&GotPlugins, runner->QuitClosure()));
228 runner->Run();
229 #if !defined(OS_WIN)
230 content::RenderProcessHost::SetRunRendererInProcess(false);
231 #endif
209 232
210 // Set the state of any of the three plugins will affect the others. 233 // Set the state of any of the three plugins will affect the others.
211 EnablePluginSynchronously(true, component_updated_plugin_1.path, true); 234 EnablePluginSynchronously(true, component_updated_plugin_1.path, true);
212 EXPECT_TRUE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_1)); 235 EXPECT_TRUE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_1));
213 EXPECT_TRUE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_2)); 236 EXPECT_TRUE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_2));
214 EXPECT_TRUE(plugin_prefs_->IsPluginEnabled(bundled_plugin)); 237 EXPECT_TRUE(plugin_prefs_->IsPluginEnabled(bundled_plugin));
215 238
216 EnablePluginSynchronously(false, bundled_plugin.path, true); 239 EnablePluginSynchronously(false, bundled_plugin.path, true);
217 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_1)); 240 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_1));
218 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_2)); 241 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_2));
(...skipping 23 matching lines...) Expand all
242 // they are not restricted by any policy. 265 // they are not restricted by any policy.
243 EnablePluginSynchronously(true, component_updated_plugin_1.path, false); 266 EnablePluginSynchronously(true, component_updated_plugin_1.path, false);
244 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_1)); 267 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_1));
245 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_2)); 268 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_2));
246 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(bundled_plugin)); 269 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(bundled_plugin));
247 270
248 EnablePluginSynchronously(true, bundled_plugin.path, true); 271 EnablePluginSynchronously(true, bundled_plugin.path, true);
249 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_1)); 272 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_1));
250 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_2)); 273 EXPECT_FALSE(plugin_prefs_->IsPluginEnabled(component_updated_plugin_2));
251 EXPECT_TRUE(plugin_prefs_->IsPluginEnabled(bundled_plugin)); 274 EXPECT_TRUE(plugin_prefs_->IsPluginEnabled(bundled_plugin));
275 }
252 276
253 PluginService::GetInstance()->SetPluginListForTesting(NULL); 277 #endif
254 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service_unittest.cc ('k') | chrome/browser/printing/print_preview_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698