blob: 2e37fd3205eaed838b9fdafd50e4078f56f4ee2f [file] [log] [blame]
[email protected]71b73f02011-04-06 15:57:291// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]3a8eecb2010-04-22 23:56:302// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]ce7f62e32010-08-10 23:43:595#include "base/utf_string_conversions.h"
[email protected]3a8eecb2010-04-22 23:56:306#include "chrome/browser/extensions/extension_apitest.h"
7#include "chrome/browser/extensions/extension_host.h"
8#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]8ecad5e2010-12-02 21:18:339#include "chrome/browser/profiles/profile.h"
[email protected]7b5dc002010-11-16 23:08:1010#include "chrome/browser/ui/browser.h"
[email protected]71b73f02011-04-06 15:57:2911#include "chrome/browser/ui/browser_list.h"
[email protected]d55c2382011-08-18 23:10:3612#include "chrome/browser/ui/browser_window.h"
[email protected]ae673742011-08-24 19:48:3713#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]3a8eecb2010-04-22 23:56:3014#include "chrome/common/chrome_switches.h"
[email protected]814a7bf0f2011-08-13 05:30:5915#include "chrome/common/extensions/extension.h"
[email protected]af44e7fb2011-07-29 18:32:3216#include "chrome/test/base/ui_test_utils.h"
[email protected]a035dfda2011-03-02 01:01:4917#include "content/browser/renderer_host/render_view_host.h"
18#include "content/browser/tab_contents/tab_contents.h"
[email protected]3a8eecb2010-04-22 23:56:3019#include "net/base/mock_host_resolver.h"
20
21class AppApiTest : public ExtensionApiTest {
[email protected]118d3122011-08-10 17:09:5322 protected:
23 // Gets the base URL for files for a specific test, making sure that it uses
24 // "localhost" as the hostname, since that is what the extent is declared
25 // as in the test apps manifests.
26 GURL GetTestBaseURL(std::string test_directory) {
27 GURL::Replacements replace_host;
28 std::string host_str("localhost"); // must stay in scope with replace_host
29 replace_host.SetHostStr(host_str);
30 GURL base_url = test_server()->GetURL(
31 "files/extensions/api_test/" + test_directory + "/");
32 return base_url.ReplaceComponents(replace_host);
33 }
[email protected]3a8eecb2010-04-22 23:56:3034};
35
36// Simulates a page calling window.open on an URL, and waits for the navigation.
37static void WindowOpenHelper(Browser* browser,
[email protected]12ea9b272010-08-24 11:31:4038 RenderViewHost* opener_host,
39 const GURL& url,
40 bool newtab_process_should_equal_opener) {
[email protected]3114db2c2011-09-12 20:09:0541 ui_test_utils::WindowedNotificationObserver observer(
42 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
[email protected]9fabbf72010-09-30 21:50:0543 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
44 opener_host, L"", L"window.open('" + UTF8ToWide(url.spec()) + L"');"));
[email protected]3a8eecb2010-04-22 23:56:3045
[email protected]12ea9b272010-08-24 11:31:4046 // The above window.open call is not user-initiated, it will create
47 // a popup window instead of a new tab in current window.
48 // Now the active tab in last active window should be the new tab.
49 Browser* last_active_browser = BrowserList::GetLastActive();
50 EXPECT_TRUE(last_active_browser);
51 TabContents* newtab = last_active_browser->GetSelectedTabContents();
52 EXPECT_TRUE(newtab);
[email protected]3114db2c2011-09-12 20:09:0553 observer.Wait();
[email protected]3a8eecb2010-04-22 23:56:3054 EXPECT_EQ(url, newtab->controller().GetLastCommittedEntry()->url());
[email protected]12ea9b272010-08-24 11:31:4055 if (newtab_process_should_equal_opener)
56 EXPECT_EQ(opener_host->process(), newtab->render_view_host()->process());
57 else
58 EXPECT_NE(opener_host->process(), newtab->render_view_host()->process());
[email protected]3a8eecb2010-04-22 23:56:3059}
60
61// Simulates a page navigating itself to an URL, and waits for the navigation.
62static void NavigateTabHelper(TabContents* contents, const GURL& url) {
63 bool result = false;
[email protected]3114db2c2011-09-12 20:09:0564 ui_test_utils::WindowedNotificationObserver observer(
65 content::NOTIFICATION_LOAD_STOP,
66 NotificationService::AllSources());
[email protected]9fabbf72010-09-30 21:50:0567 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
[email protected]3a8eecb2010-04-22 23:56:3068 contents->render_view_host(), L"",
[email protected]d38f83f2010-04-30 23:25:5769 L"window.addEventListener('unload', function() {"
70 L" window.domAutomationController.send(true);"
71 L"}, false);"
72 L"window.location = '" + UTF8ToWide(url.spec()) + L"';",
[email protected]9fabbf72010-09-30 21:50:0573 &result));
[email protected]3a8eecb2010-04-22 23:56:3074 ASSERT_TRUE(result);
[email protected]3114db2c2011-09-12 20:09:0575 observer.Wait();
[email protected]3a8eecb2010-04-22 23:56:3076 EXPECT_EQ(url, contents->controller().GetLastCommittedEntry()->url());
77}
78
[email protected]d54ade62011-07-03 00:32:1379#if defined(OS_WIN)
80// AppProcess sometimes hangs on Windows
81// http://crbug.com/88316
82#define MAYBE_AppProcess DISABLED_AppProcess
83#else
84#define MAYBE_AppProcess AppProcess
85#endif
86
87IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcess) {
[email protected]12ea9b272010-08-24 11:31:4088 CommandLine::ForCurrentProcess()->AppendSwitch(
89 switches::kDisablePopupBlocking);
90
[email protected]3a8eecb2010-04-22 23:56:3091 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]95409e12010-08-17 20:07:1192 ASSERT_TRUE(test_server()->Start());
[email protected]3a8eecb2010-04-22 23:56:3093
[email protected]cbf4d1912010-08-12 18:24:5794 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process")));
[email protected]3a8eecb2010-04-22 23:56:3095
[email protected]cbf4d1912010-08-12 18:24:5796 // Open two tabs in the app, one outside it.
[email protected]118d3122011-08-10 17:09:5397 GURL base_url = GetTestBaseURL("app_process");
[email protected]fe3048872010-10-18 14:58:5998
[email protected]f0e13332011-05-20 22:41:1499 // Test both opening a URL in a new tab, and opening a tab and then navigating
100 // it. Either way, app tabs should be considered extension processes, but
101 // they have no elevated privileges and thus should not have WebUI bindings.
102 ui_test_utils::NavigateToURLWithDisposition(
103 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB,
104 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
105 EXPECT_TRUE(browser()->GetTabContentsAt(1)->render_view_host()->process()->
106 is_extension_process());
107 EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui());
[email protected]cbf4d1912010-08-12 18:24:57108 browser()->NewTab();
109 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html"));
[email protected]f0e13332011-05-20 22:41:14110 EXPECT_TRUE(browser()->GetTabContentsAt(2)->render_view_host()->process()->
111 is_extension_process());
112 EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui());
[email protected]cbf4d1912010-08-12 18:24:57113 browser()->NewTab();
114 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path3/empty.html"));
[email protected]f0e13332011-05-20 22:41:14115 EXPECT_FALSE(browser()->GetTabContentsAt(3)->render_view_host()->process()->
116 is_extension_process());
117 EXPECT_FALSE(browser()->GetTabContentsAt(3)->web_ui());
[email protected]3a8eecb2010-04-22 23:56:30118
[email protected]056ad2a2011-07-12 02:13:55119 // We should have opened 3 new extension tabs. Including the original blank
120 // tab, we now have 4 tabs. Because the app_process app has the background
121 // permission, all of its instances are in the same process. Thus two tabs
122 // should be part of the extension app and grouped in the same process.
[email protected]3a8eecb2010-04-22 23:56:30123 ASSERT_EQ(4, browser()->tab_count());
[email protected]cbf4d1912010-08-12 18:24:57124 RenderViewHost* host = browser()->GetTabContentsAt(1)->render_view_host();
[email protected]cbf4d1912010-08-12 18:24:57125
126 EXPECT_EQ(host->process(),
[email protected]3a8eecb2010-04-22 23:56:30127 browser()->GetTabContentsAt(2)->render_view_host()->process());
[email protected]cbf4d1912010-08-12 18:24:57128 EXPECT_NE(host->process(),
[email protected]3a8eecb2010-04-22 23:56:30129 browser()->GetTabContentsAt(3)->render_view_host()->process());
130
131 // Now let's do the same using window.open. The same should happen.
[email protected]12ea9b272010-08-24 11:31:40132 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile()));
[email protected]cbf4d1912010-08-12 18:24:57133 WindowOpenHelper(browser(), host,
[email protected]12ea9b272010-08-24 11:31:40134 base_url.Resolve("path1/empty.html"), true);
[email protected]cbf4d1912010-08-12 18:24:57135 WindowOpenHelper(browser(), host,
[email protected]12ea9b272010-08-24 11:31:40136 base_url.Resolve("path2/empty.html"), true);
[email protected]992db4c2011-05-12 15:37:15137 // This should open in a new process (i.e., false for the last argument).
[email protected]cbf4d1912010-08-12 18:24:57138 WindowOpenHelper(browser(), host,
[email protected]992db4c2011-05-12 15:37:15139 base_url.Resolve("path3/empty.html"), false);
[email protected]3a8eecb2010-04-22 23:56:30140
141 // Now let's have these pages navigate, into or out of the extension web
142 // extent. They should switch processes.
[email protected]9a1e6d42010-04-26 22:29:36143 const GURL& app_url(base_url.Resolve("path1/empty.html"));
144 const GURL& non_app_url(base_url.Resolve("path3/empty.html"));
[email protected]cbf4d1912010-08-12 18:24:57145 NavigateTabHelper(browser()->GetTabContentsAt(2), non_app_url);
[email protected]3a8eecb2010-04-22 23:56:30146 NavigateTabHelper(browser()->GetTabContentsAt(3), app_url);
[email protected]992db4c2011-05-12 15:37:15147 EXPECT_NE(host->process(),
[email protected]cbf4d1912010-08-12 18:24:57148 browser()->GetTabContentsAt(2)->render_view_host()->process());
149 EXPECT_EQ(host->process(),
[email protected]3a8eecb2010-04-22 23:56:30150 browser()->GetTabContentsAt(3)->render_view_host()->process());
[email protected]08e94b82010-12-15 22:51:04151
152 // If one of the popup tabs navigates back to the app, window.opener should
153 // be valid.
154 NavigateTabHelper(browser()->GetTabContentsAt(6), app_url);
155 EXPECT_EQ(host->process(),
156 browser()->GetTabContentsAt(6)->render_view_host()->process());
157 bool windowOpenerValid = false;
158 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
159 browser()->GetTabContentsAt(6)->render_view_host(), L"",
160 L"window.domAutomationController.send(window.opener != null)",
161 &windowOpenerValid));
162 ASSERT_TRUE(windowOpenerValid);
[email protected]3a8eecb2010-04-22 23:56:30163}
[email protected]faf407b2011-01-05 01:24:32164
[email protected]727db1f2011-07-19 19:35:02165
166#if defined(OS_WIN)
167// Seems to timeout sometimes on Windows: http://crbug.com/89766
168#define MAYBE_AppProcessInstances FLAKY_AppProcessInstances
169#else
170#define MAYBE_AppProcessInstances AppProcessInstances
171#endif
172
[email protected]056ad2a2011-07-12 02:13:55173// Test that hosted apps without the background permission use a process per app
174// instance model, such that separate instances are in separate processes.
[email protected]727db1f2011-07-19 19:35:02175IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcessInstances) {
[email protected]056ad2a2011-07-12 02:13:55176 CommandLine::ForCurrentProcess()->AppendSwitch(
177 switches::kDisablePopupBlocking);
178
179 host_resolver()->AddRule("*", "127.0.0.1");
180 ASSERT_TRUE(test_server()->Start());
181
182 ASSERT_TRUE(LoadExtension(
183 test_data_dir_.AppendASCII("app_process_instances")));
184
185 // Open two tabs in the app, one outside it.
[email protected]118d3122011-08-10 17:09:53186 GURL base_url = GetTestBaseURL("app_process_instances");
[email protected]056ad2a2011-07-12 02:13:55187
188 // Test both opening a URL in a new tab, and opening a tab and then navigating
189 // it. Either way, app tabs should be considered extension processes, but
190 // they have no elevated privileges and thus should not have WebUI bindings.
191 ui_test_utils::NavigateToURLWithDisposition(
192 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB,
193 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
194 EXPECT_TRUE(browser()->GetTabContentsAt(1)->render_view_host()->process()->
195 is_extension_process());
196 EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui());
197 browser()->NewTab();
198 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html"));
199 EXPECT_TRUE(browser()->GetTabContentsAt(2)->render_view_host()->process()->
200 is_extension_process());
201 EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui());
202
203 // We should have opened 2 new extension tabs. Including the original blank
204 // tab, we now have 3 tabs. The two app tabs should not be in the same
205 // process, since they do not have the background permission. (Thus, we want
206 // to separate them to improve responsiveness.)
207 ASSERT_EQ(3, browser()->tab_count());
208 RenderViewHost* host1 = browser()->GetTabContentsAt(1)->render_view_host();
209 RenderViewHost* host2 = browser()->GetTabContentsAt(2)->render_view_host();
210 EXPECT_NE(host1->process(), host2->process());
211
212 // Opening tabs with window.open should keep the page in the opener's process.
213 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile()));
214 WindowOpenHelper(browser(), host1,
215 base_url.Resolve("path1/empty.html"), true);
216 WindowOpenHelper(browser(), host2,
217 base_url.Resolve("path2/empty.html"), true);
218}
219
[email protected]faf407b2011-01-05 01:24:32220// Tests that app process switching works properly in the following scenario:
221// 1. navigate to a page1 in the app
222// 2. page1 redirects to a page2 outside the app extent (ie, "/server-redirect")
223// 3. page2 redirects back to a page in the app
224// The final navigation should end up in the app process.
225// See http://crbug.com/61757
226IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessRedirectBack) {
227 CommandLine::ForCurrentProcess()->AppendSwitch(
228 switches::kDisablePopupBlocking);
229
230 host_resolver()->AddRule("*", "127.0.0.1");
231 ASSERT_TRUE(test_server()->Start());
232
233 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process")));
234
235 // Open two tabs in the app.
[email protected]118d3122011-08-10 17:09:53236 GURL base_url = GetTestBaseURL("app_process");
[email protected]faf407b2011-01-05 01:24:32237
238 browser()->NewTab();
239 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
240 browser()->NewTab();
[email protected]faf407b2011-01-05 01:24:32241 // Wait until the second tab finishes its redirect train (2 hops).
[email protected]089e8c332011-01-06 21:37:29242 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
243 browser(), base_url.Resolve("path1/redirect.html"), 2);
[email protected]faf407b2011-01-05 01:24:32244
245 // 3 tabs, including the initial about:blank. The last 2 should be the same
246 // process.
247 ASSERT_EQ(3, browser()->tab_count());
[email protected]089e8c332011-01-06 21:37:29248 EXPECT_EQ("/files/extensions/api_test/app_process/path1/empty.html",
249 browser()->GetTabContentsAt(2)->controller().
250 GetLastCommittedEntry()->url().path());
[email protected]faf407b2011-01-05 01:24:32251 RenderViewHost* host = browser()->GetTabContentsAt(1)->render_view_host();
252 EXPECT_EQ(host->process(),
253 browser()->GetTabContentsAt(2)->render_view_host()->process());
254}
[email protected]d292d8a2011-05-25 03:47:11255
256// Ensure that reloading a URL after installing or uninstalling it as an app
257// correctly swaps the process. (http://crbug.com/80621)
258IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadIntoAppProcess) {
259 CommandLine::ForCurrentProcess()->AppendSwitch(
260 switches::kDisablePopupBlocking);
261
262 host_resolver()->AddRule("*", "127.0.0.1");
263 ASSERT_TRUE(test_server()->Start());
264
265 // The app under test acts on URLs whose host is "localhost",
266 // so the URLs we navigate to must have host "localhost".
[email protected]118d3122011-08-10 17:09:53267 GURL base_url = GetTestBaseURL("app_process");
[email protected]d292d8a2011-05-25 03:47:11268
269 // Load an app URL before loading the app.
270 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
271 TabContents* contents = browser()->GetTabContentsAt(0);
272 EXPECT_FALSE(contents->render_view_host()->process()->is_extension_process());
273
274 // Load app and reload page.
275 const Extension* app =
276 LoadExtension(test_data_dir_.AppendASCII("app_process"));
277 ASSERT_TRUE(app);
278 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
279 EXPECT_TRUE(contents->render_view_host()->process()->is_extension_process());
280
281 // Disable app and reload page.
282 DisableExtension(app->id());
283 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
284 EXPECT_FALSE(contents->render_view_host()->process()->is_extension_process());
285
286 // Enable app and reload via JavaScript.
287 EnableExtension(app->id());
[email protected]3114db2c2011-09-12 20:09:05288 ui_test_utils::WindowedNotificationObserver observer(
289 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
[email protected]d292d8a2011-05-25 03:47:11290 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->render_view_host(),
291 L"", L"location.reload();"));
[email protected]3114db2c2011-09-12 20:09:05292 observer.Wait();
[email protected]d292d8a2011-05-25 03:47:11293 EXPECT_TRUE(contents->render_view_host()->process()->is_extension_process());
294
295 // Disable app and reload via JavaScript.
296 DisableExtension(app->id());
[email protected]3114db2c2011-09-12 20:09:05297 ui_test_utils::WindowedNotificationObserver observer2(
298 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources());
[email protected]d292d8a2011-05-25 03:47:11299 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->render_view_host(),
300 L"", L"location.reload();"));
[email protected]3114db2c2011-09-12 20:09:05301 observer2.Wait();
[email protected]d292d8a2011-05-25 03:47:11302 EXPECT_FALSE(contents->render_view_host()->process()->is_extension_process());
303}
[email protected]118d3122011-08-10 17:09:53304
305
306// Tests that if we have a non-app process (path3/container.html) that has an
307// iframe with a URL in the app's extent (path1/iframe.html), then opening a
308// link from that iframe to a new window to a URL in the app's extent (path1/
309// empty.html) results in the new window being in an app process. See
310// http://crbug.com/89272 for more details.
311IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromIframe) {
312 CommandLine::ForCurrentProcess()->AppendSwitch(
313 switches::kDisablePopupBlocking);
314
315 host_resolver()->AddRule("*", "127.0.0.1");
316 ASSERT_TRUE(test_server()->Start());
317
318 GURL base_url = GetTestBaseURL("app_process");
319
320 // Load app and start URL (not in the app).
321 const Extension* app =
322 LoadExtension(test_data_dir_.AppendASCII("app_process"));
323 ASSERT_TRUE(app);
324 ui_test_utils::NavigateToURLWithDisposition(
325 browser(),
326 base_url.Resolve("path3/container.html"),
327 CURRENT_TAB,
328 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION |
329 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
330 EXPECT_FALSE(browser()->GetTabContentsAt(0)->render_view_host()->process()->
331 is_extension_process());
332
333 // Wait for popup window to appear.
334 GURL app_url = base_url.Resolve("path1/empty.html");
335 Browser* last_active_browser = BrowserList::GetLastActive();
336 EXPECT_TRUE(last_active_browser);
337 ASSERT_NE(browser(), last_active_browser);
338 TabContents* newtab = last_active_browser->GetSelectedTabContents();
339 EXPECT_TRUE(newtab);
340 if (!newtab->controller().GetLastCommittedEntry() ||
341 newtab->controller().GetLastCommittedEntry()->url() != app_url)
342 ui_test_utils::WaitForNavigation(&newtab->controller());
343
344 // Popup window should be in the app's process.
345 EXPECT_TRUE(last_active_browser->GetTabContentsAt(0)->render_view_host()->
346 process()->is_extension_process());
347}
[email protected]a09add52011-08-12 03:59:23348
[email protected]d55c2382011-08-18 23:10:36349// Tests that if we have an app process (path1/container.html) with a non-app
350// iframe (path3/iframe.html), then opening a link from that iframe to a new
351// window to a same-origin non-app URL (path3/empty.html) should keep the window
352// in the app process.
353// This is in contrast to OpenAppFromIframe, since here the popup will not be
354// missing special permissions and should be scriptable from the iframe.
355// See http://crbug.com/92669 for more details.
356IN_PROC_BROWSER_TEST_F(AppApiTest, OpenWebPopupFromWebIframe) {
357 CommandLine::ForCurrentProcess()->AppendSwitch(
358 switches::kDisablePopupBlocking);
359
360 host_resolver()->AddRule("*", "127.0.0.1");
361 ASSERT_TRUE(test_server()->Start());
362
363 GURL base_url = GetTestBaseURL("app_process");
364
365 // Load app and start URL (in the app).
366 const Extension* app =
367 LoadExtension(test_data_dir_.AppendASCII("app_process"));
368 ASSERT_TRUE(app);
369 ui_test_utils::NavigateToURLWithDisposition(
370 browser(),
371 base_url.Resolve("path1/container.html"),
372 CURRENT_TAB,
373 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION |
374 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
375 RenderProcessHost* process =
376 browser()->GetTabContentsAt(0)->render_view_host()->process();
377 EXPECT_TRUE(process->is_extension_process());
378
379 // Wait for popup window to appear. The new Browser may not have been
380 // added with SetLastActive, in which case we need to show it first.
381 // This is necessary for popup windows without a cross-site transition.
382 if (browser() == BrowserList::GetLastActive()) {
383 // Grab the second window and show it.
384 ASSERT_TRUE(BrowserList::size() == 2);
385 Browser* popup_browser = *(++BrowserList::begin());
386 popup_browser->window()->Show();
387 }
388 Browser* last_active_browser = BrowserList::GetLastActive();
389 EXPECT_TRUE(last_active_browser);
390 ASSERT_NE(browser(), last_active_browser);
391 TabContents* newtab = last_active_browser->GetSelectedTabContents();
392 EXPECT_TRUE(newtab);
393 GURL non_app_url = base_url.Resolve("path3/empty.html");
394 if (!newtab->controller().GetLastCommittedEntry() ||
395 newtab->controller().GetLastCommittedEntry()->url() != non_app_url)
396 ui_test_utils::WaitForNavigation(&newtab->controller());
397
398 // Popup window should be in the app's process.
399 RenderProcessHost* popup_process =
400 last_active_browser->GetTabContentsAt(0)->render_view_host()->process();
401 EXPECT_EQ(process, popup_process);
402}
403
[email protected]a09add52011-08-12 03:59:23404IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadAppAfterCrash) {
405 host_resolver()->AddRule("*", "127.0.0.1");
406 ASSERT_TRUE(test_server()->Start());
407
408 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process")));
409
410 GURL base_url = GetTestBaseURL("app_process");
411
412 // Load the app, chrome.app.isInstalled should be true.
413 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html"));
414 TabContents* contents = browser()->GetTabContentsAt(0);
415 EXPECT_TRUE(contents->render_view_host()->process()->is_extension_process());
416 bool is_installed = false;
417 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
418 contents->render_view_host(), L"",
419 L"window.domAutomationController.send(chrome.app.isInstalled)",
420 &is_installed));
421 ASSERT_TRUE(is_installed);
422
423 // Crash the tab and reload it, chrome.app.isInstalled should still be true.
424 ui_test_utils::CrashTab(browser()->GetSelectedTabContents());
[email protected]ae673742011-08-24 19:48:37425 ui_test_utils::WindowedNotificationObserver observer(
426 content::NOTIFICATION_LOAD_STOP,
427 Source<NavigationController>(
428 &browser()->GetSelectedTabContentsWrapper()->controller()));
[email protected]a09add52011-08-12 03:59:23429 browser()->Reload(CURRENT_TAB);
[email protected]ae673742011-08-24 19:48:37430 observer.Wait();
[email protected]a09add52011-08-12 03:59:23431 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
432 contents->render_view_host(), L"",
433 L"window.domAutomationController.send(chrome.app.isInstalled)",
434 &is_installed));
435 ASSERT_TRUE(is_installed);
436}