OLD | NEW |
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 "chrome/browser/extensions/extension_apitest.h" | 5 #include "chrome/browser/extensions/extension_apitest.h" |
6 #include "chrome/browser/extensions/extension_host.h" | 6 #include "chrome/browser/extensions/extension_host.h" |
7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
8 #include "chrome/browser/extensions/process_map.h" | 8 #include "chrome/browser/extensions/process_map.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" |
11 #include "chrome/browser/ui/browser_commands.h" | 11 #include "chrome/browser/ui/browser_commands.h" |
12 #include "chrome/browser/ui/browser_finder.h" | 12 #include "chrome/browser/ui/browser_finder.h" |
13 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
| 14 #include "chrome/browser/ui/browser_tabstrip.h" |
14 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
15 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 16 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
16 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
19 #include "chrome/common/extensions/extension_file_util.h" | 20 #include "chrome/common/extensions/extension_file_util.h" |
20 #include "chrome/common/string_ordinal.h" | 21 #include "chrome/common/string_ordinal.h" |
21 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
22 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
23 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 75 |
75 // Test both opening a URL in a new tab, and opening a tab and then | 76 // Test both opening a URL in a new tab, and opening a tab and then |
76 // navigating it. Either way, app tabs should be considered extension | 77 // navigating it. Either way, app tabs should be considered extension |
77 // processes, but they have no elevated privileges and thus should not | 78 // processes, but they have no elevated privileges and thus should not |
78 // have WebUI bindings. | 79 // have WebUI bindings. |
79 ui_test_utils::NavigateToURLWithDisposition( | 80 ui_test_utils::NavigateToURLWithDisposition( |
80 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, | 81 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, |
81 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 82 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
82 LOG(INFO) << "Nav 1."; | 83 LOG(INFO) << "Nav 1."; |
83 EXPECT_TRUE(process_map->Contains( | 84 EXPECT_TRUE(process_map->Contains( |
84 browser()->GetWebContentsAt(1)->GetRenderProcessHost()->GetID())); | 85 chrome::GetWebContentsAt(browser(), 1)->GetRenderProcessHost()->GetID())); |
85 EXPECT_FALSE(browser()->GetWebContentsAt(1)->GetWebUI()); | 86 EXPECT_FALSE(chrome::GetWebContentsAt(browser(), 1)->GetWebUI()); |
86 | 87 |
87 ui_test_utils::WindowedNotificationObserver tab_added_observer( | 88 ui_test_utils::WindowedNotificationObserver tab_added_observer( |
88 chrome::NOTIFICATION_TAB_ADDED, | 89 chrome::NOTIFICATION_TAB_ADDED, |
89 content::NotificationService::AllSources()); | 90 content::NotificationService::AllSources()); |
90 chrome::NewTab(browser()); | 91 chrome::NewTab(browser()); |
91 tab_added_observer.Wait(); | 92 tab_added_observer.Wait(); |
92 LOG(INFO) << "New tab."; | 93 LOG(INFO) << "New tab."; |
93 ui_test_utils::NavigateToURL(browser(), | 94 ui_test_utils::NavigateToURL(browser(), |
94 base_url.Resolve("path2/empty.html")); | 95 base_url.Resolve("path2/empty.html")); |
95 LOG(INFO) << "Nav 2."; | 96 LOG(INFO) << "Nav 2."; |
96 EXPECT_TRUE(process_map->Contains( | 97 EXPECT_TRUE(process_map->Contains( |
97 browser()->GetWebContentsAt(2)->GetRenderProcessHost()->GetID())); | 98 chrome::GetWebContentsAt(browser(), 2)->GetRenderProcessHost()->GetID())
); |
98 EXPECT_FALSE(browser()->GetWebContentsAt(2)->GetWebUI()); | 99 EXPECT_FALSE(chrome::GetWebContentsAt(browser(), 2)->GetWebUI()); |
99 | 100 |
100 // We should have opened 2 new extension tabs. Including the original blank | 101 // We should have opened 2 new extension tabs. Including the original blank |
101 // tab, we now have 3 tabs. The two app tabs should not be in the same | 102 // tab, we now have 3 tabs. The two app tabs should not be in the same |
102 // process, since they do not have the background permission. (Thus, we | 103 // process, since they do not have the background permission. (Thus, we |
103 // want to separate them to improve responsiveness.) | 104 // want to separate them to improve responsiveness.) |
104 ASSERT_EQ(3, browser()->tab_count()); | 105 ASSERT_EQ(3, browser()->tab_count()); |
105 WebContents* tab1 = browser()->GetWebContentsAt(1); | 106 WebContents* tab1 = chrome::GetWebContentsAt(browser(), 1); |
106 WebContents* tab2 = browser()->GetWebContentsAt(2); | 107 WebContents* tab2 = chrome::GetWebContentsAt(browser(), 2); |
107 EXPECT_NE(tab1->GetRenderProcessHost(), tab2->GetRenderProcessHost()); | 108 EXPECT_NE(tab1->GetRenderProcessHost(), tab2->GetRenderProcessHost()); |
108 | 109 |
109 // Opening tabs with window.open should keep the page in the opener's | 110 // Opening tabs with window.open should keep the page in the opener's |
110 // process. | 111 // process. |
111 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile())); | 112 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile())); |
112 OpenWindow(tab1, base_url.Resolve("path1/empty.html"), true, NULL); | 113 OpenWindow(tab1, base_url.Resolve("path1/empty.html"), true, NULL); |
113 LOG(INFO) << "WindowOpenHelper 1."; | 114 LOG(INFO) << "WindowOpenHelper 1."; |
114 OpenWindow(tab2, base_url.Resolve("path2/empty.html"), true, NULL); | 115 OpenWindow(tab2, base_url.Resolve("path2/empty.html"), true, NULL); |
115 LOG(INFO) << "End of test."; | 116 LOG(INFO) << "End of test."; |
116 } | 117 } |
(...skipping 17 matching lines...) Expand all Loading... |
134 // Open two tabs in the app, one outside it. | 135 // Open two tabs in the app, one outside it. |
135 GURL base_url = GetTestBaseURL("app_process"); | 136 GURL base_url = GetTestBaseURL("app_process"); |
136 | 137 |
137 // Test both opening a URL in a new tab, and opening a tab and then navigating | 138 // Test both opening a URL in a new tab, and opening a tab and then navigating |
138 // it. Either way, app tabs should be considered extension processes, but | 139 // it. Either way, app tabs should be considered extension processes, but |
139 // they have no elevated privileges and thus should not have WebUI bindings. | 140 // they have no elevated privileges and thus should not have WebUI bindings. |
140 ui_test_utils::NavigateToURLWithDisposition( | 141 ui_test_utils::NavigateToURLWithDisposition( |
141 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, | 142 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, |
142 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 143 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
143 EXPECT_TRUE(process_map->Contains( | 144 EXPECT_TRUE(process_map->Contains( |
144 browser()->GetWebContentsAt(1)->GetRenderProcessHost()->GetID())); | 145 chrome::GetWebContentsAt(browser(), 1)->GetRenderProcessHost()->GetID())); |
145 EXPECT_FALSE(browser()->GetWebContentsAt(1)->GetWebUI()); | 146 EXPECT_FALSE(chrome::GetWebContentsAt(browser(), 1)->GetWebUI()); |
146 LOG(INFO) << "Nav 1."; | 147 LOG(INFO) << "Nav 1."; |
147 | 148 |
148 ui_test_utils::NavigateToURLWithDisposition( | 149 ui_test_utils::NavigateToURLWithDisposition( |
149 browser(), base_url.Resolve("path2/empty.html"), NEW_FOREGROUND_TAB, | 150 browser(), base_url.Resolve("path2/empty.html"), NEW_FOREGROUND_TAB, |
150 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 151 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
151 EXPECT_TRUE(process_map->Contains( | 152 EXPECT_TRUE(process_map->Contains( |
152 browser()->GetWebContentsAt(2)->GetRenderProcessHost()->GetID())); | 153 chrome::GetWebContentsAt(browser(), 2)->GetRenderProcessHost()->GetID())); |
153 EXPECT_FALSE(browser()->GetWebContentsAt(2)->GetWebUI()); | 154 EXPECT_FALSE(chrome::GetWebContentsAt(browser(), 2)->GetWebUI()); |
154 LOG(INFO) << "Nav 2."; | 155 LOG(INFO) << "Nav 2."; |
155 | 156 |
156 ui_test_utils::WindowedNotificationObserver tab_added_observer( | 157 ui_test_utils::WindowedNotificationObserver tab_added_observer( |
157 chrome::NOTIFICATION_TAB_ADDED, | 158 chrome::NOTIFICATION_TAB_ADDED, |
158 content::NotificationService::AllSources()); | 159 content::NotificationService::AllSources()); |
159 chrome::NewTab(browser()); | 160 chrome::NewTab(browser()); |
160 tab_added_observer.Wait(); | 161 tab_added_observer.Wait(); |
161 LOG(INFO) << "New tab."; | 162 LOG(INFO) << "New tab."; |
162 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path3/empty.html")); | 163 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path3/empty.html")); |
163 LOG(INFO) << "Nav 3."; | 164 LOG(INFO) << "Nav 3."; |
164 EXPECT_FALSE(process_map->Contains( | 165 EXPECT_FALSE(process_map->Contains( |
165 browser()->GetWebContentsAt(3)->GetRenderProcessHost()->GetID())); | 166 chrome::GetWebContentsAt(browser(), 3)->GetRenderProcessHost()->GetID())); |
166 EXPECT_FALSE(browser()->GetWebContentsAt(3)->GetWebUI()); | 167 EXPECT_FALSE(chrome::GetWebContentsAt(browser(), 3)->GetWebUI()); |
167 | 168 |
168 // We should have opened 3 new extension tabs. Including the original blank | 169 // We should have opened 3 new extension tabs. Including the original blank |
169 // tab, we now have 4 tabs. Because the app_process app has the background | 170 // tab, we now have 4 tabs. Because the app_process app has the background |
170 // permission, all of its instances are in the same process. Thus two tabs | 171 // permission, all of its instances are in the same process. Thus two tabs |
171 // should be part of the extension app and grouped in the same process. | 172 // should be part of the extension app and grouped in the same process. |
172 ASSERT_EQ(4, browser()->tab_count()); | 173 ASSERT_EQ(4, browser()->tab_count()); |
173 WebContents* tab = browser()->GetWebContentsAt(1); | 174 WebContents* tab = chrome::GetWebContentsAt(browser(), 1); |
174 | 175 |
175 EXPECT_EQ(tab->GetRenderProcessHost(), | 176 EXPECT_EQ(tab->GetRenderProcessHost(), |
176 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); | 177 chrome::GetWebContentsAt(browser(), 2)->GetRenderProcessHost()); |
177 EXPECT_NE(tab->GetRenderProcessHost(), | 178 EXPECT_NE(tab->GetRenderProcessHost(), |
178 browser()->GetWebContentsAt(3)->GetRenderProcessHost()); | 179 chrome::GetWebContentsAt(browser(), 3)->GetRenderProcessHost()); |
179 | 180 |
180 // Now let's do the same using window.open. The same should happen. | 181 // Now let's do the same using window.open. The same should happen. |
181 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile())); | 182 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile())); |
182 OpenWindow(tab, base_url.Resolve("path1/empty.html"), true, NULL); | 183 OpenWindow(tab, base_url.Resolve("path1/empty.html"), true, NULL); |
183 LOG(INFO) << "WindowOpenHelper 1."; | 184 LOG(INFO) << "WindowOpenHelper 1."; |
184 OpenWindow(tab, base_url.Resolve("path2/empty.html"), true, NULL); | 185 OpenWindow(tab, base_url.Resolve("path2/empty.html"), true, NULL); |
185 LOG(INFO) << "WindowOpenHelper 2."; | 186 LOG(INFO) << "WindowOpenHelper 2."; |
186 // TODO(creis): This should open in a new process (i.e., false for the last | 187 // TODO(creis): This should open in a new process (i.e., false for the last |
187 // argument), but we temporarily avoid swapping processes away from a hosted | 188 // argument), but we temporarily avoid swapping processes away from a hosted |
188 // app if it has an opener, because some OAuth providers make script calls | 189 // app if it has an opener, because some OAuth providers make script calls |
189 // between non-app popups and non-app iframes in the app process. | 190 // between non-app popups and non-app iframes in the app process. |
190 // See crbug.com/59285. | 191 // See crbug.com/59285. |
191 OpenWindow(tab, base_url.Resolve("path3/empty.html"), true, NULL); | 192 OpenWindow(tab, base_url.Resolve("path3/empty.html"), true, NULL); |
192 LOG(INFO) << "WindowOpenHelper 3."; | 193 LOG(INFO) << "WindowOpenHelper 3."; |
193 | 194 |
194 // Now let's have these pages navigate, into or out of the extension web | 195 // Now let's have these pages navigate, into or out of the extension web |
195 // extent. They should switch processes. | 196 // extent. They should switch processes. |
196 const GURL& app_url(base_url.Resolve("path1/empty.html")); | 197 const GURL& app_url(base_url.Resolve("path1/empty.html")); |
197 const GURL& non_app_url(base_url.Resolve("path3/empty.html")); | 198 const GURL& non_app_url(base_url.Resolve("path3/empty.html")); |
198 NavigateInRenderer(browser()->GetWebContentsAt(2), non_app_url); | 199 NavigateInRenderer(chrome::GetWebContentsAt(browser(), 2), non_app_url); |
199 LOG(INFO) << "NavigateTabHelper 1."; | 200 LOG(INFO) << "NavigateTabHelper 1."; |
200 NavigateInRenderer(browser()->GetWebContentsAt(3), app_url); | 201 NavigateInRenderer(chrome::GetWebContentsAt(browser(), 3), app_url); |
201 LOG(INFO) << "NavigateTabHelper 2."; | 202 LOG(INFO) << "NavigateTabHelper 2."; |
202 EXPECT_NE(tab->GetRenderProcessHost(), | 203 EXPECT_NE(tab->GetRenderProcessHost(), |
203 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); | 204 chrome::GetWebContentsAt(browser(), 2)->GetRenderProcessHost()); |
204 EXPECT_EQ(tab->GetRenderProcessHost(), | 205 EXPECT_EQ(tab->GetRenderProcessHost(), |
205 browser()->GetWebContentsAt(3)->GetRenderProcessHost()); | 206 chrome::GetWebContentsAt(browser(), 3)->GetRenderProcessHost()); |
206 | 207 |
207 // 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 |
208 // be valid. | 209 // be valid. |
209 NavigateInRenderer(browser()->GetWebContentsAt(6), app_url); | 210 NavigateInRenderer(chrome::GetWebContentsAt(browser(), 6), app_url); |
210 LOG(INFO) << "NavigateTabHelper 3."; | 211 LOG(INFO) << "NavigateTabHelper 3."; |
211 EXPECT_EQ(tab->GetRenderProcessHost(), | 212 EXPECT_EQ(tab->GetRenderProcessHost(), |
212 browser()->GetWebContentsAt(6)->GetRenderProcessHost()); | 213 chrome::GetWebContentsAt(browser(), 6)->GetRenderProcessHost()); |
213 bool windowOpenerValid = false; | 214 bool windowOpenerValid = false; |
214 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 215 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
215 browser()->GetWebContentsAt(6)->GetRenderViewHost(), L"", | 216 chrome::GetWebContentsAt(browser(), 6)->GetRenderViewHost(), L"", |
216 L"window.domAutomationController.send(window.opener != null)", | 217 L"window.domAutomationController.send(window.opener != null)", |
217 &windowOpenerValid)); | 218 &windowOpenerValid)); |
218 ASSERT_TRUE(windowOpenerValid); | 219 ASSERT_TRUE(windowOpenerValid); |
219 | 220 |
220 LOG(INFO) << "End of test."; | 221 LOG(INFO) << "End of test."; |
221 } | 222 } |
222 | 223 |
223 // 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 |
224 // instance model, such that separate instances are in separate processes. | 225 // instance model, such that separate instances are in separate processes. |
225 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessInstances) { | 226 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessInstances) { |
(...skipping 29 matching lines...) Expand all Loading... |
255 ASSERT_TRUE(extension.get()); | 256 ASSERT_TRUE(extension.get()); |
256 ASSERT_TRUE(extension->from_bookmark()); | 257 ASSERT_TRUE(extension->from_bookmark()); |
257 | 258 |
258 // Test both opening a URL in a new tab, and opening a tab and then navigating | 259 // Test both opening a URL in a new tab, and opening a tab and then navigating |
259 // it. Either way, bookmark app tabs should be considered normal processes | 260 // it. Either way, bookmark app tabs should be considered normal processes |
260 // with no elevated privileges and no WebUI bindings. | 261 // with no elevated privileges and no WebUI bindings. |
261 ui_test_utils::NavigateToURLWithDisposition( | 262 ui_test_utils::NavigateToURLWithDisposition( |
262 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, | 263 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, |
263 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 264 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
264 EXPECT_FALSE(process_map->Contains( | 265 EXPECT_FALSE(process_map->Contains( |
265 browser()->GetWebContentsAt(1)->GetRenderProcessHost()->GetID())); | 266 chrome::GetWebContentsAt(browser(), 1)->GetRenderProcessHost()->GetID())); |
266 EXPECT_FALSE(browser()->GetWebContentsAt(1)->GetWebUI()); | 267 EXPECT_FALSE(chrome::GetWebContentsAt(browser(), 1)->GetWebUI()); |
267 | 268 |
268 ui_test_utils::WindowedNotificationObserver tab_added_observer( | 269 ui_test_utils::WindowedNotificationObserver tab_added_observer( |
269 chrome::NOTIFICATION_TAB_ADDED, | 270 chrome::NOTIFICATION_TAB_ADDED, |
270 content::NotificationService::AllSources()); | 271 content::NotificationService::AllSources()); |
271 chrome::NewTab(browser()); | 272 chrome::NewTab(browser()); |
272 tab_added_observer.Wait(); | 273 tab_added_observer.Wait(); |
273 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); | 274 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); |
274 EXPECT_FALSE(process_map->Contains( | 275 EXPECT_FALSE(process_map->Contains( |
275 browser()->GetWebContentsAt(2)->GetRenderProcessHost()->GetID())); | 276 chrome::GetWebContentsAt(browser(), 2)->GetRenderProcessHost()->GetID())); |
276 EXPECT_FALSE(browser()->GetWebContentsAt(2)->GetWebUI()); | 277 EXPECT_FALSE(chrome::GetWebContentsAt(browser(), 2)->GetWebUI()); |
277 | 278 |
278 // 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 |
279 // tab, we now have 3 tabs. Because normal pages use the | 280 // tab, we now have 3 tabs. Because normal pages use the |
280 // 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. |
281 ASSERT_EQ(3, browser()->tab_count()); | 282 ASSERT_EQ(3, browser()->tab_count()); |
282 WebContents* tab = browser()->GetWebContentsAt(1); | 283 WebContents* tab = chrome::GetWebContentsAt(browser(), 1); |
283 EXPECT_NE(tab->GetRenderProcessHost(), | 284 EXPECT_NE(tab->GetRenderProcessHost(), |
284 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); | 285 chrome::GetWebContentsAt(browser(), 2)->GetRenderProcessHost()); |
285 | 286 |
286 // 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. |
287 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile())); | 288 ASSERT_EQ(1u, browser::GetBrowserCount(browser()->profile())); |
288 OpenWindow(tab, base_url.Resolve("path1/empty.html"), true, NULL); | 289 OpenWindow(tab, base_url.Resolve("path1/empty.html"), true, NULL); |
289 OpenWindow(tab, base_url.Resolve("path2/empty.html"), true, NULL); | 290 OpenWindow(tab, base_url.Resolve("path2/empty.html"), true, NULL); |
290 | 291 |
291 // 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 |
292 // extent. Neither navigation should switch processes. | 293 // extent. Neither navigation should switch processes. |
293 const GURL& app_url(base_url.Resolve("path1/empty.html")); | 294 const GURL& app_url(base_url.Resolve("path1/empty.html")); |
294 const GURL& non_app_url(base_url.Resolve("path3/empty.html")); | 295 const GURL& non_app_url(base_url.Resolve("path3/empty.html")); |
295 RenderViewHost* host2 = browser()->GetWebContentsAt(2)->GetRenderViewHost(); | 296 RenderViewHost* host2 = |
296 NavigateInRenderer(browser()->GetWebContentsAt(2), non_app_url); | 297 chrome::GetWebContentsAt(browser(), 2)->GetRenderViewHost(); |
| 298 NavigateInRenderer(chrome::GetWebContentsAt(browser(), 2), non_app_url); |
297 EXPECT_EQ(host2->GetProcess(), | 299 EXPECT_EQ(host2->GetProcess(), |
298 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); | 300 chrome::GetWebContentsAt(browser(), 2)->GetRenderProcessHost()); |
299 NavigateInRenderer(browser()->GetWebContentsAt(2), app_url); | 301 NavigateInRenderer(chrome::GetWebContentsAt(browser(), 2), app_url); |
300 EXPECT_EQ(host2->GetProcess(), | 302 EXPECT_EQ(host2->GetProcess(), |
301 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); | 303 chrome::GetWebContentsAt(browser(), 2)->GetRenderProcessHost()); |
302 } | 304 } |
303 | 305 |
304 // Tests that app process switching works properly in the following scenario: | 306 // Tests that app process switching works properly in the following scenario: |
305 // 1. navigate to a page1 in the app | 307 // 1. navigate to a page1 in the app |
306 // 2. page1 redirects to a page2 outside the app extent (ie, "/server-redirect") | 308 // 2. page1 redirects to a page2 outside the app extent (ie, "/server-redirect") |
307 // 3. page2 redirects back to a page in the app | 309 // 3. page2 redirects back to a page in the app |
308 // The final navigation should end up in the app process. | 310 // The final navigation should end up in the app process. |
309 // See http://crbug.com/61757 | 311 // See http://crbug.com/61757 |
310 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessRedirectBack) { | 312 IN_PROC_BROWSER_TEST_F(AppApiTest, AppProcessRedirectBack) { |
311 host_resolver()->AddRule("*", "127.0.0.1"); | 313 host_resolver()->AddRule("*", "127.0.0.1"); |
(...skipping 17 matching lines...) Expand all Loading... |
329 // transfers that to a new navigation, using RequestTransferURL. | 331 // transfers that to a new navigation, using RequestTransferURL. |
330 // 6. Renderer navigates to empty.html, and finishes loading, counting as the | 332 // 6. Renderer navigates to empty.html, and finishes loading, counting as the |
331 // second load stop | 333 // second load stop |
332 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 334 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
333 browser(), base_url.Resolve("path1/redirect.html"), 2); | 335 browser(), base_url.Resolve("path1/redirect.html"), 2); |
334 | 336 |
335 // 3 tabs, including the initial about:blank. The last 2 should be the same | 337 // 3 tabs, including the initial about:blank. The last 2 should be the same |
336 // process. | 338 // process. |
337 ASSERT_EQ(3, browser()->tab_count()); | 339 ASSERT_EQ(3, browser()->tab_count()); |
338 EXPECT_EQ("/files/extensions/api_test/app_process/path1/empty.html", | 340 EXPECT_EQ("/files/extensions/api_test/app_process/path1/empty.html", |
339 browser()->GetWebContentsAt(2)->GetController(). | 341 chrome::GetWebContentsAt(browser(), 2)->GetController(). |
340 GetLastCommittedEntry()->GetURL().path()); | 342 GetLastCommittedEntry()->GetURL().path()); |
341 EXPECT_EQ(browser()->GetWebContentsAt(1)->GetRenderProcessHost(), | 343 EXPECT_EQ(chrome::GetWebContentsAt(browser(), 1)->GetRenderProcessHost(), |
342 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); | 344 chrome::GetWebContentsAt(browser(), 2)->GetRenderProcessHost()); |
343 } | 345 } |
344 | 346 |
345 // Ensure that reloading a URL after installing or uninstalling it as an app | 347 // Ensure that reloading a URL after installing or uninstalling it as an app |
346 // correctly swaps the process. (http://crbug.com/80621) | 348 // correctly swaps the process. (http://crbug.com/80621) |
347 // | 349 // |
348 // The test times out under AddressSanitizer, see http://crbug.com/103371 | 350 // The test times out under AddressSanitizer, see http://crbug.com/103371 |
349 #if defined(ADDRESS_SANITIZER) | 351 #if defined(ADDRESS_SANITIZER) |
350 #define MAYBE_ReloadIntoAppProcess DISABLED_ReloadIntoAppProcess | 352 #define MAYBE_ReloadIntoAppProcess DISABLED_ReloadIntoAppProcess |
351 #else | 353 #else |
352 #define MAYBE_ReloadIntoAppProcess ReloadIntoAppProcess | 354 #define MAYBE_ReloadIntoAppProcess ReloadIntoAppProcess |
353 #endif | 355 #endif |
354 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_ReloadIntoAppProcess) { | 356 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_ReloadIntoAppProcess) { |
355 extensions::ProcessMap* process_map = | 357 extensions::ProcessMap* process_map = |
356 browser()->profile()->GetExtensionService()->process_map(); | 358 browser()->profile()->GetExtensionService()->process_map(); |
357 | 359 |
358 host_resolver()->AddRule("*", "127.0.0.1"); | 360 host_resolver()->AddRule("*", "127.0.0.1"); |
359 ASSERT_TRUE(test_server()->Start()); | 361 ASSERT_TRUE(test_server()->Start()); |
360 | 362 |
361 // The app under test acts on URLs whose host is "localhost", | 363 // The app under test acts on URLs whose host is "localhost", |
362 // so the URLs we navigate to must have host "localhost". | 364 // so the URLs we navigate to must have host "localhost". |
363 GURL base_url = GetTestBaseURL("app_process"); | 365 GURL base_url = GetTestBaseURL("app_process"); |
364 | 366 |
365 // Load an app URL before loading the app. | 367 // Load an app URL before loading the app. |
366 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); | 368 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
367 WebContents* contents = browser()->GetWebContentsAt(0); | 369 WebContents* contents = chrome::GetWebContentsAt(browser(), 0); |
368 EXPECT_FALSE(process_map->Contains( | 370 EXPECT_FALSE(process_map->Contains( |
369 contents->GetRenderProcessHost()->GetID())); | 371 contents->GetRenderProcessHost()->GetID())); |
370 | 372 |
371 // Load app and navigate to the page. | 373 // Load app and navigate to the page. |
372 const Extension* app = | 374 const Extension* app = |
373 LoadExtension(test_data_dir_.AppendASCII("app_process")); | 375 LoadExtension(test_data_dir_.AppendASCII("app_process")); |
374 ASSERT_TRUE(app); | 376 ASSERT_TRUE(app); |
375 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); | 377 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
376 EXPECT_TRUE(process_map->Contains( | 378 EXPECT_TRUE(process_map->Contains( |
377 contents->GetRenderProcessHost()->GetID())); | 379 contents->GetRenderProcessHost()->GetID())); |
378 | 380 |
379 // Disable app and navigate to the page. | 381 // Disable app and navigate to the page. |
380 DisableExtension(app->id()); | 382 DisableExtension(app->id()); |
381 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); | 383 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
382 EXPECT_FALSE(process_map->Contains( | 384 EXPECT_FALSE(process_map->Contains( |
383 contents->GetRenderProcessHost()->GetID())); | 385 contents->GetRenderProcessHost()->GetID())); |
384 | 386 |
385 // Enable app and reload the page. | 387 // Enable app and reload the page. |
386 EnableExtension(app->id()); | 388 EnableExtension(app->id()); |
387 ui_test_utils::WindowedNotificationObserver reload_observer( | 389 ui_test_utils::WindowedNotificationObserver reload_observer( |
388 content::NOTIFICATION_LOAD_STOP, | 390 content::NOTIFICATION_LOAD_STOP, |
389 content::Source<NavigationController>( | 391 content::Source<NavigationController>( |
390 &browser()->GetActiveWebContents()->GetController())); | 392 &chrome::GetActiveWebContents(browser())->GetController())); |
391 chrome::Reload(browser(), CURRENT_TAB); | 393 chrome::Reload(browser(), CURRENT_TAB); |
392 reload_observer.Wait(); | 394 reload_observer.Wait(); |
393 EXPECT_TRUE(process_map->Contains( | 395 EXPECT_TRUE(process_map->Contains( |
394 contents->GetRenderProcessHost()->GetID())); | 396 contents->GetRenderProcessHost()->GetID())); |
395 | 397 |
396 // Disable app and reload the page. | 398 // Disable app and reload the page. |
397 DisableExtension(app->id()); | 399 DisableExtension(app->id()); |
398 ui_test_utils::WindowedNotificationObserver reload_observer2( | 400 ui_test_utils::WindowedNotificationObserver reload_observer2( |
399 content::NOTIFICATION_LOAD_STOP, | 401 content::NOTIFICATION_LOAD_STOP, |
400 content::Source<NavigationController>( | 402 content::Source<NavigationController>( |
401 &browser()->GetActiveWebContents()->GetController())); | 403 &chrome::GetActiveWebContents(browser())->GetController())); |
402 chrome::Reload(browser(), CURRENT_TAB); | 404 chrome::Reload(browser(), CURRENT_TAB); |
403 reload_observer2.Wait(); | 405 reload_observer2.Wait(); |
404 EXPECT_FALSE(process_map->Contains( | 406 EXPECT_FALSE(process_map->Contains( |
405 contents->GetRenderProcessHost()->GetID())); | 407 contents->GetRenderProcessHost()->GetID())); |
406 | 408 |
407 // Enable app and reload via JavaScript. | 409 // Enable app and reload via JavaScript. |
408 EnableExtension(app->id()); | 410 EnableExtension(app->id()); |
409 ui_test_utils::WindowedNotificationObserver js_reload_observer( | 411 ui_test_utils::WindowedNotificationObserver js_reload_observer( |
410 content::NOTIFICATION_LOAD_STOP, | 412 content::NOTIFICATION_LOAD_STOP, |
411 content::Source<NavigationController>( | 413 content::Source<NavigationController>( |
412 &browser()->GetActiveWebContents()->GetController())); | 414 &chrome::GetActiveWebContents(browser())->GetController())); |
413 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->GetRenderViewHost(), | 415 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->GetRenderViewHost(), |
414 L"", L"location.reload();")); | 416 L"", L"location.reload();")); |
415 js_reload_observer.Wait(); | 417 js_reload_observer.Wait(); |
416 EXPECT_TRUE(process_map->Contains( | 418 EXPECT_TRUE(process_map->Contains( |
417 contents->GetRenderProcessHost()->GetID())); | 419 contents->GetRenderProcessHost()->GetID())); |
418 | 420 |
419 // Disable app and reload via JavaScript. | 421 // Disable app and reload via JavaScript. |
420 DisableExtension(app->id()); | 422 DisableExtension(app->id()); |
421 ui_test_utils::WindowedNotificationObserver js_reload_observer2( | 423 ui_test_utils::WindowedNotificationObserver js_reload_observer2( |
422 content::NOTIFICATION_LOAD_STOP, | 424 content::NOTIFICATION_LOAD_STOP, |
423 content::Source<NavigationController>( | 425 content::Source<NavigationController>( |
424 &browser()->GetActiveWebContents()->GetController())); | 426 &chrome::GetActiveWebContents(browser())->GetController())); |
425 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->GetRenderViewHost(), | 427 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->GetRenderViewHost(), |
426 L"", L"location = location;")); | 428 L"", L"location = location;")); |
427 js_reload_observer2.Wait(); | 429 js_reload_observer2.Wait(); |
428 EXPECT_FALSE(process_map->Contains( | 430 EXPECT_FALSE(process_map->Contains( |
429 contents->GetRenderProcessHost()->GetID())); | 431 contents->GetRenderProcessHost()->GetID())); |
430 } | 432 } |
431 | 433 |
432 // Tests that if we have a non-app process (path3/container.html) that has an | 434 // Tests that if we have a non-app process (path3/container.html) that has an |
433 // iframe with a URL in the app's extent (path1/iframe.html), then opening a | 435 // iframe with a URL in the app's extent (path1/iframe.html), then opening a |
434 // link from that iframe to a new window to a URL in the app's extent (path1/ | 436 // link from that iframe to a new window to a URL in the app's extent (path1/ |
(...skipping 12 matching lines...) Expand all Loading... |
447 const Extension* app = | 449 const Extension* app = |
448 LoadExtension(test_data_dir_.AppendASCII("app_process")); | 450 LoadExtension(test_data_dir_.AppendASCII("app_process")); |
449 ASSERT_TRUE(app); | 451 ASSERT_TRUE(app); |
450 | 452 |
451 ui_test_utils::WindowedNotificationObserver popup_observer( | 453 ui_test_utils::WindowedNotificationObserver popup_observer( |
452 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, | 454 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, |
453 content::NotificationService::AllSources()); | 455 content::NotificationService::AllSources()); |
454 ui_test_utils::NavigateToURL(browser(), | 456 ui_test_utils::NavigateToURL(browser(), |
455 base_url.Resolve("path3/container.html")); | 457 base_url.Resolve("path3/container.html")); |
456 EXPECT_FALSE(process_map->Contains( | 458 EXPECT_FALSE(process_map->Contains( |
457 browser()->GetWebContentsAt(0)->GetRenderProcessHost()->GetID())); | 459 chrome::GetWebContentsAt(browser(), 0)->GetRenderProcessHost()->GetID())); |
458 popup_observer.Wait(); | 460 popup_observer.Wait(); |
459 | 461 |
460 // Popup window should be in the app's process. | 462 // Popup window should be in the app's process. |
461 RenderViewHost* popup_host = | 463 RenderViewHost* popup_host = |
462 content::Source<RenderViewHost>(popup_observer.source()).ptr(); | 464 content::Source<RenderViewHost>(popup_observer.source()).ptr(); |
463 EXPECT_TRUE(process_map->Contains(popup_host->GetProcess()->GetID())); | 465 EXPECT_TRUE(process_map->Contains(popup_host->GetProcess()->GetID())); |
464 } | 466 } |
465 | 467 |
466 // Tests that if an extension launches an app via chrome.tabs.create with an URL | 468 // Tests that if an extension launches an app via chrome.tabs.create with an URL |
467 // that's not in the app's extent but that redirects to it, we still end up with | 469 // that's not in the app's extent but that redirects to it, we still end up with |
(...skipping 24 matching lines...) Expand all Loading... |
492 | 494 |
493 // Wait for app tab to be created and loaded. | 495 // Wait for app tab to be created and loaded. |
494 test_navigation_observer.WaitForObservation( | 496 test_navigation_observer.WaitForObservation( |
495 base::Bind(&ui_test_utils::RunMessageLoop), | 497 base::Bind(&ui_test_utils::RunMessageLoop), |
496 base::Bind(&MessageLoop::Quit, | 498 base::Bind(&MessageLoop::Quit, |
497 base::Unretained(MessageLoopForUI::current()))); | 499 base::Unretained(MessageLoopForUI::current()))); |
498 | 500 |
499 // App has loaded, and chrome.app.isInstalled should be true. | 501 // App has loaded, and chrome.app.isInstalled should be true. |
500 bool is_installed = false; | 502 bool is_installed = false; |
501 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 503 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
502 browser()->GetActiveWebContents()->GetRenderViewHost(), L"", | 504 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", |
503 L"window.domAutomationController.send(chrome.app.isInstalled)", | 505 L"window.domAutomationController.send(chrome.app.isInstalled)", |
504 &is_installed)); | 506 &is_installed)); |
505 ASSERT_TRUE(is_installed); | 507 ASSERT_TRUE(is_installed); |
506 } | 508 } |
507 | 509 |
508 // Tests that if we have an app process (path1/container.html) with a non-app | 510 // Tests that if we have an app process (path1/container.html) with a non-app |
509 // iframe (path3/iframe.html), then opening a link from that iframe to a new | 511 // iframe (path3/iframe.html), then opening a link from that iframe to a new |
510 // window to a same-origin non-app URL (path3/empty.html) should keep the window | 512 // window to a same-origin non-app URL (path3/empty.html) should keep the window |
511 // in the app process. | 513 // in the app process. |
512 // This is in contrast to OpenAppFromIframe, since here the popup will not be | 514 // This is in contrast to OpenAppFromIframe, since here the popup will not be |
(...skipping 12 matching lines...) Expand all Loading... |
525 const Extension* app = | 527 const Extension* app = |
526 LoadExtension(test_data_dir_.AppendASCII("app_process")); | 528 LoadExtension(test_data_dir_.AppendASCII("app_process")); |
527 ASSERT_TRUE(app); | 529 ASSERT_TRUE(app); |
528 | 530 |
529 ui_test_utils::WindowedNotificationObserver popup_observer( | 531 ui_test_utils::WindowedNotificationObserver popup_observer( |
530 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, | 532 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, |
531 content::NotificationService::AllSources()); | 533 content::NotificationService::AllSources()); |
532 ui_test_utils::NavigateToURL(browser(), | 534 ui_test_utils::NavigateToURL(browser(), |
533 base_url.Resolve("path1/container.html")); | 535 base_url.Resolve("path1/container.html")); |
534 content::RenderProcessHost* process = | 536 content::RenderProcessHost* process = |
535 browser()->GetWebContentsAt(0)->GetRenderProcessHost(); | 537 chrome::GetWebContentsAt(browser(), 0)->GetRenderProcessHost(); |
536 EXPECT_TRUE(process_map->Contains(process->GetID())); | 538 EXPECT_TRUE(process_map->Contains(process->GetID())); |
537 | 539 |
538 // Wait for popup window to appear. | 540 // Wait for popup window to appear. |
539 popup_observer.Wait(); | 541 popup_observer.Wait(); |
540 | 542 |
541 // Popup window should be in the app's process. | 543 // Popup window should be in the app's process. |
542 RenderViewHost* popup_host = | 544 RenderViewHost* popup_host = |
543 content::Source<RenderViewHost>(popup_observer.source()).ptr(); | 545 content::Source<RenderViewHost>(popup_observer.source()).ptr(); |
544 EXPECT_EQ(process, popup_host->GetProcess()); | 546 EXPECT_EQ(process, popup_host->GetProcess()); |
545 } | 547 } |
(...skipping 10 matching lines...) Expand all Loading... |
556 | 558 |
557 host_resolver()->AddRule("*", "127.0.0.1"); | 559 host_resolver()->AddRule("*", "127.0.0.1"); |
558 ASSERT_TRUE(test_server()->Start()); | 560 ASSERT_TRUE(test_server()->Start()); |
559 | 561 |
560 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); | 562 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); |
561 | 563 |
562 GURL base_url = GetTestBaseURL("app_process"); | 564 GURL base_url = GetTestBaseURL("app_process"); |
563 | 565 |
564 // Load the app, chrome.app.isInstalled should be true. | 566 // Load the app, chrome.app.isInstalled should be true. |
565 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); | 567 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
566 WebContents* contents = browser()->GetWebContentsAt(0); | 568 WebContents* contents = chrome::GetWebContentsAt(browser(), 0); |
567 EXPECT_TRUE(process_map->Contains( | 569 EXPECT_TRUE(process_map->Contains( |
568 contents->GetRenderProcessHost()->GetID())); | 570 contents->GetRenderProcessHost()->GetID())); |
569 bool is_installed = false; | 571 bool is_installed = false; |
570 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 572 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
571 contents->GetRenderViewHost(), L"", | 573 contents->GetRenderViewHost(), L"", |
572 L"window.domAutomationController.send(chrome.app.isInstalled)", | 574 L"window.domAutomationController.send(chrome.app.isInstalled)", |
573 &is_installed)); | 575 &is_installed)); |
574 ASSERT_TRUE(is_installed); | 576 ASSERT_TRUE(is_installed); |
575 | 577 |
576 // Crash the tab and reload it, chrome.app.isInstalled should still be true. | 578 // Crash the tab and reload it, chrome.app.isInstalled should still be true. |
577 ui_test_utils::CrashTab(browser()->GetActiveWebContents()); | 579 ui_test_utils::CrashTab(chrome::GetActiveWebContents(browser())); |
578 ui_test_utils::WindowedNotificationObserver observer( | 580 ui_test_utils::WindowedNotificationObserver observer( |
579 content::NOTIFICATION_LOAD_STOP, | 581 content::NOTIFICATION_LOAD_STOP, |
580 content::Source<NavigationController>( | 582 content::Source<NavigationController>( |
581 &browser()->GetActiveWebContents()->GetController())); | 583 &chrome::GetActiveWebContents(browser())->GetController())); |
582 chrome::Reload(browser(), CURRENT_TAB); | 584 chrome::Reload(browser(), CURRENT_TAB); |
583 observer.Wait(); | 585 observer.Wait(); |
584 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 586 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
585 contents->GetRenderViewHost(), L"", | 587 contents->GetRenderViewHost(), L"", |
586 L"window.domAutomationController.send(chrome.app.isInstalled)", | 588 L"window.domAutomationController.send(chrome.app.isInstalled)", |
587 &is_installed)); | 589 &is_installed)); |
588 ASSERT_TRUE(is_installed); | 590 ASSERT_TRUE(is_installed); |
589 } | 591 } |
OLD | NEW |