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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
// Copyright (c) 2011 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 "base/memory/scoped_vector.h"
#include "base/stringprintf.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/test/base/ui_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "net/base/mock_host_resolver.h"
// Disabled, http://crbug.com/64899.
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) {
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableExperimentalExtensionApis);
ResultCatcher catcher;
ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_
.AppendASCII("window_open").AppendASCII("spanning")));
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
}
void WaitForTabsAndPopups(Browser* browser,
int num_tabs,
int num_popups,
int num_panels) {
SCOPED_TRACE(
StringPrintf("WaitForTabsAndPopups tabs:%d, popups:%d, panels:%d",
num_tabs, num_popups, num_panels));
// We start with one tab and one browser already open.
++num_tabs;
size_t num_browsers = static_cast<size_t>(num_popups + num_panels) + 1;
const base::TimeDelta kWaitTime = base::TimeDelta::FromSeconds(15);
base::TimeTicks end_time = base::TimeTicks::Now() + kWaitTime;
while (base::TimeTicks::Now() < end_time) {
if (BrowserList::GetBrowserCount(browser->profile()) == num_browsers &&
browser->tab_count() == num_tabs)
break;
ui_test_utils::RunAllPendingInMessageLoop();
}
EXPECT_EQ(num_browsers, BrowserList::GetBrowserCount(browser->profile()));
EXPECT_EQ(num_tabs, browser->tab_count());
int num_popups_seen = 0;
int num_panels_seen = 0;
for (BrowserList::const_iterator iter = BrowserList::begin();
iter != BrowserList::end(); ++iter) {
if (*iter == browser)
continue;
// Check for TYPE_POPUP or TYPE_PANEL.
EXPECT_TRUE((*iter)->is_type_popup() || (*iter)->is_type_panel());
if ((*iter)->is_type_popup())
++num_popups_seen;
else
++num_panels_seen;
}
EXPECT_EQ(num_popups, num_popups_seen);
EXPECT_EQ(num_panels, num_panels_seen);
}
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) {
host_resolver()->AddRule("a.com", "127.0.0.1");
ASSERT_TRUE(StartTestServer());
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app")));
WaitForTabsAndPopups(browser(), 0, 2, 0);
for (BrowserList::const_iterator iter = BrowserList::begin();
iter != BrowserList::end(); ++iter) {
if (*iter == browser())
ASSERT_FALSE((*iter)->is_app());
else
ASSERT_TRUE((*iter)->is_app());
}
}
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupDefault) {
ASSERT_TRUE(StartTestServer());
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("window_open").AppendASCII("popup")));
const int num_tabs = 1;
const int num_popups = 0;
WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0);
}
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupLarge) {
ASSERT_TRUE(StartTestServer());
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("window_open").AppendASCII("popup_large")));
#if defined(OS_CHROMEOS)
// On ChromeOS this should open a new tab.
const int num_tabs = 1;
const int num_popups = 0;
#else
// On other systems this should open a new popup window.
const int num_tabs = 0;
const int num_popups = 1;
#endif
WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0);
}
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupSmall) {
ASSERT_TRUE(StartTestServer());
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("window_open").AppendASCII("popup_small")));
// On ChromeOS this should open a new panel (acts like a new popup window).
// On other systems this should open a new popup window.
const int num_tabs = 0;
const int num_popups = 1;
WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0);
}
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingExtension) {
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(StartTestServer());
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
.AppendASCII("extension")));
WaitForTabsAndPopups(browser(), 5, 3, 0);
}
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingHostedApp) {
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking")
.AppendASCII("hosted_app")));
// The app being tested owns the domain a.com . The test URLs we navigate
// to below must be within that domain, so that they fall within the app's
// web extent.
GURL::Replacements replace_host;
std::string a_dot_com = "a.com";
replace_host.SetHostStr(a_dot_com);
const std::string popup_app_contents_path(
"files/extensions/api_test/window_open/popup_blocking/hosted_app/");
GURL open_tab =
test_server()->GetURL(popup_app_contents_path + "open_tab.html")
.ReplaceComponents(replace_host);
GURL open_popup =
test_server()->GetURL(popup_app_contents_path + "open_popup.html")
.ReplaceComponents(replace_host);
browser()->OpenURL(open_tab, GURL(), NEW_FOREGROUND_TAB,
content::PAGE_TRANSITION_TYPED);
browser()->OpenURL(open_popup, GURL(), NEW_FOREGROUND_TAB,
content::PAGE_TRANSITION_TYPED);
WaitForTabsAndPopups(browser(), 3, 1, 0);
}
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowArgumentsOverflow) {
ASSERT_TRUE(RunExtensionTest("window_open/argument_overflow")) << message_;
}
class WindowOpenPanelDisabledTest : public ExtensionApiTest {
virtual void SetUpCommandLine(CommandLine* command_line) {
ExtensionApiTest::SetUpCommandLine(command_line);
// TODO(jennb): Re-enable when panels are enabled by default.
// command_line->AppendSwitch(switches::kDisablePanels);
}
};
IN_PROC_BROWSER_TEST_F(WindowOpenPanelDisabledTest,
DISABLED_WindowOpenPanelNotEnabled) {
ASSERT_TRUE(RunExtensionTest("window_open/panel_not_enabled")) << message_;
}
class WindowOpenPanelTest : public ExtensionApiTest {
virtual void SetUpCommandLine(CommandLine* command_line) {
ExtensionApiTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(switches::kEnablePanels);
}
};
IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, WindowOpenPanel) {
ASSERT_TRUE(RunExtensionTest("window_open/panel")) << message_;
}
#if defined(OS_MACOSX) || defined(OS_WIN)
// Focus test fails if there is no window manager on Linux.
IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, WindowOpenFocus) {
ASSERT_TRUE(RunExtensionTest("window_open/focus")) << message_;
}
#endif
IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest,
CloseNonExtensionPanelsOnUninstall) {
ASSERT_TRUE(StartTestServer());
// Setup listeners to wait on strings we expect the extension pages to send.
std::vector<std::string> test_strings;
test_strings.push_back("content_tab");
test_strings.push_back("content_panel");
test_strings.push_back("content_popup");
ScopedVector<ExtensionTestMessageListener> listeners;
for (size_t i = 0; i < test_strings.size(); ++i) {
listeners.push_back(
new ExtensionTestMessageListener(test_strings[i], false));
}
const Extension* extension = LoadExtension(
test_data_dir_.AppendASCII("window_open").AppendASCII(
"close_panels_on_uninstall"));
ASSERT_TRUE(extension);
// Two tabs. One in extension domain and one in non-extension domain.
// Two popups - one in extension domain and one in non-extension domain.
// Two panels - one in extension domain and one in non-extension domain.
WaitForTabsAndPopups(browser(), 2, 2, 2);
// Wait on test messages to make sure the pages loaded.
for (size_t i = 0; i < listeners.size(); ++i)
ASSERT_TRUE(listeners[i]->WaitUntilSatisfied());
UninstallExtension(extension->id());
// Wait for one tab and one popup in non-extension domain to stay open.
// Expect everything else, including panels, to close.
WaitForTabsAndPopups(browser(), 1, 1, 0);
}
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpener) {
ASSERT_TRUE(RunExtensionTest("window_open/opener")) << message_;
}
|