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

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: move UMA outside ifdef Created 5 years, 11 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
« no previous file with comments | « chrome/browser/about_flags.cc ('k') | chrome/browser/plugins/plugin_prefs_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(base::CommandLine* command_line,
319 bool expect_loaded) {
301 #if defined(OS_MACOSX) 320 #if defined(OS_MACOSX)
302 void SetUpCommandLine(base::CommandLine* command_line) override {
303 base::FilePath plugin_dir; 321 base::FilePath plugin_dir;
304 PathService::Get(base::DIR_MODULE, &plugin_dir); 322 PathService::Get(base::DIR_MODULE, &plugin_dir);
305 plugin_dir = plugin_dir.AppendASCII("plugins"); 323 plugin_dir = plugin_dir.AppendASCII("plugins");
306 // The plugins directory isn't read by default on the Mac, so it needs to be 324 // The plugins directory isn't read by default on the Mac, so it needs to be
307 // explicitly registered. 325 // explicitly registered.
308 command_line->AppendSwitchPath(switches::kExtraPluginDir, plugin_dir); 326 command_line->AppendSwitchPath(switches::kExtraPluginDir, plugin_dir);
327 #endif
328 command_line->AppendSwitch(switches::kAlwaysAuthorizePlugins);
329 if (expect_loaded)
330 command_line->AppendSwitch(switches::kEnableNpapi);
309 } 331 }
332 };
333
334 class DisabledPluginTest : public LoadPluginTest {
335 public:
336 DisabledPluginTest() {}
337
338 void SetUpCommandLine(base::CommandLine* command_line) override {
339 SetUpCommandLineInternal(command_line, false);
340 }
341 };
342
343 IN_PROC_BROWSER_TEST_F(DisabledPluginTest, Load) {
344 PerformTest(false);
345 }
346
347 class EnabledPluginTest : public LoadPluginTest {
348 public:
349 EnabledPluginTest() {}
350
351 void SetUpCommandLine(base::CommandLine* command_line) override {
352 SetUpCommandLineInternal(command_line, true);
353 }
354 };
355
356 IN_PROC_BROWSER_TEST_F(EnabledPluginTest, Load) {
357 PerformTest(true);
358 }
359
360 class ClickToPlayPluginTest : public ContentSettingsTest {
361 public:
362 ClickToPlayPluginTest() {}
363
364 void SetUpCommandLine(base::CommandLine* command_line) override {
365 #if defined(OS_MACOSX)
366 base::FilePath plugin_dir;
367 PathService::Get(base::DIR_MODULE, &plugin_dir);
368 plugin_dir = plugin_dir.AppendASCII("plugins");
369 // The plugins directory isn't read by default on the Mac, so it needs to be
370 // explicitly registered.
371 command_line->AppendSwitchPath(switches::kExtraPluginDir, plugin_dir);
310 #endif 372 #endif
373 command_line->AppendSwitch(switches::kEnableNpapi);
374 }
311 }; 375 };
312 376
313 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, Basic) { 377 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, Basic) {
314 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( 378 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
315 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); 379 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
316 380
317 GURL url = ui_test_utils::GetTestUrl( 381 GURL url = ui_test_utils::GetTestUrl(
318 base::FilePath(), base::FilePath().AppendASCII("clicktoplay.html")); 382 base::FilePath(), base::FilePath().AppendASCII("clicktoplay.html"));
319 ui_test_utils::NavigateToURL(browser(), url); 383 ui_test_utils::NavigateToURL(browser(), url);
320 384
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 796 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
733 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 797 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
734 switches::kAshBrowserTests)) 798 switches::kAshBrowserTests))
735 return; 799 return;
736 #endif 800 #endif
737 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); 801 RunJavaScriptBlockedTest("load_nacl_no_js.html", true);
738 } 802 }
739 #endif // !defined(DISABLE_NACL) 803 #endif // !defined(DISABLE_NACL)
740 804
741 #endif // defined(ENABLE_PLUGINS) 805 #endif // defined(ENABLE_PLUGINS)
OLDNEW
« no previous file with comments | « chrome/browser/about_flags.cc ('k') | chrome/browser/plugins/plugin_prefs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698