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