Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
|
Charlie Reis
2015/03/09 23:02:38
nit: 2015
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
|
Charlie Reis
2015/03/09 23:02:38
nit: Remove one of the two blank lines.
| |
| 5 | |
| 6 #include "content/browser/frame_host/frame_tree.h" | |
| 7 #include "content/browser/site_per_process_browsertest.h" | |
| 8 #include "content/browser/web_contents/web_contents_impl.h" | |
| 9 #include "content/public/browser/devtools_agent_host.h" | |
| 10 #include "content/public/test/content_browser_test_utils.h" | |
| 11 #include "content/public/test/test_utils.h" | |
| 12 #include "content/shell/browser/shell.h" | |
| 13 #include "content/test/content_browser_test_utils_internal.h" | |
| 14 #include "net/dns/mock_host_resolver.h" | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 class SitePerProcessDevToolsBrowserTest | |
| 19 : public SitePerProcessBrowserTest { | |
| 20 public: | |
| 21 SitePerProcessDevToolsBrowserTest() {} | |
| 22 }; | |
| 23 | |
| 24 class TestClient: public DevToolsAgentHostClient { | |
| 25 public: | |
| 26 TestClient() : closed_(false) {} | |
| 27 ~TestClient() override {} | |
| 28 | |
| 29 bool closed() { return closed_; } | |
| 30 | |
| 31 void DispatchProtocolMessage( | |
| 32 DevToolsAgentHost* agent_host, | |
| 33 const std::string& message) override { | |
| 34 } | |
| 35 | |
| 36 void AgentHostClosed( | |
| 37 DevToolsAgentHost* agent_host, | |
| 38 bool replaced_with_another_client) override { | |
| 39 closed_ = true; | |
| 40 } | |
| 41 | |
| 42 private: | |
| 43 bool closed_; | |
| 44 }; | |
| 45 | |
| 46 // Fails on Android, http://crbug.com/464993. | |
| 47 #if defined(OS_ANDROID) | |
| 48 #define MAYBE_CrossSiteIframeAgentHost DISABLED_CrossSiteIframeAgentHost | |
| 49 #else | |
| 50 #define MAYBE_CrossSiteIframeAgentHost CrossSiteIframeAgentHost | |
| 51 #endif | |
| 52 IN_PROC_BROWSER_TEST_F(SitePerProcessDevToolsBrowserTest, | |
| 53 MAYBE_CrossSiteIframeAgentHost) { | |
| 54 DevToolsAgentHost::List list; | |
| 55 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 56 ASSERT_TRUE(test_server()->Start()); | |
| 57 GURL main_url(test_server()->GetURL("files/site_per_process_main.html")); | |
| 58 NavigateToURL(shell(), main_url); | |
| 59 | |
| 60 // It is safe to obtain the root frame tree node here, as it doesn't change. | |
| 61 FrameTreeNode* root = | |
| 62 static_cast<WebContentsImpl*>(shell()->web_contents())-> | |
| 63 GetFrameTree()->root(); | |
| 64 | |
| 65 list = DevToolsAgentHost::GetOrCreateAll(); | |
| 66 EXPECT_EQ(1U, list.size()); | |
| 67 EXPECT_EQ(DevToolsAgentHost::TYPE_WEB_CONTENTS, list[0]->GetType()); | |
| 68 EXPECT_EQ(main_url.spec(), list[0]->GetURL().spec()); | |
| 69 | |
| 70 // Load same-site page into iframe. | |
| 71 FrameTreeNode* child = root->child_at(0); | |
| 72 GURL http_url(test_server()->GetURL("files/title1.html")); | |
| 73 NavigateFrameToURL(child, http_url); | |
| 74 | |
| 75 list = DevToolsAgentHost::GetOrCreateAll(); | |
| 76 EXPECT_EQ(1U, list.size()); | |
| 77 EXPECT_EQ(DevToolsAgentHost::TYPE_WEB_CONTENTS, list[0]->GetType()); | |
| 78 EXPECT_EQ(main_url.spec(), list[0]->GetURL().spec()); | |
| 79 | |
| 80 // Load cross-site page into iframe. | |
| 81 GURL::Replacements replace_host; | |
| 82 GURL cross_site_url(test_server()->GetURL("files/title2.html")); | |
| 83 replace_host.SetHostStr("foo.com"); | |
| 84 cross_site_url = cross_site_url.ReplaceComponents(replace_host); | |
| 85 NavigateFrameToURL(root->child_at(0), cross_site_url); | |
| 86 | |
| 87 list = DevToolsAgentHost::GetOrCreateAll(); | |
| 88 EXPECT_EQ(2U, list.size()); | |
| 89 EXPECT_EQ(DevToolsAgentHost::TYPE_WEB_CONTENTS, list[0]->GetType()); | |
| 90 EXPECT_EQ(main_url.spec(), list[0]->GetURL().spec()); | |
| 91 EXPECT_EQ(DevToolsAgentHost::TYPE_FRAME, list[1]->GetType()); | |
| 92 EXPECT_EQ(cross_site_url.spec(), list[1]->GetURL().spec()); | |
| 93 | |
| 94 // Attaching to child frame. | |
| 95 scoped_refptr<DevToolsAgentHost> child_host = list[1]; | |
| 96 TestClient client; | |
| 97 child_host->AttachClient(&client); | |
| 98 | |
| 99 // Load back same-site page into iframe. | |
| 100 NavigateFrameToURL(root->child_at(0), http_url); | |
| 101 | |
| 102 list = DevToolsAgentHost::GetOrCreateAll(); | |
| 103 EXPECT_EQ(1U, list.size()); | |
| 104 EXPECT_EQ(DevToolsAgentHost::TYPE_WEB_CONTENTS, list[0]->GetType()); | |
| 105 EXPECT_EQ(main_url.spec(), list[0]->GetURL().spec()); | |
| 106 // TODO(dgozman): we should get closed notification here. | |
| 107 // See http://crbug.com/464993. | |
| 108 EXPECT_FALSE(client.closed()); | |
| 109 child_host->DetachClient(); | |
| 110 child_host = nullptr; | |
| 111 } | |
| 112 | |
| 113 } // namespace content | |
| OLD | NEW |