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" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 #include "net/url_request/url_request.h" | 95 #include "net/url_request/url_request.h" |
| 96 #include "net/url_request/url_request_filter.h" | 96 #include "net/url_request/url_request_filter.h" |
| 97 #include "policy/policy_constants.h" | 97 #include "policy/policy_constants.h" |
| 98 #include "testing/gmock/include/gmock/gmock.h" | 98 #include "testing/gmock/include/gmock/gmock.h" |
| 99 #include "testing/gtest/include/gtest/gtest.h" | 99 #include "testing/gtest/include/gtest/gtest.h" |
| 100 #include "ui/base/l10n/l10n_util.h" | 100 #include "ui/base/l10n/l10n_util.h" |
| 101 #include "ui/base/resource/resource_bundle.h" | 101 #include "ui/base/resource/resource_bundle.h" |
| 102 #include "webkit/plugins/npapi/plugin_utils.h" | 102 #include "webkit/plugins/npapi/plugin_utils.h" |
| 103 #include "webkit/plugins/plugin_constants.h" | 103 #include "webkit/plugins/plugin_constants.h" |
| 104 #include "webkit/plugins/webplugininfo.h" | 104 #include "webkit/plugins/webplugininfo.h" |
| 105 | 105 #include "chrome/browser/extensions/extension_apitest.h" |
| 106 #include "chrome/browser/extensions/component_loader.h" | |
|
oscarpan
2013/02/06 04:38:45
Either remove or reorder the imports in future, as
| |
| 106 #if defined(OS_CHROMEOS) | 107 #if defined(OS_CHROMEOS) |
| 107 #include "ash/accelerators/accelerator_controller.h" | 108 #include "ash/accelerators/accelerator_controller.h" |
| 108 #include "ash/accelerators/accelerator_table.h" | 109 #include "ash/accelerators/accelerator_table.h" |
| 109 #include "ash/shell.h" | 110 #include "ash/shell.h" |
| 110 #include "ash/shell_delegate.h" | 111 #include "ash/shell_delegate.h" |
| 111 #include "chrome/browser/chromeos/audio/audio_handler.h" | 112 #include "chrome/browser/chromeos/audio/audio_handler.h" |
| 112 #endif | 113 #endif |
| 113 | 114 |
| 114 using content::BrowserThread; | 115 using content::BrowserThread; |
| 115 using content::URLRequestMockHTTPJob; | 116 using content::URLRequestMockHTTPJob; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 bool result = false; | 291 bool result = false; |
| 291 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 292 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 292 contents, | 293 contents, |
| 293 "var canvas = document.createElement('canvas');" | 294 "var canvas = document.createElement('canvas');" |
| 294 "var context = canvas.getContext('experimental-webgl');" | 295 "var context = canvas.getContext('experimental-webgl');" |
| 295 "domAutomationController.send(context != null);", | 296 "domAutomationController.send(context != null);", |
| 296 &result)); | 297 &result)); |
| 297 return result; | 298 return result; |
| 298 } | 299 } |
| 299 | 300 |
| 301 #if defined(OS_CHROMEOS) | |
| 302 // Checks if redeeming cros offers is allowed in the given WebContents. | |
| 303 bool CheckAllowRedeemCrosOffers(content::WebContents* contents) { | |
| 304 bool result = false; | |
| 305 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 306 contents, | |
| 307 "chrome.echoPrivate.allowRedeemOffers(" | |
| 308 " function(allow) {" | |
| 309 " domAutomationController.send(allow);" | |
| 310 " });", | |
| 311 &result)); | |
| 312 return result; | |
| 313 } | |
| 314 #endif | |
| 315 | |
| 300 bool IsJavascriptEnabled(content::WebContents* contents) { | 316 bool IsJavascriptEnabled(content::WebContents* contents) { |
| 301 scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue( | 317 scoped_ptr<base::Value> value = content::ExecuteScriptAndGetValue( |
| 302 contents->GetRenderViewHost(), "123"); | 318 contents->GetRenderViewHost(), "123"); |
| 303 int result = 0; | 319 int result = 0; |
| 304 if (!value->GetAsInteger(&result)) | 320 if (!value->GetAsInteger(&result)) |
| 305 EXPECT_EQ(base::Value::TYPE_NULL, value->GetType()); | 321 EXPECT_EQ(base::Value::TYPE_NULL, value->GetType()); |
| 306 return result == 123; | 322 return result == 123; |
| 307 } | 323 } |
| 308 | 324 |
| 309 void CopyPluginListAndQuit(std::vector<webkit::WebPluginInfo>* out, | 325 void CopyPluginListAndQuit(std::vector<webkit::WebPluginInfo>* out, |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 | 534 |
| 519 content::WindowedNotificationObserver observer( | 535 content::WindowedNotificationObserver observer( |
| 520 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 536 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 521 content::NotificationService::AllSources()); | 537 content::NotificationService::AllSources()); |
| 522 installer->InstallCrx(extension_path); | 538 installer->InstallCrx(extension_path); |
| 523 observer.Wait(); | 539 observer.Wait(); |
| 524 content::Details<const extensions::Extension> details = observer.details(); | 540 content::Details<const extensions::Extension> details = observer.details(); |
| 525 return details.ptr(); | 541 return details.ptr(); |
| 526 } | 542 } |
| 527 | 543 |
| 544 const extensions::Extension* LoadExtensionAsComponent( | |
| 545 const FilePath& path) { | |
| 546 ExtensionService* service = extension_service(); | |
| 547 | |
| 548 std::string manifest; | |
| 549 if (!file_util::ReadFileToString( | |
| 550 path.Append(extensions::Extension::kManifestFilename), | |
| 551 &manifest)) | |
| 552 return NULL; | |
| 553 | |
| 554 std::string extension_id = service->component_loader()->Add(manifest, path); | |
| 555 return service->extensions()->GetByID(extension_id); | |
| 556 } | |
| 557 | |
|
oscarpan
2013/02/06 04:38:45
This seems a bit ugly. I'm trying to load my exten
Mattias Nissler (ping if slow)
2013/02/06 10:03:26
That's fine. The alternative would be to add the t
| |
| 528 void UninstallExtension(const std::string& id, bool expect_success) { | 558 void UninstallExtension(const std::string& id, bool expect_success) { |
| 529 content::WindowedNotificationObserver observer( | 559 content::WindowedNotificationObserver observer( |
| 530 expect_success ? chrome::NOTIFICATION_EXTENSION_UNINSTALLED | 560 expect_success ? chrome::NOTIFICATION_EXTENSION_UNINSTALLED |
| 531 : chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, | 561 : chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, |
| 532 content::NotificationService::AllSources()); | 562 content::NotificationService::AllSources()); |
| 533 extension_service()->UninstallExtension(id, false, NULL); | 563 extension_service()->UninstallExtension(id, false, NULL); |
| 534 observer.Wait(); | 564 observer.Wait(); |
| 535 } | 565 } |
| 536 | 566 |
| 537 void UpdateProviderPolicy(const PolicyMap& policy) { | 567 void UpdateProviderPolicy(const PolicyMap& policy) { |
| (...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1307 | 1337 |
| 1308 // Enable via policy and verify that incognito windows can be opened. | 1338 // Enable via policy and verify that incognito windows can be opened. |
| 1309 policies.Set(key::kIncognitoEnabled, POLICY_LEVEL_MANDATORY, | 1339 policies.Set(key::kIncognitoEnabled, POLICY_LEVEL_MANDATORY, |
| 1310 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); | 1340 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); |
| 1311 UpdateProviderPolicy(policies); | 1341 UpdateProviderPolicy(policies); |
| 1312 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_NEW_INCOGNITO_WINDOW)); | 1342 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_NEW_INCOGNITO_WINDOW)); |
| 1313 EXPECT_EQ(2u, BrowserList::size()); | 1343 EXPECT_EQ(2u, BrowserList::size()); |
| 1314 EXPECT_TRUE(BrowserList::IsOffTheRecordSessionActive()); | 1344 EXPECT_TRUE(BrowserList::IsOffTheRecordSessionActive()); |
| 1315 } | 1345 } |
| 1316 | 1346 |
| 1347 #if defined(OS_CHROMEOS) | |
| 1348 IN_PROC_BROWSER_TEST_F(PolicyTest, AllowRedeemChromeOsRegistrationOffers) { | |
| 1349 FilePath extension_path(ui_test_utils::GetTestFilePath( | |
| 1350 FilePath(kTestExtensionsDir), FilePath("echo_component_extension"))); | |
| 1351 LoadExtensionAsComponent(extension_path); | |
| 1352 content::WebContents* contents = | |
| 1353 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 1354 contents->GetController().LoadURL( | |
| 1355 GURL("chrome-extension://lbgjohhgghbkcgejgklgcmfijhbheflf/main.html"), | |
| 1356 content::Referrer(), | |
|
oscarpan
2013/02/06 04:38:45
Although it seems it can access chrome.echoPrivate
Mattias Nissler (ping if slow)
2013/02/06 10:03:26
Seems like you want to attach a debugger and check
| |
| 1357 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
| 1358 std::string()); | |
| 1359 content::WaitForLoadStop(contents); | |
| 1360 EXPECT_TRUE(CheckAllowRedeemCrosOffers(contents)); | |
| 1361 PolicyMap policies; | |
| 1362 | |
| 1363 // Allow offer redemption and verify the flag value through js. | |
| 1364 policies.Set(key::kDeviceAllowRedeemChromeOsRegistrationOffers, | |
| 1365 POLICY_LEVEL_MANDATORY, | |
| 1366 POLICY_SCOPE_MACHINE, | |
| 1367 base::Value::CreateBooleanValue(false)); | |
| 1368 UpdateProviderPolicy(policies); | |
| 1369 EXPECT_FALSE(CheckAllowRedeemCrosOffers(contents)); | |
| 1370 | |
| 1371 // Disallow offer redemption and verify the flag value through js. | |
| 1372 policies.Set(key::kDeviceAllowRedeemChromeOsRegistrationOffers, | |
| 1373 POLICY_LEVEL_MANDATORY, | |
| 1374 POLICY_SCOPE_MACHINE, | |
| 1375 base::Value::CreateBooleanValue(true)); | |
| 1376 | |
| 1377 UpdateProviderPolicy(policies); | |
| 1378 EXPECT_TRUE(CheckAllowRedeemCrosOffers(contents)); | |
| 1379 } | |
| 1380 #endif | |
| 1381 | |
| 1317 IN_PROC_BROWSER_TEST_F(PolicyTest, Javascript) { | 1382 IN_PROC_BROWSER_TEST_F(PolicyTest, Javascript) { |
| 1318 // Verifies that Javascript can be disabled. | 1383 // Verifies that Javascript can be disabled. |
| 1319 content::WebContents* contents = | 1384 content::WebContents* contents = |
| 1320 browser()->tab_strip_model()->GetActiveWebContents(); | 1385 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1321 EXPECT_TRUE(IsJavascriptEnabled(contents)); | 1386 EXPECT_TRUE(IsJavascriptEnabled(contents)); |
| 1322 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS)); | 1387 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS)); |
| 1323 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS_CONSOLE)); | 1388 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEV_TOOLS_CONSOLE)); |
| 1324 | 1389 |
| 1325 // Disable Javascript via policy. | 1390 // Disable Javascript via policy. |
| 1326 PolicyMap policies; | 1391 PolicyMap policies; |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1872 this)); | 1937 this)); |
| 1873 | 1938 |
| 1874 MessageLoop::current()->Run(); | 1939 MessageLoop::current()->Run(); |
| 1875 } | 1940 } |
| 1876 | 1941 |
| 1877 INSTANTIATE_TEST_CASE_P(MediaStreamDevicesControllerBrowserTestInstance, | 1942 INSTANTIATE_TEST_CASE_P(MediaStreamDevicesControllerBrowserTestInstance, |
| 1878 MediaStreamDevicesControllerBrowserTest, | 1943 MediaStreamDevicesControllerBrowserTest, |
| 1879 testing::Bool()); | 1944 testing::Bool()); |
| 1880 | 1945 |
| 1881 } // namespace policy | 1946 } // namespace policy |
| OLD | NEW |