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

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

Issue 8401023: Fix flakiness in NewTab() calls of AppApiTest browser_test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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" 5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/extensions/extension_apitest.h" 6 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "chrome/browser/extensions/extension_host.h" 7 #include "chrome/browser/extensions/extension_host.h"
8 #include "chrome/browser/extensions/extension_process_manager.h" 8 #include "chrome/browser/extensions/extension_process_manager.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 L"window.addEventListener('unload', function() {" 71 L"window.addEventListener('unload', function() {"
72 L" window.domAutomationController.send(true);" 72 L" window.domAutomationController.send(true);"
73 L"}, false);" 73 L"}, false);"
74 L"window.location = '" + UTF8ToWide(url.spec()) + L"';", 74 L"window.location = '" + UTF8ToWide(url.spec()) + L"';",
75 &result)); 75 &result));
76 ASSERT_TRUE(result); 76 ASSERT_TRUE(result);
77 observer.Wait(); 77 observer.Wait();
78 EXPECT_EQ(url, contents->controller().GetLastCommittedEntry()->url()); 78 EXPECT_EQ(url, contents->controller().GetLastCommittedEntry()->url());
79 } 79 }
80 80
81 #if defined(OS_WIN) 81 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcess) {
82 // AppProcess sometimes hangs on Windows 82 LOG(INFO) << "Start of test.";
83 // http://crbug.com/88316
84 #define MAYBE_AppProcess DISABLED_AppProcess
85 #else
86 #define MAYBE_AppProcess AppProcess
87 #endif
88 83
89 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcess) {
90 CommandLine::ForCurrentProcess()->AppendSwitch( 84 CommandLine::ForCurrentProcess()->AppendSwitch(
91 switches::kDisablePopupBlocking); 85 switches::kDisablePopupBlocking);
92 86
93 ExtensionProcessManager* extension_process_manager = 87 ExtensionProcessManager* extension_process_manager =
94 browser()->profile()->GetExtensionProcessManager(); 88 browser()->profile()->GetExtensionProcessManager();
95 89
96 host_resolver()->AddRule("*", "127.0.0.1"); 90 host_resolver()->AddRule("*", "127.0.0.1");
97 ASSERT_TRUE(test_server()->Start()); 91 ASSERT_TRUE(test_server()->Start());
98 92
99 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); 93 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process")));
100 94
95 LOG(INFO) << "Loaded extension.";
96
101 // Open two tabs in the app, one outside it. 97 // Open two tabs in the app, one outside it.
102 GURL base_url = GetTestBaseURL("app_process"); 98 GURL base_url = GetTestBaseURL("app_process");
103 99
104 // Test both opening a URL in a new tab, and opening a tab and then navigating 100 // Test both opening a URL in a new tab, and opening a tab and then navigating
105 // it. Either way, app tabs should be considered extension processes, but 101 // it. Either way, app tabs should be considered extension processes, but
106 // they have no elevated privileges and thus should not have WebUI bindings. 102 // they have no elevated privileges and thus should not have WebUI bindings.
107 ui_test_utils::NavigateToURLWithDisposition( 103 ui_test_utils::NavigateToURLWithDisposition(
108 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, 104 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB,
109 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 105 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
110 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( 106 EXPECT_TRUE(extension_process_manager->IsExtensionProcess(
111 browser()->GetTabContentsAt(1)->render_view_host()->process()->id())); 107 browser()->GetTabContentsAt(1)->render_view_host()->process()->id()));
112 EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui()); 108 EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui());
113 browser()->NewTab(); 109 LOG(INFO) << "Nav 1.";
114 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); 110
111 ui_test_utils::NavigateToURLWithDisposition(
112 browser(), base_url.Resolve("path2/empty.html"), NEW_FOREGROUND_TAB,
113 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
115 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( 114 EXPECT_TRUE(extension_process_manager->IsExtensionProcess(
116 browser()->GetTabContentsAt(2)->render_view_host()->process()->id())); 115 browser()->GetTabContentsAt(2)->render_view_host()->process()->id()));
117 EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui()); 116 EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui());
117 LOG(INFO) << "Nav 2.";
118
119 ui_test_utils::WindowedNotificationObserver tab_added_observer(
120 content::NOTIFICATION_TAB_ADDED,
121 content::NotificationService::AllSources());
118 browser()->NewTab(); 122 browser()->NewTab();
123 tab_added_observer.Wait();
124 LOG(INFO) << "New tab.";
119 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path3/empty.html")); 125 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path3/empty.html"));
126 LOG(INFO) << "Nav 3.";
120 EXPECT_FALSE(extension_process_manager->IsExtensionProcess( 127 EXPECT_FALSE(extension_process_manager->IsExtensionProcess(
121 browser()->GetTabContentsAt(3)->render_view_host()->process()->id())); 128 browser()->GetTabContentsAt(3)->render_view_host()->process()->id()));
122 EXPECT_FALSE(browser()->GetTabContentsAt(3)->web_ui()); 129 EXPECT_FALSE(browser()->GetTabContentsAt(3)->web_ui());
123 130
124 // We should have opened 3 new extension tabs. Including the original blank 131 // We should have opened 3 new extension tabs. Including the original blank
125 // tab, we now have 4 tabs. Because the app_process app has the background 132 // tab, we now have 4 tabs. Because the app_process app has the background
126 // permission, all of its instances are in the same process. Thus two tabs 133 // permission, all of its instances are in the same process. Thus two tabs
127 // should be part of the extension app and grouped in the same process. 134 // should be part of the extension app and grouped in the same process.
128 ASSERT_EQ(4, browser()->tab_count()); 135 ASSERT_EQ(4, browser()->tab_count());
129 RenderViewHost* host = browser()->GetTabContentsAt(1)->render_view_host(); 136 RenderViewHost* host = browser()->GetTabContentsAt(1)->render_view_host();
130 137
131 EXPECT_EQ(host->process(), 138 EXPECT_EQ(host->process(),
132 browser()->GetTabContentsAt(2)->render_view_host()->process()); 139 browser()->GetTabContentsAt(2)->render_view_host()->process());
133 EXPECT_NE(host->process(), 140 EXPECT_NE(host->process(),
134 browser()->GetTabContentsAt(3)->render_view_host()->process()); 141 browser()->GetTabContentsAt(3)->render_view_host()->process());
135 142
136 // Now let's do the same using window.open. The same should happen. 143 // Now let's do the same using window.open. The same should happen.
137 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile())); 144 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile()));
138 WindowOpenHelper(browser(), host, 145 WindowOpenHelper(browser(), host,
139 base_url.Resolve("path1/empty.html"), true); 146 base_url.Resolve("path1/empty.html"), true);
147 LOG(INFO) << "WindowOpenHelper 1.";
140 WindowOpenHelper(browser(), host, 148 WindowOpenHelper(browser(), host,
141 base_url.Resolve("path2/empty.html"), true); 149 base_url.Resolve("path2/empty.html"), true);
150 LOG(INFO) << "WindowOpenHelper 2.";
142 // TODO(creis): This should open in a new process (i.e., false for the last 151 // TODO(creis): This should open in a new process (i.e., false for the last
143 // argument), but we temporarily avoid swapping processes away from an app 152 // argument), but we temporarily avoid swapping processes away from an app
144 // until we're able to support cross-process postMessage calls. 153 // until we're able to support cross-process postMessage calls.
145 // See crbug.com/59285. 154 // See crbug.com/59285.
146 WindowOpenHelper(browser(), host, 155 WindowOpenHelper(browser(), host,
147 base_url.Resolve("path3/empty.html"), true); 156 base_url.Resolve("path3/empty.html"), true);
157 LOG(INFO) << "WindowOpenHelper 3.";
148 158
149 // Now let's have these pages navigate, into or out of the extension web 159 // Now let's have these pages navigate, into or out of the extension web
150 // extent. They should switch processes. 160 // extent. They should switch processes.
151 const GURL& app_url(base_url.Resolve("path1/empty.html")); 161 const GURL& app_url(base_url.Resolve("path1/empty.html"));
152 const GURL& non_app_url(base_url.Resolve("path3/empty.html")); 162 const GURL& non_app_url(base_url.Resolve("path3/empty.html"));
153 NavigateTabHelper(browser()->GetTabContentsAt(2), non_app_url); 163 NavigateTabHelper(browser()->GetTabContentsAt(2), non_app_url);
164 LOG(INFO) << "NavigateTabHelper 1.";
154 NavigateTabHelper(browser()->GetTabContentsAt(3), app_url); 165 NavigateTabHelper(browser()->GetTabContentsAt(3), app_url);
166 LOG(INFO) << "NavigateTabHelper 2.";
155 // TODO(creis): This should swap out of the app's process (i.e., EXPECT_NE), 167 // TODO(creis): This should swap out of the app's process (i.e., EXPECT_NE),
156 // but we temporarily avoid swapping away from an app in case the window 168 // but we temporarily avoid swapping away from an app in case the window
157 // tries to send a postMessage to the app. See crbug.com/59285. 169 // tries to send a postMessage to the app. See crbug.com/59285.
158 EXPECT_EQ(host->process(), 170 EXPECT_EQ(host->process(),
159 browser()->GetTabContentsAt(2)->render_view_host()->process()); 171 browser()->GetTabContentsAt(2)->render_view_host()->process());
160 EXPECT_EQ(host->process(), 172 EXPECT_EQ(host->process(),
161 browser()->GetTabContentsAt(3)->render_view_host()->process()); 173 browser()->GetTabContentsAt(3)->render_view_host()->process());
162 174
163 // If one of the popup tabs navigates back to the app, window.opener should 175 // If one of the popup tabs navigates back to the app, window.opener should
164 // be valid. 176 // be valid.
165 NavigateTabHelper(browser()->GetTabContentsAt(6), app_url); 177 NavigateTabHelper(browser()->GetTabContentsAt(6), app_url);
178 LOG(INFO) << "NavigateTabHelper 3.";
166 EXPECT_EQ(host->process(), 179 EXPECT_EQ(host->process(),
167 browser()->GetTabContentsAt(6)->render_view_host()->process()); 180 browser()->GetTabContentsAt(6)->render_view_host()->process());
168 bool windowOpenerValid = false; 181 bool windowOpenerValid = false;
169 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 182 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
170 browser()->GetTabContentsAt(6)->render_view_host(), L"", 183 browser()->GetTabContentsAt(6)->render_view_host(), L"",
171 L"window.domAutomationController.send(window.opener != null)", 184 L"window.domAutomationController.send(window.opener != null)",
172 &windowOpenerValid)); 185 &windowOpenerValid));
173 ASSERT_TRUE(windowOpenerValid); 186 ASSERT_TRUE(windowOpenerValid);
187
188 LOG(INFO) << "End of test.";
174 } 189 }
175 190
176
177 #if defined(OS_WIN)
178 // Seems to timeout sometimes on Windows: http://crbug.com/89766
179 #define MAYBE_AppProcessInstances FLAKY_AppProcessInstances
180 #else
181 #define MAYBE_AppProcessInstances AppProcessInstances
182 #endif
183
184 // Test that hosted apps without the background permission use a process per app 191 // Test that hosted apps without the background permission use a process per app
185 // instance model, such that separate instances are in separate processes. 192 // instance model, such that separate instances are in separate processes.
186 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcessInstances) { 193 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessInstances) {
194 LOG(INFO) << "Start of test.";
195
187 CommandLine::ForCurrentProcess()->AppendSwitch( 196 CommandLine::ForCurrentProcess()->AppendSwitch(
188 switches::kDisablePopupBlocking); 197 switches::kDisablePopupBlocking);
189 198
190 ExtensionProcessManager* extension_process_manager = 199 ExtensionProcessManager* extension_process_manager =
191 browser()->profile()->GetExtensionProcessManager(); 200 browser()->profile()->GetExtensionProcessManager();
192 201
193 host_resolver()->AddRule("*", "127.0.0.1"); 202 host_resolver()->AddRule("*", "127.0.0.1");
194 ASSERT_TRUE(test_server()->Start()); 203 ASSERT_TRUE(test_server()->Start());
195 204
196 ASSERT_TRUE(LoadExtension( 205 ASSERT_TRUE(LoadExtension(
197 test_data_dir_.AppendASCII("app_process_instances"))); 206 test_data_dir_.AppendASCII("app_process_instances")));
198 207
199 // Open two tabs in the app, one outside it. 208 // Open two tabs in the app, one outside it.
200 GURL base_url = GetTestBaseURL("app_process_instances"); 209 GURL base_url = GetTestBaseURL("app_process_instances");
201 210
202 // Test both opening a URL in a new tab, and opening a tab and then navigating 211 // Test both opening a URL in a new tab, and opening a tab and then navigating
203 // it. Either way, app tabs should be considered extension processes, but 212 // it. Either way, app tabs should be considered extension processes, but
204 // they have no elevated privileges and thus should not have WebUI bindings. 213 // they have no elevated privileges and thus should not have WebUI bindings.
205 ui_test_utils::NavigateToURLWithDisposition( 214 ui_test_utils::NavigateToURLWithDisposition(
206 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, 215 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB,
207 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 216 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
217 LOG(INFO) << "Nav 1.";
208 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( 218 EXPECT_TRUE(extension_process_manager->IsExtensionProcess(
209 browser()->GetTabContentsAt(1)->render_view_host()->process()->id())); 219 browser()->GetTabContentsAt(1)->render_view_host()->process()->id()));
210 EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui()); 220 EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui());
221
222 ui_test_utils::WindowedNotificationObserver tab_added_observer(
223 content::NOTIFICATION_TAB_ADDED,
224 content::NotificationService::AllSources());
211 browser()->NewTab(); 225 browser()->NewTab();
226 tab_added_observer.Wait();
227 LOG(INFO) << "New tab.";
212 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); 228 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html"));
229 LOG(INFO) << "Nav 2.";
213 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( 230 EXPECT_TRUE(extension_process_manager->IsExtensionProcess(
214 browser()->GetTabContentsAt(2)->render_view_host()->process()->id())); 231 browser()->GetTabContentsAt(2)->render_view_host()->process()->id()));
215 EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui()); 232 EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui());
216 233
217 // We should have opened 2 new extension tabs. Including the original blank 234 // We should have opened 2 new extension tabs. Including the original blank
218 // tab, we now have 3 tabs. The two app tabs should not be in the same 235 // tab, we now have 3 tabs. The two app tabs should not be in the same
219 // process, since they do not have the background permission. (Thus, we want 236 // process, since they do not have the background permission. (Thus, we want
220 // to separate them to improve responsiveness.) 237 // to separate them to improve responsiveness.)
221 ASSERT_EQ(3, browser()->tab_count()); 238 ASSERT_EQ(3, browser()->tab_count());
222 RenderViewHost* host1 = browser()->GetTabContentsAt(1)->render_view_host(); 239 RenderViewHost* host1 = browser()->GetTabContentsAt(1)->render_view_host();
223 RenderViewHost* host2 = browser()->GetTabContentsAt(2)->render_view_host(); 240 RenderViewHost* host2 = browser()->GetTabContentsAt(2)->render_view_host();
224 EXPECT_NE(host1->process(), host2->process()); 241 EXPECT_NE(host1->process(), host2->process());
225 242
226 // Opening tabs with window.open should keep the page in the opener's process. 243 // Opening tabs with window.open should keep the page in the opener's process.
227 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile())); 244 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile()));
228 WindowOpenHelper(browser(), host1, 245 WindowOpenHelper(browser(), host1,
229 base_url.Resolve("path1/empty.html"), true); 246 base_url.Resolve("path1/empty.html"), true);
247 LOG(INFO) << "WindowOpenHelper 1.";
230 WindowOpenHelper(browser(), host2, 248 WindowOpenHelper(browser(), host2,
231 base_url.Resolve("path2/empty.html"), true); 249 base_url.Resolve("path2/empty.html"), true);
250 LOG(INFO) << "End of test.";
232 } 251 }
233 252
234 // Tests that app process switching works properly in the following scenario: 253 // Tests that app process switching works properly in the following scenario:
235 // 1. navigate to a page1 in the app 254 // 1. navigate to a page1 in the app
236 // 2. page1 redirects to a page2 outside the app extent (ie, "/server-redirect") 255 // 2. page1 redirects to a page2 outside the app extent (ie, "/server-redirect")
237 // 3. page2 redirects back to a page in the app 256 // 3. page2 redirects back to a page in the app
238 // The final navigation should end up in the app process. 257 // The final navigation should end up in the app process.
239 // See http://crbug.com/61757 258 // See http://crbug.com/61757
240 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessRedirectBack) { 259 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessRedirectBack) {
241 CommandLine::ForCurrentProcess()->AppendSwitch( 260 CommandLine::ForCurrentProcess()->AppendSwitch(
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 content::Source<NavigationController>( 513 content::Source<NavigationController>(
495 &browser()->GetSelectedTabContentsWrapper()->controller())); 514 &browser()->GetSelectedTabContentsWrapper()->controller()));
496 browser()->Reload(CURRENT_TAB); 515 browser()->Reload(CURRENT_TAB);
497 observer.Wait(); 516 observer.Wait();
498 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 517 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
499 contents->render_view_host(), L"", 518 contents->render_view_host(), L"",
500 L"window.domAutomationController.send(chrome.app.isInstalled)", 519 L"window.domAutomationController.send(chrome.app.isInstalled)",
501 &is_installed)); 520 &is_installed));
502 ASSERT_TRUE(is_installed); 521 ASSERT_TRUE(is_installed);
503 } 522 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698