Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / browser / devtools / site_per_process_devtools_browsertest.cc
blob1ec78c603c51f6975736c6f36c51897db8b43e96
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
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"
16 namespace content {
18 class SitePerProcessDevToolsBrowserTest
19 : public SitePerProcessBrowserTest {
20 public:
21 SitePerProcessDevToolsBrowserTest() {}
24 class TestClient: public DevToolsAgentHostClient {
25 public:
26 TestClient() : closed_(false) {}
27 ~TestClient() override {}
29 bool closed() { return closed_; }
31 void DispatchProtocolMessage(
32 DevToolsAgentHost* agent_host,
33 const std::string& message) override {
36 void AgentHostClosed(
37 DevToolsAgentHost* agent_host,
38 bool replaced_with_another_client) override {
39 closed_ = true;
42 private:
43 bool closed_;
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);
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();
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());
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);
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());
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);
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());
94 // Attaching to child frame.
95 scoped_refptr<DevToolsAgentHost> child_host = list[1];
96 TestClient client;
97 child_host->AttachClient(&client);
99 // Load back same-site page into iframe.
100 NavigateFrameToURL(root->child_at(0), http_url);
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 EXPECT_TRUE(client.closed());
107 child_host->DetachClient();
108 child_host = nullptr;
111 } // namespace content