| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 #include "content/public/browser/notification_source.h" | 88 #include "content/public/browser/notification_source.h" |
| 89 #include "content/public/browser/notification_types.h" | 89 #include "content/public/browser/notification_types.h" |
| 90 #include "content/public/browser/plugin_service.h" | 90 #include "content/public/browser/plugin_service.h" |
| 91 #include "content/public/browser/render_process_host.h" | 91 #include "content/public/browser/render_process_host.h" |
| 92 #include "content/public/browser/render_view_host.h" | 92 #include "content/public/browser/render_view_host.h" |
| 93 #include "content/public/browser/web_contents.h" | 93 #include "content/public/browser/web_contents.h" |
| 94 #include "content/public/common/content_paths.h" | 94 #include "content/public/common/content_paths.h" |
| 95 #include "content/public/common/page_transition_types.h" | 95 #include "content/public/common/page_transition_types.h" |
| 96 #include "content/public/common/process_type.h" | 96 #include "content/public/common/process_type.h" |
| 97 #include "content/public/common/url_constants.h" | 97 #include "content/public/common/url_constants.h" |
| 98 #include "content/public/common/webplugininfo.h" |
| 98 #include "content/public/test/browser_test_utils.h" | 99 #include "content/public/test/browser_test_utils.h" |
| 99 #include "content/public/test/download_test_observer.h" | 100 #include "content/public/test/download_test_observer.h" |
| 100 #include "content/public/test/mock_notification_observer.h" | 101 #include "content/public/test/mock_notification_observer.h" |
| 101 #include "content/public/test/test_navigation_observer.h" | 102 #include "content/public/test/test_navigation_observer.h" |
| 102 #include "content/public/test/test_utils.h" | 103 #include "content/public/test/test_utils.h" |
| 103 #include "content/test/net/url_request_failed_job.h" | 104 #include "content/test/net/url_request_failed_job.h" |
| 104 #include "content/test/net/url_request_mock_http_job.h" | 105 #include "content/test/net/url_request_mock_http_job.h" |
| 105 #include "grit/generated_resources.h" | 106 #include "grit/generated_resources.h" |
| 106 #include "net/base/net_errors.h" | 107 #include "net/base/net_errors.h" |
| 107 #include "net/base/net_util.h" | 108 #include "net/base/net_util.h" |
| 108 #include "net/base/url_util.h" | 109 #include "net/base/url_util.h" |
| 109 #include "net/http/http_stream_factory.h" | 110 #include "net/http/http_stream_factory.h" |
| 110 #include "net/url_request/url_request.h" | 111 #include "net/url_request/url_request.h" |
| 111 #include "net/url_request/url_request_filter.h" | 112 #include "net/url_request/url_request_filter.h" |
| 112 #include "policy/policy_constants.h" | 113 #include "policy/policy_constants.h" |
| 113 #include "testing/gmock/include/gmock/gmock.h" | 114 #include "testing/gmock/include/gmock/gmock.h" |
| 114 #include "testing/gtest/include/gtest/gtest.h" | 115 #include "testing/gtest/include/gtest/gtest.h" |
| 115 #include "third_party/WebKit/public/web/WebInputEvent.h" | 116 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 116 #include "ui/base/l10n/l10n_util.h" | 117 #include "ui/base/l10n/l10n_util.h" |
| 117 #include "ui/base/resource/resource_bundle.h" | 118 #include "ui/base/resource/resource_bundle.h" |
| 118 #include "url/gurl.h" | 119 #include "url/gurl.h" |
| 119 #include "webkit/plugins/plugin_constants.h" | 120 #include "webkit/plugins/plugin_constants.h" |
| 120 #include "webkit/plugins/webplugininfo.h" | |
| 121 | 121 |
| 122 #if defined(OS_CHROMEOS) | 122 #if defined(OS_CHROMEOS) |
| 123 #include "ash/accelerators/accelerator_controller.h" | 123 #include "ash/accelerators/accelerator_controller.h" |
| 124 #include "ash/accelerators/accelerator_table.h" | 124 #include "ash/accelerators/accelerator_table.h" |
| 125 #include "ash/magnifier/magnifier_constants.h" | 125 #include "ash/magnifier/magnifier_constants.h" |
| 126 #include "ash/shell.h" | 126 #include "ash/shell.h" |
| 127 #include "ash/shell_delegate.h" | 127 #include "ash/shell_delegate.h" |
| 128 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 128 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 129 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" | 129 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" |
| 130 #include "chrome/browser/chromeos/audio/audio_handler.h" | 130 #include "chrome/browser/chromeos/audio/audio_handler.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 327 |
| 328 bool IsJavascriptEnabled(content::WebContents* contents) { | 328 bool IsJavascriptEnabled(content::WebContents* contents) { |
| 329 scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue( | 329 scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue( |
| 330 contents->GetRenderViewHost(), "123"); | 330 contents->GetRenderViewHost(), "123"); |
| 331 int result = 0; | 331 int result = 0; |
| 332 if (!value->GetAsInteger(&result)) | 332 if (!value->GetAsInteger(&result)) |
| 333 EXPECT_EQ(base::Value::TYPE_NULL, value->GetType()); | 333 EXPECT_EQ(base::Value::TYPE_NULL, value->GetType()); |
| 334 return result == 123; | 334 return result == 123; |
| 335 } | 335 } |
| 336 | 336 |
| 337 void CopyPluginListAndQuit(std::vector<webkit::WebPluginInfo>* out, | 337 void CopyPluginListAndQuit(std::vector<content::WebPluginInfo>* out, |
| 338 const std::vector<webkit::WebPluginInfo>& in) { | 338 const std::vector<content::WebPluginInfo>& in) { |
| 339 *out = in; | 339 *out = in; |
| 340 base::MessageLoop::current()->QuitWhenIdle(); | 340 base::MessageLoop::current()->QuitWhenIdle(); |
| 341 } | 341 } |
| 342 | 342 |
| 343 template<typename T> | 343 template<typename T> |
| 344 void CopyValueAndQuit(T* out, T in) { | 344 void CopyValueAndQuit(T* out, T in) { |
| 345 *out = in; | 345 *out = in; |
| 346 base::MessageLoop::current()->QuitWhenIdle(); | 346 base::MessageLoop::current()->QuitWhenIdle(); |
| 347 } | 347 } |
| 348 | 348 |
| 349 void GetPluginList(std::vector<webkit::WebPluginInfo>* plugins) { | 349 void GetPluginList(std::vector<content::WebPluginInfo>* plugins) { |
| 350 content::PluginService* service = content::PluginService::GetInstance(); | 350 content::PluginService* service = content::PluginService::GetInstance(); |
| 351 service->GetPlugins(base::Bind(CopyPluginListAndQuit, plugins)); | 351 service->GetPlugins(base::Bind(CopyPluginListAndQuit, plugins)); |
| 352 content::RunMessageLoop(); | 352 content::RunMessageLoop(); |
| 353 } | 353 } |
| 354 | 354 |
| 355 const webkit::WebPluginInfo* GetFlashPlugin( | 355 const content::WebPluginInfo* GetFlashPlugin( |
| 356 const std::vector<webkit::WebPluginInfo>& plugins) { | 356 const std::vector<content::WebPluginInfo>& plugins) { |
| 357 const webkit::WebPluginInfo* flash = NULL; | 357 const content::WebPluginInfo* flash = NULL; |
| 358 for (size_t i = 0; i < plugins.size(); ++i) { | 358 for (size_t i = 0; i < plugins.size(); ++i) { |
| 359 if (plugins[i].name == ASCIIToUTF16(kFlashPluginName)) { | 359 if (plugins[i].name == ASCIIToUTF16(kFlashPluginName)) { |
| 360 flash = &plugins[i]; | 360 flash = &plugins[i]; |
| 361 break; | 361 break; |
| 362 } | 362 } |
| 363 } | 363 } |
| 364 #if defined(OFFICIAL_BUILD) | 364 #if defined(OFFICIAL_BUILD) |
| 365 // Official builds bundle Flash. | 365 // Official builds bundle Flash. |
| 366 EXPECT_TRUE(flash); | 366 EXPECT_TRUE(flash); |
| 367 #else | 367 #else |
| 368 if (!flash) | 368 if (!flash) |
| 369 LOG(INFO) << "Test skipped because the Flash plugin couldn't be found."; | 369 LOG(INFO) << "Test skipped because the Flash plugin couldn't be found."; |
| 370 #endif | 370 #endif |
| 371 return flash; | 371 return flash; |
| 372 } | 372 } |
| 373 | 373 |
| 374 bool SetPluginEnabled(PluginPrefs* plugin_prefs, | 374 bool SetPluginEnabled(PluginPrefs* plugin_prefs, |
| 375 const webkit::WebPluginInfo* plugin, | 375 const content::WebPluginInfo* plugin, |
| 376 bool enabled) { | 376 bool enabled) { |
| 377 bool ok = false; | 377 bool ok = false; |
| 378 plugin_prefs->EnablePlugin(enabled, plugin->path, | 378 plugin_prefs->EnablePlugin(enabled, plugin->path, |
| 379 base::Bind(CopyValueAndQuit<bool>, &ok)); | 379 base::Bind(CopyValueAndQuit<bool>, &ok)); |
| 380 content::RunMessageLoop(); | 380 content::RunMessageLoop(); |
| 381 return ok; | 381 return ok; |
| 382 } | 382 } |
| 383 | 383 |
| 384 int CountPluginsOnIOThread() { | 384 int CountPluginsOnIOThread() { |
| 385 int count = 0; | 385 int count = 0; |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 UpdateProviderPolicy(policies); | 1013 UpdateProviderPolicy(policies); |
| 1014 content::RunAllPendingInMessageLoop(); | 1014 content::RunAllPendingInMessageLoop(); |
| 1015 EXPECT_TRUE(net::HttpStreamFactory::spdy_enabled()); | 1015 EXPECT_TRUE(net::HttpStreamFactory::spdy_enabled()); |
| 1016 } | 1016 } |
| 1017 | 1017 |
| 1018 IN_PROC_BROWSER_TEST_F(PolicyTest, DisabledPlugins) { | 1018 IN_PROC_BROWSER_TEST_F(PolicyTest, DisabledPlugins) { |
| 1019 // Verifies that plugins can be forced to be disabled by policy. | 1019 // Verifies that plugins can be forced to be disabled by policy. |
| 1020 | 1020 |
| 1021 // Verify that the Flash plugin exists and that it can be enabled and disabled | 1021 // Verify that the Flash plugin exists and that it can be enabled and disabled |
| 1022 // by the user. | 1022 // by the user. |
| 1023 std::vector<webkit::WebPluginInfo> plugins; | 1023 std::vector<content::WebPluginInfo> plugins; |
| 1024 GetPluginList(&plugins); | 1024 GetPluginList(&plugins); |
| 1025 const webkit::WebPluginInfo* flash = GetFlashPlugin(plugins); | 1025 const content::WebPluginInfo* flash = GetFlashPlugin(plugins); |
| 1026 if (!flash) | 1026 if (!flash) |
| 1027 return; | 1027 return; |
| 1028 PluginPrefs* plugin_prefs = | 1028 PluginPrefs* plugin_prefs = |
| 1029 PluginPrefs::GetForProfile(browser()->profile()).get(); | 1029 PluginPrefs::GetForProfile(browser()->profile()).get(); |
| 1030 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 1030 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
| 1031 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); | 1031 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); |
| 1032 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); | 1032 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); |
| 1033 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, true)); | 1033 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, true)); |
| 1034 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 1034 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
| 1035 | 1035 |
| 1036 // Now disable it with a policy. | 1036 // Now disable it with a policy. |
| 1037 base::ListValue disabled_plugins; | 1037 base::ListValue disabled_plugins; |
| 1038 disabled_plugins.Append(base::Value::CreateStringValue("*Flash*")); | 1038 disabled_plugins.Append(base::Value::CreateStringValue("*Flash*")); |
| 1039 PolicyMap policies; | 1039 PolicyMap policies; |
| 1040 policies.Set(key::kDisabledPlugins, POLICY_LEVEL_MANDATORY, | 1040 policies.Set(key::kDisabledPlugins, POLICY_LEVEL_MANDATORY, |
| 1041 POLICY_SCOPE_USER, disabled_plugins.DeepCopy(), NULL); | 1041 POLICY_SCOPE_USER, disabled_plugins.DeepCopy(), NULL); |
| 1042 UpdateProviderPolicy(policies); | 1042 UpdateProviderPolicy(policies); |
| 1043 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); | 1043 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); |
| 1044 // The user shouldn't be able to enable it. | 1044 // The user shouldn't be able to enable it. |
| 1045 EXPECT_FALSE(SetPluginEnabled(plugin_prefs, flash, true)); | 1045 EXPECT_FALSE(SetPluginEnabled(plugin_prefs, flash, true)); |
| 1046 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); | 1046 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); |
| 1047 } | 1047 } |
| 1048 | 1048 |
| 1049 IN_PROC_BROWSER_TEST_F(PolicyTest, DisabledPluginsExceptions) { | 1049 IN_PROC_BROWSER_TEST_F(PolicyTest, DisabledPluginsExceptions) { |
| 1050 // Verifies that plugins with an exception in the blacklist can be enabled. | 1050 // Verifies that plugins with an exception in the blacklist can be enabled. |
| 1051 | 1051 |
| 1052 // Verify that the Flash plugin exists and that it can be enabled and disabled | 1052 // Verify that the Flash plugin exists and that it can be enabled and disabled |
| 1053 // by the user. | 1053 // by the user. |
| 1054 std::vector<webkit::WebPluginInfo> plugins; | 1054 std::vector<content::WebPluginInfo> plugins; |
| 1055 GetPluginList(&plugins); | 1055 GetPluginList(&plugins); |
| 1056 const webkit::WebPluginInfo* flash = GetFlashPlugin(plugins); | 1056 const content::WebPluginInfo* flash = GetFlashPlugin(plugins); |
| 1057 if (!flash) | 1057 if (!flash) |
| 1058 return; | 1058 return; |
| 1059 PluginPrefs* plugin_prefs = | 1059 PluginPrefs* plugin_prefs = |
| 1060 PluginPrefs::GetForProfile(browser()->profile()).get(); | 1060 PluginPrefs::GetForProfile(browser()->profile()).get(); |
| 1061 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 1061 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
| 1062 | 1062 |
| 1063 // Disable all plugins. | 1063 // Disable all plugins. |
| 1064 base::ListValue disabled_plugins; | 1064 base::ListValue disabled_plugins; |
| 1065 disabled_plugins.Append(base::Value::CreateStringValue("*")); | 1065 disabled_plugins.Append(base::Value::CreateStringValue("*")); |
| 1066 PolicyMap policies; | 1066 PolicyMap policies; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1083 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 1083 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
| 1084 // And the user should be able to disable and enable again. | 1084 // And the user should be able to disable and enable again. |
| 1085 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); | 1085 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); |
| 1086 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); | 1086 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); |
| 1087 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, true)); | 1087 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, true)); |
| 1088 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 1088 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
| 1089 } | 1089 } |
| 1090 | 1090 |
| 1091 IN_PROC_BROWSER_TEST_F(PolicyTest, EnabledPlugins) { | 1091 IN_PROC_BROWSER_TEST_F(PolicyTest, EnabledPlugins) { |
| 1092 // Verifies that a plugin can be force-installed with a policy. | 1092 // Verifies that a plugin can be force-installed with a policy. |
| 1093 std::vector<webkit::WebPluginInfo> plugins; | 1093 std::vector<content::WebPluginInfo> plugins; |
| 1094 GetPluginList(&plugins); | 1094 GetPluginList(&plugins); |
| 1095 const webkit::WebPluginInfo* flash = GetFlashPlugin(plugins); | 1095 const content::WebPluginInfo* flash = GetFlashPlugin(plugins); |
| 1096 if (!flash) | 1096 if (!flash) |
| 1097 return; | 1097 return; |
| 1098 PluginPrefs* plugin_prefs = | 1098 PluginPrefs* plugin_prefs = |
| 1099 PluginPrefs::GetForProfile(browser()->profile()).get(); | 1099 PluginPrefs::GetForProfile(browser()->profile()).get(); |
| 1100 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 1100 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
| 1101 | 1101 |
| 1102 // The user disables it and then a policy forces it to be enabled. | 1102 // The user disables it and then a policy forces it to be enabled. |
| 1103 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); | 1103 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); |
| 1104 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); | 1104 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); |
| 1105 base::ListValue plugin_list; | 1105 base::ListValue plugin_list; |
| (...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2484 chrome_variations::VariationsService::GetVariationsServerURL( | 2484 chrome_variations::VariationsService::GetVariationsServerURL( |
| 2485 g_browser_process->local_state()); | 2485 g_browser_process->local_state()); |
| 2486 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); | 2486 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); |
| 2487 std::string value; | 2487 std::string value; |
| 2488 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); | 2488 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); |
| 2489 EXPECT_EQ("restricted", value); | 2489 EXPECT_EQ("restricted", value); |
| 2490 } | 2490 } |
| 2491 #endif | 2491 #endif |
| 2492 | 2492 |
| 2493 } // namespace policy | 2493 } // namespace policy |
| OLD | NEW |