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