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 #include <vector> | |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/cancelable_callback.h" | 11 #include "base/cancelable_callback.h" |
| 11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 14 #include "base/location.h" | 15 #include "base/location.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 17 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 32 #include "chrome/browser/extensions/extension_service.h" | 33 #include "chrome/browser/extensions/extension_service.h" |
| 33 #include "chrome/browser/extensions/test_extension_dir.h" | 34 #include "chrome/browser/extensions/test_extension_dir.h" |
| 34 #include "chrome/browser/extensions/unpacked_installer.h" | 35 #include "chrome/browser/extensions/unpacked_installer.h" |
| 35 #include "chrome/browser/lifetime/application_lifetime.h" | 36 #include "chrome/browser/lifetime/application_lifetime.h" |
| 36 #include "chrome/browser/profiles/profile.h" | 37 #include "chrome/browser/profiles/profile.h" |
| 37 #include "chrome/browser/ui/browser.h" | 38 #include "chrome/browser/ui/browser.h" |
| 38 #include "chrome/browser/ui/browser_commands.h" | 39 #include "chrome/browser/ui/browser_commands.h" |
| 39 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 40 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 40 #include "chrome/common/chrome_paths.h" | 41 #include "chrome/common/chrome_paths.h" |
| 41 #include "chrome/common/chrome_switches.h" | 42 #include "chrome/common/chrome_switches.h" |
| 43 #include "chrome/common/extensions/extension_process_policy.h" | |
| 42 #include "chrome/common/pref_names.h" | 44 #include "chrome/common/pref_names.h" |
| 43 #include "chrome/common/url_constants.h" | 45 #include "chrome/common/url_constants.h" |
| 44 #include "chrome/test/base/in_process_browser_test.h" | 46 #include "chrome/test/base/in_process_browser_test.h" |
| 45 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" | 47 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" |
| 46 #include "chrome/test/base/ui_test_utils.h" | 48 #include "chrome/test/base/ui_test_utils.h" |
| 47 #include "components/app_modal/javascript_app_modal_dialog.h" | 49 #include "components/app_modal/javascript_app_modal_dialog.h" |
| 48 #include "components/app_modal/native_app_modal_dialog.h" | 50 #include "components/app_modal/native_app_modal_dialog.h" |
| 49 #include "components/prefs/pref_service.h" | 51 #include "components/prefs/pref_service.h" |
| 50 #include "content/public/browser/child_process_data.h" | 52 #include "content/public/browser/child_process_data.h" |
| 51 #include "content/public/browser/content_browser_client.h" | 53 #include "content/public/browser/content_browser_client.h" |
| 52 #include "content/public/browser/devtools_agent_host.h" | 54 #include "content/public/browser/devtools_agent_host.h" |
| 53 #include "content/public/browser/notification_registrar.h" | 55 #include "content/public/browser/notification_registrar.h" |
| 54 #include "content/public/browser/notification_service.h" | 56 #include "content/public/browser/notification_service.h" |
| 57 #include "content/public/browser/render_frame_host.h" | |
| 55 #include "content/public/browser/render_view_host.h" | 58 #include "content/public/browser/render_view_host.h" |
| 56 #include "content/public/browser/render_widget_host.h" | 59 #include "content/public/browser/render_widget_host.h" |
| 57 #include "content/public/browser/render_widget_host_view.h" | 60 #include "content/public/browser/render_widget_host_view.h" |
| 58 #include "content/public/browser/url_data_source.h" | 61 #include "content/public/browser/url_data_source.h" |
| 59 #include "content/public/browser/web_contents.h" | 62 #include "content/public/browser/web_contents.h" |
| 60 #include "content/public/browser/web_ui_controller.h" | 63 #include "content/public/browser/web_ui_controller.h" |
| 61 #include "content/public/browser/worker_service.h" | 64 #include "content/public/browser/worker_service.h" |
| 62 #include "content/public/browser/worker_service_observer.h" | 65 #include "content/public/browser/worker_service_observer.h" |
| 63 #include "content/public/common/content_switches.h" | 66 #include "content/public/common/content_switches.h" |
| 67 #include "content/public/common/url_constants.h" | |
| 64 #include "content/public/test/browser_test_utils.h" | 68 #include "content/public/test/browser_test_utils.h" |
| 65 #include "content/public/test/test_navigation_observer.h" | 69 #include "content/public/test/test_navigation_observer.h" |
| 66 #include "extensions/browser/extension_registry.h" | 70 #include "extensions/browser/extension_registry.h" |
| 67 #include "extensions/browser/extension_registry_observer.h" | 71 #include "extensions/browser/extension_registry_observer.h" |
| 68 #include "extensions/browser/extension_system.h" | 72 #include "extensions/browser/extension_system.h" |
| 69 #include "extensions/browser/notification_types.h" | 73 #include "extensions/browser/notification_types.h" |
| 70 #include "extensions/browser/test_extension_registry_observer.h" | 74 #include "extensions/browser/test_extension_registry_observer.h" |
| 71 #include "extensions/common/switches.h" | 75 #include "extensions/common/switches.h" |
| 72 #include "extensions/common/value_builder.h" | 76 #include "extensions/common/value_builder.h" |
| 73 #include "net/dns/mock_host_resolver.h" | 77 #include "net/dns/mock_host_resolver.h" |
| 74 #include "net/test/spawned_test_server/spawned_test_server.h" | 78 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 75 #include "net/test/url_request/url_request_mock_http_job.h" | 79 #include "net/test/url_request/url_request_mock_http_job.h" |
| 76 #include "net/url_request/url_request_context.h" | 80 #include "net/url_request/url_request_context.h" |
| 77 #include "net/url_request/url_request_filter.h" | 81 #include "net/url_request/url_request_filter.h" |
| 78 #include "net/url_request/url_request_http_job.h" | 82 #include "net/url_request/url_request_http_job.h" |
| 79 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 83 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 80 #include "ui/compositor/compositor_switches.h" | 84 #include "ui/compositor/compositor_switches.h" |
| 81 #include "ui/gl/gl_switches.h" | 85 #include "ui/gl/gl_switches.h" |
| 82 #include "url/gurl.h" | 86 #include "url/gurl.h" |
| 83 | 87 |
| 84 using app_modal::AppModalDialog; | 88 using app_modal::AppModalDialog; |
| 85 using app_modal::JavaScriptAppModalDialog; | 89 using app_modal::JavaScriptAppModalDialog; |
| 86 using app_modal::NativeAppModalDialog; | 90 using app_modal::NativeAppModalDialog; |
| 87 using content::BrowserThread; | 91 using content::BrowserThread; |
| 88 using content::DevToolsAgentHost; | 92 using content::DevToolsAgentHost; |
| 89 using content::NavigationController; | 93 using content::NavigationController; |
| 94 using content::RenderFrameHost; | |
| 90 using content::RenderViewHost; | 95 using content::RenderViewHost; |
| 91 using content::WebContents; | 96 using content::WebContents; |
| 92 using content::WorkerService; | 97 using content::WorkerService; |
| 93 using content::WorkerServiceObserver; | 98 using content::WorkerServiceObserver; |
| 94 using extensions::Extension; | 99 using extensions::Extension; |
| 95 | 100 |
| 96 namespace { | 101 namespace { |
| 97 | 102 |
| 98 const char kDebuggerTestPage[] = "files/devtools/debugger_test_page.html"; | 103 const char kDebuggerTestPage[] = "files/devtools/debugger_test_page.html"; |
| 99 const char kPauseWhenLoadingDevTools[] = | 104 const char kPauseWhenLoadingDevTools[] = |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 extensions::TestExtensionRegistryObserver observer(registry); | 499 extensions::TestExtensionRegistryObserver observer(registry); |
| 495 extensions::UnpackedInstaller::Create(service)->Load(path); | 500 extensions::UnpackedInstaller::Create(service)->Load(path); |
| 496 observer.WaitForExtensionLoaded(); | 501 observer.WaitForExtensionLoaded(); |
| 497 | 502 |
| 498 if (!WaitForExtensionViewsToLoad()) | 503 if (!WaitForExtensionViewsToLoad()) |
| 499 return nullptr; | 504 return nullptr; |
| 500 | 505 |
| 501 return GetExtensionByPath(registry->enabled_extensions(), path); | 506 return GetExtensionByPath(registry->enabled_extensions(), path); |
| 502 } | 507 } |
| 503 | 508 |
| 509 // Loads a dynamically generated extension populated with a bunch of test | |
| 510 // pages. |name| is the extension name to use in the manifest. | |
| 511 // |devtools_page|, if non-empty, indicates which test page should be be | |
| 512 // listed as a devtools_page in the manifest. If |devtools_page| is empty, a | |
| 513 // non-devtools extension is created instead. |panel_iframe_src| controls the | |
| 514 // src= attribute of the <iframe> element in the 'panel.html' test page. | |
| 515 const Extension* LoadExtensionForTest(const std::string& name, | |
| 516 const std::string& devtools_page, | |
| 517 const std::string& panel_iframe_src) { | |
| 518 test_extension_dirs_.push_back( | |
| 519 base::MakeUnique<extensions::TestExtensionDir>()); | |
| 520 extensions::TestExtensionDir* dir = test_extension_dirs_.back().get(); | |
| 521 | |
| 522 extensions::DictionaryBuilder manifest; | |
| 523 manifest.Set("name", name) | |
| 524 .Set("version", "1") | |
| 525 .Set("manifest_version", 2) | |
| 526 // simple_test_page.html is currently the only page referenced outside | |
| 527 // of its own extension in the tests | |
| 528 .Set("web_accessible_resources", | |
| 529 extensions::ListBuilder().Append("simple_test_page.html").Build()); | |
| 530 | |
| 531 // If |devtools_page| isn't empty, make it a devtools extension in the | |
| 532 // manifest. | |
| 533 if (!devtools_page.empty()) | |
| 534 manifest.Set("devtools_page", devtools_page); | |
| 535 | |
| 536 dir->WriteManifest(manifest.ToJSON()); | |
| 537 | |
| 538 GURL http_frame_url = | |
| 539 embedded_test_server()->GetURL("a.com", "/popup_iframe.html"); | |
| 540 | |
| 541 // If this is a devtools extension, |devtools_page| will indicate which of | |
| 542 // these devtools_pages will end up being used. Different tests use | |
| 543 // different devtools_pages. | |
| 544 dir->WriteFile(FILE_PATH_LITERAL("web_devtools_page.html"), | |
| 545 "<html><body><iframe src='" + http_frame_url.spec() + | |
| 546 "'></iframe></body></html>"); | |
| 547 | |
| 548 dir->WriteFile(FILE_PATH_LITERAL("simple_devtools_page.html"), | |
| 549 "<html><body></body></html>"); | |
| 550 | |
| 551 dir->WriteFile( | |
| 552 FILE_PATH_LITERAL("panel_devtools_page.html"), | |
| 553 "<html><head><script " | |
| 554 "src='panel_devtools_page.js'></script></head><body></body></html>"); | |
| 555 | |
| 556 dir->WriteFile(FILE_PATH_LITERAL("panel_devtools_page.js"), | |
| 557 "chrome.devtools.panels.create('iframe_panel',\n" | |
| 558 " null,\n" | |
| 559 " 'panel.html',\n" | |
| 560 " function(panel) {\n" | |
| 561 " chrome.devtools.inspectedWindow.eval(\n" | |
| 562 " 'console.log(\"PASS\")');\n" | |
| 563 " }\n" | |
| 564 ");\n"); | |
| 565 | |
| 566 dir->WriteFile(FILE_PATH_LITERAL("sidebarpane_devtools_page.html"), | |
| 567 "<html><head><script src='sidebarpane_devtools_page.js'>" | |
| 568 "</script></head><body></body></html>"); | |
| 569 | |
| 570 dir->WriteFile( | |
| 571 FILE_PATH_LITERAL("sidebarpane_devtools_page.js"), | |
| 572 "chrome.devtools.panels.elements.createSidebarPane('iframe_pane',\n" | |
| 573 " function(sidebar) {\n" | |
| 574 " chrome.devtools.inspectedWindow.eval(\n" | |
| 575 " 'console.log(\"PASS\")');\n" | |
| 576 " sidebar.setPage('panel.html');\n" | |
| 577 " }\n" | |
| 578 ");\n"); | |
| 579 | |
| 580 dir->WriteFile(FILE_PATH_LITERAL("panel.html"), | |
| 581 "<html><body><iframe src='" + panel_iframe_src + | |
| 582 "'></iframe></body></html>"); | |
| 583 | |
| 584 dir->WriteFile(FILE_PATH_LITERAL("simple_test_page.html"), | |
| 585 "<html><body>This is a test</body></html>"); | |
| 586 | |
| 587 GURL about_blank_url = GURL(url::kAboutBlankURL); | |
|
caseq
2017/03/30 00:03:37
just inline about:blank in the string?
davidsac (gone - try alexmos)
2017/03/30 18:28:33
Done.
| |
| 588 GURL web_url = embedded_test_server()->GetURL("a.com", "/title3.html"); | |
| 589 GURL data_url = GURL("data:text/html,foo"); | |
|
caseq
2017/03/30 00:03:37
ditto.
davidsac (gone - try alexmos)
2017/03/30 18:28:33
Done.
| |
| 590 | |
| 591 dir->WriteFile(FILE_PATH_LITERAL("multi_frame_page.html"), | |
| 592 "<html><body><iframe src='" + about_blank_url.spec() + | |
| 593 "'></iframe><iframe src='" + data_url.spec() + | |
| 594 "'></iframe><iframe src='" + web_url.spec() + | |
| 595 "'></iframe></body></html>"); | |
| 596 | |
| 597 // Install the extension. | |
| 598 const Extension* extension = LoadExtensionFromPath(dir->UnpackedPath()); | |
|
caseq
2017/03/30 00:03:37
nit: just "return LoadExtensionFromPath(...)"
davidsac (gone - try alexmos)
2017/03/30 18:28:33
Done.
| |
| 599 return extension; | |
| 600 } | |
| 601 | |
| 504 private: | 602 private: |
| 505 const Extension* GetExtensionByPath( | 603 const Extension* GetExtensionByPath( |
| 506 const extensions::ExtensionSet& extensions, | 604 const extensions::ExtensionSet& extensions, |
| 507 const base::FilePath& path) { | 605 const base::FilePath& path) { |
| 508 base::FilePath extension_path = base::MakeAbsoluteFilePath(path); | 606 base::FilePath extension_path = base::MakeAbsoluteFilePath(path); |
| 509 EXPECT_TRUE(!extension_path.empty()); | 607 EXPECT_TRUE(!extension_path.empty()); |
| 510 for (const scoped_refptr<const Extension>& extension : extensions) { | 608 for (const scoped_refptr<const Extension>& extension : extensions) { |
| 511 if (extension->path() == extension_path) { | 609 if (extension->path() == extension_path) { |
| 512 return extension.get(); | 610 return extension.get(); |
| 513 } | 611 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 546 } | 644 } |
| 547 | 645 |
| 548 void Observe(int type, | 646 void Observe(int type, |
| 549 const content::NotificationSource& source, | 647 const content::NotificationSource& source, |
| 550 const content::NotificationDetails& details) override { | 648 const content::NotificationDetails& details) override { |
| 551 DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD, | 649 DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD, |
| 552 type); | 650 type); |
| 553 base::MessageLoopForUI::current()->QuitWhenIdle(); | 651 base::MessageLoopForUI::current()->QuitWhenIdle(); |
| 554 } | 652 } |
| 555 | 653 |
| 654 std::vector<std::unique_ptr<extensions::TestExtensionDir>> | |
| 655 test_extension_dirs_; | |
| 556 base::FilePath test_extensions_dir_; | 656 base::FilePath test_extensions_dir_; |
| 557 }; | 657 }; |
| 558 | 658 |
| 559 class DevToolsExperimentalExtensionTest : public DevToolsExtensionTest { | 659 class DevToolsExperimentalExtensionTest : public DevToolsExtensionTest { |
| 560 public: | 660 public: |
| 561 void SetUpCommandLine(base::CommandLine* command_line) override { | 661 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 562 command_line->AppendSwitch( | 662 command_line->AppendSwitch( |
| 563 extensions::switches::kEnableExperimentalExtensionApis); | 663 extensions::switches::kEnableExperimentalExtensionApis); |
| 564 } | 664 } |
| 565 }; | 665 }; |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 925 kDebuggerTestPage); | 1025 kDebuggerTestPage); |
| 926 } | 1026 } |
| 927 | 1027 |
| 928 // Tests that chrome.devtools extension is correctly exposed. | 1028 // Tests that chrome.devtools extension is correctly exposed. |
| 929 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | 1029 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
| 930 TestDevToolsExtensionAPI) { | 1030 TestDevToolsExtensionAPI) { |
| 931 LoadExtension("devtools_extension"); | 1031 LoadExtension("devtools_extension"); |
| 932 RunTest("waitForTestResultsInConsole", std::string()); | 1032 RunTest("waitForTestResultsInConsole", std::string()); |
| 933 } | 1033 } |
| 934 | 1034 |
| 935 // Tests a chrome.devtools extension panel that embeds an http:// iframe. | 1035 // Tests that http Iframes within the visible devtools panel for the devtools |
| 936 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, DevToolsExtensionWithHttpIframe) { | 1036 // extension are rendered in their own processes and not in the devtools process |
| 937 ASSERT_TRUE(embedded_test_server()->Start()); | 1037 // or the extension's process. This is tested because this is one of the |
| 938 | 1038 // extension pages with devtools access |
| 939 // Our extension must load an URL from the test server, whose port is only | 1039 // (https://developer.chrome.com/extensions/devtools). Also tests that frames |
| 940 // known at runtime. So, to embed the URL, we must dynamically generate the | 1040 // with data URLs and about:blank URLs are rendered in the devtools process, |
| 941 // extension, rather than loading it from static content. | 1041 // unless a web OOPIF navigates itself to about:blank, in which case it does not |
| 942 std::unique_ptr<extensions::TestExtensionDir> dir( | 1042 // end up back in the devtools process. Also tests that when a web IFrame is |
| 943 new extensions::TestExtensionDir()); | 1043 // navigated back to a devtools extension page, it gets put back in the devtools |
| 944 | 1044 // process. |
| 945 extensions::DictionaryBuilder manifest; | 1045 // http://crbug.com/570483 |
| 946 dir->WriteManifest(extensions::DictionaryBuilder() | 1046 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
| 947 .Set("name", "Devtools Panel w/ HTTP Iframe") | 1047 HttpIframeInDevToolsExtensionPanel) { |
| 948 .Set("version", "1") | 1048 ASSERT_TRUE(embedded_test_server()->Start()); |
| 949 .Set("manifest_version", 2) | 1049 |
| 950 .Set("devtools_page", "devtools.html") | 1050 // Install the dynamically-generated extension. |
| 951 .ToJSON()); | 1051 const Extension* extension = |
| 952 | 1052 LoadExtensionForTest("Devtools Extension", "panel_devtools_page.html", |
| 953 dir->WriteFile( | 1053 "/multi_frame_page.html"); |
| 954 FILE_PATH_LITERAL("devtools.html"), | |
| 955 "<html><head><script src='devtools.js'></script></head></html>"); | |
| 956 | |
| 957 dir->WriteFile( | |
| 958 FILE_PATH_LITERAL("devtools.js"), | |
| 959 "chrome.devtools.panels.create('iframe_panel',\n" | |
| 960 " null,\n" | |
| 961 " 'panel.html',\n" | |
| 962 " function(panel) {\n" | |
| 963 " chrome.devtools.inspectedWindow.eval('console.log(\"PASS\")');\n" | |
| 964 " }\n" | |
| 965 ");\n"); | |
| 966 | |
| 967 GURL http_iframe = | |
| 968 embedded_test_server()->GetURL("a.com", "/popup_iframe.html"); | |
| 969 dir->WriteFile(FILE_PATH_LITERAL("panel.html"), | |
| 970 "<html><body>Extension panel.<iframe src='" + | |
| 971 http_iframe.spec() + "'></iframe>"); | |
| 972 | |
| 973 // Install the extension. | |
| 974 const Extension* extension = LoadExtensionFromPath(dir->UnpackedPath()); | |
| 975 ASSERT_TRUE(extension); | 1054 ASSERT_TRUE(extension); |
| 976 | 1055 |
| 977 // Open a devtools window. | 1056 OpenDevToolsWindow(kDebuggerTestPage, false); |
| 978 OpenDevToolsWindow(kDebuggerTestPage, false); | 1057 |
| 979 | 1058 // Wait for the extension's panel to finish loading -- it'll output 'PASS' |
| 980 // Wait for the panel extension to finish loading -- it'll output 'PASS' | |
| 981 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. | 1059 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. |
| 982 RunTestFunction(window_, "waitForTestResultsInConsole"); | 1060 RunTestFunction(window_, "waitForTestResultsInConsole"); |
| 983 | 1061 |
| 984 // Now that we know the panel is loaded, switch to it. We'll wait until we | 1062 // Now that we know the panel is loaded, switch to it. |
| 985 // see a 'DONE' message sent from popup_iframe.html, indicating that it | 1063 SwitchToExtensionPanel(window_, extension, "iframe_panel"); |
| 1064 content::WaitForLoadStop(main_web_contents()); | |
| 1065 | |
| 1066 std::vector<RenderFrameHost*> rfhs = main_web_contents()->GetAllFrames(); | |
| 1067 EXPECT_EQ(7U, rfhs.size()); | |
| 1068 | |
| 1069 // This test creates a page with the following frame tree: | |
| 1070 // - DevTools | |
| 1071 // - devtools_page from DevTools extension | |
| 1072 // - Panel (DevTools extension) | |
| 1073 // - iframe (DevTools extension) | |
| 1074 // - about:blank | |
| 1075 // - data: | |
| 1076 // - web URL | |
| 1077 | |
| 1078 RenderFrameHost* main_devtools_rfh = main_web_contents()->GetMainFrame(); | |
| 1079 RenderFrameHost* devtools_extension_devtools_page_rfh = | |
| 1080 ChildFrameAt(main_devtools_rfh, 0); | |
| 1081 RenderFrameHost* devtools_extension_panel_rfh = | |
| 1082 ChildFrameAt(main_devtools_rfh, 1); | |
| 1083 RenderFrameHost* panel_frame_rfh = | |
| 1084 ChildFrameAt(devtools_extension_panel_rfh, 0); | |
| 1085 RenderFrameHost* about_blank_frame_rfh = ChildFrameAt(panel_frame_rfh, 0); | |
| 1086 RenderFrameHost* data_frame_rfh = ChildFrameAt(panel_frame_rfh, 1); | |
| 1087 RenderFrameHost* web_frame_rfh = ChildFrameAt(panel_frame_rfh, 2); | |
| 1088 | |
| 1089 GURL web_url = embedded_test_server()->GetURL("a.com", "/title3.html"); | |
| 1090 GURL about_blank_url = GURL(url::kAboutBlankURL); | |
| 1091 GURL data_url = GURL("data:text/html,foo"); | |
| 1092 | |
| 1093 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1094 content::kChromeDevToolsScheme)); | |
| 1095 EXPECT_EQ(extension->GetResourceURL("/panel_devtools_page.html"), | |
| 1096 devtools_extension_devtools_page_rfh->GetLastCommittedURL()); | |
| 1097 EXPECT_EQ(extension->GetResourceURL("/panel.html"), | |
| 1098 devtools_extension_panel_rfh->GetLastCommittedURL()); | |
| 1099 EXPECT_EQ(extension->GetResourceURL("/multi_frame_page.html"), | |
| 1100 panel_frame_rfh->GetLastCommittedURL()); | |
| 1101 EXPECT_EQ(about_blank_url, about_blank_frame_rfh->GetLastCommittedURL()); | |
| 1102 EXPECT_EQ(data_url, data_frame_rfh->GetLastCommittedURL()); | |
| 1103 EXPECT_EQ(web_url, web_frame_rfh->GetLastCommittedURL()); | |
| 1104 | |
| 1105 content::SiteInstance* devtools_instance = | |
| 1106 main_devtools_rfh->GetSiteInstance(); | |
| 1107 EXPECT_TRUE( | |
| 1108 devtools_instance->GetSiteURL().SchemeIs(content::kChromeDevToolsScheme)); | |
| 1109 EXPECT_EQ(devtools_instance, | |
| 1110 devtools_extension_devtools_page_rfh->GetSiteInstance()); | |
| 1111 EXPECT_EQ(devtools_instance, devtools_extension_panel_rfh->GetSiteInstance()); | |
| 1112 EXPECT_EQ(devtools_instance, panel_frame_rfh->GetSiteInstance()); | |
| 1113 EXPECT_EQ(devtools_instance, about_blank_frame_rfh->GetSiteInstance()); | |
| 1114 EXPECT_EQ(devtools_instance, data_frame_rfh->GetSiteInstance()); | |
| 1115 EXPECT_EQ(web_url.host(), | |
| 1116 web_frame_rfh->GetSiteInstance()->GetSiteURL().host()); | |
| 1117 EXPECT_NE(devtools_instance, web_frame_rfh->GetSiteInstance()); | |
| 1118 | |
| 1119 // Check that if the web iframe navigates itself to about:blank, it stays in | |
| 1120 // the web SiteInstance. | |
| 1121 std::string about_blank_javascript = | |
| 1122 "location.href='" + about_blank_url.spec() + "';"; | |
|
caseq
2017/03/30 00:03:37
hardcode about:blank
davidsac (gone - try alexmos)
2017/03/30 18:28:33
Done.
| |
| 1123 | |
| 1124 content::TestNavigationManager web_about_blank_manager(main_web_contents(), | |
| 1125 about_blank_url); | |
| 1126 | |
| 1127 ASSERT_TRUE(content::ExecuteScript(web_frame_rfh, about_blank_javascript)); | |
| 1128 | |
| 1129 web_about_blank_manager.WaitForNavigationFinished(); | |
| 1130 | |
| 1131 EXPECT_EQ(about_blank_url, web_frame_rfh->GetLastCommittedURL()); | |
| 1132 EXPECT_EQ(web_url.host(), | |
| 1133 web_frame_rfh->GetSiteInstance()->GetSiteURL().host()); | |
| 1134 EXPECT_NE(devtools_instance, web_frame_rfh->GetSiteInstance()); | |
| 1135 | |
| 1136 // Check that if the web IFrame is navigated back to a devtools extension | |
| 1137 // page, it gets put back in the devtools process. | |
| 1138 GURL extension_simple_url = | |
| 1139 extension->GetResourceURL("/simple_test_page.html"); | |
| 1140 std::string renavigation_javascript = | |
| 1141 "location.href='" + extension_simple_url.spec() + "';"; | |
| 1142 | |
| 1143 content::TestNavigationManager renavigation_manager(main_web_contents(), | |
| 1144 extension_simple_url); | |
| 1145 | |
| 1146 ASSERT_TRUE(content::ExecuteScript(web_frame_rfh, renavigation_javascript)); | |
| 1147 | |
| 1148 renavigation_manager.WaitForNavigationFinished(); | |
| 1149 | |
| 1150 // The old RFH is no longer valid after the renavigation, so we must get the | |
| 1151 // new one. | |
| 1152 RenderFrameHost* extension_simple_frame_rfh = | |
| 1153 ChildFrameAt(panel_frame_rfh, 2); | |
| 1154 | |
| 1155 EXPECT_EQ(extension_simple_url, | |
| 1156 extension_simple_frame_rfh->GetLastCommittedURL()); | |
| 1157 EXPECT_EQ(devtools_instance, extension_simple_frame_rfh->GetSiteInstance()); | |
| 1158 } | |
| 1159 | |
| 1160 // Tests that http Iframes within the sidebar pane page for the devtools | |
| 1161 // extension that is visible in the elements panel are rendered in their own | |
| 1162 // processes and not in the devtools process or the extension's process. This | |
| 1163 // is tested because this is one of the extension pages with devtools access | |
| 1164 // (https://developer.chrome.com/extensions/devtools). http://crbug.com/570483 | |
| 1165 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | |
| 1166 HttpIframeInDevToolsExtensionSideBarPane) { | |
| 1167 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1168 | |
| 1169 GURL web_url = embedded_test_server()->GetURL("a.com", "/title3.html"); | |
| 1170 | |
| 1171 // Install the dynamically-generated extension. | |
| 1172 const Extension* extension = LoadExtensionForTest( | |
| 1173 "Devtools Extension", "sidebarpane_devtools_page.html", web_url.spec()); | |
| 1174 ASSERT_TRUE(extension); | |
| 1175 | |
| 1176 OpenDevToolsWindow(kDebuggerTestPage, false); | |
| 1177 | |
| 1178 // Wait for the extension's sidebarpane to finish loading -- it'll output | |
| 1179 // 'PASS' when it's installed. waitForTestResultsInConsole waits until that | |
| 1180 // 'PASS'. | |
| 1181 RunTestFunction(window_, "waitForTestResultsInConsole"); | |
| 1182 | |
| 1183 // Now that we know the sidebarpane is loaded, switch to it. | |
| 1184 content::TestNavigationManager web_manager(main_web_contents(), web_url); | |
| 1185 SwitchToPanel(window_, "elements"); | |
| 1186 // This is a bit of a hack to switch to the sidebar pane in the elements panel | |
| 1187 // that the Iframe has been added to. | |
| 1188 SwitchToPanel(window_, "iframe_pane"); | |
| 1189 web_manager.WaitForNavigationFinished(); | |
| 1190 | |
| 1191 std::vector<RenderFrameHost*> rfhs = main_web_contents()->GetAllFrames(); | |
| 1192 EXPECT_EQ(4U, rfhs.size()); | |
| 1193 | |
| 1194 RenderFrameHost* main_devtools_rfh = main_web_contents()->GetMainFrame(); | |
| 1195 RenderFrameHost* devtools_extension_devtools_page_rfh = | |
| 1196 ChildFrameAt(main_devtools_rfh, 0); | |
| 1197 RenderFrameHost* devtools_sidebar_pane_extension_rfh = | |
| 1198 ChildFrameAt(main_devtools_rfh, 1); | |
| 1199 RenderFrameHost* http_iframe_rfh = | |
| 1200 ChildFrameAt(devtools_sidebar_pane_extension_rfh, 0); | |
| 1201 | |
| 1202 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1203 content::kChromeDevToolsScheme)); | |
| 1204 EXPECT_EQ(extension->GetResourceURL("/sidebarpane_devtools_page.html"), | |
| 1205 devtools_extension_devtools_page_rfh->GetLastCommittedURL()); | |
| 1206 EXPECT_EQ(extension->GetResourceURL("/panel.html"), | |
| 1207 devtools_sidebar_pane_extension_rfh->GetLastCommittedURL()); | |
| 1208 EXPECT_EQ(web_url, http_iframe_rfh->GetLastCommittedURL()); | |
| 1209 | |
| 1210 content::SiteInstance* devtools_instance = | |
| 1211 main_devtools_rfh->GetSiteInstance(); | |
| 1212 EXPECT_TRUE( | |
| 1213 devtools_instance->GetSiteURL().SchemeIs(content::kChromeDevToolsScheme)); | |
| 1214 EXPECT_EQ(devtools_instance, | |
| 1215 devtools_extension_devtools_page_rfh->GetSiteInstance()); | |
| 1216 EXPECT_EQ(devtools_instance, | |
| 1217 devtools_sidebar_pane_extension_rfh->GetSiteInstance()); | |
| 1218 EXPECT_EQ(web_url.host(), | |
| 1219 http_iframe_rfh->GetSiteInstance()->GetSiteURL().host()); | |
| 1220 EXPECT_NE(devtools_instance, http_iframe_rfh->GetSiteInstance()); | |
| 1221 } | |
| 1222 | |
| 1223 // Tests that http Iframes within the devtools background page, which is | |
| 1224 // different from the extension's background page, are rendered in their own | |
| 1225 // processes and not in the devtools process or the extension's process. This | |
| 1226 // is tested because this is one of the extension pages with devtools access | |
| 1227 // (https://developer.chrome.com/extensions/devtools). http://crbug.com/570483 | |
| 1228 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | |
| 1229 HttpIframeInDevToolsExtensionDevtools) { | |
| 1230 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1231 | |
| 1232 // Install the dynamically-generated extension. | |
| 1233 const Extension* extension = | |
| 1234 LoadExtensionForTest("Devtools Extension", "web_devtools_page.html", | |
| 1235 "" /* panel_iframe_src */); | |
| 1236 ASSERT_TRUE(extension); | |
| 1237 | |
| 1238 // Wait for a 'DONE' message sent from popup_iframe.html, indicating that it | |
| 986 // loaded successfully. | 1239 // loaded successfully. |
| 987 content::DOMMessageQueue message_queue; | 1240 content::DOMMessageQueue message_queue; |
| 988 SwitchToExtensionPanel(window_, extension, "iframe_panel"); | |
| 989 std::string message; | 1241 std::string message; |
| 1242 OpenDevToolsWindow(kDebuggerTestPage, false); | |
| 1243 | |
| 990 while (true) { | 1244 while (true) { |
| 991 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | 1245 ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
| 992 if (message == "\"DONE\"") | 1246 if (message == "\"DONE\"") |
| 993 break; | 1247 break; |
| 994 } | 1248 } |
| 1249 | |
| 1250 std::vector<RenderFrameHost*> rfhs = main_web_contents()->GetAllFrames(); | |
| 1251 EXPECT_EQ(3U, rfhs.size()); | |
| 1252 | |
| 1253 RenderFrameHost* main_devtools_rfh = main_web_contents()->GetMainFrame(); | |
| 1254 RenderFrameHost* devtools_extension_devtools_page_rfh = | |
| 1255 ChildFrameAt(main_devtools_rfh, 0); | |
| 1256 RenderFrameHost* http_iframe_rfh = | |
| 1257 ChildFrameAt(devtools_extension_devtools_page_rfh, 0); | |
| 1258 | |
| 1259 GURL web_url = embedded_test_server()->GetURL("a.com", "/popup_iframe.html"); | |
| 1260 | |
| 1261 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1262 content::kChromeDevToolsScheme)); | |
| 1263 EXPECT_EQ(extension->GetResourceURL("/web_devtools_page.html"), | |
| 1264 devtools_extension_devtools_page_rfh->GetLastCommittedURL()); | |
| 1265 EXPECT_EQ(web_url, http_iframe_rfh->GetLastCommittedURL()); | |
| 1266 | |
| 1267 content::SiteInstance* devtools_instance = | |
| 1268 main_devtools_rfh->GetSiteInstance(); | |
| 1269 EXPECT_TRUE( | |
| 1270 devtools_instance->GetSiteURL().SchemeIs(content::kChromeDevToolsScheme)); | |
| 1271 EXPECT_EQ(devtools_instance, | |
| 1272 devtools_extension_devtools_page_rfh->GetSiteInstance()); | |
| 1273 EXPECT_EQ(web_url.host(), | |
| 1274 http_iframe_rfh->GetSiteInstance()->GetSiteURL().host()); | |
| 1275 EXPECT_NE(devtools_instance, http_iframe_rfh->GetSiteInstance()); | |
| 1276 } | |
| 1277 | |
| 1278 // Tests that iframes to a non-devtools extension embedded in a devtools | |
| 1279 // extension will be isolated from devtools and the devtools extension. | |
| 1280 // http://crbug.com/570483 | |
| 1281 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | |
| 1282 NonDevToolsExtensionInDevToolsExtension) { | |
| 1283 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1284 | |
| 1285 // Install the dynamically-generated non-devtools extension. | |
| 1286 const Extension* non_devtools_extension = | |
| 1287 LoadExtensionForTest("Non-DevTools Extension", "" /* devtools_page */, | |
| 1288 "" /* panel_iframe_src */); | |
| 1289 ASSERT_TRUE(non_devtools_extension); | |
| 1290 | |
| 1291 GURL non_dt_extension_test_url = | |
| 1292 non_devtools_extension->GetResourceURL("/simple_test_page.html"); | |
| 1293 | |
| 1294 // Install the dynamically-generated devtools extension. | |
| 1295 const Extension* devtools_extension = | |
| 1296 LoadExtensionForTest("Devtools Extension", "panel_devtools_page.html", | |
| 1297 non_dt_extension_test_url.spec()); | |
| 1298 ASSERT_TRUE(devtools_extension); | |
| 1299 | |
| 1300 OpenDevToolsWindow(kDebuggerTestPage, false); | |
| 1301 | |
| 1302 // Wait for the extension's panel to finish loading -- it'll output 'PASS' | |
| 1303 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. | |
| 1304 RunTestFunction(window_, "waitForTestResultsInConsole"); | |
| 1305 | |
| 1306 // Now that we know the panel is loaded, switch to it. | |
| 1307 content::TestNavigationManager non_devtools_manager( | |
| 1308 main_web_contents(), non_dt_extension_test_url); | |
| 1309 SwitchToExtensionPanel(window_, devtools_extension, "iframe_panel"); | |
| 1310 non_devtools_manager.WaitForNavigationFinished(); | |
| 1311 | |
| 1312 std::vector<RenderFrameHost*> rfhs = main_web_contents()->GetAllFrames(); | |
| 1313 EXPECT_EQ(4U, rfhs.size()); | |
| 1314 | |
| 1315 RenderFrameHost* main_devtools_rfh = main_web_contents()->GetMainFrame(); | |
| 1316 RenderFrameHost* devtools_extension_devtools_page_rfh = | |
| 1317 ChildFrameAt(main_devtools_rfh, 0); | |
| 1318 RenderFrameHost* devtools_extension_panel_rfh = | |
| 1319 ChildFrameAt(main_devtools_rfh, 1); | |
| 1320 RenderFrameHost* non_devtools_extension_rfh = | |
| 1321 ChildFrameAt(devtools_extension_panel_rfh, 0); | |
| 1322 | |
| 1323 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1324 content::kChromeDevToolsScheme)); | |
| 1325 EXPECT_EQ(devtools_extension->GetResourceURL("/panel_devtools_page.html"), | |
| 1326 devtools_extension_devtools_page_rfh->GetLastCommittedURL()); | |
| 1327 EXPECT_EQ(devtools_extension->GetResourceURL("/panel.html"), | |
| 1328 devtools_extension_panel_rfh->GetLastCommittedURL()); | |
| 1329 EXPECT_EQ(non_dt_extension_test_url, | |
| 1330 non_devtools_extension_rfh->GetLastCommittedURL()); | |
| 1331 | |
| 1332 // simple_test_page.html's frame should be in |non_devtools_extension|'s | |
| 1333 // process, not in devtools or |devtools_extension|'s process. | |
| 1334 content::SiteInstance* devtools_instance = | |
| 1335 main_devtools_rfh->GetSiteInstance(); | |
| 1336 EXPECT_TRUE( | |
| 1337 devtools_instance->GetSiteURL().SchemeIs(content::kChromeDevToolsScheme)); | |
| 1338 EXPECT_EQ(devtools_instance, | |
| 1339 devtools_extension_devtools_page_rfh->GetSiteInstance()); | |
| 1340 EXPECT_EQ(devtools_instance, devtools_extension_panel_rfh->GetSiteInstance()); | |
| 1341 EXPECT_EQ(non_dt_extension_test_url.GetOrigin(), | |
| 1342 non_devtools_extension_rfh->GetSiteInstance()->GetSiteURL()); | |
| 1343 EXPECT_NE(devtools_instance, non_devtools_extension_rfh->GetSiteInstance()); | |
| 1344 } | |
| 1345 | |
| 1346 // Tests that if a devtools extension's devtools panel page has a subframe to a | |
| 1347 // page for another devtools extension, the subframe is rendered in the devtools | |
| 1348 // process as well. http://crbug.com/570483 | |
| 1349 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | |
| 1350 DevToolsExtensionInDevToolsExtension) { | |
| 1351 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1352 | |
| 1353 // Install the dynamically-generated extension. | |
| 1354 const Extension* devtools_b_extension = | |
| 1355 LoadExtensionForTest("Devtools Extension B", "simple_devtools_page.html", | |
| 1356 "" /* panel_iframe_src */); | |
| 1357 ASSERT_TRUE(devtools_b_extension); | |
| 1358 | |
| 1359 GURL extension_b_page_url = | |
| 1360 devtools_b_extension->GetResourceURL("/simple_test_page.html"); | |
| 1361 | |
| 1362 // Install another dynamically-generated extension. This extension's | |
| 1363 // panel.html's iframe will point to an extension b URL. | |
| 1364 const Extension* devtools_a_extension = | |
| 1365 LoadExtensionForTest("Devtools Extension A", "panel_devtools_page.html", | |
| 1366 extension_b_page_url.spec()); | |
| 1367 ASSERT_TRUE(devtools_a_extension); | |
| 1368 | |
| 1369 OpenDevToolsWindow(kDebuggerTestPage, false); | |
| 1370 | |
| 1371 // Wait for the extension's panel to finish loading -- it'll output 'PASS' | |
| 1372 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. | |
| 1373 RunTestFunction(window_, "waitForTestResultsInConsole"); | |
| 1374 | |
| 1375 // Now that we know the panel is loaded, switch to it. | |
| 1376 content::TestNavigationManager extension_b_manager(main_web_contents(), | |
| 1377 extension_b_page_url); | |
| 1378 SwitchToExtensionPanel(window_, devtools_a_extension, "iframe_panel"); | |
| 1379 extension_b_manager.WaitForNavigationFinished(); | |
| 1380 | |
| 1381 std::vector<RenderFrameHost*> rfhs = main_web_contents()->GetAllFrames(); | |
| 1382 EXPECT_EQ(5U, rfhs.size()); | |
| 1383 | |
| 1384 RenderFrameHost* main_devtools_rfh = main_web_contents()->GetMainFrame(); | |
| 1385 | |
| 1386 RenderFrameHost* devtools_extension_a_devtools_rfh = | |
| 1387 content::FrameMatchingPredicate( | |
| 1388 main_web_contents(), base::Bind(&content::FrameHasSourceUrl, | |
| 1389 devtools_a_extension->GetResourceURL( | |
| 1390 "/panel_devtools_page.html"))); | |
| 1391 EXPECT_TRUE(devtools_extension_a_devtools_rfh); | |
| 1392 RenderFrameHost* devtools_extension_b_devtools_rfh = | |
| 1393 content::FrameMatchingPredicate( | |
| 1394 main_web_contents(), base::Bind(&content::FrameHasSourceUrl, | |
| 1395 devtools_b_extension->GetResourceURL( | |
| 1396 "/simple_devtools_page.html"))); | |
| 1397 EXPECT_TRUE(devtools_extension_b_devtools_rfh); | |
| 1398 | |
| 1399 RenderFrameHost* devtools_extension_a_panel_rfh = | |
| 1400 ChildFrameAt(main_devtools_rfh, 2); | |
| 1401 RenderFrameHost* devtools_extension_b_frame_rfh = | |
| 1402 ChildFrameAt(devtools_extension_a_panel_rfh, 0); | |
| 1403 | |
| 1404 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1405 content::kChromeDevToolsScheme)); | |
| 1406 EXPECT_EQ(devtools_a_extension->GetResourceURL("/panel_devtools_page.html"), | |
| 1407 devtools_extension_a_devtools_rfh->GetLastCommittedURL()); | |
| 1408 EXPECT_EQ(devtools_b_extension->GetResourceURL("/simple_devtools_page.html"), | |
| 1409 devtools_extension_b_devtools_rfh->GetLastCommittedURL()); | |
| 1410 EXPECT_EQ(devtools_a_extension->GetResourceURL("/panel.html"), | |
| 1411 devtools_extension_a_panel_rfh->GetLastCommittedURL()); | |
| 1412 EXPECT_EQ(extension_b_page_url, | |
| 1413 devtools_extension_b_frame_rfh->GetLastCommittedURL()); | |
| 1414 | |
| 1415 // All frames should be in the devtools process. | |
| 1416 content::SiteInstance* devtools_instance = | |
| 1417 main_devtools_rfh->GetSiteInstance(); | |
| 1418 EXPECT_TRUE( | |
| 1419 devtools_instance->GetSiteURL().SchemeIs(content::kChromeDevToolsScheme)); | |
| 1420 EXPECT_EQ(devtools_instance, | |
| 1421 devtools_extension_a_devtools_rfh->GetSiteInstance()); | |
| 1422 EXPECT_EQ(devtools_instance, | |
| 1423 devtools_extension_b_devtools_rfh->GetSiteInstance()); | |
| 1424 EXPECT_EQ(devtools_instance, | |
| 1425 devtools_extension_a_panel_rfh->GetSiteInstance()); | |
| 1426 EXPECT_EQ(devtools_instance, | |
| 1427 devtools_extension_b_frame_rfh->GetSiteInstance()); | |
| 1428 } | |
| 1429 | |
| 1430 // Tests that a devtools extension can still have subframes to itself in a | |
| 1431 // "devtools page" and that they will be rendered within the devtools process as | |
| 1432 // well, not in the extension process. http://crbug.com/570483 | |
| 1433 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, DevToolsExtensionInItself) { | |
| 1434 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1435 | |
| 1436 // Install the dynamically-generated extension. | |
| 1437 const Extension* extension = | |
| 1438 LoadExtensionForTest("Devtools Extension", "panel_devtools_page.html", | |
| 1439 "/simple_test_page.html"); | |
| 1440 ASSERT_TRUE(extension); | |
| 1441 | |
| 1442 OpenDevToolsWindow(kDebuggerTestPage, false); | |
| 1443 | |
| 1444 // Wait for the extension's panel to finish loading -- it'll output 'PASS' | |
| 1445 // when it's installed. waitForTestResultsInConsole waits until that 'PASS'. | |
| 1446 RunTestFunction(window_, "waitForTestResultsInConsole"); | |
| 1447 | |
| 1448 // Now that we know the panel is loaded, switch to it. | |
| 1449 GURL extension_test_url = extension->GetResourceURL("/simple_test_page.html"); | |
| 1450 content::TestNavigationManager test_page_manager(main_web_contents(), | |
| 1451 extension_test_url); | |
| 1452 SwitchToExtensionPanel(window_, extension, "iframe_panel"); | |
| 1453 test_page_manager.WaitForNavigationFinished(); | |
| 1454 | |
| 1455 std::vector<RenderFrameHost*> rfhs = main_web_contents()->GetAllFrames(); | |
| 1456 EXPECT_EQ(4U, rfhs.size()); | |
| 1457 | |
| 1458 RenderFrameHost* main_devtools_rfh = main_web_contents()->GetMainFrame(); | |
| 1459 RenderFrameHost* devtools_extension_devtools_page_rfh = | |
| 1460 ChildFrameAt(main_devtools_rfh, 0); | |
| 1461 RenderFrameHost* devtools_extension_panel_rfh = | |
| 1462 ChildFrameAt(main_devtools_rfh, 1); | |
| 1463 RenderFrameHost* devtools_extension_panel_frame_rfh = | |
| 1464 ChildFrameAt(devtools_extension_panel_rfh, 0); | |
| 1465 | |
| 1466 // All frames should be in the devtools process, including | |
| 1467 // simple_test_page.html | |
| 1468 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1469 content::kChromeDevToolsScheme)); | |
| 1470 EXPECT_EQ(extension->GetResourceURL("/panel_devtools_page.html"), | |
| 1471 devtools_extension_devtools_page_rfh->GetLastCommittedURL()); | |
| 1472 EXPECT_EQ(extension->GetResourceURL("/panel.html"), | |
| 1473 devtools_extension_panel_rfh->GetLastCommittedURL()); | |
| 1474 EXPECT_EQ(extension_test_url, | |
| 1475 devtools_extension_panel_frame_rfh->GetLastCommittedURL()); | |
| 1476 | |
| 1477 content::SiteInstance* devtools_instance = | |
| 1478 main_devtools_rfh->GetSiteInstance(); | |
| 1479 EXPECT_TRUE( | |
| 1480 devtools_instance->GetSiteURL().SchemeIs(content::kChromeDevToolsScheme)); | |
| 1481 EXPECT_EQ(devtools_instance, | |
| 1482 devtools_extension_devtools_page_rfh->GetSiteInstance()); | |
| 1483 EXPECT_EQ(devtools_instance, devtools_extension_panel_rfh->GetSiteInstance()); | |
| 1484 EXPECT_EQ(devtools_instance, | |
| 1485 devtools_extension_panel_frame_rfh->GetSiteInstance()); | |
| 1486 } | |
| 1487 | |
| 1488 // Tests that a devtools (not a devtools extension) Iframe can be injected into | |
| 1489 // devtools. http://crbug.com/570483 | |
| 1490 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, DevtoolsInDevTools) { | |
| 1491 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 1492 | |
| 1493 GURL devtools_url = GURL(chrome::kChromeUIDevToolsURL); | |
| 1494 | |
| 1495 OpenDevToolsWindow(kDebuggerTestPage, false); | |
| 1496 | |
| 1497 std::string javascript = | |
| 1498 "var devtoolsFrame = document.createElement('iframe');" | |
| 1499 "document.body.appendChild(devtoolsFrame);" | |
| 1500 "devtoolsFrame.src = '" + | |
| 1501 devtools_url.spec() + "';"; | |
| 1502 | |
| 1503 RenderFrameHost* main_devtools_rfh = main_web_contents()->GetMainFrame(); | |
| 1504 | |
| 1505 content::TestNavigationManager manager(main_web_contents(), devtools_url); | |
| 1506 ASSERT_TRUE(content::ExecuteScript(main_devtools_rfh, javascript)); | |
| 1507 manager.WaitForNavigationFinished(); | |
| 1508 | |
| 1509 std::vector<RenderFrameHost*> rfhs = main_web_contents()->GetAllFrames(); | |
| 1510 EXPECT_EQ(2U, rfhs.size()); | |
| 1511 RenderFrameHost* devtools_iframe_rfh = ChildFrameAt(main_devtools_rfh, 0); | |
| 1512 EXPECT_TRUE(main_devtools_rfh->GetLastCommittedURL().SchemeIs( | |
| 1513 content::kChromeDevToolsScheme)); | |
| 1514 EXPECT_EQ(devtools_url, devtools_iframe_rfh->GetLastCommittedURL()); | |
| 1515 content::SiteInstance* devtools_instance = | |
| 1516 main_devtools_rfh->GetSiteInstance(); | |
| 1517 EXPECT_TRUE( | |
| 1518 devtools_instance->GetSiteURL().SchemeIs(content::kChromeDevToolsScheme)); | |
| 1519 EXPECT_EQ(devtools_instance, devtools_iframe_rfh->GetSiteInstance()); | |
| 1520 | |
| 1521 std::string message; | |
| 1522 EXPECT_TRUE(ExecuteScriptAndExtractString( | |
| 1523 devtools_iframe_rfh, "domAutomationController.send(document.origin)", | |
| 1524 &message)); | |
| 1525 EXPECT_EQ(devtools_url.GetOrigin().spec(), message + "/"); | |
| 995 } | 1526 } |
| 996 | 1527 |
| 997 // Some web features, when used from an extension, are subject to browser-side | 1528 // Some web features, when used from an extension, are subject to browser-side |
| 998 // security policy enforcement. Make sure they work properly from inside a | 1529 // security policy enforcement. Make sure they work properly from inside a |
| 999 // devtools extension. | 1530 // devtools extension. |
| 1000 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, | 1531 IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest, |
| 1001 DevToolsExtensionSecurityPolicyGrants) { | 1532 DevToolsExtensionSecurityPolicyGrants) { |
| 1002 ASSERT_TRUE(embedded_test_server()->Start()); | 1533 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1003 | 1534 |
| 1004 std::unique_ptr<extensions::TestExtensionDir> dir( | 1535 std::unique_ptr<extensions::TestExtensionDir> dir( |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1594 RunTestFunction(window, "testWindowInitializedOnNavigateBack"); | 2125 RunTestFunction(window, "testWindowInitializedOnNavigateBack"); |
| 1595 | 2126 |
| 1596 DevToolsWindowTesting::CloseDevToolsWindowSync(window); | 2127 DevToolsWindowTesting::CloseDevToolsWindowSync(window); |
| 1597 content::WebUIControllerFactory::UnregisterFactoryForTesting(&test_factory); | 2128 content::WebUIControllerFactory::UnregisterFactoryForTesting(&test_factory); |
| 1598 } | 2129 } |
| 1599 | 2130 |
| 1600 // Tests scripts panel showing. | 2131 // Tests scripts panel showing. |
| 1601 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsSharedWorker) { | 2132 IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsSharedWorker) { |
| 1602 RunTest("testDevToolsSharedWorker", url::kAboutBlankURL); | 2133 RunTest("testDevToolsSharedWorker", url::kAboutBlankURL); |
| 1603 } | 2134 } |
| OLD | NEW |