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 "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_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/extensions/process_map.h" | 9 #include "chrome/browser/extensions/process_map.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 // The above window.open call is not user-initiated, it will create | 57 // The above window.open call is not user-initiated, it will create |
58 // a popup window instead of a new tab in current window. | 58 // a popup window instead of a new tab in current window. |
59 // Now the active tab in last active window should be the new tab. | 59 // Now the active tab in last active window should be the new tab. |
60 Browser* last_active_browser = BrowserList::GetLastActive(); | 60 Browser* last_active_browser = BrowserList::GetLastActive(); |
61 EXPECT_TRUE(last_active_browser); | 61 EXPECT_TRUE(last_active_browser); |
62 WebContents* newtab = last_active_browser->GetSelectedWebContents(); | 62 WebContents* newtab = last_active_browser->GetSelectedWebContents(); |
63 EXPECT_TRUE(newtab); | 63 EXPECT_TRUE(newtab); |
64 observer.Wait(); | 64 observer.Wait(); |
65 EXPECT_EQ(url, newtab->GetController().GetLastCommittedEntry()->GetURL()); | 65 EXPECT_EQ(url, newtab->GetController().GetLastCommittedEntry()->GetURL()); |
66 if (newtab_process_should_equal_opener) | 66 if (newtab_process_should_equal_opener) |
67 EXPECT_EQ(opener_host->process(), newtab->GetRenderProcessHost()); | 67 EXPECT_EQ(opener_host->GetProcess(), newtab->GetRenderProcessHost()); |
68 else | 68 else |
69 EXPECT_NE(opener_host->process(), newtab->GetRenderProcessHost()); | 69 EXPECT_NE(opener_host->GetProcess(), newtab->GetRenderProcessHost()); |
70 } | 70 } |
71 | 71 |
72 // Simulates a page navigating itself to an URL, and waits for the navigation. | 72 // Simulates a page navigating itself to an URL, and waits for the navigation. |
73 static void NavigateTabHelper(WebContents* contents, const GURL& url) { | 73 static void NavigateTabHelper(WebContents* contents, const GURL& url) { |
74 bool result = false; | 74 bool result = false; |
75 ui_test_utils::WindowedNotificationObserver observer( | 75 ui_test_utils::WindowedNotificationObserver observer( |
76 content::NOTIFICATION_LOAD_STOP, | 76 content::NOTIFICATION_LOAD_STOP, |
77 content::NotificationService::AllSources()); | 77 content::NotificationService::AllSources()); |
78 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 78 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
79 contents->GetRenderViewHost(), L"", | 79 contents->GetRenderViewHost(), L"", |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 browser()->GetWebContentsAt(3)->GetRenderProcessHost()->GetID())); | 137 browser()->GetWebContentsAt(3)->GetRenderProcessHost()->GetID())); |
138 EXPECT_FALSE(browser()->GetWebContentsAt(3)->GetWebUI()); | 138 EXPECT_FALSE(browser()->GetWebContentsAt(3)->GetWebUI()); |
139 | 139 |
140 // We should have opened 3 new extension tabs. Including the original blank | 140 // We should have opened 3 new extension tabs. Including the original blank |
141 // tab, we now have 4 tabs. Because the app_process app has the background | 141 // tab, we now have 4 tabs. Because the app_process app has the background |
142 // permission, all of its instances are in the same process. Thus two tabs | 142 // permission, all of its instances are in the same process. Thus two tabs |
143 // should be part of the extension app and grouped in the same process. | 143 // should be part of the extension app and grouped in the same process. |
144 ASSERT_EQ(4, browser()->tab_count()); | 144 ASSERT_EQ(4, browser()->tab_count()); |
145 RenderViewHost* host = browser()->GetWebContentsAt(1)->GetRenderViewHost(); | 145 RenderViewHost* host = browser()->GetWebContentsAt(1)->GetRenderViewHost(); |
146 | 146 |
147 EXPECT_EQ(host->process(), | 147 EXPECT_EQ(host->GetProcess(), |
148 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); | 148 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); |
149 EXPECT_NE(host->process(), | 149 EXPECT_NE(host->GetProcess(), |
150 browser()->GetWebContentsAt(3)->GetRenderProcessHost()); | 150 browser()->GetWebContentsAt(3)->GetRenderProcessHost()); |
151 | 151 |
152 // Now let's do the same using window.open. The same should happen. | 152 // Now let's do the same using window.open. The same should happen. |
153 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile())); | 153 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile())); |
154 WindowOpenHelper(browser(), host, | 154 WindowOpenHelper(browser(), host, |
155 base_url.Resolve("path1/empty.html"), true); | 155 base_url.Resolve("path1/empty.html"), true); |
156 LOG(INFO) << "WindowOpenHelper 1."; | 156 LOG(INFO) << "WindowOpenHelper 1."; |
157 WindowOpenHelper(browser(), host, | 157 WindowOpenHelper(browser(), host, |
158 base_url.Resolve("path2/empty.html"), true); | 158 base_url.Resolve("path2/empty.html"), true); |
159 LOG(INFO) << "WindowOpenHelper 2."; | 159 LOG(INFO) << "WindowOpenHelper 2."; |
160 // TODO(creis): This should open in a new process (i.e., false for the last | 160 // TODO(creis): This should open in a new process (i.e., false for the last |
161 // argument), but we temporarily avoid swapping processes away from an app | 161 // argument), but we temporarily avoid swapping processes away from an app |
162 // until we're able to support cross-process postMessage calls. | 162 // until we're able to support cross-process postMessage calls. |
163 // See crbug.com/59285. | 163 // See crbug.com/59285. |
164 WindowOpenHelper(browser(), host, | 164 WindowOpenHelper(browser(), host, |
165 base_url.Resolve("path3/empty.html"), true); | 165 base_url.Resolve("path3/empty.html"), true); |
166 LOG(INFO) << "WindowOpenHelper 3."; | 166 LOG(INFO) << "WindowOpenHelper 3."; |
167 | 167 |
168 // Now let's have these pages navigate, into or out of the extension web | 168 // Now let's have these pages navigate, into or out of the extension web |
169 // extent. They should switch processes. | 169 // extent. They should switch processes. |
170 const GURL& app_url(base_url.Resolve("path1/empty.html")); | 170 const GURL& app_url(base_url.Resolve("path1/empty.html")); |
171 const GURL& non_app_url(base_url.Resolve("path3/empty.html")); | 171 const GURL& non_app_url(base_url.Resolve("path3/empty.html")); |
172 NavigateTabHelper(browser()->GetWebContentsAt(2), non_app_url); | 172 NavigateTabHelper(browser()->GetWebContentsAt(2), non_app_url); |
173 LOG(INFO) << "NavigateTabHelper 1."; | 173 LOG(INFO) << "NavigateTabHelper 1."; |
174 NavigateTabHelper(browser()->GetWebContentsAt(3), app_url); | 174 NavigateTabHelper(browser()->GetWebContentsAt(3), app_url); |
175 LOG(INFO) << "NavigateTabHelper 2."; | 175 LOG(INFO) << "NavigateTabHelper 2."; |
176 // TODO(creis): This should swap out of the app's process (i.e., EXPECT_NE), | 176 // TODO(creis): This should swap out of the app's process (i.e., EXPECT_NE), |
177 // but we temporarily avoid swapping away from an app in case the window | 177 // but we temporarily avoid swapping away from an app in case the window |
178 // tries to send a postMessage to the app. See crbug.com/59285. | 178 // tries to send a postMessage to the app. See crbug.com/59285. |
179 EXPECT_EQ(host->process(), | 179 EXPECT_EQ(host->GetProcess(), |
180 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); | 180 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); |
181 EXPECT_EQ(host->process(), | 181 EXPECT_EQ(host->GetProcess(), |
182 browser()->GetWebContentsAt(3)->GetRenderProcessHost()); | 182 browser()->GetWebContentsAt(3)->GetRenderProcessHost()); |
183 | 183 |
184 // If one of the popup tabs navigates back to the app, window.opener should | 184 // If one of the popup tabs navigates back to the app, window.opener should |
185 // be valid. | 185 // be valid. |
186 NavigateTabHelper(browser()->GetWebContentsAt(6), app_url); | 186 NavigateTabHelper(browser()->GetWebContentsAt(6), app_url); |
187 LOG(INFO) << "NavigateTabHelper 3."; | 187 LOG(INFO) << "NavigateTabHelper 3."; |
188 EXPECT_EQ(host->process(), | 188 EXPECT_EQ(host->GetProcess(), |
189 browser()->GetWebContentsAt(6)->GetRenderProcessHost()); | 189 browser()->GetWebContentsAt(6)->GetRenderProcessHost()); |
190 bool windowOpenerValid = false; | 190 bool windowOpenerValid = false; |
191 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 191 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
192 browser()->GetWebContentsAt(6)->GetRenderViewHost(), L"", | 192 browser()->GetWebContentsAt(6)->GetRenderViewHost(), L"", |
193 L"window.domAutomationController.send(window.opener != null)", | 193 L"window.domAutomationController.send(window.opener != null)", |
194 &windowOpenerValid)); | 194 &windowOpenerValid)); |
195 ASSERT_TRUE(windowOpenerValid); | 195 ASSERT_TRUE(windowOpenerValid); |
196 | 196 |
197 LOG(INFO) << "End of test."; | 197 LOG(INFO) << "End of test."; |
198 } | 198 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 browser()->GetWebContentsAt(2)->GetRenderProcessHost()->GetID())); | 240 browser()->GetWebContentsAt(2)->GetRenderProcessHost()->GetID())); |
241 EXPECT_FALSE(browser()->GetWebContentsAt(2)->GetWebUI()); | 241 EXPECT_FALSE(browser()->GetWebContentsAt(2)->GetWebUI()); |
242 | 242 |
243 // We should have opened 2 new extension tabs. Including the original blank | 243 // We should have opened 2 new extension tabs. Including the original blank |
244 // tab, we now have 3 tabs. The two app tabs should not be in the same | 244 // tab, we now have 3 tabs. The two app tabs should not be in the same |
245 // process, since they do not have the background permission. (Thus, we want | 245 // process, since they do not have the background permission. (Thus, we want |
246 // to separate them to improve responsiveness.) | 246 // to separate them to improve responsiveness.) |
247 ASSERT_EQ(3, browser()->tab_count()); | 247 ASSERT_EQ(3, browser()->tab_count()); |
248 RenderViewHost* host1 = browser()->GetWebContentsAt(1)->GetRenderViewHost(); | 248 RenderViewHost* host1 = browser()->GetWebContentsAt(1)->GetRenderViewHost(); |
249 RenderViewHost* host2 = browser()->GetWebContentsAt(2)->GetRenderViewHost(); | 249 RenderViewHost* host2 = browser()->GetWebContentsAt(2)->GetRenderViewHost(); |
250 EXPECT_NE(host1->process(), host2->process()); | 250 EXPECT_NE(host1->GetProcess(), host2->GetProcess()); |
251 | 251 |
252 // Opening tabs with window.open should keep the page in the opener's process. | 252 // Opening tabs with window.open should keep the page in the opener's process. |
253 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile())); | 253 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile())); |
254 WindowOpenHelper(browser(), host1, | 254 WindowOpenHelper(browser(), host1, |
255 base_url.Resolve("path1/empty.html"), true); | 255 base_url.Resolve("path1/empty.html"), true); |
256 LOG(INFO) << "WindowOpenHelper 1."; | 256 LOG(INFO) << "WindowOpenHelper 1."; |
257 WindowOpenHelper(browser(), host2, | 257 WindowOpenHelper(browser(), host2, |
258 base_url.Resolve("path2/empty.html"), true); | 258 base_url.Resolve("path2/empty.html"), true); |
259 LOG(INFO) << "End of test."; | 259 LOG(INFO) << "End of test."; |
260 } | 260 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); | 302 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); |
303 EXPECT_FALSE(process_map->Contains( | 303 EXPECT_FALSE(process_map->Contains( |
304 browser()->GetWebContentsAt(2)->GetRenderProcessHost()->GetID())); | 304 browser()->GetWebContentsAt(2)->GetRenderProcessHost()->GetID())); |
305 EXPECT_FALSE(browser()->GetWebContentsAt(2)->GetWebUI()); | 305 EXPECT_FALSE(browser()->GetWebContentsAt(2)->GetWebUI()); |
306 | 306 |
307 // We should have opened 2 new bookmark app tabs. Including the original blank | 307 // We should have opened 2 new bookmark app tabs. Including the original blank |
308 // tab, we now have 3 tabs. Because normal pages use the | 308 // tab, we now have 3 tabs. Because normal pages use the |
309 // process-per-site-instance model, each should be in its own process. | 309 // process-per-site-instance model, each should be in its own process. |
310 ASSERT_EQ(3, browser()->tab_count()); | 310 ASSERT_EQ(3, browser()->tab_count()); |
311 RenderViewHost* host = browser()->GetWebContentsAt(1)->GetRenderViewHost(); | 311 RenderViewHost* host = browser()->GetWebContentsAt(1)->GetRenderViewHost(); |
312 EXPECT_NE(host->process(), | 312 EXPECT_NE(host->GetProcess(), |
313 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); | 313 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); |
314 | 314 |
315 // Now let's do the same using window.open. The same should happen. | 315 // Now let's do the same using window.open. The same should happen. |
316 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile())); | 316 ASSERT_EQ(1u, BrowserList::GetBrowserCount(browser()->profile())); |
317 WindowOpenHelper(browser(), host, | 317 WindowOpenHelper(browser(), host, |
318 base_url.Resolve("path1/empty.html"), true); | 318 base_url.Resolve("path1/empty.html"), true); |
319 WindowOpenHelper(browser(), host, | 319 WindowOpenHelper(browser(), host, |
320 base_url.Resolve("path2/empty.html"), true); | 320 base_url.Resolve("path2/empty.html"), true); |
321 | 321 |
322 // Now let's have a tab navigate out of and back into the app's web | 322 // Now let's have a tab navigate out of and back into the app's web |
323 // extent. Neither navigation should switch processes. | 323 // extent. Neither navigation should switch processes. |
324 const GURL& app_url(base_url.Resolve("path1/empty.html")); | 324 const GURL& app_url(base_url.Resolve("path1/empty.html")); |
325 const GURL& non_app_url(base_url.Resolve("path3/empty.html")); | 325 const GURL& non_app_url(base_url.Resolve("path3/empty.html")); |
326 RenderViewHost* host2 = browser()->GetWebContentsAt(2)->GetRenderViewHost(); | 326 RenderViewHost* host2 = browser()->GetWebContentsAt(2)->GetRenderViewHost(); |
327 NavigateTabHelper(browser()->GetWebContentsAt(2), non_app_url); | 327 NavigateTabHelper(browser()->GetWebContentsAt(2), non_app_url); |
328 EXPECT_EQ(host2->process(), | 328 EXPECT_EQ(host2->GetProcess(), |
329 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); | 329 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); |
330 NavigateTabHelper(browser()->GetWebContentsAt(2), app_url); | 330 NavigateTabHelper(browser()->GetWebContentsAt(2), app_url); |
331 EXPECT_EQ(host2->process(), | 331 EXPECT_EQ(host2->GetProcess(), |
332 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); | 332 browser()->GetWebContentsAt(2)->GetRenderProcessHost()); |
333 } | 333 } |
334 | 334 |
335 // Tests that app process switching works properly in the following scenario: | 335 // Tests that app process switching works properly in the following scenario: |
336 // 1. navigate to a page1 in the app | 336 // 1. navigate to a page1 in the app |
337 // 2. page1 redirects to a page2 outside the app extent (ie, "/server-redirect") | 337 // 2. page1 redirects to a page2 outside the app extent (ie, "/server-redirect") |
338 // 3. page2 redirects back to a page in the app | 338 // 3. page2 redirects back to a page in the app |
339 // The final navigation should end up in the app process. | 339 // The final navigation should end up in the app process. |
340 // See http://crbug.com/61757 | 340 // See http://crbug.com/61757 |
341 // This test doesn't complete on WebKit Win (dbg). See crbug.com/108853. | 341 // This test doesn't complete on WebKit Win (dbg). See crbug.com/108853. |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> | 658 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> |
659 GetController())); | 659 GetController())); |
660 browser()->Reload(CURRENT_TAB); | 660 browser()->Reload(CURRENT_TAB); |
661 observer.Wait(); | 661 observer.Wait(); |
662 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 662 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
663 contents->GetRenderViewHost(), L"", | 663 contents->GetRenderViewHost(), L"", |
664 L"window.domAutomationController.send(chrome.app.isInstalled)", | 664 L"window.domAutomationController.send(chrome.app.isInstalled)", |
665 &is_installed)); | 665 &is_installed)); |
666 ASSERT_TRUE(is_installed); | 666 ASSERT_TRUE(is_installed); |
667 } | 667 } |
OLD | NEW |