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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
// Copyright (c) 2012 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 "base/command_line.h"
#include "chrome/browser/debugger/devtools_window.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_view_host_delegate.h"
using content::RenderViewHost;
using content::RenderWidgetHost;
namespace {
int RenderProcessHostCount() {
content::RenderProcessHost::iterator hosts =
content::RenderProcessHost::AllHostsIterator();
int count = 0;
while (!hosts.IsAtEnd()) {
if (hosts.GetCurrentValue()->HasConnection())
count++;
hosts.Advance();
}
return count;
}
RenderViewHost* FindFirstDevToolsHost() {
content::RenderProcessHost::iterator hosts =
content::RenderProcessHost::AllHostsIterator();
for (; !hosts.IsAtEnd(); hosts.Advance()) {
content::RenderProcessHost* render_process_host = hosts.GetCurrentValue();
DCHECK(render_process_host);
if (!render_process_host->HasConnection())
continue;
content::RenderProcessHost::RenderWidgetHostsIterator iter(
render_process_host->GetRenderWidgetHostsIterator());
for (; !iter.IsAtEnd(); iter.Advance()) {
const RenderWidgetHost* widget = iter.GetCurrentValue();
DCHECK(widget);
if (!widget || !widget->IsRenderView())
continue;
RenderViewHost* host =
RenderViewHost::From(const_cast<RenderWidgetHost*>(widget));
content::RenderViewHostDelegate* host_delegate = host->GetDelegate();
GURL url = host_delegate->GetURL();
if (url.SchemeIs(chrome::kChromeDevToolsScheme))
return host;
}
}
return NULL;
}
} // namespace
typedef InProcessBrowserTest ChromeRenderProcessHostTest;
// Ensure that DevTools opened to debug DevTools is launched in a separate
// process when --process-per-tab is set. See crbug.com/69873.
IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest,
DevToolsOnSelfInOwnProcessPPT) {
CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
parsed_command_line.AppendSwitch(switches::kProcessPerTab);
int tab_count = 1;
int host_count = 1;
#if defined(USE_VIRTUAL_KEYBOARD)
++host_count; // For the virtual keyboard.
#endif
GURL page1("data:text/html,hello world1");
browser()->ShowSingletonTab(page1);
if (browser()->tab_count() == tab_count)
ui_test_utils::WaitForNewTab(browser());
tab_count++;
host_count++;
EXPECT_EQ(tab_count, browser()->tab_count());
EXPECT_EQ(host_count, RenderProcessHostCount());
// DevTools start in docked mode (no new tab), in a separate process.
browser()->ToggleDevToolsWindow(DEVTOOLS_TOGGLE_ACTION_INSPECT);
host_count++;
EXPECT_EQ(tab_count, browser()->tab_count());
EXPECT_EQ(host_count, RenderProcessHostCount());
RenderViewHost* devtools = FindFirstDevToolsHost();
DCHECK(devtools);
// DevTools start in a separate process.
DevToolsWindow::ToggleDevToolsWindow(
devtools, DEVTOOLS_TOGGLE_ACTION_INSPECT);
host_count++;
EXPECT_EQ(tab_count, browser()->tab_count());
EXPECT_EQ(host_count, RenderProcessHostCount());
}
// Ensure that DevTools opened to debug DevTools is launched in a separate
// process. See crbug.com/69873.
IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest,
DevToolsOnSelfInOwnProcess) {
int tab_count = 1;
int host_count = 1;
#if defined(USE_VIRTUAL_KEYBOARD)
++host_count; // For the virtual keyboard.
#endif
GURL page1("data:text/html,hello world1");
browser()->ShowSingletonTab(page1);
if (browser()->tab_count() == tab_count)
ui_test_utils::WaitForNewTab(browser());
tab_count++;
host_count++;
EXPECT_EQ(tab_count, browser()->tab_count());
EXPECT_EQ(host_count, RenderProcessHostCount());
// DevTools start in docked mode (no new tab), in a separate process.
browser()->ToggleDevToolsWindow(DEVTOOLS_TOGGLE_ACTION_INSPECT);
host_count++;
EXPECT_EQ(tab_count, browser()->tab_count());
EXPECT_EQ(host_count, RenderProcessHostCount());
RenderViewHost* devtools = FindFirstDevToolsHost();
DCHECK(devtools);
// DevTools start in a separate process.
DevToolsWindow::ToggleDevToolsWindow(
devtools, DEVTOOLS_TOGGLE_ACTION_INSPECT);
host_count++;
EXPECT_EQ(tab_count, browser()->tab_count());
EXPECT_EQ(host_count, RenderProcessHostCount());
}
|