Chromium Code Reviews| 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" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/string16.h" | 18 #include "base/string16.h" |
| 19 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
| 20 #include "base/test/test_file_util.h" | 20 #include "base/test/test_file_util.h" |
| 21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
| 22 #include "base/values.h" | 22 #include "base/values.h" |
| 23 #include "chrome/app/chrome_command_ids.h" | 23 #include "chrome/app/chrome_command_ids.h" |
| 24 #include "chrome/browser/api/infobars/infobar_service.h" | 24 #include "chrome/browser/api/infobars/infobar_service.h" |
| 25 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 25 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
| 26 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
| 27 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 27 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 28 #include "chrome/browser/devtools/devtools_window.h" | 28 #include "chrome/browser/devtools/devtools_window.h" |
| 29 #include "chrome/browser/download/download_prefs.h" | 29 #include "chrome/browser/download/download_prefs.h" |
| 30 #include "chrome/browser/extensions/component_loader.h" | |
| 30 #include "chrome/browser/extensions/crx_installer.h" | 31 #include "chrome/browser/extensions/crx_installer.h" |
| 31 #include "chrome/browser/extensions/extension_service.h" | 32 #include "chrome/browser/extensions/extension_service.h" |
| 32 #include "chrome/browser/extensions/extension_system.h" | 33 #include "chrome/browser/extensions/extension_system.h" |
| 33 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 34 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| 34 #include "chrome/browser/media/media_stream_devices_controller.h" | 35 #include "chrome/browser/media/media_stream_devices_controller.h" |
| 35 #include "chrome/browser/net/url_request_mock_util.h" | 36 #include "chrome/browser/net/url_request_mock_util.h" |
| 36 #include "chrome/browser/plugins/plugin_prefs.h" | 37 #include "chrome/browser/plugins/plugin_prefs.h" |
| 37 #include "chrome/browser/policy/browser_policy_connector.h" | 38 #include "chrome/browser/policy/browser_policy_connector.h" |
| 38 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 39 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| 39 #include "chrome/browser/policy/policy_map.h" | 40 #include "chrome/browser/policy/policy_map.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 #include "net/url_request/url_request.h" | 96 #include "net/url_request/url_request.h" |
| 96 #include "net/url_request/url_request_filter.h" | 97 #include "net/url_request/url_request_filter.h" |
| 97 #include "policy/policy_constants.h" | 98 #include "policy/policy_constants.h" |
| 98 #include "testing/gmock/include/gmock/gmock.h" | 99 #include "testing/gmock/include/gmock/gmock.h" |
| 99 #include "testing/gtest/include/gtest/gtest.h" | 100 #include "testing/gtest/include/gtest/gtest.h" |
| 100 #include "ui/base/l10n/l10n_util.h" | 101 #include "ui/base/l10n/l10n_util.h" |
| 101 #include "ui/base/resource/resource_bundle.h" | 102 #include "ui/base/resource/resource_bundle.h" |
| 102 #include "webkit/plugins/npapi/plugin_utils.h" | 103 #include "webkit/plugins/npapi/plugin_utils.h" |
| 103 #include "webkit/plugins/plugin_constants.h" | 104 #include "webkit/plugins/plugin_constants.h" |
| 104 #include "webkit/plugins/webplugininfo.h" | 105 #include "webkit/plugins/webplugininfo.h" |
| 105 | |
| 106 #if defined(OS_CHROMEOS) | 106 #if defined(OS_CHROMEOS) |
| 107 #include "ash/accelerators/accelerator_controller.h" | 107 #include "ash/accelerators/accelerator_controller.h" |
| 108 #include "ash/accelerators/accelerator_table.h" | 108 #include "ash/accelerators/accelerator_table.h" |
| 109 #include "ash/shell.h" | 109 #include "ash/shell.h" |
| 110 #include "ash/shell_delegate.h" | 110 #include "ash/shell_delegate.h" |
| 111 #include "chrome/browser/chromeos/audio/audio_handler.h" | 111 #include "chrome/browser/chromeos/audio/audio_handler.h" |
| 112 #endif | 112 #endif |
| 113 | 113 |
| 114 using content::BrowserThread; | 114 using content::BrowserThread; |
| 115 using content::URLRequestMockHTTPJob; | 115 using content::URLRequestMockHTTPJob; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 bool result = false; | 290 bool result = false; |
| 291 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 291 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 292 contents, | 292 contents, |
| 293 "var canvas = document.createElement('canvas');" | 293 "var canvas = document.createElement('canvas');" |
| 294 "var context = canvas.getContext('experimental-webgl');" | 294 "var context = canvas.getContext('experimental-webgl');" |
| 295 "domAutomationController.send(context != null);", | 295 "domAutomationController.send(context != null);", |
| 296 &result)); | 296 &result)); |
| 297 return result; | 297 return result; |
| 298 } | 298 } |
| 299 | 299 |
| 300 #if defined(OS_CHROMEOS) | |
| 301 // Checks if redeeming cros offers is allowed in the given WebContents. | |
| 302 bool CheckAllowRedeemCrosOffers(content::WebContents* contents) { | |
| 303 bool result = false; | |
| 304 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 305 contents, | |
| 306 "chrome.echoPrivate.allowRedeemOffers(" | |
| 307 " function(allow) {" | |
| 308 " domAutomationController.send(allow);" | |
| 309 " });", | |
| 310 &result)); | |
| 311 return result; | |
| 312 } | |
| 313 #endif | |
| 314 | |
| 300 bool IsJavascriptEnabled(content::WebContents* contents) { | 315 bool IsJavascriptEnabled(content::WebContents* contents) { |
| 301 scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue( | 316 scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue( |
| 302 contents->GetRenderViewHost(), "123"); | 317 contents->GetRenderViewHost(), "123"); |
| 303 int result = 0; | 318 int result = 0; |
| 304 if (!value->GetAsInteger(&result)) | 319 if (!value->GetAsInteger(&result)) |
| 305 EXPECT_EQ(base::Value::TYPE_NULL, value->GetType()); | 320 EXPECT_EQ(base::Value::TYPE_NULL, value->GetType()); |
| 306 return result == 123; | 321 return result == 123; |
| 307 } | 322 } |
| 308 | 323 |
| 309 void CopyPluginListAndQuit(std::vector<webkit::WebPluginInfo>* out, | 324 void CopyPluginListAndQuit(std::vector<webkit::WebPluginInfo>* out, |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 | 533 |
| 519 content::WindowedNotificationObserver observer( | 534 content::WindowedNotificationObserver observer( |
| 520 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 535 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 521 content::NotificationService::AllSources()); | 536 content::NotificationService::AllSources()); |
| 522 installer->InstallCrx(extension_path); | 537 installer->InstallCrx(extension_path); |
| 523 observer.Wait(); | 538 observer.Wait(); |
| 524 content::Details<const extensions::Extension> details = observer.details(); | 539 content::Details<const extensions::Extension> details = observer.details(); |
| 525 return details.ptr(); | 540 return details.ptr(); |
| 526 } | 541 } |
| 527 | 542 |
| 543 const extensions::Extension* LoadExtensionAsComponent( | |
| 544 const FilePath& path) { | |
| 545 ExtensionService* service = extension_service(); | |
| 546 | |
| 547 std::string manifest; | |
| 548 if (!file_util::ReadFileToString( | |
| 549 path.Append(extensions::Extension::kManifestFilename), | |
| 550 &manifest)) | |
| 551 return NULL; | |
| 552 | |
| 553 std::string extension_id = service->component_loader()->Add(manifest, path); | |
| 554 return service->extensions()->GetByID(extension_id); | |
| 555 } | |
| 556 | |
| 528 void UninstallExtension(const std::string& id, bool expect_success) { | 557 void UninstallExtension(const std::string& id, bool expect_success) { |
| 529 content::WindowedNotificationObserver observer( | 558 content::WindowedNotificationObserver observer( |
| 530 expect_success ? chrome::NOTIFICATION_EXTENSION_UNINSTALLED | 559 expect_success ? chrome::NOTIFICATION_EXTENSION_UNINSTALLED |
| 531 : chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, | 560 : chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, |
| 532 content::NotificationService::AllSources()); | 561 content::NotificationService::AllSources()); |
| 533 extension_service()->UninstallExtension(id, false, NULL); | 562 extension_service()->UninstallExtension(id, false, NULL); |
| 534 observer.Wait(); | 563 observer.Wait(); |
| 535 } | 564 } |
| 536 | 565 |
| 537 void UpdateProviderPolicy(const PolicyMap& policy) { | 566 void UpdateProviderPolicy(const PolicyMap& policy) { |
| (...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1307 | 1336 |
| 1308 // Enable via policy and verify that incognito windows can be opened. | 1337 // Enable via policy and verify that incognito windows can be opened. |
| 1309 policies.Set(key::kIncognitoEnabled, POLICY_LEVEL_MANDATORY, | 1338 policies.Set(key::kIncognitoEnabled, POLICY_LEVEL_MANDATORY, |
| 1310 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); | 1339 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); |
| 1311 UpdateProviderPolicy(policies); | 1340 UpdateProviderPolicy(policies); |
| 1312 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_NEW_INCOGNITO_WINDOW)); | 1341 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_NEW_INCOGNITO_WINDOW)); |
| 1313 EXPECT_EQ(2u, BrowserList::size()); | 1342 EXPECT_EQ(2u, BrowserList::size()); |
| 1314 EXPECT_TRUE(BrowserList::IsOffTheRecordSessionActive()); | 1343 EXPECT_TRUE(BrowserList::IsOffTheRecordSessionActive()); |
| 1315 } | 1344 } |
| 1316 | 1345 |
| 1346 #if defined(OS_CHROMEOS) | |
| 1347 IN_PROC_BROWSER_TEST_F(PolicyTest, AllowRedeemChromeOsRegistrationOffers) { | |
| 1348 FilePath extension_path(ui_test_utils::GetTestFilePath( | |
| 1349 FilePath(kTestExtensionsDir), FilePath("echo_component_extension"))); | |
| 1350 LoadExtensionAsComponent(extension_path); | |
| 1351 content::WebContents* contents = | |
| 1352 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 1353 contents->GetController().LoadURL( | |
| 1354 GURL("chrome-extension://lbgjohhgghbkcgejgklgcmfijhbheflf/main.html"), | |
| 1355 content::Referrer(), | |
| 1356 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
| 1357 std::string()); | |
| 1358 content::WaitForLoadStop(contents); | |
| 1359 EXPECT_TRUE(CheckAllowRedeemCrosOffers(contents)); | |
| 1360 PolicyMap policies; | |
| 1361 | |
| 1362 // Allow offer redemption and verify the flag value through js. | |
| 1363 policies.Set(key::kDeviceAllowRedeemChromeOsRegistrationOffers, | |
| 1364 POLICY_LEVEL_MANDATORY, | |
| 1365 POLICY_SCOPE_MACHINE, | |
| 1366 base::Value::CreateBooleanValue(false)); | |
| 1367 UpdateProviderPolicy(policies); | |
|
oscarpan
2013/02/07 00:40:39
So I confirmed that all other codes are running as
Mattias Nissler (ping if slow)
2013/02/07 10:45:57
Ah, that makes sense!
| |
| 1368 EXPECT_FALSE(CheckAllowRedeemCrosOffers(contents)); | |
| 1369 | |
| 1370 // Disallow offer redemption and verify the flag value through js. | |
| 1371 policies.Set(key::kDeviceAllowRedeemChromeOsRegistrationOffers, | |
| 1372 POLICY_LEVEL_MANDATORY, | |
| 1373 POLICY_SCOPE_MACHINE, | |
| 1374 base::Value::CreateBooleanValue(true)); | |
| 1375 UpdateProviderPolicy(policies); | |
| 1376 EXPECT_TRUE(CheckAllowRedeemCrosOffers(contents)); | |
| 1377 } | |
| 1378 #endif | |
| 1379 | |
| 1317 IN_PROC_BROWSER_TEST_F(PolicyTest, Javascript) { | 1380 IN_PROC_BROWSER_TEST_F(PolicyTest, Javascript) { |
| 1318 // Verifies that Javascript can be disabled. | 1381 // Verifies that Javascript can be disabled. |
| 1319 content::WebContents* contents = | 1382 content::WebContents* contents = |
| 1320 browser()->tab_strip_model()->GetActiveWebContents(); | 1383 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1321 EXPECT_TRUE(IsJavascriptEnabled(contents)); | 1384 EXPECT_TRUE(IsJavascriptEnabled(contents)); |
| 1322 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS)); | 1385 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS)); |
| 1323 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS_CONSOLE)); | 1386 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS_CONSOLE)); |
| 1324 | 1387 |
| 1325 // Disable Javascript via policy. | 1388 // Disable Javascript via policy. |
| 1326 PolicyMap policies; | 1389 PolicyMap policies; |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1872 this)); | 1935 this)); |
| 1873 | 1936 |
| 1874 MessageLoop::current()->Run(); | 1937 MessageLoop::current()->Run(); |
| 1875 } | 1938 } |
| 1876 | 1939 |
| 1877 INSTANTIATE_TEST_CASE_P(MediaStreamDevicesControllerBrowserTestInstance, | 1940 INSTANTIATE_TEST_CASE_P(MediaStreamDevicesControllerBrowserTestInstance, |
| 1878 MediaStreamDevicesControllerBrowserTest, | 1941 MediaStreamDevicesControllerBrowserTest, |
| 1879 testing::Bool()); | 1942 testing::Bool()); |
| 1880 | 1943 |
| 1881 } // namespace policy | 1944 } // namespace policy |
| OLD | NEW |