| OLD | NEW |
| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 // http://crbug.com/88316 | 81 // http://crbug.com/88316 |
| 82 #define MAYBE_AppProcess DISABLED_AppProcess | 82 #define MAYBE_AppProcess DISABLED_AppProcess |
| 83 #else | 83 #else |
| 84 #define MAYBE_AppProcess AppProcess | 84 #define MAYBE_AppProcess AppProcess |
| 85 #endif | 85 #endif |
| 86 | 86 |
| 87 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcess) { | 87 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcess) { |
| 88 CommandLine::ForCurrentProcess()->AppendSwitch( | 88 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 89 switches::kDisablePopupBlocking); | 89 switches::kDisablePopupBlocking); |
| 90 | 90 |
| 91 ExtensionProcessManager* extension_process_manager = |
| 92 browser()->profile()->GetExtensionProcessManager(); |
| 93 |
| 91 host_resolver()->AddRule("*", "127.0.0.1"); | 94 host_resolver()->AddRule("*", "127.0.0.1"); |
| 92 ASSERT_TRUE(test_server()->Start()); | 95 ASSERT_TRUE(test_server()->Start()); |
| 93 | 96 |
| 94 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); | 97 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); |
| 95 | 98 |
| 96 // Open two tabs in the app, one outside it. | 99 // Open two tabs in the app, one outside it. |
| 97 GURL base_url = GetTestBaseURL("app_process"); | 100 GURL base_url = GetTestBaseURL("app_process"); |
| 98 | 101 |
| 99 // Test both opening a URL in a new tab, and opening a tab and then navigating | 102 // Test both opening a URL in a new tab, and opening a tab and then navigating |
| 100 // it. Either way, app tabs should be considered extension processes, but | 103 // it. Either way, app tabs should be considered extension processes, but |
| 101 // they have no elevated privileges and thus should not have WebUI bindings. | 104 // they have no elevated privileges and thus should not have WebUI bindings. |
| 102 ui_test_utils::NavigateToURLWithDisposition( | 105 ui_test_utils::NavigateToURLWithDisposition( |
| 103 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, | 106 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, |
| 104 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 107 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 105 EXPECT_TRUE(browser()->GetTabContentsAt(1)->render_view_host()->process()-> | 108 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( |
| 106 is_extension_process()); | 109 browser()->GetTabContentsAt(1)->render_view_host()->process()->id())); |
| 107 EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui()); | 110 EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui()); |
| 108 browser()->NewTab(); | 111 browser()->NewTab(); |
| 109 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); | 112 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); |
| 110 EXPECT_TRUE(browser()->GetTabContentsAt(2)->render_view_host()->process()-> | 113 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( |
| 111 is_extension_process()); | 114 browser()->GetTabContentsAt(2)->render_view_host()->process()->id())); |
| 112 EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui()); | 115 EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui()); |
| 113 browser()->NewTab(); | 116 browser()->NewTab(); |
| 114 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path3/empty.html")); | 117 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path3/empty.html")); |
| 115 EXPECT_FALSE(browser()->GetTabContentsAt(3)->render_view_host()->process()-> | 118 EXPECT_FALSE(extension_process_manager->IsExtensionProcess( |
| 116 is_extension_process()); | 119 browser()->GetTabContentsAt(3)->render_view_host()->process()->id())); |
| 117 EXPECT_FALSE(browser()->GetTabContentsAt(3)->web_ui()); | 120 EXPECT_FALSE(browser()->GetTabContentsAt(3)->web_ui()); |
| 118 | 121 |
| 119 // We should have opened 3 new extension tabs. Including the original blank | 122 // We should have opened 3 new extension tabs. Including the original blank |
| 120 // tab, we now have 4 tabs. Because the app_process app has the background | 123 // tab, we now have 4 tabs. Because the app_process app has the background |
| 121 // permission, all of its instances are in the same process. Thus two tabs | 124 // permission, all of its instances are in the same process. Thus two tabs |
| 122 // should be part of the extension app and grouped in the same process. | 125 // should be part of the extension app and grouped in the same process. |
| 123 ASSERT_EQ(4, browser()->tab_count()); | 126 ASSERT_EQ(4, browser()->tab_count()); |
| 124 RenderViewHost* host = browser()->GetTabContentsAt(1)->render_view_host(); | 127 RenderViewHost* host = browser()->GetTabContentsAt(1)->render_view_host(); |
| 125 | 128 |
| 126 EXPECT_EQ(host->process(), | 129 EXPECT_EQ(host->process(), |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 #else | 172 #else |
| 170 #define MAYBE_AppProcessInstances AppProcessInstances | 173 #define MAYBE_AppProcessInstances AppProcessInstances |
| 171 #endif | 174 #endif |
| 172 | 175 |
| 173 // Test that hosted apps without the background permission use a process per app | 176 // Test that hosted apps without the background permission use a process per app |
| 174 // instance model, such that separate instances are in separate processes. | 177 // instance model, such that separate instances are in separate processes. |
| 175 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcessInstances) { | 178 IN_PROC_BROWSER_TEST_F(AppApiTest, MAYBE_AppProcessInstances) { |
| 176 CommandLine::ForCurrentProcess()->AppendSwitch( | 179 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 177 switches::kDisablePopupBlocking); | 180 switches::kDisablePopupBlocking); |
| 178 | 181 |
| 182 ExtensionProcessManager* extension_process_manager = |
| 183 browser()->profile()->GetExtensionProcessManager(); |
| 184 |
| 179 host_resolver()->AddRule("*", "127.0.0.1"); | 185 host_resolver()->AddRule("*", "127.0.0.1"); |
| 180 ASSERT_TRUE(test_server()->Start()); | 186 ASSERT_TRUE(test_server()->Start()); |
| 181 | 187 |
| 182 ASSERT_TRUE(LoadExtension( | 188 ASSERT_TRUE(LoadExtension( |
| 183 test_data_dir_.AppendASCII("app_process_instances"))); | 189 test_data_dir_.AppendASCII("app_process_instances"))); |
| 184 | 190 |
| 185 // Open two tabs in the app, one outside it. | 191 // Open two tabs in the app, one outside it. |
| 186 GURL base_url = GetTestBaseURL("app_process_instances"); | 192 GURL base_url = GetTestBaseURL("app_process_instances"); |
| 187 | 193 |
| 188 // Test both opening a URL in a new tab, and opening a tab and then navigating | 194 // Test both opening a URL in a new tab, and opening a tab and then navigating |
| 189 // it. Either way, app tabs should be considered extension processes, but | 195 // it. Either way, app tabs should be considered extension processes, but |
| 190 // they have no elevated privileges and thus should not have WebUI bindings. | 196 // they have no elevated privileges and thus should not have WebUI bindings. |
| 191 ui_test_utils::NavigateToURLWithDisposition( | 197 ui_test_utils::NavigateToURLWithDisposition( |
| 192 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, | 198 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, |
| 193 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 199 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 194 EXPECT_TRUE(browser()->GetTabContentsAt(1)->render_view_host()->process()-> | 200 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( |
| 195 is_extension_process()); | 201 browser()->GetTabContentsAt(1)->render_view_host()->process()->id())); |
| 196 EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui()); | 202 EXPECT_FALSE(browser()->GetTabContentsAt(1)->web_ui()); |
| 197 browser()->NewTab(); | 203 browser()->NewTab(); |
| 198 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); | 204 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); |
| 199 EXPECT_TRUE(browser()->GetTabContentsAt(2)->render_view_host()->process()-> | 205 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( |
| 200 is_extension_process()); | 206 browser()->GetTabContentsAt(2)->render_view_host()->process()->id())); |
| 201 EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui()); | 207 EXPECT_FALSE(browser()->GetTabContentsAt(2)->web_ui()); |
| 202 | 208 |
| 203 // We should have opened 2 new extension tabs. Including the original blank | 209 // We should have opened 2 new extension tabs. Including the original blank |
| 204 // tab, we now have 3 tabs. The two app tabs should not be in the same | 210 // tab, we now have 3 tabs. The two app tabs should not be in the same |
| 205 // process, since they do not have the background permission. (Thus, we want | 211 // process, since they do not have the background permission. (Thus, we want |
| 206 // to separate them to improve responsiveness.) | 212 // to separate them to improve responsiveness.) |
| 207 ASSERT_EQ(3, browser()->tab_count()); | 213 ASSERT_EQ(3, browser()->tab_count()); |
| 208 RenderViewHost* host1 = browser()->GetTabContentsAt(1)->render_view_host(); | 214 RenderViewHost* host1 = browser()->GetTabContentsAt(1)->render_view_host(); |
| 209 RenderViewHost* host2 = browser()->GetTabContentsAt(2)->render_view_host(); | 215 RenderViewHost* host2 = browser()->GetTabContentsAt(2)->render_view_host(); |
| 210 EXPECT_NE(host1->process(), host2->process()); | 216 EXPECT_NE(host1->process(), host2->process()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 EXPECT_EQ(host->process(), | 258 EXPECT_EQ(host->process(), |
| 253 browser()->GetTabContentsAt(2)->render_view_host()->process()); | 259 browser()->GetTabContentsAt(2)->render_view_host()->process()); |
| 254 } | 260 } |
| 255 | 261 |
| 256 // Ensure that reloading a URL after installing or uninstalling it as an app | 262 // Ensure that reloading a URL after installing or uninstalling it as an app |
| 257 // correctly swaps the process. (http://crbug.com/80621) | 263 // correctly swaps the process. (http://crbug.com/80621) |
| 258 IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadIntoAppProcess) { | 264 IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadIntoAppProcess) { |
| 259 CommandLine::ForCurrentProcess()->AppendSwitch( | 265 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 260 switches::kDisablePopupBlocking); | 266 switches::kDisablePopupBlocking); |
| 261 | 267 |
| 268 ExtensionProcessManager* extension_process_manager = |
| 269 browser()->profile()->GetExtensionProcessManager(); |
| 270 |
| 262 host_resolver()->AddRule("*", "127.0.0.1"); | 271 host_resolver()->AddRule("*", "127.0.0.1"); |
| 263 ASSERT_TRUE(test_server()->Start()); | 272 ASSERT_TRUE(test_server()->Start()); |
| 264 | 273 |
| 265 // The app under test acts on URLs whose host is "localhost", | 274 // The app under test acts on URLs whose host is "localhost", |
| 266 // so the URLs we navigate to must have host "localhost". | 275 // so the URLs we navigate to must have host "localhost". |
| 267 GURL base_url = GetTestBaseURL("app_process"); | 276 GURL base_url = GetTestBaseURL("app_process"); |
| 268 | 277 |
| 269 // Load an app URL before loading the app. | 278 // Load an app URL before loading the app. |
| 270 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); | 279 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
| 271 TabContents* contents = browser()->GetTabContentsAt(0); | 280 TabContents* contents = browser()->GetTabContentsAt(0); |
| 272 EXPECT_FALSE(contents->render_view_host()->process()->is_extension_process()); | 281 EXPECT_FALSE(extension_process_manager->IsExtensionProcess( |
| 282 contents->render_view_host()->process()->id())); |
| 273 | 283 |
| 274 // Load app and reload page. | 284 // Load app and reload page. |
| 275 const Extension* app = | 285 const Extension* app = |
| 276 LoadExtension(test_data_dir_.AppendASCII("app_process")); | 286 LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 277 ASSERT_TRUE(app); | 287 ASSERT_TRUE(app); |
| 278 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); | 288 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
| 279 EXPECT_TRUE(contents->render_view_host()->process()->is_extension_process()); | 289 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( |
| 290 contents->render_view_host()->process()->id())); |
| 280 | 291 |
| 281 // Disable app and reload page. | 292 // Disable app and reload page. |
| 282 DisableExtension(app->id()); | 293 DisableExtension(app->id()); |
| 283 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); | 294 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
| 284 EXPECT_FALSE(contents->render_view_host()->process()->is_extension_process()); | 295 EXPECT_FALSE(extension_process_manager->IsExtensionProcess( |
| 296 contents->render_view_host()->process()->id())); |
| 285 | 297 |
| 286 // Enable app and reload via JavaScript. | 298 // Enable app and reload via JavaScript. |
| 287 EnableExtension(app->id()); | 299 EnableExtension(app->id()); |
| 288 ui_test_utils::WindowedNotificationObserver observer( | 300 ui_test_utils::WindowedNotificationObserver observer( |
| 289 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources()); | 301 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources()); |
| 290 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->render_view_host(), | 302 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->render_view_host(), |
| 291 L"", L"location.reload();")); | 303 L"", L"location.reload();")); |
| 292 observer.Wait(); | 304 observer.Wait(); |
| 293 EXPECT_TRUE(contents->render_view_host()->process()->is_extension_process()); | 305 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( |
| 306 contents->render_view_host()->process()->id())); |
| 294 | 307 |
| 295 // Disable app and reload via JavaScript. | 308 // Disable app and reload via JavaScript. |
| 296 DisableExtension(app->id()); | 309 DisableExtension(app->id()); |
| 297 ui_test_utils::WindowedNotificationObserver observer2( | 310 ui_test_utils::WindowedNotificationObserver observer2( |
| 298 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources()); | 311 content::NOTIFICATION_LOAD_STOP, NotificationService::AllSources()); |
| 299 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->render_view_host(), | 312 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->render_view_host(), |
| 300 L"", L"location.reload();")); | 313 L"", L"location.reload();")); |
| 301 observer2.Wait(); | 314 observer2.Wait(); |
| 302 EXPECT_FALSE(contents->render_view_host()->process()->is_extension_process()); | 315 EXPECT_FALSE(extension_process_manager->IsExtensionProcess( |
| 316 contents->render_view_host()->process()->id())); |
| 303 } | 317 } |
| 304 | 318 |
| 305 | 319 |
| 306 // Tests that if we have a non-app process (path3/container.html) that has an | 320 // Tests that if we have a non-app process (path3/container.html) that has an |
| 307 // iframe with a URL in the app's extent (path1/iframe.html), then opening a | 321 // iframe with a URL in the app's extent (path1/iframe.html), then opening a |
| 308 // link from that iframe to a new window to a URL in the app's extent (path1/ | 322 // link from that iframe to a new window to a URL in the app's extent (path1/ |
| 309 // empty.html) results in the new window being in an app process. See | 323 // empty.html) results in the new window being in an app process. See |
| 310 // http://crbug.com/89272 for more details. | 324 // http://crbug.com/89272 for more details. |
| 311 IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromIframe) { | 325 IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromIframe) { |
| 312 CommandLine::ForCurrentProcess()->AppendSwitch( | 326 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 313 switches::kDisablePopupBlocking); | 327 switches::kDisablePopupBlocking); |
| 314 | 328 |
| 329 ExtensionProcessManager* extension_process_manager = |
| 330 browser()->profile()->GetExtensionProcessManager(); |
| 331 |
| 315 host_resolver()->AddRule("*", "127.0.0.1"); | 332 host_resolver()->AddRule("*", "127.0.0.1"); |
| 316 ASSERT_TRUE(test_server()->Start()); | 333 ASSERT_TRUE(test_server()->Start()); |
| 317 | 334 |
| 318 GURL base_url = GetTestBaseURL("app_process"); | 335 GURL base_url = GetTestBaseURL("app_process"); |
| 319 | 336 |
| 320 // Load app and start URL (not in the app). | 337 // Load app and start URL (not in the app). |
| 321 const Extension* app = | 338 const Extension* app = |
| 322 LoadExtension(test_data_dir_.AppendASCII("app_process")); | 339 LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 323 ASSERT_TRUE(app); | 340 ASSERT_TRUE(app); |
| 324 ui_test_utils::NavigateToURLWithDisposition( | 341 ui_test_utils::NavigateToURLWithDisposition( |
| 325 browser(), | 342 browser(), |
| 326 base_url.Resolve("path3/container.html"), | 343 base_url.Resolve("path3/container.html"), |
| 327 CURRENT_TAB, | 344 CURRENT_TAB, |
| 328 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION | | 345 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION | |
| 329 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); | 346 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); |
| 330 EXPECT_FALSE(browser()->GetTabContentsAt(0)->render_view_host()->process()-> | 347 EXPECT_FALSE(extension_process_manager->IsExtensionProcess( |
| 331 is_extension_process()); | 348 browser()->GetTabContentsAt(0)->render_view_host()->process()->id())); |
| 332 | 349 |
| 333 // Wait for popup window to appear. | 350 // Wait for popup window to appear. |
| 334 GURL app_url = base_url.Resolve("path1/empty.html"); | 351 GURL app_url = base_url.Resolve("path1/empty.html"); |
| 335 Browser* last_active_browser = BrowserList::GetLastActive(); | 352 Browser* last_active_browser = BrowserList::GetLastActive(); |
| 336 EXPECT_TRUE(last_active_browser); | 353 EXPECT_TRUE(last_active_browser); |
| 337 ASSERT_NE(browser(), last_active_browser); | 354 ASSERT_NE(browser(), last_active_browser); |
| 338 TabContents* newtab = last_active_browser->GetSelectedTabContents(); | 355 TabContents* newtab = last_active_browser->GetSelectedTabContents(); |
| 339 EXPECT_TRUE(newtab); | 356 EXPECT_TRUE(newtab); |
| 340 if (!newtab->controller().GetLastCommittedEntry() || | 357 if (!newtab->controller().GetLastCommittedEntry() || |
| 341 newtab->controller().GetLastCommittedEntry()->url() != app_url) | 358 newtab->controller().GetLastCommittedEntry()->url() != app_url) |
| 342 ui_test_utils::WaitForNavigation(&newtab->controller()); | 359 ui_test_utils::WaitForNavigation(&newtab->controller()); |
| 343 | 360 |
| 344 // Popup window should be in the app's process. | 361 // Popup window should be in the app's process. |
| 345 EXPECT_TRUE(last_active_browser->GetTabContentsAt(0)->render_view_host()-> | 362 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( |
| 346 process()->is_extension_process()); | 363 last_active_browser->GetTabContentsAt(0)->render_view_host()->process()-> |
| 364 id())); |
| 347 } | 365 } |
| 348 | 366 |
| 349 // Tests that if we have an app process (path1/container.html) with a non-app | 367 // Tests that if we have an app process (path1/container.html) with a non-app |
| 350 // iframe (path3/iframe.html), then opening a link from that iframe to a new | 368 // iframe (path3/iframe.html), then opening a link from that iframe to a new |
| 351 // window to a same-origin non-app URL (path3/empty.html) should keep the window | 369 // window to a same-origin non-app URL (path3/empty.html) should keep the window |
| 352 // in the app process. | 370 // in the app process. |
| 353 // This is in contrast to OpenAppFromIframe, since here the popup will not be | 371 // This is in contrast to OpenAppFromIframe, since here the popup will not be |
| 354 // missing special permissions and should be scriptable from the iframe. | 372 // missing special permissions and should be scriptable from the iframe. |
| 355 // See http://crbug.com/92669 for more details. | 373 // See http://crbug.com/92669 for more details. |
| 356 IN_PROC_BROWSER_TEST_F(AppApiTest, OpenWebPopupFromWebIframe) { | 374 IN_PROC_BROWSER_TEST_F(AppApiTest, OpenWebPopupFromWebIframe) { |
| 357 CommandLine::ForCurrentProcess()->AppendSwitch( | 375 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 358 switches::kDisablePopupBlocking); | 376 switches::kDisablePopupBlocking); |
| 359 | 377 |
| 378 ExtensionProcessManager* extension_process_manager = |
| 379 browser()->profile()->GetExtensionProcessManager(); |
| 380 |
| 360 host_resolver()->AddRule("*", "127.0.0.1"); | 381 host_resolver()->AddRule("*", "127.0.0.1"); |
| 361 ASSERT_TRUE(test_server()->Start()); | 382 ASSERT_TRUE(test_server()->Start()); |
| 362 | 383 |
| 363 GURL base_url = GetTestBaseURL("app_process"); | 384 GURL base_url = GetTestBaseURL("app_process"); |
| 364 | 385 |
| 365 // Load app and start URL (in the app). | 386 // Load app and start URL (in the app). |
| 366 const Extension* app = | 387 const Extension* app = |
| 367 LoadExtension(test_data_dir_.AppendASCII("app_process")); | 388 LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 368 ASSERT_TRUE(app); | 389 ASSERT_TRUE(app); |
| 369 ui_test_utils::NavigateToURLWithDisposition( | 390 ui_test_utils::NavigateToURLWithDisposition( |
| 370 browser(), | 391 browser(), |
| 371 base_url.Resolve("path1/container.html"), | 392 base_url.Resolve("path1/container.html"), |
| 372 CURRENT_TAB, | 393 CURRENT_TAB, |
| 373 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION | | 394 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION | |
| 374 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); | 395 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); |
| 375 RenderProcessHost* process = | 396 RenderProcessHost* process = |
| 376 browser()->GetTabContentsAt(0)->render_view_host()->process(); | 397 browser()->GetTabContentsAt(0)->render_view_host()->process(); |
| 377 EXPECT_TRUE(process->is_extension_process()); | 398 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( |
| 399 process->id())); |
| 378 | 400 |
| 379 // Wait for popup window to appear. The new Browser may not have been | 401 // Wait for popup window to appear. The new Browser may not have been |
| 380 // added with SetLastActive, in which case we need to show it first. | 402 // added with SetLastActive, in which case we need to show it first. |
| 381 // This is necessary for popup windows without a cross-site transition. | 403 // This is necessary for popup windows without a cross-site transition. |
| 382 if (browser() == BrowserList::GetLastActive()) { | 404 if (browser() == BrowserList::GetLastActive()) { |
| 383 // Grab the second window and show it. | 405 // Grab the second window and show it. |
| 384 ASSERT_TRUE(BrowserList::size() == 2); | 406 ASSERT_TRUE(BrowserList::size() == 2); |
| 385 Browser* popup_browser = *(++BrowserList::begin()); | 407 Browser* popup_browser = *(++BrowserList::begin()); |
| 386 popup_browser->window()->Show(); | 408 popup_browser->window()->Show(); |
| 387 } | 409 } |
| 388 Browser* last_active_browser = BrowserList::GetLastActive(); | 410 Browser* last_active_browser = BrowserList::GetLastActive(); |
| 389 EXPECT_TRUE(last_active_browser); | 411 EXPECT_TRUE(last_active_browser); |
| 390 ASSERT_NE(browser(), last_active_browser); | 412 ASSERT_NE(browser(), last_active_browser); |
| 391 TabContents* newtab = last_active_browser->GetSelectedTabContents(); | 413 TabContents* newtab = last_active_browser->GetSelectedTabContents(); |
| 392 EXPECT_TRUE(newtab); | 414 EXPECT_TRUE(newtab); |
| 393 GURL non_app_url = base_url.Resolve("path3/empty.html"); | 415 GURL non_app_url = base_url.Resolve("path3/empty.html"); |
| 394 if (!newtab->controller().GetLastCommittedEntry() || | 416 if (!newtab->controller().GetLastCommittedEntry() || |
| 395 newtab->controller().GetLastCommittedEntry()->url() != non_app_url) | 417 newtab->controller().GetLastCommittedEntry()->url() != non_app_url) |
| 396 ui_test_utils::WaitForNavigation(&newtab->controller()); | 418 ui_test_utils::WaitForNavigation(&newtab->controller()); |
| 397 | 419 |
| 398 // Popup window should be in the app's process. | 420 // Popup window should be in the app's process. |
| 399 RenderProcessHost* popup_process = | 421 RenderProcessHost* popup_process = |
| 400 last_active_browser->GetTabContentsAt(0)->render_view_host()->process(); | 422 last_active_browser->GetTabContentsAt(0)->render_view_host()->process(); |
| 401 EXPECT_EQ(process, popup_process); | 423 EXPECT_EQ(process, popup_process); |
| 402 } | 424 } |
| 403 | 425 |
| 404 IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadAppAfterCrash) { | 426 IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadAppAfterCrash) { |
| 427 ExtensionProcessManager* extension_process_manager = |
| 428 browser()->profile()->GetExtensionProcessManager(); |
| 405 host_resolver()->AddRule("*", "127.0.0.1"); | 429 host_resolver()->AddRule("*", "127.0.0.1"); |
| 406 ASSERT_TRUE(test_server()->Start()); | 430 ASSERT_TRUE(test_server()->Start()); |
| 407 | 431 |
| 408 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); | 432 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); |
| 409 | 433 |
| 410 GURL base_url = GetTestBaseURL("app_process"); | 434 GURL base_url = GetTestBaseURL("app_process"); |
| 411 | 435 |
| 412 // Load the app, chrome.app.isInstalled should be true. | 436 // Load the app, chrome.app.isInstalled should be true. |
| 413 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); | 437 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
| 414 TabContents* contents = browser()->GetTabContentsAt(0); | 438 TabContents* contents = browser()->GetTabContentsAt(0); |
| 415 EXPECT_TRUE(contents->render_view_host()->process()->is_extension_process()); | 439 EXPECT_TRUE(extension_process_manager->IsExtensionProcess( |
| 440 contents->render_view_host()->process()->id())); |
| 416 bool is_installed = false; | 441 bool is_installed = false; |
| 417 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 442 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 418 contents->render_view_host(), L"", | 443 contents->render_view_host(), L"", |
| 419 L"window.domAutomationController.send(chrome.app.isInstalled)", | 444 L"window.domAutomationController.send(chrome.app.isInstalled)", |
| 420 &is_installed)); | 445 &is_installed)); |
| 421 ASSERT_TRUE(is_installed); | 446 ASSERT_TRUE(is_installed); |
| 422 | 447 |
| 423 // Crash the tab and reload it, chrome.app.isInstalled should still be true. | 448 // Crash the tab and reload it, chrome.app.isInstalled should still be true. |
| 424 ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); | 449 ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); |
| 425 ui_test_utils::WindowedNotificationObserver observer( | 450 ui_test_utils::WindowedNotificationObserver observer( |
| 426 content::NOTIFICATION_LOAD_STOP, | 451 content::NOTIFICATION_LOAD_STOP, |
| 427 Source<NavigationController>( | 452 Source<NavigationController>( |
| 428 &browser()->GetSelectedTabContentsWrapper()->controller())); | 453 &browser()->GetSelectedTabContentsWrapper()->controller())); |
| 429 browser()->Reload(CURRENT_TAB); | 454 browser()->Reload(CURRENT_TAB); |
| 430 observer.Wait(); | 455 observer.Wait(); |
| 431 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 456 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 432 contents->render_view_host(), L"", | 457 contents->render_view_host(), L"", |
| 433 L"window.domAutomationController.send(chrome.app.isInstalled)", | 458 L"window.domAutomationController.send(chrome.app.isInstalled)", |
| 434 &is_installed)); | 459 &is_installed)); |
| 435 ASSERT_TRUE(is_installed); | 460 ASSERT_TRUE(is_installed); |
| 436 } | 461 } |
| OLD | NEW |