Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: chrome/browser/extensions/app_process_apitest.cc

Issue 10412047: Fix flakiness by removing GetLastActive from extension browser tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial patch Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/extensions/extension_apitest.h" 5 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "chrome/browser/extensions/extension_host.h" 6 #include "chrome/browser/extensions/extension_host.h"
8 #include "chrome/browser/extensions/extension_service.h" 7 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/process_map.h" 8 #include "chrome/browser/extensions/process_map.h"
10 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_finder.h" 11 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/browser_list.h" 12 #include "chrome/browser/ui/browser_list.h"
14 #include "chrome/browser/ui/browser_window.h" 13 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
16 #include "chrome/common/chrome_notification_types.h" 15 #include "chrome/common/chrome_notification_types.h"
17 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
19 #include "chrome/common/extensions/extension_file_util.h" 18 #include "chrome/common/extensions/extension_file_util.h"
20 #include "chrome/common/string_ordinal.h" 19 #include "chrome/common/string_ordinal.h"
21 #include "chrome/test/base/ui_test_utils.h" 20 #include "chrome/test/base/ui_test_utils.h"
22 #include "content/public/browser/navigation_entry.h" 21 #include "content/public/browser/navigation_entry.h"
23 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/render_process_host.h" 23 #include "content/public/browser/render_process_host.h"
25 #include "content/public/browser/render_view_host.h" 24 #include "content/public/browser/render_view_host.h"
26 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
27 #include "content/test/test_navigation_observer.h" 26 #include "content/test/test_navigation_observer.h"
28 #include "net/base/mock_host_resolver.h" 27 #include "net/base/mock_host_resolver.h"
29 28
30 using content::NavigationController; 29 using content::NavigationController;
31 using content::RenderViewHost; 30 using content::RenderViewHost;
32 using content::WebContents; 31 using content::WebContents;
33 using extensions::Extension; 32 using extensions::Extension;
34 33
35 // Simulates a page calling window.open on an URL, and waits for the navigation.
36 static void WindowOpenHelper(Browser* browser,
37 RenderViewHost* opener_host,
38 const GURL& url,
39 bool newtab_process_should_equal_opener) {
40 ui_test_utils::WindowedNotificationObserver observer(
41 content::NOTIFICATION_LOAD_STOP,
42 content::NotificationService::AllSources());
43 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
44 opener_host, L"", L"window.open('" + UTF8ToWide(url.spec()) + L"');"));
45
46 // 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 ASSERT_TRUE(last_active_browser);
51 WebContents* newtab = last_active_browser->GetSelectedWebContents();
52 ASSERT_TRUE(newtab);
53 observer.Wait();
54 EXPECT_EQ(url, newtab->GetController().GetLastCommittedEntry()->GetURL());
55 if (newtab_process_should_equal_opener)
56 EXPECT_EQ(opener_host->GetProcess(), newtab->GetRenderProcessHost());
57 else
58 EXPECT_NE(opener_host->GetProcess(), newtab->GetRenderProcessHost());
59 }
60
61 // Simulates a page navigating itself to an URL, and waits for the navigation.
62 static void NavigateTabHelper(WebContents* contents, const GURL& url) {
63 bool result = false;
64 ui_test_utils::WindowedNotificationObserver observer(
65 content::NOTIFICATION_LOAD_STOP,
66 content::NotificationService::AllSources());
67 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
68 contents->GetRenderViewHost(), L"",
69 L"window.addEventListener('unload', function() {"
70 L" window.domAutomationController.send(true);"
71 L"}, false);"
72 L"window.location = '" + UTF8ToWide(url.spec()) + L"';",
73 &result));
74 ASSERT_TRUE(result);
75 observer.Wait();
76 EXPECT_EQ(url, contents->GetController().GetLastCommittedEntry()->GetURL());
77 }
78
79 class AppApiTest : public ExtensionApiTest { 34 class AppApiTest : public ExtensionApiTest {
80 protected: 35 protected:
81 // Gets the base URL for files for a specific test, making sure that it uses 36 // Gets the base URL for files for a specific test, making sure that it uses
82 // "localhost" as the hostname, since that is what the extent is declared 37 // "localhost" as the hostname, since that is what the extent is declared
83 // as in the test apps manifests. 38 // as in the test apps manifests.
84 GURL GetTestBaseURL(std::string test_directory) { 39 GURL GetTestBaseURL(std::string test_directory) {
85 GURL::Replacements replace_host; 40 GURL::Replacements replace_host;
86 std::string host_str("localhost"); // must stay in scope with replace_host 41 std::string host_str("localhost"); // must stay in scope with replace_host
87 replace_host.SetHostStr(host_str); 42 replace_host.SetHostStr(host_str);
88 GURL base_url = test_server()->GetURL( 43 GURL base_url = test_server()->GetURL(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 LOG(INFO) << "Nav 2."; 94 LOG(INFO) << "Nav 2.";
140 EXPECT_TRUE(process_map->Contains( 95 EXPECT_TRUE(process_map->Contains(
141 browser()->GetWebContentsAt(2)->GetRenderProcessHost()->GetID())); 96 browser()->GetWebContentsAt(2)->GetRenderProcessHost()->GetID()));
142 EXPECT_FALSE(browser()->GetWebContentsAt(2)->GetWebUI()); 97 EXPECT_FALSE(browser()->GetWebContentsAt(2)->GetWebUI());
143 98
144 // We should have opened 2 new extension tabs. Including the original blank 99 // We should have opened 2 new extension tabs. Including the original blank
145 // tab, we now have 3 tabs. The two app tabs should not be in the same 100 // tab, we now have 3 tabs. The two app tabs should not be in the same
146 // process, since they do not have the background permission. (Thus, we 101 // process, since they do not have the background permission. (Thus, we
147 // want to separate them to improve responsiveness.) 102 // want to separate them to improve responsiveness.)
148 ASSERT_EQ(3, browser()->tab_count()); 103 ASSERT_EQ(3, browser()->tab_count());
149 RenderViewHost* host1 = browser()->GetWebContentsAt(1)->GetRenderViewHost(); 104 WebContents* tab1 = browser()->GetWebContentsAt(1);
150 RenderViewHost* host2 = browser()->GetWebContentsAt(2)->GetRenderViewHost(); 105 WebContents* tab2 = browser()->GetWebContentsAt(2);
151 EXPECT_NE(host1->GetProcess(), host2->GetProcess()); 106 EXPECT_NE(tab1->GetRenderProcessHost(), tab2->GetRenderProcessHost());
152 107
153 // Opening tabs with window.open should keep the page in the opener's 108 // Opening tabs with window.open should keep the page in the opener's
154 // process. 109 // process.
155 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile())); 110 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile()));
156 WindowOpenHelper(browser(), host1, 111 OpenWindow(tab1, base_url.Resolve("path1/empty.html"), true, NULL);
157 base_url.Resolve("path1/empty.html"), true);
158 LOG(INFO) << "WindowOpenHelper 1."; 112 LOG(INFO) << "WindowOpenHelper 1.";
159 WindowOpenHelper(browser(), host2, 113 OpenWindow(tab2, base_url.Resolve("path2/empty.html"), true, NULL);
160 base_url.Resolve("path2/empty.html"), true);
161 LOG(INFO) << "End of test."; 114 LOG(INFO) << "End of test.";
162 } 115 }
163 }; 116 };
164 117
165 // Tests that hosted apps with the background permission get a process-per-app 118 // Tests that hosted apps with the background permission get a process-per-app
166 // model, since all pages need to be able to script the background page. 119 // model, since all pages need to be able to script the background page.
167 #if defined(OS_WIN) 120 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcess) {
168 #define MAYBE_AppProcess FLAKY_AppProcess
169 #else
170 #define MAYBE_AppProcess AppProcess
171 #endif
172 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcess) {
173 LOG(INFO) << "Start of test."; 121 LOG(INFO) << "Start of test.";
174 122
175 extensions::ProcessMap* process_map = 123 extensions::ProcessMap* process_map =
176 browser()->profile()->GetExtensionService()->process_map(); 124 browser()->profile()->GetExtensionService()->process_map();
177 125
178 host_resolver()->AddRule("*", "127.0.0.1"); 126 host_resolver()->AddRule("*", "127.0.0.1");
179 ASSERT_TRUE(test_server()->Start()); 127 ASSERT_TRUE(test_server()->Start());
180 128
181 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); 129 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process")));
182 130
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 LOG(INFO) << "Nav 3."; 162 LOG(INFO) << "Nav 3.";
215 EXPECT_FALSE(process_map->Contains( 163 EXPECT_FALSE(process_map->Contains(
216 browser()->GetWebContentsAt(3)->GetRenderProcessHost()->GetID())); 164 browser()->GetWebContentsAt(3)->GetRenderProcessHost()->GetID()));
217 EXPECT_FALSE(browser()->GetWebContentsAt(3)->GetWebUI()); 165 EXPECT_FALSE(browser()->GetWebContentsAt(3)->GetWebUI());
218 166
219 // We should have opened 3 new extension tabs. Including the original blank 167 // We should have opened 3 new extension tabs. Including the original blank
220 // tab, we now have 4 tabs. Because the app_process app has the background 168 // tab, we now have 4 tabs. Because the app_process app has the background
221 // permission, all of its instances are in the same process. Thus two tabs 169 // permission, all of its instances are in the same process. Thus two tabs
222 // should be part of the extension app and grouped in the same process. 170 // should be part of the extension app and grouped in the same process.
223 ASSERT_EQ(4, browser()->tab_count()); 171 ASSERT_EQ(4, browser()->tab_count());
224 RenderViewHost* host = browser()->GetWebContentsAt(1)->GetRenderViewHost(); 172 WebContents* tab = browser()->GetWebContentsAt(1);
225 173
226 EXPECT_EQ(host->GetProcess(), 174 EXPECT_EQ(tab->GetRenderProcessHost(),
227 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); 175 browser()->GetWebContentsAt(2)->GetRenderProcessHost());
228 EXPECT_NE(host->GetProcess(), 176 EXPECT_NE(tab->GetRenderProcessHost(),
229 browser()->GetWebContentsAt(3)->GetRenderProcessHost()); 177 browser()->GetWebContentsAt(3)->GetRenderProcessHost());
230 178
231 // Now let's do the same using window.open. The same should happen. 179 // Now let's do the same using window.open. The same should happen.
232 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile())); 180 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile()));
233 WindowOpenHelper(browser(), host, 181 OpenWindow(tab, base_url.Resolve("path1/empty.html"), true, NULL);
234 base_url.Resolve("path1/empty.html"), true);
235 LOG(INFO) << "WindowOpenHelper 1."; 182 LOG(INFO) << "WindowOpenHelper 1.";
236 WindowOpenHelper(browser(), host, 183 OpenWindow(tab, base_url.Resolve("path2/empty.html"), true, NULL);
237 base_url.Resolve("path2/empty.html"), true);
238 LOG(INFO) << "WindowOpenHelper 2."; 184 LOG(INFO) << "WindowOpenHelper 2.";
239 // TODO(creis): This should open in a new process (i.e., false for the last 185 // TODO(creis): This should open in a new process (i.e., false for the last
240 // argument), but we temporarily avoid swapping processes away from an app 186 // argument), but we temporarily avoid swapping processes away from an app
241 // until we're able to support cross-process postMessage calls. 187 // until we're able to support cross-process postMessage calls.
242 // See crbug.com/59285. 188 // See crbug.com/59285.
243 WindowOpenHelper(browser(), host, 189 OpenWindow(tab, base_url.Resolve("path3/empty.html"), true, NULL);
244 base_url.Resolve("path3/empty.html"), true);
245 LOG(INFO) << "WindowOpenHelper 3."; 190 LOG(INFO) << "WindowOpenHelper 3.";
246 191
247 // Now let's have these pages navigate, into or out of the extension web 192 // Now let's have these pages navigate, into or out of the extension web
248 // extent. They should switch processes. 193 // extent. They should switch processes.
249 const GURL& app_url(base_url.Resolve("path1/empty.html")); 194 const GURL& app_url(base_url.Resolve("path1/empty.html"));
250 const GURL& non_app_url(base_url.Resolve("path3/empty.html")); 195 const GURL& non_app_url(base_url.Resolve("path3/empty.html"));
251 NavigateTabHelper(browser()->GetWebContentsAt(2), non_app_url); 196 NavigateInRenderer(browser()->GetWebContentsAt(2), non_app_url);
252 LOG(INFO) << "NavigateTabHelper 1."; 197 LOG(INFO) << "NavigateTabHelper 1.";
253 NavigateTabHelper(browser()->GetWebContentsAt(3), app_url); 198 NavigateInRenderer(browser()->GetWebContentsAt(3), app_url);
254 LOG(INFO) << "NavigateTabHelper 2."; 199 LOG(INFO) << "NavigateTabHelper 2.";
255 // TODO(creis): This should swap out of the app's process (i.e., EXPECT_NE), 200 // TODO(creis): This should swap out of the app's process (i.e., EXPECT_NE),
256 // but we temporarily avoid swapping away from an app in case the window 201 // but we temporarily avoid swapping away from an app in case the window
257 // tries to send a postMessage to the app. See crbug.com/59285. 202 // tries to send a postMessage to the app. See crbug.com/59285.
258 EXPECT_EQ(host->GetProcess(), 203 EXPECT_EQ(tab->GetRenderProcessHost(),
259 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); 204 browser()->GetWebContentsAt(2)->GetRenderProcessHost());
260 EXPECT_EQ(host->GetProcess(), 205 EXPECT_EQ(tab->GetRenderProcessHost(),
261 browser()->GetWebContentsAt(3)->GetRenderProcessHost()); 206 browser()->GetWebContentsAt(3)->GetRenderProcessHost());
262 207
263 // If one of the popup tabs navigates back to the app, window.opener should 208 // If one of the popup tabs navigates back to the app, window.opener should
264 // be valid. 209 // be valid.
265 NavigateTabHelper(browser()->GetWebContentsAt(6), app_url); 210 NavigateInRenderer(browser()->GetWebContentsAt(6), app_url);
266 LOG(INFO) << "NavigateTabHelper 3."; 211 LOG(INFO) << "NavigateTabHelper 3.";
267 EXPECT_EQ(host->GetProcess(), 212 EXPECT_EQ(tab->GetRenderProcessHost(),
268 browser()->GetWebContentsAt(6)->GetRenderProcessHost()); 213 browser()->GetWebContentsAt(6)->GetRenderProcessHost());
269 bool windowOpenerValid = false; 214 bool windowOpenerValid = false;
270 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 215 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
271 browser()->GetWebContentsAt(6)->GetRenderViewHost(), L"", 216 browser()->GetWebContentsAt(6)->GetRenderViewHost(), L"",
272 L"window.domAutomationController.send(window.opener != null)", 217 L"window.domAutomationController.send(window.opener != null)",
273 &windowOpenerValid)); 218 &windowOpenerValid));
274 ASSERT_TRUE(windowOpenerValid); 219 ASSERT_TRUE(windowOpenerValid);
275 220
276 LOG(INFO) << "End of test."; 221 LOG(INFO) << "End of test.";
277 } 222 }
278 223
279 // Test that hosted apps without the background permission use a process per app 224 // Test that hosted apps without the background permission use a process per app
280 // instance model, such that separate instances are in separate processes. 225 // instance model, such that separate instances are in separate processes.
281 #if defined(OS_WIN) 226 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessInstances) {
282 #define MAYBE_AppProcessInstances FLAKY_AppProcessInstances
283 #else
284 #define MAYBE_AppProcessInstances AppProcessInstances
285 #endif
286 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcessInstances) {
287 TestAppInstancesHelper("app_process_instances"); 227 TestAppInstancesHelper("app_process_instances");
288 } 228 }
289 229
290 // Test that hosted apps with the background permission but that set 230 // Test that hosted apps with the background permission but that set
291 // allow_js_access to false also use a process per app instance model. 231 // allow_js_access to false also use a process per app instance model.
292 // Separate instances should be in separate processes. 232 // Separate instances should be in separate processes.
293 #if defined(OS_WIN) 233 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessBackgroundInstances) {
294 #define MAYBE_AppProcessBackgroundInstances FLAKY_AppProcessBackgroundInstances
295 #else
296 #define MAYBE_AppProcessBackgroundInstances AppProcessBackgroundInstances
297 #endif
298 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcessBackgroundInstances) {
299 TestAppInstancesHelper("app_process_background_instances"); 234 TestAppInstancesHelper("app_process_background_instances");
300 } 235 }
301 236
302 // Tests that bookmark apps do not use the app process model and are treated 237 // Tests that bookmark apps do not use the app process model and are treated
303 // like normal web pages instead. http://crbug.com/104636. 238 // like normal web pages instead. http://crbug.com/104636.
304 #if defined(OS_WIN) 239 IN_PROC_BROWSER_TEST_F(AppApiTest, BookmarkAppGetsNormalProcess) {
305 #define MAYBE_BookmarkAppGetsNormalProcess FLAKY_BookmarkAppGetsNormalProcess
306 #else
307 #define MAYBE_BookmarkAppGetsNormalProcess BookmarkAppGetsNormalProcess
308 #endif
309 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_BookmarkAppGetsNormalProcess) {
310 ExtensionService* service = browser()->profile()->GetExtensionService(); 240 ExtensionService* service = browser()->profile()->GetExtensionService();
311 extensions::ProcessMap* process_map = service->process_map(); 241 extensions::ProcessMap* process_map = service->process_map();
312 242
313 host_resolver()->AddRule("*", "127.0.0.1"); 243 host_resolver()->AddRule("*", "127.0.0.1");
314 ASSERT_TRUE(test_server()->Start()); 244 ASSERT_TRUE(test_server()->Start());
315 GURL base_url = GetTestBaseURL("app_process"); 245 GURL base_url = GetTestBaseURL("app_process");
316 246
317 // Load an app as a bookmark app. 247 // Load an app as a bookmark app.
318 std::string error; 248 std::string error;
319 scoped_refptr<const Extension> extension(extension_file_util::LoadExtension( 249 scoped_refptr<const Extension> extension(extension_file_util::LoadExtension(
(...skipping 23 matching lines...) Expand all
343 tab_added_observer.Wait(); 273 tab_added_observer.Wait();
344 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); 274 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html"));
345 EXPECT_FALSE(process_map->Contains( 275 EXPECT_FALSE(process_map->Contains(
346 browser()->GetWebContentsAt(2)->GetRenderProcessHost()->GetID())); 276 browser()->GetWebContentsAt(2)->GetRenderProcessHost()->GetID()));
347 EXPECT_FALSE(browser()->GetWebContentsAt(2)->GetWebUI()); 277 EXPECT_FALSE(browser()->GetWebContentsAt(2)->GetWebUI());
348 278
349 // We should have opened 2 new bookmark app tabs. Including the original blank 279 // We should have opened 2 new bookmark app tabs. Including the original blank
350 // tab, we now have 3 tabs. Because normal pages use the 280 // tab, we now have 3 tabs. Because normal pages use the
351 // process-per-site-instance model, each should be in its own process. 281 // process-per-site-instance model, each should be in its own process.
352 ASSERT_EQ(3, browser()->tab_count()); 282 ASSERT_EQ(3, browser()->tab_count());
353 RenderViewHost* host = browser()->GetWebContentsAt(1)->GetRenderViewHost(); 283 WebContents* tab = browser()->GetWebContentsAt(1);
354 EXPECT_NE(host->GetProcess(), 284 EXPECT_NE(tab->GetRenderProcessHost(),
355 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); 285 browser()->GetWebContentsAt(2)->GetRenderProcessHost());
356 286
357 // Now let's do the same using window.open. The same should happen. 287 // Now let's do the same using window.open. The same should happen.
358 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile())); 288 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile()));
359 WindowOpenHelper(browser(), host, 289 OpenWindow(tab, base_url.Resolve("path1/empty.html"), true, NULL);
360 base_url.Resolve("path1/empty.html"), true); 290 OpenWindow(tab, base_url.Resolve("path2/empty.html"), true, NULL);
361 WindowOpenHelper(browser(), host,
362 base_url.Resolve("path2/empty.html"), true);
363 291
364 // Now let's have a tab navigate out of and back into the app's web 292 // Now let's have a tab navigate out of and back into the app's web
365 // extent. Neither navigation should switch processes. 293 // extent. Neither navigation should switch processes.
366 const GURL& app_url(base_url.Resolve("path1/empty.html")); 294 const GURL& app_url(base_url.Resolve("path1/empty.html"));
367 const GURL& non_app_url(base_url.Resolve("path3/empty.html")); 295 const GURL& non_app_url(base_url.Resolve("path3/empty.html"));
368 RenderViewHost* host2 = browser()->GetWebContentsAt(2)->GetRenderViewHost(); 296 RenderViewHost* host2 = browser()->GetWebContentsAt(2)->GetRenderViewHost();
369 NavigateTabHelper(browser()->GetWebContentsAt(2), non_app_url); 297 NavigateInRenderer(browser()->GetWebContentsAt(2), non_app_url);
370 EXPECT_EQ(host2->GetProcess(), 298 EXPECT_EQ(host2->GetProcess(),
371 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); 299 browser()->GetWebContentsAt(2)->GetRenderProcessHost());
372 NavigateTabHelper(browser()->GetWebContentsAt(2), app_url); 300 NavigateInRenderer(browser()->GetWebContentsAt(2), app_url);
373 EXPECT_EQ(host2->GetProcess(), 301 EXPECT_EQ(host2->GetProcess(),
374 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); 302 browser()->GetWebContentsAt(2)->GetRenderProcessHost());
375 } 303 }
376 304
377 // Tests that app process switching works properly in the following scenario: 305 // Tests that app process switching works properly in the following scenario:
378 // 1. navigate to a page1 in the app 306 // 1. navigate to a page1 in the app
379 // 2. page1 redirects to a page2 outside the app extent (ie, "/server-redirect") 307 // 2. page1 redirects to a page2 outside the app extent (ie, "/server-redirect")
380 // 3. page2 redirects back to a page in the app 308 // 3. page2 redirects back to a page in the app
381 // The final navigation should end up in the app process. 309 // The final navigation should end up in the app process.
382 // See http://crbug.com/61757 310 // See http://crbug.com/61757
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 js_reload_observer2.Wait(); 441 js_reload_observer2.Wait();
514 EXPECT_FALSE(process_map->Contains( 442 EXPECT_FALSE(process_map->Contains(
515 contents->GetRenderProcessHost()->GetID())); 443 contents->GetRenderProcessHost()->GetID()));
516 } 444 }
517 445
518 // Tests that if we have a non-app process (path3/container.html) that has an 446 // Tests that if we have a non-app process (path3/container.html) that has an
519 // iframe with a URL in the app's extent (path1/iframe.html), then opening a 447 // iframe with a URL in the app's extent (path1/iframe.html), then opening a
520 // link from that iframe to a new window to a URL in the app's extent (path1/ 448 // link from that iframe to a new window to a URL in the app's extent (path1/
521 // empty.html) results in the new window being in an app process. See 449 // empty.html) results in the new window being in an app process. See
522 // http://crbug.com/89272 for more details. 450 // http://crbug.com/89272 for more details.
523 #if defined(OS_WIN) 451 IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromIframe) {
524 #define MAYBE_OpenAppFromIframe FLAKY_OpenAppFromIframe
525 #else
526 #define MAYBE_OpenAppFromIframe OpenAppFromIframe
527 #endif
528 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_OpenAppFromIframe) {
529 extensions::ProcessMap* process_map = 452 extensions::ProcessMap* process_map =
530 browser()->profile()->GetExtensionService()->process_map(); 453 browser()->profile()->GetExtensionService()->process_map();
531 454
532 host_resolver()->AddRule("*", "127.0.0.1"); 455 host_resolver()->AddRule("*", "127.0.0.1");
533 ASSERT_TRUE(test_server()->Start()); 456 ASSERT_TRUE(test_server()->Start());
534 457
535 GURL base_url = GetTestBaseURL("app_process"); 458 GURL base_url = GetTestBaseURL("app_process");
536 459
537 // Load app and start URL (not in the app). 460 // Load app and start URL (not in the app).
538 const Extension* app = 461 const Extension* app =
539 LoadExtension(test_data_dir_.AppendASCII("app_process")); 462 LoadExtension(test_data_dir_.AppendASCII("app_process"));
540 ASSERT_TRUE(app); 463 ASSERT_TRUE(app);
541 ui_test_utils::NavigateToURLWithDisposition( 464
542 browser(), 465 ui_test_utils::WindowedNotificationObserver popup_observer(
543 base_url.Resolve("path3/container.html"), 466 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED,
544 CURRENT_TAB, 467 content::NotificationService::AllSources());
545 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION | 468 ui_test_utils::NavigateToURL(browser(),
546 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); 469 base_url.Resolve("path3/container.html"));
547 EXPECT_FALSE(process_map->Contains( 470 EXPECT_FALSE(process_map->Contains(
548 browser()->GetWebContentsAt(0)->GetRenderProcessHost()->GetID())); 471 browser()->GetWebContentsAt(0)->GetRenderProcessHost()->GetID()));
549 472 popup_observer.Wait();
550 // Wait for popup window to appear.
551 GURL app_url = base_url.Resolve("path1/empty.html");
552 Browser* last_active_browser = BrowserList::GetLastActive();
553 EXPECT_TRUE(last_active_browser);
554 ASSERT_NE(browser(), last_active_browser);
555 WebContents* newtab = last_active_browser->GetSelectedWebContents();
556 EXPECT_TRUE(newtab);
557 if (!newtab->GetController().GetLastCommittedEntry() ||
558 newtab->GetController().GetLastCommittedEntry()->GetURL() != app_url) {
559 // TODO(gbillock): This still looks racy. Need to make a custom
560 // observer to intercept new window creation and then look for
561 // NAV_ENTRY_COMMITTED on the new tab there.
562 ui_test_utils::WindowedNotificationObserver observer(
563 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
564 content::Source<NavigationController>(&(newtab->GetController())));
565 observer.Wait();
566 }
567 473
568 // Popup window should be in the app's process. 474 // Popup window should be in the app's process.
569 EXPECT_TRUE(process_map->Contains( 475 RenderViewHost* popup_host =
570 last_active_browser->GetWebContentsAt(0)->GetRenderProcessHost()-> 476 content::Source<RenderViewHost>(popup_observer.source()).ptr();
571 GetID())); 477 EXPECT_TRUE(process_map->Contains(popup_host->GetProcess()->GetID()));
572 } 478 }
573 479
574 // Tests that if an extension launches an app via chrome.tabs.create with an URL 480 // Tests that if an extension launches an app via chrome.tabs.create with an URL
575 // that's not in the app's extent but that redirects to it, we still end up with 481 // that's not in the app's extent but that redirects to it, we still end up with
576 // an app process. See http://crbug.com/99349 for more details. 482 // an app process. See http://crbug.com/99349 for more details.
577 IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromExtension) { 483 IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromExtension) {
578 host_resolver()->AddRule("*", "127.0.0.1"); 484 host_resolver()->AddRule("*", "127.0.0.1");
579 ASSERT_TRUE(StartTestServer()); 485 ASSERT_TRUE(StartTestServer());
580 486
581 LoadExtension(test_data_dir_.AppendASCII("app_process")); 487 LoadExtension(test_data_dir_.AppendASCII("app_process"));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 ASSERT_TRUE(is_installed); 519 ASSERT_TRUE(is_installed);
614 } 520 }
615 521
616 // Tests that if we have an app process (path1/container.html) with a non-app 522 // Tests that if we have an app process (path1/container.html) with a non-app
617 // iframe (path3/iframe.html), then opening a link from that iframe to a new 523 // iframe (path3/iframe.html), then opening a link from that iframe to a new
618 // window to a same-origin non-app URL (path3/empty.html) should keep the window 524 // window to a same-origin non-app URL (path3/empty.html) should keep the window
619 // in the app process. 525 // in the app process.
620 // This is in contrast to OpenAppFromIframe, since here the popup will not be 526 // This is in contrast to OpenAppFromIframe, since here the popup will not be
621 // missing special permissions and should be scriptable from the iframe. 527 // missing special permissions and should be scriptable from the iframe.
622 // See http://crbug.com/92669 for more details. 528 // See http://crbug.com/92669 for more details.
623 #if defined(OS_WIN) 529 IN_PROC_BROWSER_TEST_F(AppApiTest, OpenWebPopupFromWebIframe) {
624 #define MAYBE_OpenWebPopupFromWebIframe FLAKY_OpenWebPopupFromWebIframe
625 #else
626 #define MAYBE_OpenWebPopupFromWebIframe OpenWebPopupFromWebIframe
627 #endif
628 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_OpenWebPopupFromWebIframe) {
629 extensions::ProcessMap* process_map = 530 extensions::ProcessMap* process_map =
630 browser()->profile()->GetExtensionService()->process_map(); 531 browser()->profile()->GetExtensionService()->process_map();
631 532
632 host_resolver()->AddRule("*", "127.0.0.1"); 533 host_resolver()->AddRule("*", "127.0.0.1");
633 ASSERT_TRUE(test_server()->Start()); 534 ASSERT_TRUE(test_server()->Start());
634 535
635 GURL base_url = GetTestBaseURL("app_process"); 536 GURL base_url = GetTestBaseURL("app_process");
636 537
637 // Load app and start URL (in the app). 538 // Load app and start URL (in the app).
638 const Extension* app = 539 const Extension* app =
639 LoadExtension(test_data_dir_.AppendASCII("app_process")); 540 LoadExtension(test_data_dir_.AppendASCII("app_process"));
640 ASSERT_TRUE(app); 541 ASSERT_TRUE(app);
641 ui_test_utils::WindowedNotificationObserver observer( 542
642 content::NOTIFICATION_LOAD_STOP, 543 ui_test_utils::WindowedNotificationObserver popup_observer(
643 content::NotificationService::AllSources()); 544 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED,
644 ui_test_utils::NavigateToURLWithDisposition( 545 content::NotificationService::AllSources());
645 browser(), 546 ui_test_utils::NavigateToURL(browser(),
646 base_url.Resolve("path1/container.html"), 547 base_url.Resolve("path1/container.html"));
647 CURRENT_TAB,
648 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION |
649 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
650 content::RenderProcessHost* process = 548 content::RenderProcessHost* process =
651 browser()->GetWebContentsAt(0)->GetRenderProcessHost(); 549 browser()->GetWebContentsAt(0)->GetRenderProcessHost();
652 EXPECT_TRUE(process_map->Contains(process->GetID())); 550 EXPECT_TRUE(process_map->Contains(process->GetID()));
653 551
654 // Wait for popup window to appear. The new Browser may not have been 552 // Wait for popup window to appear.
655 // added with SetLastActive, in which case we need to show it first. 553 popup_observer.Wait();
656 // This is necessary for popup windows without a cross-site transition.
657 if (browser() == BrowserList::GetLastActive()) {
658 // Grab the second window and show it.
659 ASSERT_TRUE(BrowserList::size() == 2);
660 Browser* popup_browser = *(++BrowserList::begin());
661 popup_browser->window()->Show();
662 }
663 Browser* last_active_browser = BrowserList::GetLastActive();
664 EXPECT_TRUE(last_active_browser);
665 ASSERT_NE(browser(), last_active_browser);
666 WebContents* newtab = last_active_browser->GetSelectedWebContents();
667 EXPECT_TRUE(newtab);
668 GURL non_app_url = base_url.Resolve("path3/empty.html");
669 observer.Wait();
670 554
671 // Popup window should be in the app's process. 555 // Popup window should be in the app's process.
672 content::RenderProcessHost* popup_process = 556 RenderViewHost* popup_host =
673 last_active_browser->GetWebContentsAt(0)->GetRenderProcessHost(); 557 content::Source<RenderViewHost>(popup_observer.source()).ptr();
674 EXPECT_EQ(process, popup_process); 558 EXPECT_EQ(process, popup_host->GetProcess());
675 } 559 }
676 560
677 // http://crbug.com/118502 561 // http://crbug.com/118502
678 #if defined(OS_MACOSX) || defined(OS_LINUX) 562 #if defined(OS_MACOSX) || defined(OS_LINUX)
679 #define MAYBE_ReloadAppAfterCrash DISABLED_ReloadAppAfterCrash 563 #define MAYBE_ReloadAppAfterCrash DISABLED_ReloadAppAfterCrash
680 #else 564 #else
681 #define MAYBE_ReloadAppAfterCrash ReloadAppAfterCrash 565 #define MAYBE_ReloadAppAfterCrash ReloadAppAfterCrash
682 #endif 566 #endif
683 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_ReloadAppAfterCrash) { 567 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_ReloadAppAfterCrash) {
684 extensions::ProcessMap* process_map = 568 extensions::ProcessMap* process_map =
(...skipping 26 matching lines...) Expand all
711 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> 595 &browser()->GetSelectedTabContentsWrapper()->web_contents()->
712 GetController())); 596 GetController()));
713 browser()->Reload(CURRENT_TAB); 597 browser()->Reload(CURRENT_TAB);
714 observer.Wait(); 598 observer.Wait();
715 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 599 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
716 contents->GetRenderViewHost(), L"", 600 contents->GetRenderViewHost(), L"",
717 L"window.domAutomationController.send(chrome.app.isInstalled)", 601 L"window.domAutomationController.send(chrome.app.isInstalled)",
718 &is_installed)); 602 &is_installed));
719 ASSERT_TRUE(is_installed); 603 ASSERT_TRUE(is_installed);
720 } 604 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_browsertest.h » ('j') | chrome/browser/extensions/extension_browsertest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698