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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
(...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 content::DOMMessageQueue message_queue; | 958 content::DOMMessageQueue message_queue; |
959 SwitchToExtensionPanel(window_, extension, "iframe_panel"); | 959 SwitchToExtensionPanel(window_, extension, "iframe_panel"); |
960 std::string message; | 960 std::string message; |
961 while (true) { | 961 while (true) { |
962 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | 962 ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
963 if (message == "\"DONE\"") | 963 if (message == "\"DONE\"") |
964 break; | 964 break; |
965 } | 965 } |
966 } | 966 } |
967 | 967 |
968 // Some web features, when used from an extension, are subject to browser-side | |
969 // security policy enforcement. Make sure they work properly from inside a | |
970 // devtools extension. | |
971 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | |
972 DevToolsExtensionSecurityPolicyGrants) { | |
973 ASSERT_TRUE(embedded_test_server()->Start()); | |
974 | |
975 std::unique_ptr<extensions::TestExtensionDir> dir( | |
976 new extensions::TestExtensionDir()); | |
977 | |
978 extensions::DictionaryBuilder manifest; | |
979 dir->WriteManifest(extensions::DictionaryBuilder() | |
980 .Set("name", "Devtools Panel") | |
981 .Set("version", "1") | |
982 .Set("manifest_version", 2) | |
983 .Set("devtools_page", "devtools.html") | |
984 .ToJSON()); | |
985 | |
986 dir->WriteFile( | |
987 FILE_PATH_LITERAL("devtools.html"), | |
988 "<html><head><script src='devtools.js'></script></head></html>"); | |
989 | |
990 dir->WriteFile( | |
991 FILE_PATH_LITERAL("devtools.js"), | |
992 "chrome.devtools.panels.create('the_panel_name',\n" | |
993 " null,\n" | |
994 " 'panel.html',\n" | |
995 " function(panel) {\n" | |
996 " chrome.devtools.inspectedWindow.eval('console.log(\"PASS\")');\n" | |
997 " }\n" | |
998 ");\n"); | |
999 | |
1000 dir->WriteFile(FILE_PATH_LITERAL("panel.html"), | |
1001 "<html><body>A panel." | |
1002 "<script src='blob_xhr.js'></script>" | |
1003 "</body></html>"); | |
1004 // Creating blobs from chrome-extension:// origins is only permitted if the | |
1005 // process has been granted permission to commit 'chrome-extension' schemes. | |
1006 dir->WriteFile( | |
1007 FILE_PATH_LITERAL("blob_xhr.js"), | |
1008 "var blob_url = URL.createObjectURL(new Blob(['blob contents']));\n" | |
1009 "var xhr = new XMLHttpRequest();\n" | |
1010 "xhr.open('GET', blob_url, true);\n" | |
1011 "xhr.onload = function (e) {\n" | |
1012 " domAutomationController.setAutomationId(0);\n" | |
1013 " domAutomationController.send(xhr.response);\n" | |
1014 "};\n" | |
1015 "xhr.send(null);\n"); | |
1016 // Install the extension. | |
1017 const Extension* extension = LoadExtensionFromPath(dir->UnpackedPath()); | |
1018 ASSERT_TRUE(extension); | |
1019 | |
1020 // Open a devtools window. | |
1021 OpenDevToolsWindow(kDebuggerTestPage, false); | |
1022 | |
1023 // Wait for the panel extension to finish loading -- it'll output 'PASS' | |
1024 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. | |
1025 RunTestFunction(window_, "waitForTestResultsInConsole"); | |
1026 | |
1027 // Now that we know the panel is loaded, switch to it. We'll wait until we | |
1028 // see a 'DONE' message sent from popup_iframe.html, indicating that it | |
1029 // loaded successfully. | |
1030 content::DOMMessageQueue message_queue; | |
1031 SwitchToExtensionPanel(window_, extension, "the_panel_name"); | |
1032 std::string message; | |
1033 while (true) { | |
1034 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | |
1035 if (message == "\"blob contents\"") | |
1036 break; | |
1037 } | |
1038 } | |
1039 | |
1040 // Disabled on Windows due to flakiness. http://crbug.com/183649 | 968 // Disabled on Windows due to flakiness. http://crbug.com/183649 |
1041 #if defined(OS_WIN) | 969 #if defined(OS_WIN) |
1042 #define MAYBE_TestDevToolsExtensionMessaging DISABLED_TestDevToolsExtensionMessa
ging | 970 #define MAYBE_TestDevToolsExtensionMessaging DISABLED_TestDevToolsExtensionMessa
ging |
1043 #else | 971 #else |
1044 #define MAYBE_TestDevToolsExtensionMessaging TestDevToolsExtensionMessaging | 972 #define MAYBE_TestDevToolsExtensionMessaging TestDevToolsExtensionMessaging |
1045 #endif | 973 #endif |
1046 | 974 |
1047 // Tests that chrome.devtools extension can communicate with background page | 975 // Tests that chrome.devtools extension can communicate with background page |
1048 // using extension messaging. | 976 // using extension messaging. |
1049 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | 977 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1519 DevToolsWindowTesting::OpenDevToolsWindowSync(GetInspectedTab(), true); | 1447 DevToolsWindowTesting::OpenDevToolsWindowSync(GetInspectedTab(), true); |
1520 chrome::DuplicateTab(browser()); | 1448 chrome::DuplicateTab(browser()); |
1521 chrome::SelectPreviousTab(browser()); | 1449 chrome::SelectPreviousTab(browser()); |
1522 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 1450 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
1523 chrome::GoBack(browser(), WindowOpenDisposition::CURRENT_TAB); | 1451 chrome::GoBack(browser(), WindowOpenDisposition::CURRENT_TAB); |
1524 RunTestFunction(window, "testWindowInitializedOnNavigateBack"); | 1452 RunTestFunction(window, "testWindowInitializedOnNavigateBack"); |
1525 | 1453 |
1526 DevToolsWindowTesting::CloseDevToolsWindowSync(window); | 1454 DevToolsWindowTesting::CloseDevToolsWindowSync(window); |
1527 content::WebUIControllerFactory::UnregisterFactoryForTesting(&test_factory); | 1455 content::WebUIControllerFactory::UnregisterFactoryForTesting(&test_factory); |
1528 } | 1456 } |
OLD | NEW |