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

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

Issue 645203002: Block NPAPI plugins by default (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reorder initializers for clang Created 6 years, 2 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) 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/content_settings/cookie_settings.h" 10 #include "chrome/browser/content_settings/cookie_settings.h"
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 content::WebContents* web_contents = 287 content::WebContents* web_contents =
288 browser()->tab_strip_model()->GetActiveWebContents(); 288 browser()->tab_strip_model()->GetActiveWebContents();
289 289
290 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)-> 290 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)->
291 IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES)); 291 IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES));
292 } 292 }
293 293
294 // On Aura NPAPI only works on Windows. 294 // On Aura NPAPI only works on Windows.
295 #if !defined(USE_AURA) || defined(OS_WIN) 295 #if !defined(USE_AURA) || defined(OS_WIN)
296 296
297 class ClickToPlayPluginTest : public ContentSettingsTest { 297 class LoadPluginTest : public ContentSettingsTest {
298 public: 298 protected:
299 ClickToPlayPluginTest() {} 299 void PerformTest(bool expect_loaded) {
300 GURL url = ui_test_utils::GetTestUrl(
301 base::FilePath(),
302 base::FilePath().AppendASCII("load_npapi_plugin.html"));
303 ui_test_utils::NavigateToURL(browser(), url);
300 304
305 const char* expected_result = expect_loaded ? "Loaded" : "Not Loaded";
306 const char* unexpected_result = expect_loaded ? "Not Loaded" : "Loaded";
307
308 base::string16 expected_title(base::ASCIIToUTF16(expected_result));
309 base::string16 unexpected_title(base::ASCIIToUTF16(unexpected_result));
310
311 content::TitleWatcher title_watcher(
312 browser()->tab_strip_model()->GetActiveWebContents(), expected_title);
313 title_watcher.AlsoWaitForTitle(unexpected_title);
314
315 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
316 }
317
318 void SetUpCommandLineInternal(CommandLine* command_line, bool expect_loaded) {
301 #if defined(OS_MACOSX) 319 #if defined(OS_MACOSX)
302 virtual void SetUpCommandLine(CommandLine* command_line) override {
303 base::FilePath plugin_dir; 320 base::FilePath plugin_dir;
304 PathService::Get(base::DIR_MODULE, &plugin_dir); 321 PathService::Get(base::DIR_MODULE, &plugin_dir);
305 plugin_dir = plugin_dir.AppendASCII("plugins"); 322 plugin_dir = plugin_dir.AppendASCII("plugins");
306 // The plugins directory isn't read by default on the Mac, so it needs to be 323 // The plugins directory isn't read by default on the Mac, so it needs to be
307 // explicitly registered. 324 // explicitly registered.
308 command_line->AppendSwitchPath(switches::kExtraPluginDir, plugin_dir); 325 command_line->AppendSwitchPath(switches::kExtraPluginDir, plugin_dir);
326 #endif
327 command_line->AppendSwitch(switches::kAlwaysAuthorizePlugins);
328 #if defined(OS_MACOSX) || defined(OS_WIN)
jam 2014/10/20 15:50:32 ditto
Will Harris 2014/10/20 17:59:56 Done.
329 if (expect_loaded)
330 command_line->AppendSwitch(switches::kEnableNpapi);
331 #endif
332 }
333 };
334
335 class DisabledPluginTest : public LoadPluginTest {
336 public:
337 DisabledPluginTest() {}
338
339 virtual void SetUpCommandLine(CommandLine* command_line) override {
340 SetUpCommandLineInternal(command_line, false);
341 }
342 };
343
344 IN_PROC_BROWSER_TEST_F(DisabledPluginTest, Load) {
345 PerformTest(false);
346 }
347
348 class EnabledPluginTest : public LoadPluginTest {
349 public:
350 EnabledPluginTest() {}
351
352 virtual void SetUpCommandLine(CommandLine* command_line) override {
353 SetUpCommandLineInternal(command_line, true);
354 }
355 };
356
357 IN_PROC_BROWSER_TEST_F(EnabledPluginTest, Load) {
358 PerformTest(true);
359 }
360
361 class ClickToPlayPluginTest : public ContentSettingsTest {
362 public:
363 ClickToPlayPluginTest() {}
364 #if defined(OS_WIN) || defined(OS_MACOSX)
365 virtual void SetUpCommandLine(CommandLine* command_line) override {
366 #if defined(OS_MACOSX)
367 base::FilePath plugin_dir;
368 PathService::Get(base::DIR_MODULE, &plugin_dir);
369 plugin_dir = plugin_dir.AppendASCII("plugins");
370 // The plugins directory isn't read by default on the Mac, so it needs to be
371 // explicitly registered.
372 command_line->AppendSwitchPath(switches::kExtraPluginDir, plugin_dir);
373 #endif
374 command_line->AppendSwitch(switches::kEnableNpapi);
309 } 375 }
310 #endif 376 #endif
311 }; 377 };
312 378
313 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, Basic) { 379 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, Basic) {
314 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( 380 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
315 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); 381 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
316 382
317 GURL url = ui_test_utils::GetTestUrl( 383 GURL url = ui_test_utils::GetTestUrl(
318 base::FilePath(), base::FilePath().AppendASCII("clicktoplay.html")); 384 base::FilePath(), base::FilePath().AppendASCII("clicktoplay.html"));
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 #if defined(OS_WIN) && defined(USE_ASH) 793 #if defined(OS_WIN) && defined(USE_ASH)
728 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 794 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
729 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 795 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
730 return; 796 return;
731 #endif 797 #endif
732 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); 798 RunJavaScriptBlockedTest("load_nacl_no_js.html", true);
733 } 799 }
734 #endif // !defined(DISABLE_NACL) 800 #endif // !defined(DISABLE_NACL)
735 801
736 #endif // defined(ENABLE_PLUGINS) 802 #endif // defined(ENABLE_PLUGINS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698