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

Side by Side Diff: chrome/browser/devtools/devtools_sanity_browsertest.cc

Issue 2646683002: Implement OOPIFs within Devtools Extensions (Closed)
Patch Set: finish rough draft of tests Created 3 years, 10 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 | « no previous file | content/browser/frame_host/render_frame_host_manager.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 <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 20 matching lines...) Expand all
31 #include "chrome/browser/extensions/extension_service.h" 31 #include "chrome/browser/extensions/extension_service.h"
32 #include "chrome/browser/extensions/test_extension_dir.h" 32 #include "chrome/browser/extensions/test_extension_dir.h"
33 #include "chrome/browser/extensions/unpacked_installer.h" 33 #include "chrome/browser/extensions/unpacked_installer.h"
34 #include "chrome/browser/lifetime/application_lifetime.h" 34 #include "chrome/browser/lifetime/application_lifetime.h"
35 #include "chrome/browser/profiles/profile.h" 35 #include "chrome/browser/profiles/profile.h"
36 #include "chrome/browser/ui/browser.h" 36 #include "chrome/browser/ui/browser.h"
37 #include "chrome/browser/ui/browser_commands.h" 37 #include "chrome/browser/ui/browser_commands.h"
38 #include "chrome/browser/ui/tabs/tab_strip_model.h" 38 #include "chrome/browser/ui/tabs/tab_strip_model.h"
39 #include "chrome/common/chrome_paths.h" 39 #include "chrome/common/chrome_paths.h"
40 #include "chrome/common/chrome_switches.h" 40 #include "chrome/common/chrome_switches.h"
41 #include "chrome/common/extensions/extension_process_policy.h"
41 #include "chrome/common/pref_names.h" 42 #include "chrome/common/pref_names.h"
42 #include "chrome/common/url_constants.h" 43 #include "chrome/common/url_constants.h"
43 #include "chrome/test/base/in_process_browser_test.h" 44 #include "chrome/test/base/in_process_browser_test.h"
44 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" 45 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h"
45 #include "chrome/test/base/ui_test_utils.h" 46 #include "chrome/test/base/ui_test_utils.h"
46 #include "components/app_modal/javascript_app_modal_dialog.h" 47 #include "components/app_modal/javascript_app_modal_dialog.h"
47 #include "components/app_modal/native_app_modal_dialog.h" 48 #include "components/app_modal/native_app_modal_dialog.h"
48 #include "components/prefs/pref_service.h" 49 #include "components/prefs/pref_service.h"
49 #include "content/public/browser/child_process_data.h" 50 #include "content/public/browser/child_process_data.h"
50 #include "content/public/browser/content_browser_client.h" 51 #include "content/public/browser/content_browser_client.h"
51 #include "content/public/browser/devtools_agent_host.h" 52 #include "content/public/browser/devtools_agent_host.h"
52 #include "content/public/browser/notification_registrar.h" 53 #include "content/public/browser/notification_registrar.h"
53 #include "content/public/browser/notification_service.h" 54 #include "content/public/browser/notification_service.h"
55 #include "content/public/browser/render_frame_host.h"
54 #include "content/public/browser/render_view_host.h" 56 #include "content/public/browser/render_view_host.h"
55 #include "content/public/browser/render_widget_host.h" 57 #include "content/public/browser/render_widget_host.h"
56 #include "content/public/browser/render_widget_host_view.h" 58 #include "content/public/browser/render_widget_host_view.h"
57 #include "content/public/browser/url_data_source.h" 59 #include "content/public/browser/url_data_source.h"
58 #include "content/public/browser/web_contents.h" 60 #include "content/public/browser/web_contents.h"
59 #include "content/public/browser/web_ui_controller.h" 61 #include "content/public/browser/web_ui_controller.h"
60 #include "content/public/browser/worker_service.h" 62 #include "content/public/browser/worker_service.h"
61 #include "content/public/browser/worker_service_observer.h" 63 #include "content/public/browser/worker_service_observer.h"
62 #include "content/public/common/content_switches.h" 64 #include "content/public/common/content_switches.h"
63 #include "content/public/test/browser_test_utils.h" 65 #include "content/public/test/browser_test_utils.h"
(...skipping 14 matching lines...) Expand all
78 #include "ui/gl/gl_switches.h" 80 #include "ui/gl/gl_switches.h"
79 #include "url/gurl.h" 81 #include "url/gurl.h"
80 82
81 using app_modal::AppModalDialog; 83 using app_modal::AppModalDialog;
82 using app_modal::JavaScriptAppModalDialog; 84 using app_modal::JavaScriptAppModalDialog;
83 using app_modal::NativeAppModalDialog; 85 using app_modal::NativeAppModalDialog;
84 using content::BrowserThread; 86 using content::BrowserThread;
85 using content::DevToolsAgentHost; 87 using content::DevToolsAgentHost;
86 using content::NavigationController; 88 using content::NavigationController;
87 using content::RenderViewHost; 89 using content::RenderViewHost;
90 using content::RenderFrameHost;
alexmos 2017/02/08 21:48:00 not needed, since you're including the .h for it a
davidsac (gone - try alexmos) 2017/02/14 04:24:12 Done.
88 using content::WebContents; 91 using content::WebContents;
89 using content::WorkerService; 92 using content::WorkerService;
90 using content::WorkerServiceObserver; 93 using content::WorkerServiceObserver;
91 using extensions::Extension; 94 using extensions::Extension;
92 95
93 namespace { 96 namespace {
94 97
95 const char kDebuggerTestPage[] = "files/devtools/debugger_test_page.html"; 98 const char kDebuggerTestPage[] = "files/devtools/debugger_test_page.html";
96 const char kPauseWhenLoadingDevTools[] = 99 const char kPauseWhenLoadingDevTools[] =
97 "files/devtools/pause_when_loading_devtools.html"; 100 "files/devtools/pause_when_loading_devtools.html";
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, 902 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
900 TestDevToolsExtensionAPI) { 903 TestDevToolsExtensionAPI) {
901 LoadExtension("devtools_extension"); 904 LoadExtension("devtools_extension");
902 RunTest("waitForTestResultsInConsole", std::string()); 905 RunTest("waitForTestResultsInConsole", std::string());
903 } 906 }
904 907
905 // Tests a chrome.devtools extension panel that embeds an http:// iframe. 908 // Tests a chrome.devtools extension panel that embeds an http:// iframe.
906 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, DevToolsExtensionWithHttpIframe) { 909 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, DevToolsExtensionWithHttpIframe) {
907 ASSERT_TRUE(embedded_test_server()->Start()); 910 ASSERT_TRUE(embedded_test_server()->Start());
908 911
909 // Our extension must load an URL from the test server, whose port is only 912 // Our extension must load a URL from the test server, whose port is only
910 // known at runtime. So, to embed the URL, we must dynamically generate the 913 // known at runtime. So, to embed the URL, we must dynamically generate the
911 // extension, rather than loading it from static content. 914 // extension, rather than loading it from static content.
912 std::unique_ptr<extensions::TestExtensionDir> dir( 915 std::unique_ptr<extensions::TestExtensionDir> dir(
913 new extensions::TestExtensionDir()); 916 new extensions::TestExtensionDir());
914 917
915 extensions::DictionaryBuilder manifest; 918 extensions::DictionaryBuilder manifest;
916 dir->WriteManifest(extensions::DictionaryBuilder() 919 dir->WriteManifest(extensions::DictionaryBuilder()
917 .Set("name", "Devtools Panel w/ HTTP Iframe") 920 .Set("name", "Devtools Panel w/ HTTP Iframe")
918 .Set("version", "1") 921 .Set("version", "1")
919 .Set("manifest_version", 2) 922 .Set("manifest_version", 2)
920 .Set("devtools_page", "devtools.html") 923 .Set("devtools_page", "devtools.html")
921 .ToJSON()); 924 .ToJSON());
922 925
923 dir->WriteFile( 926 GURL http_iframe_url =
924 FILE_PATH_LITERAL("devtools.html"), 927 embedded_test_server()->GetURL("a.com", "/popup_iframe.html");
925 "<html><head><script src='devtools.js'></script></head></html>"); 928
929 GURL simple_page_url =
930 embedded_test_server()->GetURL("a.com", "/title1.html");
931
932 dir->WriteFile(FILE_PATH_LITERAL("devtools.html"),
933 "<html><head><script "
934 "src='devtools.js'></script></head><body><iframe src='" +
alexmos 2017/02/08 21:48:00 Does this load when you install the extension, wit
davidsac (gone - try alexmos) 2017/02/14 04:24:12 Done.
935 simple_page_url.spec() + "'></iframe></body></html>");
926 936
927 dir->WriteFile( 937 dir->WriteFile(
928 FILE_PATH_LITERAL("devtools.js"), 938 FILE_PATH_LITERAL("devtools.js"),
929 "chrome.devtools.panels.create('iframe_panel',\n" 939 "chrome.devtools.panels.create('iframe_panel',\n"
930 " null,\n" 940 " null,\n"
931 " 'panel.html',\n" 941 " 'panel.html',\n"
932 " function(panel) {\n" 942 " function(panel) {\n"
933 " chrome.devtools.inspectedWindow.eval('console.log(\"PASS\")');\n" 943 " chrome.devtools.inspectedWindow.eval('console.log(\"PASS\")');\n"
934 " }\n" 944 " }\n"
935 ");\n"); 945 ");\n"
946 "chrome.devtools.panels.elements.createSidebarPane('iframe_pane',\n"
alexmos 2017/02/08 21:48:00 This test is getting kind of long; it's worth thin
davidsac (gone - try alexmos) 2017/02/14 04:24:12 Done.
947 "function(sidebar) {\n"
948 "sidebar.setPage('panel.html');\n"
949 "});\n");
936 950
937 GURL http_iframe =
938 embedded_test_server()->GetURL("a.com", "/popup_iframe.html");
939 dir->WriteFile(FILE_PATH_LITERAL("panel.html"), 951 dir->WriteFile(FILE_PATH_LITERAL("panel.html"),
940 "<html><body>Extension panel.<iframe src='" + 952 "<html><body>Extension panel.<iframe src='" +
941 http_iframe.spec() + "'></iframe>"); 953 http_iframe_url.spec() + "'></iframe>");
942 954
943 // Install the extension. 955 // Install the extension.
944 const Extension* extension = LoadExtensionFromPath(dir->UnpackedPath()); 956 const Extension* extension = LoadExtensionFromPath(dir->UnpackedPath());
945 ASSERT_TRUE(extension); 957 ASSERT_TRUE(extension);
946 958
947 // Open a devtools window. 959 // Open a devtools window.
948 OpenDevToolsWindow(kDebuggerTestPage, false); 960 OpenDevToolsWindow(kDebuggerTestPage, false);
949 961
950 // Wait for the panel extension to finish loading -- it'll output 'PASS' 962 // Wait for the panel extension to finish loading -- it'll output 'PASS'
951 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. 963 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'.
952 RunTestFunction(window_, "waitForTestResultsInConsole"); 964 RunTestFunction(window_, "waitForTestResultsInConsole");
953 965
954 // Now that we know the panel is loaded, switch to it. We'll wait until we 966 // Now that we know the panel is loaded, switch to it. We'll wait until we
955 // see a 'DONE' message sent from popup_iframe.html, indicating that it 967 // see a 'DONE' message sent from popup_iframe.html, indicating that it
956 // loaded successfully. 968 // loaded successfully.
969 SwitchToExtensionPanel(window_, extension, "iframe_panel");
957 content::DOMMessageQueue message_queue; 970 content::DOMMessageQueue message_queue;
alexmos 2017/02/08 21:48:00 DOMMessageQueue has to be instantiated before the
davidsac (gone - try alexmos) 2017/02/14 04:24:12 Done.
958 SwitchToExtensionPanel(window_, extension, "iframe_panel"); 971 std::string message1;
959 std::string message; 972
960 while (true) { 973 while (true) {
961 ASSERT_TRUE(message_queue.WaitForMessage(&message)); 974 ASSERT_TRUE(message_queue.WaitForMessage(&message1));
962 if (message == "\"DONE\"") 975 if (message1 == "\"DONE\"")
963 break; 976 break;
964 } 977 }
978
979 SwitchToPanel(window_, "elements");
alexmos 2017/02/08 21:48:00 What is this one for?
davidsac (gone - try alexmos) 2017/02/14 04:24:12 added comment: "//This is a bit of a hack to switc
980 SwitchToPanel(window_, "iframe_pane");
981 content::DOMMessageQueue message_queue2;
982 std::string message2;
983
984 while (true) {
985 ASSERT_TRUE(message_queue2.WaitForMessage(&message2));
986 if (message2 == "\"DONE\"")
987 break;
988 }
989
990 int oopif_count = 0;
991 int frame_count = 0;
992 std::vector<RenderFrameHost*> rfhs = main_web_contents()->GetAllFrames();
993 for (std::vector<RenderFrameHost*>::size_type i = 0; i != rfhs.size(); i++) {
994 frame_count++;
995 if (rfhs[i]->IsCrossProcessSubframe()) {
996 oopif_count++;
997 }
998 }
999 ASSERT_EQ(frame_count, 7);
alexmos 2017/02/08 21:48:00 I think this kind of checking might not be suffici
davidsac (gone - try alexmos) 2017/02/14 04:24:12 Done.
1000 if (content::AreAllSitesIsolatedForTesting() ||
1001 extensions::IsIsolateExtensionsEnabled()) {
1002 ASSERT_EQ(oopif_count, 3);
1003 } else {
1004 ASSERT_EQ(oopif_count, 0);
1005 }
1006 }
1007
1008 // Tests a chrome.devtools extension panel that embeds an http:// iframe.
alexmos 2017/02/08 21:48:00 Is this true? Looks like test.html is a iframe fr
davidsac (gone - try alexmos) 2017/02/14 04:24:12 Sorry, comments have been corrected.
1009 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
1010 DevToolsExtensionWithRegExtension) {
alexmos 2017/02/08 21:48:00 What does RegExtension stand for?
davidsac (gone - try alexmos) 2017/02/14 04:24:12 All occurrences have been renamed to non-devtools
1011 ASSERT_TRUE(embedded_test_server()->Start());
1012
1013 // Our extension must load a URL from the test server, whose port is only
1014 // known at runtime. So, to embed the URL, we must dynamically generate the
1015 // extension, rather than loading it from static content.
1016 std::unique_ptr<extensions::TestExtensionDir> devtools_dir(
1017 new extensions::TestExtensionDir());
1018
1019 devtools_dir->WriteManifest(extensions::DictionaryBuilder()
1020 .Set("name", "Devtools Extension")
1021 .Set("version", "1")
1022 .Set("manifest_version", 2)
1023 .Set("devtools_page", "devtools.html")
1024 .ToJSON());
1025
1026 devtools_dir->WriteFile(FILE_PATH_LITERAL("devtools.html"),
1027 "<html><head><script "
1028 "src='devtools.js'></script></head><body><iframe></"
1029 "iframe></body></html>");
1030
1031 devtools_dir->WriteFile(
1032 FILE_PATH_LITERAL("devtools.js"),
1033 "chrome.devtools.panels.create('iframe_panel',\n"
1034 " null,\n"
1035 " 'panel.html',\n"
1036 " function(panel) {\n"
1037 " chrome.devtools.inspectedWindow.eval('console.log(\"PASS\")');\n"
1038 " }\n"
1039 ");\n");
1040
1041 devtools_dir->WriteFile(FILE_PATH_LITERAL("panel.html"),
1042 "<html><body>does nothing</body></html>");
1043
1044 // Our extension must load a URL from the test server, whose port is only
1045 // known at runtime. So, to embed the URL, we must dynamically generate the
1046 // extension, rather than loading it from static content.
1047 std::unique_ptr<extensions::TestExtensionDir> reg_dir(
1048 new extensions::TestExtensionDir());
1049
1050 reg_dir->WriteManifest(
1051 extensions::DictionaryBuilder()
1052 .Set("name", "Regular Extension")
1053 .Set("version", "1")
1054 .Set("manifest_version", 2)
1055 .Set("web_accessible_resources",
1056 extensions::ListBuilder().Append("test.html").Build())
1057 .ToJSON());
1058
1059 reg_dir->WriteFile(FILE_PATH_LITERAL("test.html"),
1060 "<html><head></head><body>This is a test</body></html>");
1061
1062 // Install the extensions.
1063 const Extension* devtools_extension =
1064 LoadExtensionFromPath(devtools_dir->UnpackedPath());
1065 ASSERT_TRUE(devtools_extension);
1066
1067 const Extension* reg_extension =
1068 LoadExtensionFromPath(reg_dir->UnpackedPath());
1069 ASSERT_TRUE(reg_extension);
1070
1071 // Open a devtools window.
1072 OpenDevToolsWindow(kDebuggerTestPage, false);
1073
1074 // Wait for the panel extension to finish loading -- it'll output 'PASS'
1075 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'.
1076 RunTestFunction(window_, "waitForTestResultsInConsole");
1077
1078 GURL extension_file_url = reg_extension->GetResourceURL("/test.html");
1079
1080 RenderFrameHost* rfh = main_web_contents()->GetAllFrames()[2];
alexmos 2017/02/08 21:48:00 Which one is this one? You can rename the var so
davidsac (gone - try alexmos) 2017/02/14 04:24:12 Done.
1081
1082 base::string16 javascript =
1083 base::UTF8ToUTF16("location.href='" + extension_file_url.spec() + "';");
1084
1085 content::TestNavigationManager manager(main_web_contents(),
1086 extension_file_url);
1087
1088 rfh->ExecuteJavaScript(javascript);
alexmos 2017/02/08 21:48:00 Why use this instead of EXPECT_TRUE(ExecuteScript(
davidsac (gone - try alexmos) 2017/02/16 20:29:01 Done.
1089
1090 manager.WaitForNavigationFinished();
1091
1092 std::vector<RenderFrameHost*> rfhs = main_web_contents()->GetAllFrames();
1093
1094 ASSERT_EQ(rfhs.size(), (unsigned)3);
alexmos 2017/02/08 21:48:01 Reverse order. It should be (expected, actual) ev
davidsac (gone - try alexmos) 2017/02/14 04:24:12 Done.
1095 ASSERT_TRUE(rfhs[0]->GetLastCommittedURL().SchemeIs("chrome-devtools"));
alexmos 2017/02/08 21:48:00 ASSERT->EXPECT. ASSERT should be used when the te
alexmos 2017/02/08 21:48:00 It's very difficult to know what indices correspon
davidsac (gone - try alexmos) 2017/02/14 04:24:12 Done.
davidsac (gone - try alexmos) 2017/02/14 04:24:12 Done.
1096 ASSERT_EQ(rfhs[1]->GetLastCommittedURL(),
1097 devtools_extension->GetResourceURL("/devtools.html"));
1098 ASSERT_EQ(rfhs[2]->GetLastCommittedURL(), extension_file_url);
1099
1100 if (content::AreAllSitesIsolatedForTesting() ||
1101 extensions::IsIsolateExtensionsEnabled()) {
1102 // test.html's frame should be in extension b's
1103 // process, not in devtools or extension a's process.
1104 ASSERT_TRUE(
1105 rfhs[0]->GetSiteInstance()->GetSiteURL().SchemeIs("chrome-devtools"));
alexmos 2017/02/08 21:48:01 Use kChromeDevToolsScheme instead of "chrome-devto
davidsac (gone - try alexmos) 2017/02/14 04:24:12 Done.
1106 ASSERT_TRUE(
1107 rfhs[1]->GetSiteInstance()->GetSiteURL().SchemeIs("chrome-devtools"));
1108 ASSERT_EQ(rfhs[2]->GetSiteInstance()->GetSiteURL(),
1109 extension_file_url.GetOrigin());
1110 } else {
1111 // test.html's frame should be in the devtools process.
1112 ASSERT_TRUE(
1113 rfhs[0]->GetSiteInstance()->GetSiteURL().SchemeIs("chrome-devtools"));
1114 ASSERT_TRUE(
1115 rfhs[1]->GetSiteInstance()->GetSiteURL().SchemeIs("chrome-devtools"));
1116 ASSERT_TRUE(
1117 rfhs[1]->GetSiteInstance()->GetSiteURL().SchemeIs("chrome-devtools"));
alexmos 2017/02/08 21:48:00 rfhs[2] (same bug copy-pasted in a couple of othe
davidsac (gone - try alexmos) 2017/02/14 04:24:12 Done.
1118 }
1119 }
1120
1121 // TODO(davidsac): fix comments, replace dynamic extension loading with files
1122 // where possible
1123 // Tests that if a devtools extension's devtools page has a subframe to a page
1124 // for another devtools extension, the subframe is rendered in either:
1125 // A) its own extension's process and not in devtools or the parent devtools
1126 // extension when in isolate-extensions or site-per-process mode.
1127 // B) the devtools process otherwise.
1128 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
1129 DevToolsExtensionWithinDevToolsExtension) {
1130 ASSERT_TRUE(embedded_test_server()->Start());
1131
1132 // Our extension must load a URL from the test server, whose port is only
1133 // known at runtime. So, to embed the URL, we must dynamically generate the
1134 // extension, rather than loading it from static content.
1135 std::unique_ptr<extensions::TestExtensionDir> devtools_a_dir(
1136 new extensions::TestExtensionDir());
1137
1138 devtools_a_dir->WriteManifest(extensions::DictionaryBuilder()
1139 .Set("name", "Devtools Extension A")
1140 .Set("version", "1")
1141 .Set("manifest_version", 2)
1142 .Set("devtools_page", "devtools.html")
1143 .ToJSON());
1144
1145 devtools_a_dir->WriteFile(FILE_PATH_LITERAL("devtools.html"),
1146 "<html><head><script "
1147 "src='devtools.js'></script></head><body><iframe "
1148 "id='test-frame'></iframe></body></html>");
1149
1150 devtools_a_dir->WriteFile(
1151 FILE_PATH_LITERAL("devtools.js"),
1152 "chrome.devtools.panels.create('iframe_panel',\n"
1153 " null,\n"
1154 " 'panel.html',\n"
1155 " function(panel) {\n"
1156 " chrome.devtools.inspectedWindow.eval('console.log(\"PASS\")');\n"
1157 " }\n"
1158 ");\n");
1159
1160 devtools_a_dir->WriteFile(FILE_PATH_LITERAL("panel.html"),
1161 "<html><body>does nothing</body></html>");
alexmos 2017/02/08 21:48:01 Might be better for this test to put the iframe wi
davidsac (gone - try alexmos) 2017/02/16 20:29:01 Done.
1162
1163 // Install the extension.
1164 const Extension* devtools_a_extension =
1165 LoadExtensionFromPath(devtools_a_dir->UnpackedPath());
1166 ASSERT_TRUE(devtools_a_extension);
1167
1168 // Open a devtools window.
1169 OpenDevToolsWindow(kDebuggerTestPage, false);
1170
1171 // Wait for the panel extension to finish loading -- it'll output 'PASS'
1172 // when it is. waitForTestResultsInConsole waits until that 'PASS'.
1173 RunTestFunction(window_, "waitForTestResultsInConsole");
1174
1175 // Our extension must load a URL from the test server, whose port is only
1176 // known at runtime. So, to embed the URL, we must dynamically generate the
1177 // extension, rather than loading it from static content.
1178 std::unique_ptr<extensions::TestExtensionDir> devtools_b_dir(
1179 new extensions::TestExtensionDir());
1180
1181 devtools_b_dir->WriteManifest(
1182 extensions::DictionaryBuilder()
1183 .Set("name", "Devtools Extension B")
1184 .Set("version", "1")
1185 .Set("manifest_version", 2)
1186 .Set("devtools_page", "devtools.html")
1187 .Set("web_accessible_resources",
1188 extensions::ListBuilder().Append("test.html").Build())
1189 .ToJSON());
1190
1191 devtools_b_dir->WriteFile(FILE_PATH_LITERAL("devtools.html"),
1192 "<html><head></head><body></body></html>");
1193
1194 devtools_b_dir->WriteFile(
1195 FILE_PATH_LITERAL("test.html"),
1196 "<html><head></head><body>This is a test</body></html>");
1197
1198 const Extension* devtools_b_extension =
1199 LoadExtensionFromPath(devtools_b_dir->UnpackedPath());
1200 ASSERT_TRUE(devtools_b_extension);
1201
1202 GURL extension_file_url = devtools_b_extension->GetResourceURL("/test.html");
1203
1204 LOG(INFO) << extension_file_url.spec();
1205
1206 RenderFrameHost* rfh = main_web_contents()->GetAllFrames()[2];
1207
1208 base::string16 javascript =
1209 base::UTF8ToUTF16("location.href='" + extension_file_url.spec() + "';");
1210
1211 content::TestNavigationManager manager(main_web_contents(),
1212 extension_file_url);
1213
1214 rfh->ExecuteJavaScript(javascript);
1215
1216 manager.WaitForNavigationFinished();
1217
1218 std::vector<RenderFrameHost*> rfhs = main_web_contents()->GetAllFrames();
1219
1220 // TODO the expected result is the exact same as a reg extension in devtools
1221 ASSERT_EQ(rfhs.size(), (unsigned)3);
1222 ASSERT_TRUE(rfhs[0]->GetLastCommittedURL().SchemeIs("chrome-devtools"));
1223 ASSERT_EQ(rfhs[1]->GetLastCommittedURL(),
1224 devtools_extension->GetResourceURL("/devtools.html"));
1225 ASSERT_EQ(rfhs[2]->GetLastCommittedURL(), extension_file_url);
1226
1227 if (content::AreAllSitesIsolatedForTesting() ||
1228 extensions::IsIsolateExtensionsEnabled()) {
1229 // test.html's frame should be in extension b's
1230 // process, not in devtools or extension a's process.
1231 ASSERT_TRUE(
1232 rfhs[0]->GetSiteInstance()->GetSiteURL().SchemeIs("chrome-devtools"));
1233 ASSERT_TRUE(
1234 rfhs[1]->GetSiteInstance()->GetSiteURL().SchemeIs("chrome-devtools"));
1235 ASSERT_EQ(rfhs[2]->GetSiteInstance()->GetSiteURL(),
1236 extension_file_url.GetOrigin());
1237 } else {
1238 // test.html's frame should be in the devtools process.
1239 ASSERT_TRUE(
1240 rfhs[0]->GetSiteInstance()->GetSiteURL().SchemeIs("chrome-devtools"));
1241 ASSERT_TRUE(
1242 rfhs[1]->GetSiteInstance()->GetSiteURL().SchemeIs("chrome-devtools"));
1243 ASSERT_TRUE(
1244 rfhs[1]->GetSiteInstance()->GetSiteURL().SchemeIs("chrome-devtools"));
1245 }
1246 }
1247
1248 // Tests a chrome.devtools extension panel that embeds an http:// iframe.
1249 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, DevToolsExtensionWithinItself) {
1250 ASSERT_TRUE(embedded_test_server()->Start());
1251
1252 // Our extension must load a URL from the test server, whose port is only
1253 // known at runtime. So, to embed the URL, we must dynamically generate the
1254 // extension, rather than loading it from static content.
1255 std::unique_ptr<extensions::TestExtensionDir> dir(
1256 new extensions::TestExtensionDir());
1257
1258 extensions::DictionaryBuilder manifest;
1259 dir->WriteManifest(
1260 extensions::DictionaryBuilder()
1261 .Set("name", "Devtools Extension")
1262 .Set("version", "1")
1263 .Set("manifest_version", 2)
1264 .Set("devtools_page", "devtools.html")
1265 .Set("web_accessible_resources",
1266 extensions::ListBuilder().Append("test.html").Build())
1267 .ToJSON());
1268
1269 dir->WriteFile(FILE_PATH_LITERAL("devtools.html"),
1270 "<html><head><script "
1271 "src='devtools.js'></script></head><body><iframe></iframe></"
1272 "body></html>");
1273
1274 dir->WriteFile(
1275 FILE_PATH_LITERAL("devtools.js"),
1276 "chrome.devtools.panels.create('iframe_panel',\n"
1277 " null,\n"
1278 " 'panel.html',\n"
1279 " function(panel) {\n"
1280 " chrome.devtools.inspectedWindow.eval('console.log(\"PASS\")');\n"
1281 " }\n"
1282 ");\n");
1283
1284 dir->WriteFile(FILE_PATH_LITERAL("panel.html"),
1285 "<html><body>does nothing</body></html>");
1286
1287 dir->WriteFile(FILE_PATH_LITERAL("test.html"),
1288 "<html><head></head><body>This is a test</body></html>");
1289
1290 // Install the extension.
1291 const Extension* extension = LoadExtensionFromPath(dir->UnpackedPath());
1292 ASSERT_TRUE(extension);
1293
1294 // Open a devtools window.
1295 OpenDevToolsWindow(kDebuggerTestPage, false);
1296
1297 // Wait for the panel extension to finish loading -- it'll output 'PASS'
1298 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'.
1299 RunTestFunction(window_, "waitForTestResultsInConsole");
1300
1301 GURL extension_file_url = extension->GetResourceURL("/test.html");
1302
1303 LOG(INFO) << extension_file_url.spec();
1304
1305 RenderFrameHost* rfh = main_web_contents()->GetAllFrames()[2];
1306
1307 base::string16 javascript =
1308 base::UTF8ToUTF16("location.href='" + extension_file_url.spec() + "';");
1309
1310 content::TestNavigationManager manager(main_web_contents(),
1311 extension_file_url);
1312
1313 rfh->ExecuteJavaScript(javascript);
1314
1315 manager.WaitForNavigationFinished();
1316
1317 std::vector<RenderFrameHost*> rfhs = main_web_contents()->GetAllFrames();
1318
1319 // all frames should be in the devtools process.
1320 ASSERT_EQ(rfhs.size(), (unsigned)3);
1321 ASSERT_TRUE(rfhs[0]->GetLastCommittedURL().SchemeIs("chrome-devtools"));
1322 ASSERT_EQ(rfhs[1]->GetLastCommittedURL(),
1323 devtools_extension->GetResourceURL("/devtools.html"));
1324 ASSERT_EQ(rfhs[2]->GetLastCommittedURL(), extension_file_url);
1325 ASSERT_TRUE(
1326 rfhs[0]->GetSiteInstance()->GetSiteURL().SchemeIs("chrome-devtools"));
1327 ASSERT_TRUE(
1328 rfhs[1]->GetSiteInstance()->GetSiteURL().SchemeIs("chrome-devtools"));
1329 ASSERT_TRUE(
1330 rfhs[1]->GetSiteInstance()->GetSiteURL().SchemeIs("chrome-devtools"));
1331 }
1332
1333 // Tests that a regular extension without devtools permissions cannot be
1334 // injected into devtools when isolate-extensions or site-per-process mode.
1335 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, RegularExtensionInDevtools) {
1336 ASSERT_TRUE(embedded_test_server()->Start());
1337
1338 // TODO:(davidsac) Get rid of this dynamic loading and opt into static
1339 // loading? Our extension must load a URL from the test server, whose port is
1340 // only
1341 // known at runtime. So, to embed the URL, we must dynamically generate the
1342 // extension, rather than loading it from static content.
1343 std::unique_ptr<extensions::TestExtensionDir> dir(
1344 new extensions::TestExtensionDir());
1345
1346 extensions::DictionaryBuilder manifest;
1347 dir->WriteManifest(
1348 extensions::DictionaryBuilder()
1349 .Set("name", "Regular Extension")
1350 .Set("version", "1")
1351 .Set("manifest_version", 2)
1352 .Set("web_accessible_resources",
1353 extensions::ListBuilder().Append("test.html").Build())
1354 .ToJSON());
1355
1356 dir->WriteFile(FILE_PATH_LITERAL("test.html"),
1357 "<html><head></head><body>This is a test</body></html>");
1358
1359 // Install the extension.
1360 const Extension* extension = LoadExtensionFromPath(dir->UnpackedPath());
1361 ASSERT_TRUE(extension);
1362
1363 // Open a devtools window.
1364 OpenDevToolsWindow(kDebuggerTestPage, false);
1365
1366 GURL extension_file_url = extension->GetResourceURL("/test.html");
1367
1368 LOG(INFO) << extension_file_url.spec();
1369
1370 RenderFrameHost* rfh = main_web_contents()->GetMainFrame();
1371
1372 base::string16 javascript = base::UTF8ToUTF16(
1373 "var extensionFrame = document.createElement('iframe');"
1374 "document.body.appendChild(extensionFrame);"
1375 "extensionFrame.setAttribute('src', '" +
1376 extension_file_url.spec() + "');");
1377
1378 content::TestNavigationManager manager(main_web_contents(),
1379 extension_file_url);
1380
1381 rfh->ExecuteJavaScript(javascript);
1382
1383 if (content::AreAllSitesIsolatedForTesting() ||
1384 extensions::IsIsolateExtensionsEnabled()) {
1385 ASSERT_FALSE(manager.WaitForRequestStart());
1386 // TODO(davidsac): check to make sure that the rfh is about:blank or
1387 // something
alexmos 2017/02/08 21:48:00 Can you investigate how the request is actually bl
davidsac (gone - try alexmos) 2017/03/09 19:36:47 Done. Irrelevant. This (and later tests) have be
1388 } else {
1389 manager.WaitForNavigationFinished();
1390 std::vector<RenderFrameHost*> rfhs = main_web_contents()->GetAllFrames();
1391 ASSERT_EQ(rfhs[1]->GetSiteInstance()->GetSiteURL(),
1392 rfhs[0]->GetSiteInstance()->GetSiteURL());
1393 ASSERT_EQ(rfhs[1]->GetLastCommittedURL(), extension_file_url);
1394 }
1395 }
1396
1397 // Tests that http iframes cannot be injected into devtools outside of devtools
1398 // extensions when isolate-extensions or site-per-process mode.
1399 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
1400 DevToolsHttpIframeOutsideExtension) {
alexmos 2017/02/08 21:48:00 Feels like you can combine this one with the previ
davidsac (gone - try alexmos) 2017/02/16 20:29:01 That's definitely a possibility. In either case,
davidsac (gone - try alexmos) 2017/03/09 19:36:47 As mentioned earlier, this is no longer relevant a
1401 ASSERT_TRUE(embedded_test_server()->Start());
1402
1403 GURL simple_page_url =
1404 embedded_test_server()->GetURL("a.com", "/title1.html");
1405
1406 // Open a devtools window.
1407 OpenDevToolsWindow(kDebuggerTestPage, false);
1408
1409 base::string16 javascript = base::UTF8ToUTF16(
1410 "var httpFrame = document.createElement('iframe');"
1411 "document.body.appendChild(httpFrame);"
1412 "httpFrame.setAttribute('src', '" +
1413 simple_page_url.spec() + "');");
1414
1415 RenderFrameHost* rfh = main_web_contents()->GetMainFrame();
1416
1417 content::TestNavigationManager manager(main_web_contents(), simple_page_url);
1418
1419 rfh->ExecuteJavaScript(javascript);
1420
1421 if (content::AreAllSitesIsolatedForTesting() ||
1422 extensions::IsIsolateExtensionsEnabled()) {
1423 ASSERT_FALSE(manager.WaitForRequestStart());
1424 // TODO(davidsac): check to make sure that the rfh is about:blank or
1425 // something
1426 } else {
1427 manager.WaitForNavigationFinished();
1428 std::vector<RenderFrameHost*> rfhs = main_web_contents()->GetAllFrames();
1429 ASSERT_EQ(rfhs[1]->GetSiteInstance()->GetSiteURL(),
1430 rfhs[0]->GetSiteInstance()->GetSiteURL());
1431 ASSERT_EQ(rfhs[1]->GetLastCommittedURL(), simple_page_url);
1432 }
965 } 1433 }
966 1434
967 // Some web features, when used from an extension, are subject to browser-side 1435 // Some web features, when used from an extension, are subject to browser-side
968 // security policy enforcement. Make sure they work properly from inside a 1436 // security policy enforcement. Make sure they work properly from inside a
969 // devtools extension. 1437 // devtools extension.
970 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, 1438 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
971 DevToolsExtensionSecurityPolicyGrants) { 1439 DevToolsExtensionSecurityPolicyGrants) {
972 ASSERT_TRUE(embedded_test_server()->Start()); 1440 ASSERT_TRUE(embedded_test_server()->Start());
973 1441
974 std::unique_ptr<extensions::TestExtensionDir> dir( 1442 std::unique_ptr<extensions::TestExtensionDir> dir(
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
1566 2034
1567 DevToolsWindowTesting::CloseDevToolsWindowSync(window); 2035 DevToolsWindowTesting::CloseDevToolsWindowSync(window);
1568 content::WebUIControllerFactory::UnregisterFactoryForTesting(&test_factory); 2036 content::WebUIControllerFactory::UnregisterFactoryForTesting(&test_factory);
1569 } 2037 }
1570 2038
1571 // Tests scripts panel showing. 2039 // Tests scripts panel showing.
1572 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsSharedWorker) { 2040 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsSharedWorker) {
1573 RunTest("testDevToolsSharedWorker", url::kAboutBlankURL); 2041 RunTest("testDevToolsSharedWorker", url::kAboutBlankURL);
1574 } 2042 }
1575 2043
OLDNEW
« no previous file with comments | « no previous file | content/browser/frame_host/render_frame_host_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698