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 21 matching lines...) Expand all Loading... | |
| 32 #include "chrome/browser/extensions/extension_service.h" | 32 #include "chrome/browser/extensions/extension_service.h" |
| 33 #include "chrome/browser/extensions/test_extension_dir.h" | 33 #include "chrome/browser/extensions/test_extension_dir.h" |
| 34 #include "chrome/browser/extensions/unpacked_installer.h" | 34 #include "chrome/browser/extensions/unpacked_installer.h" |
| 35 #include "chrome/browser/lifetime/application_lifetime.h" | 35 #include "chrome/browser/lifetime/application_lifetime.h" |
| 36 #include "chrome/browser/profiles/profile.h" | 36 #include "chrome/browser/profiles/profile.h" |
| 37 #include "chrome/browser/ui/browser.h" | 37 #include "chrome/browser/ui/browser.h" |
| 38 #include "chrome/browser/ui/browser_commands.h" | 38 #include "chrome/browser/ui/browser_commands.h" |
| 39 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 39 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 40 #include "chrome/common/chrome_paths.h" | 40 #include "chrome/common/chrome_paths.h" |
| 41 #include "chrome/common/chrome_switches.h" | 41 #include "chrome/common/chrome_switches.h" |
| 42 #include "chrome/common/extensions/extension_process_policy.h" | |
| 42 #include "chrome/common/pref_names.h" | 43 #include "chrome/common/pref_names.h" |
| 43 #include "chrome/common/url_constants.h" | 44 #include "chrome/common/url_constants.h" |
| 44 #include "chrome/test/base/in_process_browser_test.h" | 45 #include "chrome/test/base/in_process_browser_test.h" |
| 45 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" | 46 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" |
| 46 #include "chrome/test/base/ui_test_utils.h" | 47 #include "chrome/test/base/ui_test_utils.h" |
| 47 #include "components/app_modal/javascript_app_modal_dialog.h" | 48 #include "components/app_modal/javascript_app_modal_dialog.h" |
| 48 #include "components/app_modal/native_app_modal_dialog.h" | 49 #include "components/app_modal/native_app_modal_dialog.h" |
| 49 #include "components/prefs/pref_service.h" | 50 #include "components/prefs/pref_service.h" |
| 50 #include "content/public/browser/child_process_data.h" | 51 #include "content/public/browser/child_process_data.h" |
| 51 #include "content/public/browser/content_browser_client.h" | 52 #include "content/public/browser/content_browser_client.h" |
| 52 #include "content/public/browser/devtools_agent_host.h" | 53 #include "content/public/browser/devtools_agent_host.h" |
| 53 #include "content/public/browser/notification_registrar.h" | 54 #include "content/public/browser/notification_registrar.h" |
| 54 #include "content/public/browser/notification_service.h" | 55 #include "content/public/browser/notification_service.h" |
| 56 #include "content/public/browser/render_frame_host.h" | |
| 55 #include "content/public/browser/render_view_host.h" | 57 #include "content/public/browser/render_view_host.h" |
| 56 #include "content/public/browser/render_widget_host.h" | 58 #include "content/public/browser/render_widget_host.h" |
| 57 #include "content/public/browser/render_widget_host_view.h" | 59 #include "content/public/browser/render_widget_host_view.h" |
| 58 #include "content/public/browser/url_data_source.h" | 60 #include "content/public/browser/url_data_source.h" |
| 59 #include "content/public/browser/web_contents.h" | 61 #include "content/public/browser/web_contents.h" |
| 60 #include "content/public/browser/web_ui_controller.h" | 62 #include "content/public/browser/web_ui_controller.h" |
| 61 #include "content/public/browser/worker_service.h" | 63 #include "content/public/browser/worker_service.h" |
| 62 #include "content/public/browser/worker_service_observer.h" | 64 #include "content/public/browser/worker_service_observer.h" |
| 63 #include "content/public/common/content_switches.h" | 65 #include "content/public/common/content_switches.h" |
| 66 #include "content/public/common/url_constants.h" | |
| 64 #include "content/public/test/browser_test_utils.h" | 67 #include "content/public/test/browser_test_utils.h" |
| 65 #include "content/public/test/test_navigation_observer.h" | 68 #include "content/public/test/test_navigation_observer.h" |
| 66 #include "extensions/browser/extension_registry.h" | 69 #include "extensions/browser/extension_registry.h" |
| 67 #include "extensions/browser/extension_system.h" | 70 #include "extensions/browser/extension_system.h" |
| 68 #include "extensions/browser/notification_types.h" | 71 #include "extensions/browser/notification_types.h" |
| 69 #include "extensions/common/switches.h" | 72 #include "extensions/common/switches.h" |
| 70 #include "extensions/common/value_builder.h" | 73 #include "extensions/common/value_builder.h" |
| 71 #include "net/dns/mock_host_resolver.h" | 74 #include "net/dns/mock_host_resolver.h" |
| 72 #include "net/test/spawned_test_server/spawned_test_server.h" | 75 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 73 #include "net/test/url_request/url_request_mock_http_job.h" | 76 #include "net/test/url_request/url_request_mock_http_job.h" |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 506 size_t num_after = registry->enabled_extensions().size(); | 509 size_t num_after = registry->enabled_extensions().size(); |
| 507 if (num_after != (num_before + 1)) | 510 if (num_after != (num_before + 1)) |
| 508 return nullptr; | 511 return nullptr; |
| 509 | 512 |
| 510 if (!WaitForExtensionViewsToLoad()) | 513 if (!WaitForExtensionViewsToLoad()) |
| 511 return nullptr; | 514 return nullptr; |
| 512 | 515 |
| 513 return GetExtensionByPath(registry->enabled_extensions(), path); | 516 return GetExtensionByPath(registry->enabled_extensions(), path); |
| 514 } | 517 } |
| 515 | 518 |
| 519 // TODO(davidsac): should I refactor this with a diff method for each page and | |
| 520 // call them individually in each test instead of these if/elses? | |
|
ncarter (slow)
2017/03/09 23:28:49
I might split this into two functions (for the is_
davidsac (gone - try alexmos)
2017/03/11 01:51:47
Done. Kinda. I had talked to Alex about this ear
| |
| 521 const Extension* LoadExtensionForTest( | |
| 522 const std::string& name, | |
| 523 extensions::TestExtensionDir* dir, | |
|
ncarter (slow)
2017/03/09 23:28:49
Having to pass in a TestExtensionDir seems like a
davidsac (gone - try alexmos)
2017/03/11 01:51:47
Done.
| |
| 524 bool has_popup_test_page, | |
| 525 bool is_devtools_extension, | |
| 526 bool should_create_panel_and_pane, | |
| 527 const std::string& test_page_url = "test.html") { | |
|
ncarter (slow)
2017/03/09 23:28:48
Could you combine should_create_panel_and_pane and
davidsac (gone - try alexmos)
2017/03/11 01:51:47
Done.
| |
| 528 extensions::DictionaryBuilder manifest; | |
| 529 manifest.Set("name", name) | |
| 530 .Set("version", "1") | |
| 531 .Set("manifest_version", 2) | |
| 532 .Set("web_accessible_resources", | |
| 533 extensions::ListBuilder().Append("test.html").Build()); | |
| 534 if (is_devtools_extension) { | |
| 535 manifest.Set("devtools_page", "devtools.html"); | |
| 536 } | |
| 537 | |
| 538 dir->WriteManifest(manifest.ToJSON()); | |
| 539 | |
| 540 if (is_devtools_extension) { | |
| 541 if (should_create_panel_and_pane) { | |
| 542 dir->WriteFile( | |
| 543 FILE_PATH_LITERAL("devtools.html"), | |
| 544 "<html><head><script " | |
| 545 "src='devtools.js'></script></head><body></body></html>"); | |
| 546 | |
| 547 dir->WriteFile( | |
| 548 FILE_PATH_LITERAL("devtools.js"), | |
| 549 "chrome.devtools.panels.create('iframe_panel',\n" | |
| 550 " null,\n" | |
| 551 " 'panel.html',\n" | |
| 552 " function(panel) {\n" | |
| 553 " " | |
| 554 "chrome.devtools.inspectedWindow.eval('console.log(" | |
| 555 "\"PASS\")');\n" | |
| 556 " }\n" | |
| 557 ");\n" | |
| 558 "chrome.devtools.panels.elements.createSidebarPane('iframe_pane',\n" | |
| 559 "function(sidebar) {\n" | |
| 560 "chrome.devtools.inspectedWindow.eval('console.log(\"PASS\")');\n" | |
| 561 "sidebar.setPage('panel.html');\n" | |
| 562 "});\n"); | |
| 563 | |
| 564 dir->WriteFile(FILE_PATH_LITERAL("panel.html"), | |
| 565 "<html><body><iframe src='" + test_page_url + | |
| 566 "'></iframe></body></html>"); | |
| 567 | |
| 568 } else { | |
| 569 dir->WriteFile(FILE_PATH_LITERAL("devtools.html"), | |
| 570 "<html><head></head><body></body></html>"); | |
| 571 } | |
| 572 } | |
| 573 if (has_popup_test_page) { | |
|
ncarter (slow)
2017/03/09 23:28:49
Rather than parameterizing this with a boolean |ha
davidsac (gone - try alexmos)
2017/03/11 01:51:47
Done.
| |
| 574 dir->WriteFile( | |
| 575 FILE_PATH_LITERAL("test.html"), | |
| 576 "<html><head><script src='test.js'></script></head><body>This " | |
| 577 "is a test</body></html>"); | |
| 578 | |
| 579 dir->WriteFile(FILE_PATH_LITERAL("test.js"), | |
| 580 "window.onload = function() {\n" | |
| 581 " domAutomationController.setAutomationId(0);\n" | |
| 582 " domAutomationController.send('DONE');\n" | |
| 583 "}\n"); | |
| 584 } else { | |
| 585 dir->WriteFile(FILE_PATH_LITERAL("test.html"), | |
| 586 "<html><head></head><body>This is a test</body></html>"); | |
| 587 } | |
| 588 | |
| 589 // Install the extension. | |
| 590 const Extension* extension = LoadExtensionFromPath(dir->UnpackedPath()); | |
| 591 return extension; | |
| 592 } | |
| 593 | |
| 516 private: | 594 private: |
| 517 const Extension* GetExtensionByPath( | 595 const Extension* GetExtensionByPath( |
| 518 const extensions::ExtensionSet& extensions, | 596 const extensions::ExtensionSet& extensions, |
| 519 const base::FilePath& path) { | 597 const base::FilePath& path) { |
| 520 base::FilePath extension_path = base::MakeAbsoluteFilePath(path); | 598 base::FilePath extension_path = base::MakeAbsoluteFilePath(path); |
| 521 EXPECT_TRUE(!extension_path.empty()); | 599 EXPECT_TRUE(!extension_path.empty()); |
| 522 for (const scoped_refptr<const Extension>& extension : extensions) { | 600 for (const scoped_refptr<const Extension>& extension : extensions) { |
| 523 if (extension->path() == extension_path) { | 601 if (extension->path() == extension_path) { |
| 524 return extension.get(); | 602 return extension.get(); |
| 525 } | 603 } |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 896 kDebuggerTestPage); | 974 kDebuggerTestPage); |
| 897 } | 975 } |
| 898 | 976 |
| 899 // Tests that chrome.devtools extension is correctly exposed. | 977 // Tests that chrome.devtools extension is correctly exposed. |
| 900 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | 978 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
| 901 TestDevToolsExtensionAPI) { | 979 TestDevToolsExtensionAPI) { |
| 902 LoadExtension("devtools_extension"); | 980 LoadExtension("devtools_extension"); |
| 903 RunTest("waitForTestResultsInConsole", std::string()); | 981 RunTest("waitForTestResultsInConsole", std::string()); |
| 904 } | 982 } |
| 905 | 983 |
| 906 // Tests a chrome.devtools extension panel that embeds an http:// iframe. | 984 // The following three tests check that http Iframes within the three "devtools |
| 907 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, DevToolsExtensionWithHttpIframe) { | 985 // pages" (the visible devtools panel for the devtools extension, the sidebar |
| 986 // pane page for the devtools extension that is visible in the elemanets panel, | |
| 987 // and the devtools background page, which is different from the extension's | |
| 988 // background page)(https://developer.chrome.com/extensions/devtools) are | |
| 989 // rendered in their own processes and not in the devtools process or the | |
| 990 // extension's process. | |
| 991 | |
| 992 // Tests that http Iframes within the visible devtools panel for the devtools | |
| 993 // extension are rendered in their own processes and not in the devtools process | |
| 994 // or the extension's process. Also tests that data URLs and about blank URLs | |
| 995 // are rendered in the devtools process, unless an OOPIF is navigated to | |
| 996 // about:blank, in which case it does not end up back in the devtools process. | |
| 997 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | |
| 998 HttpIframeInDevToolsExtensionPanel) { | |
| 908 ASSERT_TRUE(embedded_test_server()->Start()); | 999 ASSERT_TRUE(embedded_test_server()->Start()); |
| 909 | 1000 |
| 910 // Our extension must load an URL from the test server, whose port is only | 1001 // TODO do I need to add/remove/fix any comments anywhere? |
| 1002 std::unique_ptr<extensions::TestExtensionDir> dir( | |
| 1003 new extensions::TestExtensionDir()); | |
| 1004 | |
| 1005 GURL http_popup_url = | |
| 1006 embedded_test_server()->GetURL("a.com", "/popup_iframe.html"); | |
| 1007 | |
| 1008 GURL about_blank_url = GURL(url::kAboutBlankURL); | |
| 1009 | |
| 1010 GURL data_url = GURL("data:text/html,foo"); | |
| 1011 | |
| 1012 // Add the custom page that we want rendered in the extension panel. | |
| 1013 dir->WriteFile(FILE_PATH_LITERAL("renavigation_test.html"), | |
| 1014 "<html><body><iframe src='" + about_blank_url.spec() + | |
| 1015 "'></iframe><iframe src='" + data_url.spec() + | |
| 1016 "'></iframe><iframe src='" + http_popup_url.spec() + | |
| 1017 "'></iframe></body></html>"); | |
| 1018 | |
| 1019 // Install the dynamically-generated extension. | |
| 1020 const Extension* extension = LoadExtensionForTest( | |
| 1021 "Devtools Extension", dir.get(), true /* has_popup_test_page */, | |
| 1022 true /* is_devtools_extension */, true /* should_create_panel_and_pane */, | |
| 1023 "/renavigation_test.html"); | |
| 1024 ASSERT_TRUE(extension); | |
| 1025 | |
| 1026 OpenDevToolsWindow(kDebuggerTestPage, false); | |
| 1027 | |
| 1028 // Wait for the panel extension to finish loading -- it'll output 'PASS' | |
| 1029 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. | |
| 1030 RunTestFunction(window_, "waitForTestResultsInConsole"); | |
| 1031 | |
| 1032 // Now that we know the panel is loaded, switch to it. We'll wait until we | |
| 1033 // see a 'DONE' message sent from popup_iframe.html, indicating that it | |
| 1034 // loaded successfully. | |
| 1035 content::DOMMessageQueue message_queue; | |
| 1036 std::string message; | |
| 1037 SwitchToExtensionPanel(window_, extension, "iframe_panel"); | |
| 1038 | |
| 1039 while (true) { | |
| 1040 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | |
| 1041 if (message == "\"DONE\"") | |
| 1042 break; | |
| 1043 } | |
| 1044 | |
| 1045 std::vector<content::RenderFrameHost*> rfhs = | |
| 1046 main_web_contents()->GetAllFrames(); | |
| 1047 EXPECT_EQ(7U, rfhs.size()); | |
| 1048 | |
| 1049 content::RenderFrameHost* main_devtools_rfh = | |
| 1050 main_web_contents()->GetMainFrame(); | |
| 1051 content::RenderFrameHost* devtools_extension_devtools_rfh = | |
| 1052 ChildFrameAt(main_devtools_rfh, 0); | |
| 1053 content::RenderFrameHost* devtools_panel_extension_rfh = | |
| 1054 ChildFrameAt(main_devtools_rfh, 1); | |
| 1055 content::RenderFrameHost* test_frame_rfh = | |
| 1056 ChildFrameAt(devtools_panel_extension_rfh, 0); | |
| 1057 content::RenderFrameHost* about_blank_frame_rfh = | |
| 1058 ChildFrameAt(test_frame_rfh, 0); | |
| 1059 content::RenderFrameHost* data_frame_rfh = ChildFrameAt(test_frame_rfh, 1); | |
| 1060 content::RenderFrameHost* about_blank_http_iframe_rfh = | |
| 1061 ChildFrameAt(test_frame_rfh, 2); | |
| 1062 | |
| 1063 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1064 content::kChromeDevToolsScheme)); | |
| 1065 EXPECT_EQ(extension->GetResourceURL("/devtools.html"), | |
| 1066 devtools_extension_devtools_rfh->GetLastCommittedURL()); | |
| 1067 EXPECT_EQ(extension->GetResourceURL("/panel.html"), | |
| 1068 devtools_panel_extension_rfh->GetLastCommittedURL()); | |
| 1069 EXPECT_EQ(extension->GetResourceURL("/renavigation_test.html"), | |
| 1070 test_frame_rfh->GetLastCommittedURL()); | |
| 1071 EXPECT_EQ(about_blank_url, about_blank_frame_rfh->GetLastCommittedURL()); | |
| 1072 EXPECT_EQ(data_url, data_frame_rfh->GetLastCommittedURL()); | |
| 1073 EXPECT_EQ(http_popup_url, about_blank_http_iframe_rfh->GetLastCommittedURL()); | |
| 1074 | |
| 1075 if (content::AreAllSitesIsolatedForTesting() || | |
| 1076 extensions::IsIsolateExtensionsEnabled()) { | |
| 1077 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1078 content::kChromeDevToolsScheme)); | |
| 1079 EXPECT_EQ(main_devtools_rfh->GetSiteInstance(), | |
| 1080 devtools_extension_devtools_rfh->GetSiteInstance()); | |
| 1081 EXPECT_EQ(main_devtools_rfh->GetSiteInstance(), | |
| 1082 devtools_panel_extension_rfh->GetSiteInstance()); | |
| 1083 EXPECT_EQ(main_devtools_rfh->GetSiteInstance(), | |
| 1084 test_frame_rfh->GetSiteInstance()); | |
| 1085 EXPECT_EQ(main_devtools_rfh->GetSiteInstance(), | |
| 1086 about_blank_frame_rfh->GetSiteInstance()); | |
| 1087 EXPECT_EQ(main_devtools_rfh->GetSiteInstance(), | |
| 1088 data_frame_rfh->GetSiteInstance()); | |
| 1089 EXPECT_EQ( | |
| 1090 http_popup_url.host(), | |
| 1091 about_blank_http_iframe_rfh->GetSiteInstance()->GetSiteURL().host()); | |
| 1092 | |
| 1093 std::string about_blank_javascript = | |
| 1094 "location.href='" + about_blank_url.spec() + "';"; | |
| 1095 | |
| 1096 content::TestNavigationManager manager(main_web_contents(), | |
| 1097 about_blank_url); | |
| 1098 | |
| 1099 ASSERT_TRUE(content::ExecuteScript(about_blank_http_iframe_rfh, | |
| 1100 about_blank_javascript)); | |
| 1101 | |
| 1102 manager.WaitForNavigationFinished(); | |
| 1103 | |
| 1104 /*LOG(INFO) << "about blank last committed" | |
|
ncarter (slow)
2017/03/09 23:28:48
There's some debugging cruft in this file that you
davidsac (gone - try alexmos)
2017/03/11 01:51:47
Done.
| |
| 1105 << about_blank_http_iframe_rfh->GetLastCommittedURL(); | |
| 1106 LOG(INFO) | |
| 1107 << "about blank site instance" | |
| 1108 << | |
| 1109 about_blank_http_iframe_rfh->GetSiteInstance()->GetSiteURL().spec();*/ | |
| 1110 | |
| 1111 EXPECT_EQ(about_blank_url, | |
| 1112 about_blank_http_iframe_rfh->GetLastCommittedURL()); | |
| 1113 EXPECT_EQ( | |
| 1114 http_popup_url.host(), | |
| 1115 about_blank_http_iframe_rfh->GetSiteInstance()->GetSiteURL().host()); | |
| 1116 | |
| 1117 } else { | |
| 1118 // TODO get rid of this? make sure that this test is only ever run in | |
| 1119 // isolate extensions mode ro site-per-process mode. | |
| 1120 /*EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1121 content::kChromeDevToolsScheme)); | |
| 1122 EXPECT_TRUE(devtools_extension_devtools_rfh->GetSiteInstance() | |
| 1123 ->GetSiteURL() | |
| 1124 .SchemeIs(content::kChromeDevToolsScheme)); | |
| 1125 EXPECT_TRUE( | |
| 1126 devtools_panel_extension_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1127 content::kChromeDevToolsScheme)); | |
| 1128 EXPECT_TRUE(http_iframe_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1129 content::kChromeDevToolsScheme));*/ | |
| 1130 } | |
| 1131 } | |
| 1132 | |
| 1133 // Tests that http Iframes within the sidebar pane page for the devtools | |
| 1134 // extension that is visible in the elemanets panel are rendered in their own | |
| 1135 // processes and not in the devtools process or the extension's process. | |
| 1136 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | |
| 1137 HttpIframeInDevToolsExtensionSideBarPane) { | |
| 1138 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1139 | |
| 1140 // Our extension must load a URL from the test server, whose port is only | |
| 911 // known at runtime. So, to embed the URL, we must dynamically generate the | 1141 // known at runtime. So, to embed the URL, we must dynamically generate the |
| 912 // extension, rather than loading it from static content. | 1142 // extension, rather than loading it from static content. |
| 913 std::unique_ptr<extensions::TestExtensionDir> dir( | 1143 std::unique_ptr<extensions::TestExtensionDir> dir( |
| 914 new extensions::TestExtensionDir()); | 1144 new extensions::TestExtensionDir()); |
| 915 | 1145 |
| 916 extensions::DictionaryBuilder manifest; | 1146 GURL http_iframe_url = |
| 1147 embedded_test_server()->GetURL("a.com", "/popup_iframe.html"); | |
| 1148 | |
| 1149 // Install the dynamically-generated extension. | |
| 1150 const Extension* extension = LoadExtensionForTest( | |
| 1151 "Devtools Extension", dir.get(), false /* !has_popup_test_page */, | |
| 1152 true /* is_devtools_extension */, true /* should_create_panel_and_pane */, | |
| 1153 http_iframe_url.spec()); | |
| 1154 ASSERT_TRUE(extension); | |
| 1155 | |
| 1156 OpenDevToolsWindow(kDebuggerTestPage, false); | |
| 1157 | |
| 1158 // Wait for the panel extension to finish loading -- it'll output 'PASS' | |
| 1159 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. | |
| 1160 RunTestFunction(window_, "waitForTestResultsInConsole"); | |
| 1161 | |
| 1162 // Now that we know the panel is loaded, switch to it. | |
| 1163 content::DOMMessageQueue message_queue; | |
| 1164 SwitchToPanel(window_, "elements"); | |
| 1165 // This is a bit of a hack to switch to the sidebar pane in the elements panel | |
| 1166 // that the Iframe has been added to. We'll wait until we see a 'DONE' | |
| 1167 // message sent from popup_iframe.html, indicating that it loaded | |
| 1168 // successfully. | |
| 1169 SwitchToPanel(window_, "iframe_pane"); | |
| 1170 std::string message; | |
| 1171 | |
| 1172 while (true) { | |
| 1173 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | |
| 1174 if (message == "\"DONE\"") | |
| 1175 break; | |
| 1176 } | |
| 1177 | |
| 1178 std::vector<content::RenderFrameHost*> rfhs = | |
| 1179 main_web_contents()->GetAllFrames(); | |
| 1180 EXPECT_EQ(4U, rfhs.size()); | |
| 1181 | |
| 1182 content::RenderFrameHost* main_devtools_rfh = | |
| 1183 main_web_contents()->GetMainFrame(); | |
| 1184 content::RenderFrameHost* devtools_extension_devtools_rfh = | |
| 1185 ChildFrameAt(main_devtools_rfh, 0); | |
| 1186 content::RenderFrameHost* devtools_sidebar_pane_extension_rfh = | |
| 1187 ChildFrameAt(main_devtools_rfh, 1); | |
| 1188 content::RenderFrameHost* http_iframe_rfh = | |
| 1189 ChildFrameAt(devtools_sidebar_pane_extension_rfh, 0); | |
| 1190 | |
| 1191 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1192 content::kChromeDevToolsScheme)); | |
| 1193 EXPECT_EQ(extension->GetResourceURL("/devtools.html"), | |
| 1194 devtools_extension_devtools_rfh->GetLastCommittedURL()); | |
| 1195 EXPECT_EQ(extension->GetResourceURL("/panel.html"), | |
| 1196 devtools_sidebar_pane_extension_rfh->GetLastCommittedURL()); | |
| 1197 EXPECT_EQ(http_iframe_url, http_iframe_rfh->GetLastCommittedURL()); | |
| 1198 | |
| 1199 if (content::AreAllSitesIsolatedForTesting() || | |
| 1200 extensions::IsIsolateExtensionsEnabled()) { | |
| 1201 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1202 content::kChromeDevToolsScheme)); | |
| 1203 EXPECT_EQ(main_devtools_rfh->GetSiteInstance(), | |
| 1204 devtools_extension_devtools_rfh->GetSiteInstance()); | |
| 1205 EXPECT_EQ(main_devtools_rfh->GetSiteInstance(), | |
| 1206 devtools_sidebar_pane_extension_rfh->GetSiteInstance()); | |
| 1207 EXPECT_EQ(http_iframe_url.host(), | |
| 1208 http_iframe_rfh->GetSiteInstance()->GetSiteURL().host()); | |
| 1209 } else { | |
| 1210 // TODO get rid of this? make sure that this test is only ever run in | |
| 1211 // isolate extensions mode ro site-per-process mode. | |
| 1212 /*EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1213 content::kChromeDevToolsScheme)); | |
| 1214 EXPECT_TRUE(devtools_extension_devtools_rfh->GetSiteInstance() | |
| 1215 ->GetSiteURL() | |
| 1216 .SchemeIs(content::kChromeDevToolsScheme)); | |
| 1217 EXPECT_TRUE(devtools_sidebar_pane_extension_rfh->GetSiteInstance() | |
| 1218 ->GetSiteURL() | |
| 1219 .SchemeIs(content::kChromeDevToolsScheme)); | |
| 1220 EXPECT_TRUE(http_iframe_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1221 content::kChromeDevToolsScheme));*/ | |
| 1222 } | |
| 1223 } | |
| 1224 | |
| 1225 // Tests that http Iframes within the devtools background page, which is | |
| 1226 // different from the extension's background page, are rendered in their own | |
| 1227 // processes and not in the devtools process or the extension's process. | |
| 1228 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | |
| 1229 HttpIframeInDevToolsExtensionDevtools) { | |
| 1230 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1231 | |
| 1232 GURL http_iframe_url = | |
| 1233 embedded_test_server()->GetURL("a.com", "/popup_iframe.html"); | |
| 1234 | |
| 1235 std::unique_ptr<extensions::TestExtensionDir> dir( | |
| 1236 new extensions::TestExtensionDir()); | |
| 1237 | |
| 1238 // TODO(davidsac): is this worth refactoring to use |LoadExtensionForTest|? | |
|
ncarter (slow)
2017/03/09 23:28:48
Yes. I think you just pass in http_iframe_url and
davidsac (gone - try alexmos)
2017/03/11 01:51:47
Done. It was actually a bit more complicated than
| |
| 917 dir->WriteManifest(extensions::DictionaryBuilder() | 1239 dir->WriteManifest(extensions::DictionaryBuilder() |
| 918 .Set("name", "Devtools Panel w/ HTTP Iframe") | 1240 .Set("name", "Devtools Panel w/ HTTP Iframe") |
| 919 .Set("version", "1") | 1241 .Set("version", "1") |
| 920 .Set("manifest_version", 2) | 1242 .Set("manifest_version", 2) |
| 921 .Set("devtools_page", "devtools.html") | 1243 .Set("devtools_page", "devtools.html") |
| 922 .ToJSON()); | 1244 .ToJSON()); |
| 923 | 1245 |
| 924 dir->WriteFile( | 1246 dir->WriteFile(FILE_PATH_LITERAL("devtools.html"), |
| 925 FILE_PATH_LITERAL("devtools.html"), | 1247 "<html><head></head><body><iframe src='" + |
| 926 "<html><head><script src='devtools.js'></script></head></html>"); | 1248 http_iframe_url.spec() + "'></iframe></body></html>"); |
| 927 | 1249 |
| 928 dir->WriteFile( | 1250 // Install the dynamically-generated extension. |
| 929 FILE_PATH_LITERAL("devtools.js"), | |
| 930 "chrome.devtools.panels.create('iframe_panel',\n" | |
| 931 " null,\n" | |
| 932 " 'panel.html',\n" | |
| 933 " function(panel) {\n" | |
| 934 " chrome.devtools.inspectedWindow.eval('console.log(\"PASS\")');\n" | |
| 935 " }\n" | |
| 936 ");\n"); | |
| 937 | |
| 938 GURL http_iframe = | |
| 939 embedded_test_server()->GetURL("a.com", "/popup_iframe.html"); | |
| 940 dir->WriteFile(FILE_PATH_LITERAL("panel.html"), | |
| 941 "<html><body>Extension panel.<iframe src='" + | |
| 942 http_iframe.spec() + "'></iframe>"); | |
| 943 | |
| 944 // Install the extension. | |
| 945 const Extension* extension = LoadExtensionFromPath(dir->UnpackedPath()); | 1251 const Extension* extension = LoadExtensionFromPath(dir->UnpackedPath()); |
| 946 ASSERT_TRUE(extension); | 1252 ASSERT_TRUE(extension); |
| 947 | 1253 |
| 948 // Open a devtools window. | 1254 OpenDevToolsWindow(kDebuggerTestPage, false); |
| 1255 | |
| 1256 // Now that we know the panel is loaded, switch to it. We'll wait until we | |
| 1257 // see a 'DONE' message sent from popup_iframe.html, indicating that it | |
| 1258 // loaded successfully. | |
| 1259 content::DOMMessageQueue message_queue; | |
| 1260 std::string message; | |
| 1261 | |
| 1262 while (true) { | |
| 1263 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | |
| 1264 if (message == "\"DONE\"") | |
| 1265 break; | |
| 1266 } | |
| 1267 | |
| 1268 std::vector<content::RenderFrameHost*> rfhs = | |
| 1269 main_web_contents()->GetAllFrames(); | |
| 1270 EXPECT_EQ(3U, rfhs.size()); | |
| 1271 | |
| 1272 content::RenderFrameHost* main_devtools_rfh = | |
| 1273 main_web_contents()->GetMainFrame(); | |
| 1274 content::RenderFrameHost* devtools_extension_devtools_rfh = | |
| 1275 ChildFrameAt(main_devtools_rfh, 0); | |
| 1276 content::RenderFrameHost* http_iframe_rfh = | |
| 1277 ChildFrameAt(devtools_extension_devtools_rfh, 0); | |
| 1278 | |
| 1279 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1280 content::kChromeDevToolsScheme)); | |
| 1281 EXPECT_EQ(extension->GetResourceURL("/devtools.html"), | |
| 1282 devtools_extension_devtools_rfh->GetLastCommittedURL()); | |
| 1283 EXPECT_EQ(http_iframe_url, http_iframe_rfh->GetLastCommittedURL()); | |
| 1284 | |
| 1285 if (content::AreAllSitesIsolatedForTesting() || | |
| 1286 extensions::IsIsolateExtensionsEnabled()) { | |
| 1287 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1288 content::kChromeDevToolsScheme)); | |
| 1289 EXPECT_EQ(main_devtools_rfh->GetSiteInstance(), | |
| 1290 devtools_extension_devtools_rfh->GetSiteInstance()); | |
| 1291 EXPECT_EQ(http_iframe_url.host(), | |
| 1292 http_iframe_rfh->GetSiteInstance()->GetSiteURL().host()); | |
| 1293 | |
| 1294 } else { | |
| 1295 // TODO get rid of this? make sure that this test is only ever run in | |
| 1296 // isolate extensions mode ro site-per-process mode. | |
| 1297 /*EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1298 content::kChromeDevToolsScheme)); | |
| 1299 EXPECT_TRUE(devtools_extension_devtools_rfh->GetSiteInstance() | |
| 1300 ->GetSiteURL() | |
| 1301 .SchemeIs(content::kChromeDevToolsScheme)); | |
| 1302 EXPECT_TRUE(http_iframe_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1303 content::kChromeDevToolsScheme));*/ | |
| 1304 } | |
| 1305 } | |
| 1306 | |
| 1307 // Tests that iframes to a non-devtools extension embedded in a devtools | |
| 1308 // extension will be isolated from devtools and the devtools extension. | |
| 1309 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | |
| 1310 NonDevToolsExtensionInDevToolsExtension) { | |
| 1311 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1312 | |
| 1313 std::unique_ptr<extensions::TestExtensionDir> dir( | |
| 1314 new extensions::TestExtensionDir()); | |
| 1315 | |
| 1316 // Install the dynamically-generated non-devtools extension. | |
| 1317 const Extension* non_devtools_extension = LoadExtensionForTest( | |
| 1318 "Non-DevTools Extension", dir.get(), true /* has_popup_test_page */, | |
| 1319 false /* !is_devtools_extension */, | |
| 1320 false /* !should_create_panel_and_pane */); | |
| 1321 ASSERT_TRUE(non_devtools_extension); | |
| 1322 | |
| 1323 GURL non_dt_extension_test_url = | |
| 1324 non_devtools_extension->GetResourceURL("/test.html"); | |
| 1325 | |
| 1326 std::unique_ptr<extensions::TestExtensionDir> dir2( | |
| 1327 new extensions::TestExtensionDir()); | |
| 1328 | |
| 1329 // Install the dynamically-generated devtools extension. | |
| 1330 const Extension* devtools_extension = LoadExtensionForTest( | |
| 1331 "Devtools Extension", dir2.get(), false /* !has_popup_test_page */, | |
| 1332 true /* is_devtools_extension */, true /* should_create_panel_and_pane */, | |
| 1333 non_dt_extension_test_url.spec()); | |
| 1334 ASSERT_TRUE(devtools_extension); | |
| 1335 | |
| 949 OpenDevToolsWindow(kDebuggerTestPage, false); | 1336 OpenDevToolsWindow(kDebuggerTestPage, false); |
| 950 | 1337 |
| 951 // Wait for the panel extension to finish loading -- it'll output 'PASS' | 1338 // Wait for the panel extension to finish loading -- it'll output 'PASS' |
| 1339 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. | |
| 1340 RunTestFunction(window_, "waitForTestResultsInConsole"); | |
| 1341 | |
| 1342 // Now that we know the panel is loaded, switch to it. We'll wait until we | |
| 1343 // see a 'DONE' message sent from popup_iframe.html, indicating that it | |
| 1344 // loaded successfully. | |
| 1345 content::DOMMessageQueue message_queue; | |
| 1346 SwitchToExtensionPanel(window_, devtools_extension, "iframe_panel"); | |
| 1347 std::string message; | |
| 1348 | |
| 1349 while (true) { | |
| 1350 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | |
| 1351 if (message == "\"DONE\"") | |
| 1352 break; | |
| 1353 } | |
| 1354 | |
| 1355 std::vector<content::RenderFrameHost*> rfhs = | |
| 1356 main_web_contents()->GetAllFrames(); | |
| 1357 EXPECT_EQ(4U, rfhs.size()); | |
| 1358 | |
| 1359 content::RenderFrameHost* main_devtools_rfh = | |
| 1360 main_web_contents()->GetMainFrame(); | |
| 1361 content::RenderFrameHost* devtools_extension_devtools_rfh = | |
| 1362 ChildFrameAt(main_devtools_rfh, 0); | |
| 1363 content::RenderFrameHost* devtools_extension_panel_rfh = | |
| 1364 ChildFrameAt(main_devtools_rfh, 1); | |
| 1365 content::RenderFrameHost* non_devtools_extension_test_rfh = | |
| 1366 ChildFrameAt(devtools_extension_panel_rfh, 0); | |
| 1367 | |
| 1368 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1369 content::kChromeDevToolsScheme)); | |
| 1370 EXPECT_EQ(devtools_extension->GetResourceURL("/devtools.html"), | |
| 1371 devtools_extension_devtools_rfh->GetLastCommittedURL()); | |
| 1372 EXPECT_EQ(devtools_extension->GetResourceURL("/panel.html"), | |
| 1373 devtools_extension_panel_rfh->GetLastCommittedURL()); | |
| 1374 EXPECT_EQ(non_dt_extension_test_url, | |
| 1375 non_devtools_extension_test_rfh->GetLastCommittedURL()); | |
| 1376 | |
| 1377 if (content::AreAllSitesIsolatedForTesting() || | |
| 1378 extensions::IsIsolateExtensionsEnabled()) { | |
| 1379 // test.html's frame should be in extension b's | |
| 1380 // process, not in devtools or extension a's process. | |
| 1381 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1382 content::kChromeDevToolsScheme)); | |
| 1383 EXPECT_EQ(main_devtools_rfh->GetSiteInstance(), | |
| 1384 devtools_extension_devtools_rfh->GetSiteInstance()); | |
| 1385 EXPECT_EQ(main_devtools_rfh->GetSiteInstance(), | |
| 1386 devtools_extension_panel_rfh->GetSiteInstance()); | |
| 1387 EXPECT_EQ(non_dt_extension_test_url.GetOrigin(), | |
| 1388 non_devtools_extension_test_rfh->GetSiteInstance()->GetSiteURL()); | |
| 1389 } else { | |
| 1390 // TODO get rid of this? make sure that this test is only ever run in | |
| 1391 // isolate extensions mode ro site-per-process mode. test.html's frame | |
| 1392 // should be in the devtools process. | |
| 1393 /*EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1394 content::kChromeDevToolsScheme)); | |
| 1395 EXPECT_TRUE(devtools_extension_devtools_rfh->GetSiteInstance() | |
| 1396 ->GetSiteURL() | |
| 1397 .SchemeIs(content::kChromeDevToolsScheme)); | |
| 1398 EXPECT_TRUE(non_devtools_extension_test_rfh->GetSiteInstance() | |
| 1399 ->GetSiteURL() | |
| 1400 .SchemeIs(content::kChromeDevToolsScheme));*/ | |
| 1401 } | |
| 1402 } | |
| 1403 | |
| 1404 // Tests that if a devtools extension's devtools page has a subframe to a | |
| 1405 // page for another devtools extension, the subframe is rendered in the devtools | |
| 1406 // process as well. | |
| 1407 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | |
| 1408 DevToolsExtensionInDevToolsExtension) { | |
| 1409 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1410 | |
| 1411 std::unique_ptr<extensions::TestExtensionDir> dir( | |
| 1412 new extensions::TestExtensionDir()); | |
| 1413 | |
| 1414 // Install the dynamically-generated extension. | |
| 1415 const Extension* devtools_b_extension = LoadExtensionForTest( | |
| 1416 "Devtools Extension B", dir.get(), true /* has_popup_test_page */, | |
| 1417 true /* is_devtools_extension */, | |
| 1418 false /* !should_create_panel_and_pane */); | |
| 1419 ASSERT_TRUE(devtools_b_extension); | |
| 1420 | |
| 1421 GURL extension_b_test_url = | |
| 1422 devtools_b_extension->GetResourceURL("/test.html"); | |
| 1423 | |
| 1424 std::unique_ptr<extensions::TestExtensionDir> dir2( | |
| 1425 new extensions::TestExtensionDir()); | |
| 1426 | |
| 1427 // Install the dynamically-generated extension. | |
| 1428 const Extension* devtools_a_extension = LoadExtensionForTest( | |
| 1429 "Devtools Extension A", dir2.get(), false /* !has_popup_test_page */, | |
| 1430 true /* is_devtools_extension */, true /* should_create_panel_and_pane */, | |
| 1431 extension_b_test_url.spec()); | |
| 1432 ASSERT_TRUE(devtools_a_extension); | |
| 1433 | |
| 1434 OpenDevToolsWindow(kDebuggerTestPage, false); | |
| 1435 | |
| 1436 // Wait for the panel extension to finish loading -- it'll output 'PASS' | |
| 1437 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. | |
| 1438 RunTestFunction(window_, "waitForTestResultsInConsole"); | |
| 1439 | |
| 1440 // Now that we know the panel is loaded, switch to it. We'll wait until we | |
| 1441 // see a 'DONE' message sent from popup_iframe.html, indicating that it | |
| 1442 // loaded successfully. | |
| 1443 content::DOMMessageQueue message_queue; | |
| 1444 SwitchToExtensionPanel(window_, devtools_a_extension, "iframe_panel"); | |
| 1445 std::string message; | |
| 1446 | |
| 1447 while (true) { | |
| 1448 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | |
| 1449 if (message == "\"DONE\"") | |
| 1450 break; | |
| 1451 } | |
| 1452 | |
| 1453 std::vector<content::RenderFrameHost*> rfhs = | |
| 1454 main_web_contents()->GetAllFrames(); | |
| 1455 EXPECT_EQ(5U, rfhs.size()); | |
| 1456 | |
| 1457 content::RenderFrameHost* main_devtools_rfh = | |
| 1458 main_web_contents()->GetMainFrame(); | |
| 1459 content::RenderFrameHost* devtools_extension_a_devtools_rfh = | |
| 1460 ChildFrameAt(main_devtools_rfh, 1); | |
| 1461 content::RenderFrameHost* devtools_extension_b_devtools_rfh = | |
| 1462 ChildFrameAt(main_devtools_rfh, 0); | |
| 1463 content::RenderFrameHost* devtools_extension_a_panel_rfh = | |
| 1464 ChildFrameAt(main_devtools_rfh, 2); | |
| 1465 content::RenderFrameHost* devtools_extension_b_test_rfh = | |
| 1466 ChildFrameAt(devtools_extension_a_panel_rfh, 0); | |
| 1467 | |
| 1468 // TODO davidsac: the two devtools pages can be flipped in order depending on | |
| 1469 // the alphabetization of their id. It doesn't matter, but it makes this test | |
| 1470 // flaky. | |
|
ncarter (slow)
2017/03/09 23:28:49
How unfortunate. Looks like the source of this non
davidsac (gone - try alexmos)
2017/03/11 01:51:47
Done. Thanks a bunch! That was very useful.
| |
| 1471 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1472 content::kChromeDevToolsScheme)); | |
| 1473 EXPECT_EQ(devtools_a_extension->GetResourceURL("/devtools.html"), | |
| 1474 devtools_extension_a_devtools_rfh->GetLastCommittedURL()); | |
| 1475 EXPECT_EQ(devtools_b_extension->GetResourceURL("/devtools.html"), | |
| 1476 devtools_extension_b_devtools_rfh->GetLastCommittedURL()); | |
| 1477 EXPECT_EQ(devtools_a_extension->GetResourceURL("/panel.html"), | |
| 1478 devtools_extension_a_panel_rfh->GetLastCommittedURL()); | |
| 1479 EXPECT_EQ(extension_b_test_url, | |
| 1480 devtools_extension_b_test_rfh->GetLastCommittedURL()); | |
| 1481 | |
| 1482 // all frames should be in the devtools process. | |
| 1483 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1484 content::kChromeDevToolsScheme)); | |
| 1485 EXPECT_EQ(main_devtools_rfh->GetSiteInstance(), | |
| 1486 devtools_extension_a_devtools_rfh->GetSiteInstance()); | |
| 1487 EXPECT_EQ(main_devtools_rfh->GetSiteInstance(), | |
| 1488 devtools_extension_b_devtools_rfh->GetSiteInstance()); | |
| 1489 EXPECT_EQ(main_devtools_rfh->GetSiteInstance(), | |
| 1490 devtools_extension_a_panel_rfh->GetSiteInstance()); | |
| 1491 EXPECT_EQ(main_devtools_rfh->GetSiteInstance(), | |
| 1492 devtools_extension_b_test_rfh->GetSiteInstance()); | |
| 1493 } | |
| 1494 | |
| 1495 // Tests that a devtools extension can still have subframes to itself in a | |
| 1496 // "devtools page" and that they will be rendered within the devtools process as | |
| 1497 // well, not in the extension process. | |
| 1498 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, DevToolsExtensionInItself) { | |
| 1499 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1500 | |
| 1501 std::unique_ptr<extensions::TestExtensionDir> dir( | |
| 1502 new extensions::TestExtensionDir()); | |
| 1503 | |
| 1504 // Install the dynamically-generated extension. | |
| 1505 const Extension* extension = LoadExtensionForTest( | |
| 1506 "Devtools Extension", dir.get(), true /* has_popup_test_page */, | |
| 1507 true /* is_devtools_extension */, | |
| 1508 true /* should_create_panel_and_pane */); | |
| 1509 ASSERT_TRUE(extension); | |
| 1510 | |
| 1511 OpenDevToolsWindow(kDebuggerTestPage, false); | |
| 1512 | |
| 1513 // Wait for the panel extension to finish loading -- it'll output 'PASS' | |
| 952 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. | 1514 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. |
| 953 RunTestFunction(window_, "waitForTestResultsInConsole"); | 1515 RunTestFunction(window_, "waitForTestResultsInConsole"); |
| 954 | 1516 |
| 955 // Now that we know the panel is loaded, switch to it. We'll wait until we | 1517 // Now that we know the panel is loaded, switch to it. We'll wait until we |
| 956 // see a 'DONE' message sent from popup_iframe.html, indicating that it | 1518 // see a 'DONE' message sent from popup_iframe.html, indicating that it |
| 957 // loaded successfully. | 1519 // loaded successfully. |
| 958 content::DOMMessageQueue message_queue; | 1520 content::DOMMessageQueue message_queue; |
| 959 SwitchToExtensionPanel(window_, extension, "iframe_panel"); | 1521 SwitchToExtensionPanel(window_, extension, "iframe_panel"); |
| 960 std::string message; | 1522 std::string message; |
| 1523 | |
| 961 while (true) { | 1524 while (true) { |
| 962 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | 1525 ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
| 963 if (message == "\"DONE\"") | 1526 if (message == "\"DONE\"") |
| 964 break; | 1527 break; |
| 965 } | 1528 } |
| 1529 | |
| 1530 GURL extension_test_url = extension->GetResourceURL("/test.html"); | |
| 1531 | |
| 1532 std::vector<content::RenderFrameHost*> rfhs = | |
| 1533 main_web_contents()->GetAllFrames(); | |
| 1534 EXPECT_EQ(4U, rfhs.size()); | |
| 1535 | |
| 1536 content::RenderFrameHost* main_devtools_rfh = | |
| 1537 main_web_contents()->GetMainFrame(); | |
| 1538 content::RenderFrameHost* devtools_extension_devtools_rfh = | |
| 1539 ChildFrameAt(main_devtools_rfh, 0); | |
| 1540 content::RenderFrameHost* devtools_extension_panel_rfh = | |
| 1541 ChildFrameAt(main_devtools_rfh, 1); | |
| 1542 content::RenderFrameHost* devtools_extension_test_rfh = | |
| 1543 ChildFrameAt(devtools_extension_panel_rfh, 0); | |
| 1544 | |
| 1545 // all frames should be in the devtools process, including test.html's frame | |
| 1546 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1547 content::kChromeDevToolsScheme)); | |
| 1548 EXPECT_EQ(extension->GetResourceURL("/devtools.html"), | |
| 1549 devtools_extension_devtools_rfh->GetLastCommittedURL()); | |
| 1550 EXPECT_EQ(extension->GetResourceURL("/panel.html"), | |
| 1551 devtools_extension_panel_rfh->GetLastCommittedURL()); | |
| 1552 EXPECT_EQ(extension_test_url, | |
| 1553 devtools_extension_test_rfh->GetLastCommittedURL()); | |
| 1554 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1555 content::kChromeDevToolsScheme)); | |
| 1556 EXPECT_EQ(main_devtools_rfh->GetSiteInstance(), | |
| 1557 devtools_extension_devtools_rfh->GetSiteInstance()); | |
| 1558 EXPECT_EQ(main_devtools_rfh->GetSiteInstance(), | |
| 1559 devtools_extension_panel_rfh->GetSiteInstance()); | |
| 1560 EXPECT_EQ(main_devtools_rfh->GetSiteInstance(), | |
| 1561 devtools_extension_test_rfh->GetSiteInstance()); | |
| 1562 } | |
| 1563 | |
| 1564 // TODO(davidsac): Dear code reviewer, should I get rid of this test? I am | |
| 1565 // strongly leaning towards it. This tests a very trivial case. If there is a | |
| 1566 // mistake in the logic, all of the rest of the tests will catch it as well. | |
| 1567 // Tests that a devtools Iframe can still be injected into devtools. | |
| 1568 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, DevtoolsInDevTools) { | |
| 1569 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1570 | |
| 1571 GURL devtools_url = GURL("chrome-devtools://devtools/bundled/inspector.html"); | |
| 1572 | |
| 1573 OpenDevToolsWindow(kDebuggerTestPage, false); | |
| 1574 | |
| 1575 std::string javascript = | |
| 1576 "var devtoolsFrame = document.createElement('iframe');" | |
| 1577 "document.body.appendChild(devtoolsFrame);" | |
| 1578 "devtoolsFrame.setAttribute('src', '" + | |
| 1579 devtools_url.spec() + "');"; | |
| 1580 | |
| 1581 content::RenderFrameHost* main_devtools_rfh = | |
| 1582 main_web_contents()->GetMainFrame(); | |
| 1583 | |
| 1584 content::TestNavigationManager manager(main_web_contents(), devtools_url); | |
| 1585 | |
| 1586 ASSERT_TRUE(content::ExecuteScript(main_devtools_rfh, javascript)); | |
| 1587 | |
| 1588 manager.WaitForNavigationFinished(); | |
| 1589 std::vector<content::RenderFrameHost*> rfhs = | |
| 1590 main_web_contents()->GetAllFrames(); | |
| 1591 EXPECT_EQ(2U, rfhs.size()); | |
| 1592 content::RenderFrameHost* devtools_iframe_rfh = | |
| 1593 ChildFrameAt(main_devtools_rfh, 0); | |
| 1594 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1595 content::kChromeDevToolsScheme)); | |
| 1596 EXPECT_EQ(devtools_url, devtools_iframe_rfh->GetLastCommittedURL()); | |
| 1597 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1598 content::kChromeDevToolsScheme)); | |
| 1599 EXPECT_EQ(main_devtools_rfh->GetSiteInstance(), | |
| 1600 devtools_iframe_rfh->GetSiteInstance()); | |
| 1601 } | |
| 1602 | |
| 1603 // TODO(davidsac): Dear code reviewer, should I get rid of this test? I am | |
| 1604 // strongly leaning towards it. This is kinda tested even more toroguhly in the | |
| 1605 // |HttpIframeInDevToolsExtensionPanel| test. Tests that a blank Iframe can | |
| 1606 // still be injected into devtools. | |
| 1607 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, AboutBlankInDevTools) { | |
| 1608 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1609 | |
| 1610 GURL about_blank_url = GURL(url::kAboutBlankURL); | |
| 1611 | |
| 1612 OpenDevToolsWindow(kDebuggerTestPage, false); | |
| 1613 std::string javascript = | |
| 1614 "var blankFrame = document.createElement('iframe');" | |
| 1615 "document.body.appendChild(blankFrame);" | |
| 1616 "blankFrame.setAttribute('src', '" + | |
| 1617 about_blank_url.spec() + "');"; | |
| 1618 | |
| 1619 content::RenderFrameHost* main_devtools_rfh = | |
| 1620 main_web_contents()->GetMainFrame(); | |
| 1621 | |
| 1622 content::TestNavigationManager manager(main_web_contents(), about_blank_url); | |
| 1623 | |
| 1624 ASSERT_TRUE(content::ExecuteScript(main_devtools_rfh, javascript)); | |
| 1625 | |
| 1626 manager.WaitForNavigationFinished(); | |
| 1627 std::vector<content::RenderFrameHost*> rfhs = | |
| 1628 main_web_contents()->GetAllFrames(); | |
| 1629 EXPECT_EQ(2U, rfhs.size()); | |
| 1630 content::RenderFrameHost* about_blank_rfh = | |
| 1631 ChildFrameAt(main_devtools_rfh, 0); | |
| 1632 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1633 content::kChromeDevToolsScheme)); | |
| 1634 EXPECT_EQ(about_blank_url, about_blank_rfh->GetLastCommittedURL()); | |
| 1635 EXPECT_TRUE(main_devtools_rfh->GetSiteInstance()->GetSiteURL().SchemeIs( | |
| 1636 content::kChromeDevToolsScheme)); | |
| 1637 EXPECT_EQ(main_devtools_rfh->GetSiteInstance(), | |
| 1638 about_blank_rfh->GetSiteInstance()); | |
| 966 } | 1639 } |
| 967 | 1640 |
| 968 // Some web features, when used from an extension, are subject to browser-side | 1641 // 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 | 1642 // security policy enforcement. Make sure they work properly from inside a |
| 970 // devtools extension. | 1643 // devtools extension. |
| 971 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | 1644 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
| 972 DevToolsExtensionSecurityPolicyGrants) { | 1645 DevToolsExtensionSecurityPolicyGrants) { |
| 973 ASSERT_TRUE(embedded_test_server()->Start()); | 1646 ASSERT_TRUE(embedded_test_server()->Start()); |
| 974 | 1647 |
| 975 std::unique_ptr<extensions::TestExtensionDir> dir( | 1648 std::unique_ptr<extensions::TestExtensionDir> dir( |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1566 RunTestFunction(window, "testWindowInitializedOnNavigateBack"); | 2239 RunTestFunction(window, "testWindowInitializedOnNavigateBack"); |
| 1567 | 2240 |
| 1568 DevToolsWindowTesting::CloseDevToolsWindowSync(window); | 2241 DevToolsWindowTesting::CloseDevToolsWindowSync(window); |
| 1569 content::WebUIControllerFactory::UnregisterFactoryForTesting(&test_factory); | 2242 content::WebUIControllerFactory::UnregisterFactoryForTesting(&test_factory); |
| 1570 } | 2243 } |
| 1571 | 2244 |
| 1572 // Tests scripts panel showing. | 2245 // Tests scripts panel showing. |
| 1573 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsSharedWorker) { | 2246 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsSharedWorker) { |
| 1574 RunTest("testDevToolsSharedWorker", url::kAboutBlankURL); | 2247 RunTest("testDevToolsSharedWorker", url::kAboutBlankURL); |
| 1575 } | 2248 } |
| OLD | NEW |