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 <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 Loading... | |
| 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" |
| 65 #include "content/public/common/url_constants.h" | |
| 63 #include "content/public/test/browser_test_utils.h" | 66 #include "content/public/test/browser_test_utils.h" |
| 64 #include "content/public/test/test_navigation_observer.h" | 67 #include "content/public/test/test_navigation_observer.h" |
| 65 #include "extensions/browser/extension_registry.h" | 68 #include "extensions/browser/extension_registry.h" |
| 66 #include "extensions/browser/extension_system.h" | 69 #include "extensions/browser/extension_system.h" |
| 67 #include "extensions/browser/notification_types.h" | 70 #include "extensions/browser/notification_types.h" |
| 68 #include "extensions/common/switches.h" | 71 #include "extensions/common/switches.h" |
| 69 #include "extensions/common/value_builder.h" | 72 #include "extensions/common/value_builder.h" |
| 70 #include "net/dns/mock_host_resolver.h" | 73 #include "net/dns/mock_host_resolver.h" |
| 71 #include "net/test/spawned_test_server/spawned_test_server.h" | 74 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 72 #include "net/test/url_request/url_request_mock_http_job.h" | 75 #include "net/test/url_request/url_request_mock_http_job.h" |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 size_t num_after = registry->enabled_extensions().size(); | 508 size_t num_after = registry->enabled_extensions().size(); |
| 506 if (num_after != (num_before + 1)) | 509 if (num_after != (num_before + 1)) |
| 507 return nullptr; | 510 return nullptr; |
| 508 | 511 |
| 509 if (!WaitForExtensionViewsToLoad()) | 512 if (!WaitForExtensionViewsToLoad()) |
| 510 return nullptr; | 513 return nullptr; |
| 511 | 514 |
| 512 return GetExtensionByPath(registry->enabled_extensions(), path); | 515 return GetExtensionByPath(registry->enabled_extensions(), path); |
| 513 } | 516 } |
| 514 | 517 |
| 518 // | |
| 519 //////////////////////////// | |
| 520 // | |
| 521 //////////////////////////////// | |
| 522 // | |
| 523 ///////////////////////////// | |
| 524 // | |
| 525 // | |
|
ncarter (slow)
2017/02/21 22:19:53
Remove these comments.
davidsac (gone - try alexmos)
2017/03/09 19:36:47
Done.
| |
| 526 | |
| 527 const Extension* LoadExtensionForTest( | |
| 528 const std::string& name, | |
| 529 extensions::TestExtensionDir* dir, | |
| 530 bool has_popup_test_page, | |
| 531 bool is_devtools_extension, | |
| 532 bool should_create_panel_and_pane, | |
| 533 const std::string& test_page_url = "test.html") { | |
| 534 extensions::DictionaryBuilder manifest; | |
| 535 manifest.Set("name", name) | |
| 536 .Set("version", "1") | |
| 537 .Set("manifest_version", 2) | |
| 538 .Set("web_accessible_resources", | |
| 539 extensions::ListBuilder().Append("test.html").Build()); | |
| 540 if (is_devtools_extension) { | |
| 541 manifest.Set("devtools_page", "devtools.html"); | |
| 542 } | |
| 543 | |
| 544 dir->WriteManifest(manifest.ToJSON()); | |
| 545 | |
| 546 if (is_devtools_extension) { | |
| 547 if (should_create_panel_and_pane) { | |
| 548 dir->WriteFile( | |
| 549 FILE_PATH_LITERAL("devtools.html"), | |
| 550 "<html><head><script " | |
| 551 "src='devtools.js'></script></head><body></body></html>"); | |
| 552 | |
| 553 dir->WriteFile( | |
| 554 FILE_PATH_LITERAL("devtools.js"), | |
| 555 "chrome.devtools.panels.create('iframe_panel',\n" | |
| 556 " null,\n" | |
| 557 " 'panel.html',\n" | |
| 558 " function(panel) {\n" | |
| 559 " " | |
| 560 "chrome.devtools.inspectedWindow.eval('console.log(" | |
| 561 "\"PASS\")');\n" | |
| 562 " }\n" | |
| 563 ");\n" | |
| 564 "chrome.devtools.panels.elements.createSidebarPane('iframe_pane',\n" | |
| 565 "function(sidebar) {\n" | |
| 566 "chrome.devtools.inspectedWindow.eval('console.log(\"PASS\")');\n" | |
| 567 "sidebar.setPage('panel.html');\n" | |
| 568 "});\n"); | |
| 569 | |
| 570 dir->WriteFile(FILE_PATH_LITERAL("panel.html"), | |
| 571 "<html><body><iframe src='" + test_page_url + | |
| 572 "'></iframe></body></html>"); | |
| 573 | |
| 574 } else { | |
| 575 dir->WriteFile(FILE_PATH_LITERAL("devtools.html"), | |
| 576 "<html><head></head><body></body></html>"); | |
| 577 } | |
| 578 } | |
| 579 if (has_popup_test_page) { | |
| 580 dir->WriteFile( | |
| 581 FILE_PATH_LITERAL("test.html"), | |
| 582 "<html><head><script src='test.js'></script></head><body>This " | |
| 583 "is a test</body></html>"); | |
| 584 | |
| 585 dir->WriteFile(FILE_PATH_LITERAL("test.js"), | |
| 586 "window.onload = function() {\n" | |
| 587 " domAutomationController.setAutomationId(0);\n" | |
| 588 " domAutomationController.send('DONE');\n" | |
| 589 "}\n"); | |
| 590 } else { | |
| 591 dir->WriteFile(FILE_PATH_LITERAL("test.html"), | |
| 592 "<html><head></head><body>This is a test</body></html>"); | |
| 593 } | |
| 594 | |
| 595 // Install the extension. | |
| 596 const Extension* extension = LoadExtensionFromPath(dir->UnpackedPath()); | |
| 597 return extension; | |
| 598 } | |
| 599 | |
| 515 private: | 600 private: |
| 516 const Extension* GetExtensionByPath( | 601 const Extension* GetExtensionByPath( |
| 517 const extensions::ExtensionSet& extensions, | 602 const extensions::ExtensionSet& extensions, |
| 518 const base::FilePath& path) { | 603 const base::FilePath& path) { |
| 519 base::FilePath extension_path = base::MakeAbsoluteFilePath(path); | 604 base::FilePath extension_path = base::MakeAbsoluteFilePath(path); |
| 520 EXPECT_TRUE(!extension_path.empty()); | 605 EXPECT_TRUE(!extension_path.empty()); |
| 521 for (const scoped_refptr<const Extension>& extension : extensions) { | 606 for (const scoped_refptr<const Extension>& extension : extensions) { |
| 522 if (extension->path() == extension_path) { | 607 if (extension->path() == extension_path) { |
| 523 return extension.get(); | 608 return extension.get(); |
| 524 } | 609 } |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 895 kDebuggerTestPage); | 980 kDebuggerTestPage); |
| 896 } | 981 } |
| 897 | 982 |
| 898 // Tests that chrome.devtools extension is correctly exposed. | 983 // Tests that chrome.devtools extension is correctly exposed. |
| 899 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | 984 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
| 900 TestDevToolsExtensionAPI) { | 985 TestDevToolsExtensionAPI) { |
| 901 LoadExtension("devtools_extension"); | 986 LoadExtension("devtools_extension"); |
| 902 RunTest("waitForTestResultsInConsole", std::string()); | 987 RunTest("waitForTestResultsInConsole", std::string()); |
| 903 } | 988 } |
| 904 | 989 |
| 905 // Tests a chrome.devtools extension panel that embeds an http:// iframe. | 990 // Tests that http Iframes within the three "devtools pages" (the visible |
| 906 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, DevToolsExtensionWithHttpIframe) { | 991 // devtools panel for the devtools extension, the sidebar pane page for the |
| 992 // devtools extension that is visible in the elemanets panel, and the devtools | |
| 993 // background page, which is different from the extension's background | |
| 994 // page)(https://developer.chrome.com/extensions/devtools) are rendered in their | |
| 995 // own processes and not in the devtools process or the extension's process. | |
| 996 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | |
| 997 HttpIframeInDevToolsExtensionPanel) { | |
| 907 ASSERT_TRUE(embedded_test_server()->Start()); | 998 ASSERT_TRUE(embedded_test_server()->Start()); |
| 908 | 999 |
| 909 // Our extension must load an URL from the test server, whose port is only | 1000 // 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 | 1001 // known at runtime. So, to embed the URL, we must dynamically generate the |
| 911 // extension, rather than loading it from static content. | 1002 // extension, rather than loading it from static content. |
| 912 std::unique_ptr<extensions::TestExtensionDir> dir( | 1003 std::unique_ptr<extensions::TestExtensionDir> dir( |
| 913 new extensions::TestExtensionDir()); | 1004 new extensions::TestExtensionDir()); |
| 914 | 1005 |
| 915 extensions::DictionaryBuilder manifest; | 1006 GURL http_iframe_url = |
| 1007 embedded_test_server()->GetURL("a.com", "/popup_iframe.html"); | |
| 1008 | |
| 1009 // Install the extension. | |
| 1010 const Extension* extension = LoadExtensionForTest( | |
| 1011 "Devtools Extension", dir.get(), false /* !has_popup_test_page */, | |
| 1012 true /* is_devtools_extension */, true /* should_create_panel_and_pane */, | |
| 1013 http_iframe_url.spec()); | |
| 1014 ASSERT_TRUE(extension); | |
| 1015 | |
| 1016 // Open a devtools window. | |
| 1017 OpenDevToolsWindow(kDebuggerTestPage, false); | |
| 1018 | |
| 1019 // Wait for the panel extension to finish loading -- it'll output 'PASS' | |
| 1020 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. | |
| 1021 RunTestFunction(window_, "waitForTestResultsInConsole"); | |
| 1022 | |
| 1023 // Now that we know the panel is loaded, switch to it. We'll wait until we | |
| 1024 // see a 'DONE' message sent from popup_iframe.html, indicating that it | |
| 1025 // loaded successfully. | |
| 1026 content::DOMMessageQueue message_queue; | |
| 1027 SwitchToExtensionPanel(window_, extension, "iframe_panel"); | |
| 1028 std::string message; | |
| 1029 | |
| 1030 while (true) { | |
| 1031 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | |
| 1032 if (message == "\"DONE\"") | |
| 1033 break; | |
| 1034 } | |
| 1035 | |
| 1036 std::vector<content::RenderFrameHost*> rfhs = | |
| 1037 main_web_contents()->GetAllFrames(); | |
| 1038 EXPECT_EQ(4U, rfhs.size()); | |
| 1039 | |
| 1040 content::RenderFrameHost* main_devtools_rfh = | |
| 1041 main_web_contents()->GetMainFrame(); | |
| 1042 content::RenderFrameHost* devtools_devtools_extension_rfh = | |
| 1043 ChildFrameAt(main_devtools_rfh, 0); | |
| 1044 content::RenderFrameHost* devtools_panel_extension_rfh = | |
| 1045 ChildFrameAt(main_devtools_rfh, 1); | |
| 1046 content::RenderFrameHost* http_iframe_rfh = | |
| 1047 ChildFrameAt(devtools_panel_extension_rfh, 0); | |
| 1048 | |
| 1049 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1050 content::kChromeDevToolsScheme)); | |
| 1051 EXPECT_EQ(extension->GetResourceURL("/devtools.html"), | |
| 1052 devtools_devtools_extension_rfh->GetLastCommittedURL()); | |
| 1053 EXPECT_EQ(extension->GetResourceURL("/panel.html"), | |
| 1054 devtools_panel_extension_rfh->GetLastCommittedURL()); | |
| 1055 EXPECT_EQ(http_iframe_url, http_iframe_rfh->GetLastCommittedURL()); | |
| 1056 | |
| 1057 if (content::AreAllSitesIsolatedForTesting() || | |
| 1058 extensions::IsIsolateExtensionsEnabled()) { | |
| 1059 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1060 content::kChromeDevToolsScheme)); | |
| 1061 EXPECT_TRUE(devtools_devtools_extension_rfh->GetSiteInstance() | |
| 1062 ->GetSiteURL() | |
| 1063 .SchemeIs(content::kChromeDevToolsScheme)); | |
| 1064 EXPECT_TRUE( | |
| 1065 devtools_panel_extension_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1066 content::kChromeDevToolsScheme)); | |
| 1067 EXPECT_EQ(http_iframe_url.host(), | |
| 1068 http_iframe_rfh->GetSiteInstance()->GetSiteURL().host()); | |
| 1069 | |
| 1070 } else { | |
| 1071 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1072 content::kChromeDevToolsScheme)); | |
| 1073 EXPECT_TRUE(devtools_devtools_extension_rfh->GetSiteInstance() | |
| 1074 ->GetSiteURL() | |
| 1075 .SchemeIs(content::kChromeDevToolsScheme)); | |
| 1076 EXPECT_TRUE( | |
| 1077 devtools_panel_extension_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1078 content::kChromeDevToolsScheme)); | |
| 1079 EXPECT_TRUE(http_iframe_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1080 content::kChromeDevToolsScheme)); | |
| 1081 } | |
| 1082 } | |
| 1083 | |
| 1084 // Tests that http Iframes within the three "devtools pages" (the visible | |
| 1085 // devtools panel for the devtools extension, the sidebar pane page for the | |
| 1086 // devtools extension that is visible in the elemanets panel, and the devtools | |
| 1087 // background page, which is different from the extension's background | |
| 1088 // page)(https://developer.chrome.com/extensions/devtools) are rendered in their | |
| 1089 // own processes and not in the devtools process or the extension's process. | |
| 1090 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | |
| 1091 HttpIframeInDevToolsExtensionSideBarPane) { | |
| 1092 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1093 | |
| 1094 // Our extension must load a URL from the test server, whose port is only | |
| 1095 // known at runtime. So, to embed the URL, we must dynamically generate the | |
| 1096 // extension, rather than loading it from static content. | |
| 1097 std::unique_ptr<extensions::TestExtensionDir> dir( | |
| 1098 new extensions::TestExtensionDir()); | |
| 1099 | |
| 1100 GURL http_iframe_url = | |
| 1101 embedded_test_server()->GetURL("a.com", "/popup_iframe.html"); | |
| 1102 | |
| 1103 // Install the extension. | |
| 1104 const Extension* extension = LoadExtensionForTest( | |
| 1105 "Devtools Extension", dir.get(), false /* !has_popup_test_page */, | |
| 1106 true /* is_devtools_extension */, true /* should_create_panel_and_pane */, | |
| 1107 http_iframe_url.spec()); | |
| 1108 ASSERT_TRUE(extension); | |
| 1109 | |
| 1110 // Open a devtools window. | |
| 1111 OpenDevToolsWindow(kDebuggerTestPage, false); | |
| 1112 | |
| 1113 // Wait for the panel extension to finish loading -- it'll output 'PASS' | |
| 1114 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. | |
| 1115 RunTestFunction(window_, "waitForTestResultsInConsole"); | |
| 1116 | |
| 1117 content::DOMMessageQueue message_queue; | |
| 1118 SwitchToPanel(window_, "elements"); | |
| 1119 // This is a bit of a hack to switch to the sidebar pane in the elements panel | |
| 1120 // that the Iframe has been added to. | |
| 1121 SwitchToPanel(window_, "iframe_pane"); | |
| 1122 std::string message; | |
| 1123 | |
| 1124 while (true) { | |
| 1125 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | |
| 1126 if (message == "\"DONE\"") | |
| 1127 break; | |
| 1128 } | |
| 1129 | |
| 1130 std::vector<content::RenderFrameHost*> rfhs = | |
| 1131 main_web_contents()->GetAllFrames(); | |
| 1132 EXPECT_EQ(4U, rfhs.size()); | |
| 1133 | |
| 1134 content::RenderFrameHost* main_devtools_rfh = | |
| 1135 main_web_contents()->GetMainFrame(); | |
| 1136 content::RenderFrameHost* devtools_devtools_extension_rfh = | |
| 1137 ChildFrameAt(main_devtools_rfh, 0); | |
| 1138 content::RenderFrameHost* devtools_sidebar_pane_extension_rfh = | |
| 1139 ChildFrameAt(main_devtools_rfh, 1); | |
| 1140 content::RenderFrameHost* http_iframe_rfh = | |
| 1141 ChildFrameAt(devtools_sidebar_pane_extension_rfh, 0); | |
| 1142 | |
| 1143 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1144 content::kChromeDevToolsScheme)); | |
| 1145 EXPECT_EQ(extension->GetResourceURL("/devtools.html"), | |
| 1146 devtools_devtools_extension_rfh->GetLastCommittedURL()); | |
| 1147 EXPECT_EQ(extension->GetResourceURL("/panel.html"), | |
| 1148 devtools_sidebar_pane_extension_rfh->GetLastCommittedURL()); | |
| 1149 EXPECT_EQ(http_iframe_url, http_iframe_rfh->GetLastCommittedURL()); | |
| 1150 | |
| 1151 if (content::AreAllSitesIsolatedForTesting() || | |
| 1152 extensions::IsIsolateExtensionsEnabled()) { | |
| 1153 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1154 content::kChromeDevToolsScheme)); | |
| 1155 EXPECT_TRUE(devtools_devtools_extension_rfh->GetSiteInstance() | |
| 1156 ->GetSiteURL() | |
| 1157 .SchemeIs(content::kChromeDevToolsScheme)); | |
| 1158 EXPECT_TRUE(devtools_sidebar_pane_extension_rfh->GetSiteInstance() | |
| 1159 ->GetSiteURL() | |
| 1160 .SchemeIs(content::kChromeDevToolsScheme)); | |
| 1161 EXPECT_EQ(http_iframe_url.host(), | |
| 1162 http_iframe_rfh->GetSiteInstance()->GetSiteURL().host()); | |
| 1163 | |
| 1164 } else { | |
| 1165 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1166 content::kChromeDevToolsScheme)); | |
| 1167 EXPECT_TRUE(devtools_devtools_extension_rfh->GetSiteInstance() | |
| 1168 ->GetSiteURL() | |
| 1169 .SchemeIs(content::kChromeDevToolsScheme)); | |
| 1170 EXPECT_TRUE(devtools_sidebar_pane_extension_rfh->GetSiteInstance() | |
| 1171 ->GetSiteURL() | |
| 1172 .SchemeIs(content::kChromeDevToolsScheme)); | |
| 1173 EXPECT_TRUE(http_iframe_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1174 content::kChromeDevToolsScheme)); | |
| 1175 } | |
| 1176 } | |
| 1177 | |
| 1178 // Tests that http Iframes within the three "devtools pages" (the visible | |
| 1179 // devtools panel for the devtools extension, the sidebar pane page for the | |
| 1180 // devtools extension that is visible in the elemanets panel, and the devtools | |
| 1181 // background page, which is different from the extension's background | |
| 1182 // page)(https://developer.chrome.com/extensions/devtools) are rendered in their | |
| 1183 // own processes and not in the devtools process or the extension's process. | |
| 1184 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | |
| 1185 HttpIframeInDevToolsExtensionDevtools) { | |
| 1186 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1187 | |
| 1188 GURL http_iframe_url = | |
| 1189 embedded_test_server()->GetURL("a.com", "/popup_iframe.html"); | |
| 1190 | |
| 1191 // Our extension must load a URL from the test server, whose port is only | |
| 1192 // known at runtime. So, to embed the URL, we must dynamically generate the | |
| 1193 // extension, rather than loading it from static content. | |
| 1194 std::unique_ptr<extensions::TestExtensionDir> dir( | |
| 1195 new extensions::TestExtensionDir()); | |
| 1196 | |
| 1197 // TODO(davidsac): is this worth refactoring to use |LoadExtensionForTest|? | |
| 916 dir->WriteManifest(extensions::DictionaryBuilder() | 1198 dir->WriteManifest(extensions::DictionaryBuilder() |
| 917 .Set("name", "Devtools Panel w/ HTTP Iframe") | 1199 .Set("name", "Devtools Panel w/ HTTP Iframe") |
| 918 .Set("version", "1") | 1200 .Set("version", "1") |
| 919 .Set("manifest_version", 2) | 1201 .Set("manifest_version", 2) |
| 920 .Set("devtools_page", "devtools.html") | 1202 .Set("devtools_page", "devtools.html") |
| 921 .ToJSON()); | 1203 .ToJSON()); |
| 922 | 1204 |
| 923 dir->WriteFile( | 1205 dir->WriteFile(FILE_PATH_LITERAL("devtools.html"), |
| 924 FILE_PATH_LITERAL("devtools.html"), | 1206 "<html><head></head><body><iframe src='" + |
| 925 "<html><head><script src='devtools.js'></script></head></html>"); | 1207 http_iframe_url.spec() + "'></iframe></body></html>"); |
| 926 | |
| 927 dir->WriteFile( | |
| 928 FILE_PATH_LITERAL("devtools.js"), | |
| 929 "chrome.devtools.panels.create('iframe_panel',\n" | |
| 930 " null,\n" | |
| 931 " 'panel.html',\n" | |
| 932 " function(panel) {\n" | |
| 933 " chrome.devtools.inspectedWindow.eval('console.log(\"PASS\")');\n" | |
| 934 " }\n" | |
| 935 ");\n"); | |
| 936 | |
| 937 GURL http_iframe = | |
| 938 embedded_test_server()->GetURL("a.com", "/popup_iframe.html"); | |
| 939 dir->WriteFile(FILE_PATH_LITERAL("panel.html"), | |
| 940 "<html><body>Extension panel.<iframe src='" + | |
| 941 http_iframe.spec() + "'></iframe>"); | |
| 942 | 1208 |
| 943 // Install the extension. | 1209 // Install the extension. |
| 944 const Extension* extension = LoadExtensionFromPath(dir->UnpackedPath()); | 1210 const Extension* extension = LoadExtensionFromPath(dir->UnpackedPath()); |
| 945 ASSERT_TRUE(extension); | 1211 ASSERT_TRUE(extension); |
| 946 | 1212 |
| 947 // Open a devtools window. | 1213 // Open a devtools window. |
| 1214 OpenDevToolsWindow(kDebuggerTestPage, false); | |
| 1215 | |
| 1216 // Now that we know the panel is loaded, switch to it. We'll wait until we | |
| 1217 // see a 'DONE' message sent from popup_iframe.html, indicating that it | |
| 1218 // loaded successfully. | |
| 1219 content::DOMMessageQueue message_queue; | |
| 1220 std::string message; | |
| 1221 | |
| 1222 while (true) { | |
| 1223 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | |
| 1224 if (message == "\"DONE\"") | |
| 1225 break; | |
| 1226 } | |
| 1227 | |
| 1228 std::vector<content::RenderFrameHost*> rfhs = | |
| 1229 main_web_contents()->GetAllFrames(); | |
| 1230 EXPECT_EQ(3U, rfhs.size()); | |
| 1231 | |
| 1232 content::RenderFrameHost* main_devtools_rfh = | |
| 1233 main_web_contents()->GetMainFrame(); | |
| 1234 content::RenderFrameHost* devtools_devtools_extension_rfh = | |
| 1235 ChildFrameAt(main_devtools_rfh, 0); | |
| 1236 content::RenderFrameHost* http_iframe_rfh = | |
| 1237 ChildFrameAt(devtools_devtools_extension_rfh, 0); | |
| 1238 | |
| 1239 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1240 content::kChromeDevToolsScheme)); | |
| 1241 EXPECT_EQ(extension->GetResourceURL("/devtools.html"), | |
| 1242 devtools_devtools_extension_rfh->GetLastCommittedURL()); | |
| 1243 EXPECT_EQ(http_iframe_url, http_iframe_rfh->GetLastCommittedURL()); | |
| 1244 | |
| 1245 if (content::AreAllSitesIsolatedForTesting() || | |
| 1246 extensions::IsIsolateExtensionsEnabled()) { | |
| 1247 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1248 content::kChromeDevToolsScheme)); | |
| 1249 EXPECT_TRUE(devtools_devtools_extension_rfh->GetSiteInstance() | |
| 1250 ->GetSiteURL() | |
| 1251 .SchemeIs(content::kChromeDevToolsScheme)); | |
| 1252 EXPECT_EQ(http_iframe_url.host(), | |
| 1253 http_iframe_rfh->GetSiteInstance()->GetSiteURL().host()); | |
| 1254 | |
| 1255 } else { | |
| 1256 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1257 content::kChromeDevToolsScheme)); | |
| 1258 EXPECT_TRUE(devtools_devtools_extension_rfh->GetSiteInstance() | |
| 1259 ->GetSiteURL() | |
| 1260 .SchemeIs(content::kChromeDevToolsScheme)); | |
| 1261 EXPECT_TRUE(http_iframe_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1262 content::kChromeDevToolsScheme)); | |
| 1263 } | |
| 1264 } | |
| 1265 | |
| 1266 // tests that an iframe to a non-devtools extension embedded in a devtools | |
| 1267 // extension will be isolated from devtools and the devtools extension. | |
| 1268 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | |
| 1269 NonDevToolsExtensionInDevToolsExtension) { | |
| 1270 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1271 | |
| 1272 std::unique_ptr<extensions::TestExtensionDir> dir( | |
| 1273 new extensions::TestExtensionDir()); | |
| 1274 | |
| 1275 // Install the extension. | |
| 1276 const Extension* non_devtools_extension = LoadExtensionForTest( | |
| 1277 "Non-DevTools Extension", dir.get(), true /* has_popup_test_page */, | |
| 1278 false /* !is_devtools_extension */, | |
| 1279 false /* !should_create_panel_and_pane */); | |
| 1280 ASSERT_TRUE(non_devtools_extension); | |
| 1281 | |
| 1282 GURL non_dt_extension_test_url = | |
| 1283 non_devtools_extension->GetResourceURL("/test.html"); | |
| 1284 | |
| 1285 std::unique_ptr<extensions::TestExtensionDir> dir2( | |
| 1286 new extensions::TestExtensionDir()); | |
| 1287 | |
| 1288 // Install the extension. | |
| 1289 const Extension* devtools_extension = LoadExtensionForTest( | |
| 1290 "Devtools Extension", dir2.get(), false /* !has_popup_test_page */, | |
| 1291 true /* is_devtools_extension */, true /* should_create_panel_and_pane */, | |
| 1292 non_dt_extension_test_url.spec()); | |
| 1293 ASSERT_TRUE(devtools_extension); | |
| 1294 | |
| 1295 // Wait for the panel extension to finish loading -- it'll output 'PASS' | |
| 1296 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. | |
| 1297 RunTestFunction(window_, "waitForTestResultsInConsole"); | |
| 1298 | |
| 1299 // Now that we know the panel is loaded, switch to it. We'll wait until we | |
| 1300 // see a 'DONE' message sent from popup_iframe.html, indicating that it | |
| 1301 // loaded successfully. | |
| 1302 content::DOMMessageQueue message_queue; | |
| 1303 SwitchToExtensionPanel(window_, devtools_extension, "iframe_panel"); | |
| 1304 std::string message1; | |
|
ncarter (slow)
2017/02/21 22:19:53
You use 'message1' in several places as a name, bu
davidsac (gone - try alexmos)
2017/03/09 19:36:47
Done.
| |
| 1305 | |
| 1306 while (true) { | |
| 1307 ASSERT_TRUE(message_queue.WaitForMessage(&message1)); | |
| 1308 if (message1 == "\"DONE\"") | |
| 1309 break; | |
| 1310 } | |
| 1311 | |
| 1312 std::vector<content::RenderFrameHost*> rfhs = | |
| 1313 main_web_contents()->GetAllFrames(); | |
| 1314 EXPECT_EQ(3U, rfhs.size()); | |
| 1315 | |
| 1316 content::RenderFrameHost* main_devtools_rfh = | |
| 1317 main_web_contents()->GetMainFrame(); | |
| 1318 content::RenderFrameHost* devtools_devtools_extension_rfh = | |
| 1319 ChildFrameAt(main_devtools_rfh, 0); | |
| 1320 content::RenderFrameHost* non_devtools_extension_rfh = | |
| 1321 ChildFrameAt(devtools_devtools_extension_rfh, 0); | |
| 1322 | |
| 1323 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1324 content::kChromeDevToolsScheme)); | |
| 1325 EXPECT_EQ(devtools_extension->GetResourceURL("/devtools.html"), | |
| 1326 devtools_devtools_extension_rfh->GetLastCommittedURL()); | |
| 1327 EXPECT_EQ(non_dt_extension_test_url, | |
| 1328 non_devtools_extension_rfh->GetLastCommittedURL()); | |
| 1329 | |
| 1330 if (content::AreAllSitesIsolatedForTesting() || | |
| 1331 extensions::IsIsolateExtensionsEnabled()) { | |
| 1332 // test.html's frame should be in extension b's | |
| 1333 // process, not in devtools or extension a's process. | |
| 1334 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1335 content::kChromeDevToolsScheme)); | |
| 1336 EXPECT_TRUE(devtools_devtools_extension_rfh->GetSiteInstance() | |
| 1337 ->GetSiteURL() | |
| 1338 .SchemeIs(content::kChromeDevToolsScheme)); | |
| 1339 EXPECT_EQ(non_dt_extension_test_url.GetOrigin(), | |
| 1340 non_devtools_extension_rfh->GetSiteInstance()->GetSiteURL()); | |
| 1341 } else { | |
| 1342 // test.html's frame should be in the devtools process. | |
| 1343 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1344 content::kChromeDevToolsScheme)); | |
| 1345 EXPECT_TRUE(devtools_devtools_extension_rfh->GetSiteInstance() | |
| 1346 ->GetSiteURL() | |
| 1347 .SchemeIs(content::kChromeDevToolsScheme)); | |
| 1348 EXPECT_TRUE( | |
| 1349 non_devtools_extension_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1350 content::kChromeDevToolsScheme)); | |
| 1351 } | |
| 1352 } | |
| 1353 | |
| 1354 // Tests that if a devtools extension's devtools page has a subframe to a | |
| 1355 // page for another devtools extension, the subframe is rendered in the devtools | |
| 1356 // process as well. | |
| 1357 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | |
| 1358 DevToolsExtensionInDevToolsExtension) { | |
| 1359 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1360 | |
| 1361 std::unique_ptr<extensions::TestExtensionDir> dir( | |
| 1362 new extensions::TestExtensionDir()); | |
| 1363 | |
| 1364 const Extension* devtools_b_extension = LoadExtensionForTest( | |
| 1365 "Devtools Extension B", dir.get(), true /* has_popup_test_page */, | |
| 1366 true /* is_devtools_extension */, | |
| 1367 false /* !should_create_panel_and_pane */); | |
| 1368 ASSERT_TRUE(devtools_b_extension); | |
| 1369 | |
| 1370 GURL extension_b_test_url = | |
| 1371 devtools_b_extension->GetResourceURL("/test.html"); | |
| 1372 | |
| 1373 std::unique_ptr<extensions::TestExtensionDir> dir2( | |
| 1374 new extensions::TestExtensionDir()); | |
| 1375 | |
| 1376 // Install the extension. | |
| 1377 const Extension* devtools_a_extension = LoadExtensionForTest( | |
| 1378 "Devtools Extension A", dir2.get(), false /* !has_popup_test_page */, | |
| 1379 true /* is_devtools_extension */, true /* should_create_panel_and_pane */, | |
| 1380 extension_b_test_url.spec()); | |
| 1381 ASSERT_TRUE(devtools_a_extension); | |
| 1382 | |
| 1383 // Open a devtools window. | |
| 1384 OpenDevToolsWindow(kDebuggerTestPage, false); | |
| 1385 | |
| 1386 // Wait for the panel extension to finish loading -- it'll output 'PASS' | |
| 1387 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. | |
| 1388 RunTestFunction(window_, "waitForTestResultsInConsole"); | |
| 1389 | |
| 1390 // Now that we know the panel is loaded, switch to it. We'll wait until we | |
| 1391 // see a 'DONE' message sent from popup_iframe.html, indicating that it | |
| 1392 // loaded successfully. | |
| 1393 content::DOMMessageQueue message_queue; | |
| 1394 SwitchToExtensionPanel(window_, devtools_a_extension, "iframe_panel"); | |
| 1395 std::string message1; | |
| 1396 | |
| 1397 while (true) { | |
| 1398 ASSERT_TRUE(message_queue.WaitForMessage(&message1)); | |
| 1399 if (message1 == "\"DONE\"") | |
| 1400 break; | |
| 1401 } | |
| 1402 | |
| 1403 std::vector<content::RenderFrameHost*> rfhs = | |
| 1404 main_web_contents()->GetAllFrames(); | |
| 1405 EXPECT_EQ(3U, rfhs.size()); | |
| 1406 | |
| 1407 content::RenderFrameHost* main_devtools_rfh = | |
| 1408 main_web_contents()->GetMainFrame(); | |
| 1409 content::RenderFrameHost* devtools_extension_a_devtools_rfh = | |
| 1410 ChildFrameAt(main_devtools_rfh, 0); | |
| 1411 content::RenderFrameHost* devtools_extension_b_devtools_rfh = | |
| 1412 ChildFrameAt(devtools_extension_a_devtools_rfh, 0); | |
| 1413 | |
| 1414 // TODO the expected result is the exact same as a non-devtools extension in | |
| 1415 // devtools | |
| 1416 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1417 content::kChromeDevToolsScheme)); | |
| 1418 EXPECT_EQ(devtools_a_extension->GetResourceURL("/devtools.html"), | |
| 1419 devtools_extension_a_devtools_rfh->GetLastCommittedURL()); | |
| 1420 EXPECT_EQ(extension_b_test_url, | |
| 1421 devtools_extension_b_devtools_rfh->GetLastCommittedURL()); | |
| 1422 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1423 content::kChromeDevToolsScheme)); | |
| 1424 EXPECT_TRUE(devtools_extension_a_devtools_rfh->GetSiteInstance() | |
| 1425 ->GetSiteURL() | |
| 1426 .SchemeIs(content::kChromeDevToolsScheme)); | |
| 1427 // test.html's frame should be in the devtools process. | |
| 1428 EXPECT_TRUE(devtools_extension_b_devtools_rfh->GetSiteInstance() | |
| 1429 ->GetSiteURL() | |
| 1430 .SchemeIs(content::kChromeDevToolsScheme)); | |
| 1431 } | |
| 1432 | |
| 1433 // Tests that a devtools extension can still have subframes to itself in a | |
| 1434 // "devtools page" and that they will be rendered within the devtools process as | |
| 1435 // well, not in the extension process. | |
| 1436 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, DevToolsExtensionInItself) { | |
| 1437 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1438 | |
| 1439 std::unique_ptr<extensions::TestExtensionDir> dir( | |
| 1440 new extensions::TestExtensionDir()); | |
| 1441 // Install the extension. | |
| 1442 const Extension* extension = LoadExtensionForTest( | |
| 1443 "Devtools Extension", dir.get(), true /* has_popup_test_page */, | |
| 1444 true /* is_devtools_extension */, | |
| 1445 true /* should_create_panel_and_pane */); | |
| 1446 ASSERT_TRUE(extension); | |
| 1447 | |
| 1448 // Open a devtools window. | |
| 948 OpenDevToolsWindow(kDebuggerTestPage, false); | 1449 OpenDevToolsWindow(kDebuggerTestPage, false); |
| 949 | 1450 |
| 950 // Wait for the panel extension to finish loading -- it'll output 'PASS' | 1451 // Wait for the panel extension to finish loading -- it'll output 'PASS' |
| 951 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. | 1452 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. |
| 952 RunTestFunction(window_, "waitForTestResultsInConsole"); | 1453 RunTestFunction(window_, "waitForTestResultsInConsole"); |
| 953 | 1454 |
| 954 // Now that we know the panel is loaded, switch to it. We'll wait until we | 1455 // 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 | 1456 // see a 'DONE' message sent from popup_iframe.html, indicating that it |
| 956 // loaded successfully. | 1457 // loaded successfully. |
| 957 content::DOMMessageQueue message_queue; | 1458 content::DOMMessageQueue message_queue; |
| 958 SwitchToExtensionPanel(window_, extension, "iframe_panel"); | 1459 SwitchToExtensionPanel(window_, extension, "iframe_panel"); |
| 959 std::string message; | 1460 std::string message1; |
| 1461 | |
| 960 while (true) { | 1462 while (true) { |
| 961 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | 1463 ASSERT_TRUE(message_queue.WaitForMessage(&message1)); |
| 962 if (message == "\"DONE\"") | 1464 if (message1 == "\"DONE\"") |
| 963 break; | 1465 break; |
| 964 } | 1466 } |
| 1467 | |
| 1468 GURL extension_test_url = extension->GetResourceURL("/test.html"); | |
| 1469 | |
| 1470 std::vector<content::RenderFrameHost*> rfhs = | |
| 1471 main_web_contents()->GetAllFrames(); | |
| 1472 EXPECT_EQ(3U, rfhs.size()); | |
| 1473 | |
| 1474 content::RenderFrameHost* main_devtools_rfh = | |
| 1475 main_web_contents()->GetMainFrame(); | |
| 1476 content::RenderFrameHost* devtools_extension_devtools_rfh = | |
| 1477 ChildFrameAt(main_devtools_rfh, 0); | |
| 1478 content::RenderFrameHost* devtools_extension_test_rfh = | |
| 1479 ChildFrameAt(devtools_extension_devtools_rfh, 0); | |
| 1480 | |
| 1481 // all frames should be in the devtools process. | |
| 1482 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1483 content::kChromeDevToolsScheme)); | |
| 1484 EXPECT_EQ(extension->GetResourceURL("/devtools.html"), | |
| 1485 devtools_extension_devtools_rfh->GetLastCommittedURL()); | |
| 1486 EXPECT_EQ(extension_test_url, | |
| 1487 devtools_extension_test_rfh->GetLastCommittedURL()); | |
| 1488 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1489 content::kChromeDevToolsScheme)); | |
| 1490 EXPECT_TRUE( | |
| 1491 devtools_extension_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1492 content::kChromeDevToolsScheme)); | |
| 1493 // test.html's frame should be in the devtools process. | |
| 1494 EXPECT_TRUE( | |
| 1495 devtools_extension_test_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1496 content::kChromeDevToolsScheme)); | |
| 1497 } | |
| 1498 | |
| 1499 // Tests that an Iframe to a non-devtools extension cannot be injected into | |
| 1500 // devtools when not contained in a devtools extension. | |
| 1501 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | |
| 1502 NonDevToolsExtensionInDevToolsOutsideDevToolsExtension) { | |
| 1503 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1504 | |
| 1505 std::unique_ptr<extensions::TestExtensionDir> dir( | |
| 1506 new extensions::TestExtensionDir()); | |
| 1507 | |
| 1508 // Install the extension. | |
| 1509 const Extension* extension = LoadExtensionForTest( | |
| 1510 "Non-DevTools Extension", dir.get(), false /* !has_popup_test_page */, | |
| 1511 false /* !is_devtools_extension */, | |
| 1512 false /* !should_create_panel_and_pane */); | |
| 1513 ASSERT_TRUE(extension); | |
| 1514 | |
| 1515 // Open a devtools window. | |
| 1516 OpenDevToolsWindow(kDebuggerTestPage, false); | |
| 1517 | |
| 1518 GURL extension_test_url = extension->GetResourceURL("/test.html"); | |
| 1519 | |
| 1520 content::RenderFrameHost* main_devtools_rfh = | |
| 1521 main_web_contents()->GetMainFrame(); | |
| 1522 | |
| 1523 std::string javascript = | |
| 1524 "var extensionFrame = document.createElement('iframe');" | |
| 1525 "document.body.appendChild(extensionFrame);" | |
| 1526 "extensionFrame.setAttribute('src', '" + | |
| 1527 extension_test_url.spec() + "');"; | |
| 1528 | |
| 1529 content::TestNavigationManager manager(main_web_contents(), | |
| 1530 extension_test_url); | |
| 1531 | |
| 1532 ASSERT_TRUE(content::ExecuteScript(main_devtools_rfh, javascript)); | |
| 1533 | |
| 1534 if (content::AreAllSitesIsolatedForTesting() || | |
| 1535 extensions::IsIsolateExtensionsEnabled()) { | |
| 1536 EXPECT_FALSE(manager.WaitForRequestStart()); | |
| 1537 | |
| 1538 std::vector<content::RenderFrameHost*> rfhs = | |
| 1539 main_web_contents()->GetAllFrames(); | |
| 1540 | |
| 1541 EXPECT_EQ(1U, rfhs.size()); | |
| 1542 | |
| 1543 // TODO(davidsac): check to make sure that the rfh is about:blank or | |
| 1544 // something | |
| 1545 } else { | |
| 1546 manager.WaitForNavigationFinished(); | |
| 1547 std::vector<content::RenderFrameHost*> rfhs = | |
| 1548 main_web_contents()->GetAllFrames(); | |
| 1549 | |
| 1550 EXPECT_EQ(2U, rfhs.size()); | |
| 1551 | |
| 1552 content::RenderFrameHost* extension_test_rfh = | |
| 1553 ChildFrameAt(main_devtools_rfh, 0); | |
| 1554 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1555 content::kChromeDevToolsScheme)); | |
| 1556 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1557 content::kChromeDevToolsScheme)); | |
| 1558 EXPECT_TRUE(extension_test_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1559 content::kChromeDevToolsScheme)); | |
| 1560 EXPECT_EQ(extension_test_url, extension_test_rfh->GetLastCommittedURL()); | |
| 1561 } | |
| 1562 } | |
| 1563 | |
| 1564 // Tests that a web Iframe cannot be injected into devtools when not contained | |
| 1565 // in a devtools extension. | |
| 1566 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | |
| 1567 HttpIframeInDevToolsOutsideDevToolsExtension) { | |
| 1568 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1569 | |
| 1570 GURL simple_page_url = | |
| 1571 embedded_test_server()->GetURL("a.com", "/title1.html"); | |
| 1572 | |
| 1573 // Open a devtools window. | |
| 1574 OpenDevToolsWindow(kDebuggerTestPage, false); | |
| 1575 | |
| 1576 std::string javascript = | |
| 1577 "var httpFrame = document.createElement('iframe');" | |
| 1578 "document.body.appendChild(httpFrame);" | |
| 1579 "httpFrame.setAttribute('src', '" + | |
| 1580 simple_page_url.spec() + "');"; | |
| 1581 | |
| 1582 content::RenderFrameHost* main_devtools_rfh = | |
| 1583 main_web_contents()->GetMainFrame(); | |
| 1584 | |
| 1585 content::TestNavigationManager manager(main_web_contents(), simple_page_url); | |
| 1586 | |
| 1587 ASSERT_TRUE(content::ExecuteScript(main_devtools_rfh, javascript)); | |
| 1588 | |
| 1589 if (content::AreAllSitesIsolatedForTesting() || | |
| 1590 extensions::IsIsolateExtensionsEnabled()) { | |
| 1591 EXPECT_FALSE(manager.WaitForRequestStart()); | |
| 1592 | |
| 1593 std::vector<content::RenderFrameHost*> rfhs = | |
| 1594 main_web_contents()->GetAllFrames(); | |
| 1595 | |
| 1596 EXPECT_EQ(1U, rfhs.size()); | |
| 1597 // TODO(davidsac): check to make sure that the rfh is about:blank or | |
| 1598 // something | |
| 1599 } else { | |
| 1600 manager.WaitForNavigationFinished(); | |
| 1601 std::vector<content::RenderFrameHost*> rfhs = | |
| 1602 main_web_contents()->GetAllFrames(); | |
| 1603 EXPECT_EQ(2U, rfhs.size()); | |
| 1604 content::RenderFrameHost* http_iframe_rfh = | |
| 1605 ChildFrameAt(main_devtools_rfh, 0); | |
| 1606 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1607 content::kChromeDevToolsScheme)); | |
| 1608 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1609 content::kChromeDevToolsScheme)); | |
| 1610 EXPECT_TRUE(http_iframe_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1611 content::kChromeDevToolsScheme)); | |
| 1612 EXPECT_EQ(simple_page_url, http_iframe_rfh->GetLastCommittedURL()); | |
| 1613 } | |
| 1614 } | |
| 1615 | |
| 1616 // Tests that a devtools Iframe can still be injected into devtools. | |
| 1617 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, DevtoolsInDevTools) { | |
| 1618 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1619 | |
| 1620 // Open a devtools window. | |
| 1621 OpenDevToolsWindow(kDebuggerTestPage, false); | |
| 1622 | |
| 1623 GURL devtools_url = | |
| 1624 GURL("chrome-devtools://devtools/bundled/inspector.html?ws="); | |
| 1625 | |
| 1626 std::string javascript = | |
| 1627 "var devtoolsFrame = document.createElement('iframe');" | |
| 1628 "document.body.appendChild(devtoolsFrame);" | |
| 1629 "devtoolsFrame.setAttribute('src', '" + | |
| 1630 devtools_url.spec() + "');"; | |
| 1631 | |
| 1632 content::RenderFrameHost* main_devtools_rfh = | |
| 1633 main_web_contents()->GetMainFrame(); | |
| 1634 | |
| 1635 content::TestNavigationManager manager(main_web_contents(), devtools_url); | |
| 1636 | |
| 1637 ASSERT_TRUE(content::ExecuteScript(main_devtools_rfh, javascript)); | |
| 1638 | |
| 1639 manager.WaitForNavigationFinished(); | |
| 1640 std::vector<content::RenderFrameHost*> rfhs = | |
| 1641 main_web_contents()->GetAllFrames(); | |
| 1642 EXPECT_EQ(2U, rfhs.size()); | |
| 1643 content::RenderFrameHost* devtools_iframe_rfh = | |
| 1644 ChildFrameAt(main_devtools_rfh, 0); | |
| 1645 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1646 content::kChromeDevToolsScheme)); | |
| 1647 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1648 content::kChromeDevToolsScheme)); | |
| 1649 EXPECT_TRUE(devtools_iframe_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1650 content::kChromeDevToolsScheme)); | |
| 1651 EXPECT_TRUE(devtools_iframe_rfh->GetLastCommittedURL().SchemeIs( | |
| 1652 content::kChromeDevToolsScheme)); | |
| 1653 } | |
| 1654 | |
| 1655 // Tests that a blank Iframe can still be injected into devtools. | |
| 1656 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, AboutBlankInDevTools) { | |
| 1657 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1658 | |
| 1659 GURL about_blank_url = GURL(url::kAboutBlankURL); | |
| 1660 | |
| 1661 // Open a devtools window. | |
| 1662 OpenDevToolsWindow(kDebuggerTestPage, false); | |
| 1663 std::string javascript = | |
| 1664 "var blankFrame = document.createElement('iframe');" | |
| 1665 "document.body.appendChild(blankFrame);" | |
| 1666 "blankFrame.setAttribute('src', '" + | |
| 1667 about_blank_url.spec() + "');"; | |
| 1668 | |
| 1669 content::RenderFrameHost* main_devtools_rfh = | |
| 1670 main_web_contents()->GetMainFrame(); | |
| 1671 | |
| 1672 content::TestNavigationManager manager(main_web_contents(), about_blank_url); | |
| 1673 | |
| 1674 ASSERT_TRUE(content::ExecuteScript(main_devtools_rfh, javascript)); | |
| 1675 | |
| 1676 manager.WaitForNavigationFinished(); | |
| 1677 std::vector<content::RenderFrameHost*> rfhs = | |
| 1678 main_web_contents()->GetAllFrames(); | |
| 1679 EXPECT_EQ(2U, rfhs.size()); | |
| 1680 content::RenderFrameHost* about_blank_rfh = | |
| 1681 ChildFrameAt(main_devtools_rfh, 0); | |
| 1682 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1683 content::kChromeDevToolsScheme)); | |
| 1684 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1685 content::kChromeDevToolsScheme)); | |
| 1686 EXPECT_TRUE(about_blank_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1687 content::kChromeDevToolsScheme)); | |
| 1688 EXPECT_EQ(about_blank_url, about_blank_rfh->GetLastCommittedURL()); | |
| 965 } | 1689 } |
| 966 | 1690 |
| 967 // Some web features, when used from an extension, are subject to browser-side | 1691 // 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 | 1692 // security policy enforcement. Make sure they work properly from inside a |
| 969 // devtools extension. | 1693 // devtools extension. |
| 970 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | 1694 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
| 971 DevToolsExtensionSecurityPolicyGrants) { | 1695 DevToolsExtensionSecurityPolicyGrants) { |
| 972 ASSERT_TRUE(embedded_test_server()->Start()); | 1696 ASSERT_TRUE(embedded_test_server()->Start()); |
| 973 | 1697 |
| 974 std::unique_ptr<extensions::TestExtensionDir> dir( | 1698 std::unique_ptr<extensions::TestExtensionDir> dir( |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1566 | 2290 |
| 1567 DevToolsWindowTesting::CloseDevToolsWindowSync(window); | 2291 DevToolsWindowTesting::CloseDevToolsWindowSync(window); |
| 1568 content::WebUIControllerFactory::UnregisterFactoryForTesting(&test_factory); | 2292 content::WebUIControllerFactory::UnregisterFactoryForTesting(&test_factory); |
| 1569 } | 2293 } |
| 1570 | 2294 |
| 1571 // Tests scripts panel showing. | 2295 // Tests scripts panel showing. |
| 1572 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsSharedWorker) { | 2296 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsSharedWorker) { |
| 1573 RunTest("testDevToolsSharedWorker", url::kAboutBlankURL); | 2297 RunTest("testDevToolsSharedWorker", url::kAboutBlankURL); |
| 1574 } | 2298 } |
| 1575 | 2299 |
| OLD | NEW |