| 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" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 // processes, but they have no elevated privileges and thus should not | 78 // processes, but they have no elevated privileges and thus should not |
| 79 // have WebUI bindings. | 79 // have WebUI bindings. |
| 80 ui_test_utils::NavigateToURLWithDisposition( | 80 ui_test_utils::NavigateToURLWithDisposition( |
| 81 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, | 81 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, |
| 82 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 82 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 83 LOG(INFO) << "Nav 1."; | 83 LOG(INFO) << "Nav 1."; |
| 84 EXPECT_TRUE(process_map->Contains( | 84 EXPECT_TRUE(process_map->Contains( |
| 85 chrome::GetWebContentsAt(browser(), 1)->GetRenderProcessHost()->GetID())); | 85 chrome::GetWebContentsAt(browser(), 1)->GetRenderProcessHost()->GetID())); |
| 86 EXPECT_FALSE(chrome::GetWebContentsAt(browser(), 1)->GetWebUI()); | 86 EXPECT_FALSE(chrome::GetWebContentsAt(browser(), 1)->GetWebUI()); |
| 87 | 87 |
| 88 ui_test_utils::WindowedNotificationObserver tab_added_observer( | 88 content::WindowedNotificationObserver tab_added_observer( |
| 89 chrome::NOTIFICATION_TAB_ADDED, | 89 chrome::NOTIFICATION_TAB_ADDED, |
| 90 content::NotificationService::AllSources()); | 90 content::NotificationService::AllSources()); |
| 91 chrome::NewTab(browser()); | 91 chrome::NewTab(browser()); |
| 92 tab_added_observer.Wait(); | 92 tab_added_observer.Wait(); |
| 93 LOG(INFO) << "New tab."; | 93 LOG(INFO) << "New tab."; |
| 94 ui_test_utils::NavigateToURL(browser(), | 94 ui_test_utils::NavigateToURL(browser(), |
| 95 base_url.Resolve("path2/empty.html")); | 95 base_url.Resolve("path2/empty.html")); |
| 96 LOG(INFO) << "Nav 2."; | 96 LOG(INFO) << "Nav 2."; |
| 97 EXPECT_TRUE(process_map->Contains( | 97 EXPECT_TRUE(process_map->Contains( |
| 98 chrome::GetWebContentsAt(browser(), 2)->GetRenderProcessHost()->GetID())
); | 98 chrome::GetWebContentsAt(browser(), 2)->GetRenderProcessHost()->GetID())
); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 LOG(INFO) << "Nav 1."; | 147 LOG(INFO) << "Nav 1."; |
| 148 | 148 |
| 149 ui_test_utils::NavigateToURLWithDisposition( | 149 ui_test_utils::NavigateToURLWithDisposition( |
| 150 browser(), base_url.Resolve("path2/empty.html"), NEW_FOREGROUND_TAB, | 150 browser(), base_url.Resolve("path2/empty.html"), NEW_FOREGROUND_TAB, |
| 151 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 151 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 152 EXPECT_TRUE(process_map->Contains( | 152 EXPECT_TRUE(process_map->Contains( |
| 153 chrome::GetWebContentsAt(browser(), 2)->GetRenderProcessHost()->GetID())); | 153 chrome::GetWebContentsAt(browser(), 2)->GetRenderProcessHost()->GetID())); |
| 154 EXPECT_FALSE(chrome::GetWebContentsAt(browser(), 2)->GetWebUI()); | 154 EXPECT_FALSE(chrome::GetWebContentsAt(browser(), 2)->GetWebUI()); |
| 155 LOG(INFO) << "Nav 2."; | 155 LOG(INFO) << "Nav 2."; |
| 156 | 156 |
| 157 ui_test_utils::WindowedNotificationObserver tab_added_observer( | 157 content::WindowedNotificationObserver tab_added_observer( |
| 158 chrome::NOTIFICATION_TAB_ADDED, | 158 chrome::NOTIFICATION_TAB_ADDED, |
| 159 content::NotificationService::AllSources()); | 159 content::NotificationService::AllSources()); |
| 160 chrome::NewTab(browser()); | 160 chrome::NewTab(browser()); |
| 161 tab_added_observer.Wait(); | 161 tab_added_observer.Wait(); |
| 162 LOG(INFO) << "New tab."; | 162 LOG(INFO) << "New tab."; |
| 163 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path3/empty.html")); | 163 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path3/empty.html")); |
| 164 LOG(INFO) << "Nav 3."; | 164 LOG(INFO) << "Nav 3."; |
| 165 EXPECT_FALSE(process_map->Contains( | 165 EXPECT_FALSE(process_map->Contains( |
| 166 chrome::GetWebContentsAt(browser(), 3)->GetRenderProcessHost()->GetID())); | 166 chrome::GetWebContentsAt(browser(), 3)->GetRenderProcessHost()->GetID())); |
| 167 EXPECT_FALSE(chrome::GetWebContentsAt(browser(), 3)->GetWebUI()); | 167 EXPECT_FALSE(chrome::GetWebContentsAt(browser(), 3)->GetWebUI()); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 // 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 |
| 260 // it. Either way, bookmark app tabs should be considered normal processes | 260 // it. Either way, bookmark app tabs should be considered normal processes |
| 261 // with no elevated privileges and no WebUI bindings. | 261 // with no elevated privileges and no WebUI bindings. |
| 262 ui_test_utils::NavigateToURLWithDisposition( | 262 ui_test_utils::NavigateToURLWithDisposition( |
| 263 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, | 263 browser(), base_url.Resolve("path1/empty.html"), NEW_FOREGROUND_TAB, |
| 264 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 264 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 265 EXPECT_FALSE(process_map->Contains( | 265 EXPECT_FALSE(process_map->Contains( |
| 266 chrome::GetWebContentsAt(browser(), 1)->GetRenderProcessHost()->GetID())); | 266 chrome::GetWebContentsAt(browser(), 1)->GetRenderProcessHost()->GetID())); |
| 267 EXPECT_FALSE(chrome::GetWebContentsAt(browser(), 1)->GetWebUI()); | 267 EXPECT_FALSE(chrome::GetWebContentsAt(browser(), 1)->GetWebUI()); |
| 268 | 268 |
| 269 ui_test_utils::WindowedNotificationObserver tab_added_observer( | 269 content::WindowedNotificationObserver tab_added_observer( |
| 270 chrome::NOTIFICATION_TAB_ADDED, | 270 chrome::NOTIFICATION_TAB_ADDED, |
| 271 content::NotificationService::AllSources()); | 271 content::NotificationService::AllSources()); |
| 272 chrome::NewTab(browser()); | 272 chrome::NewTab(browser()); |
| 273 tab_added_observer.Wait(); | 273 tab_added_observer.Wait(); |
| 274 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); | 274 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path2/empty.html")); |
| 275 EXPECT_FALSE(process_map->Contains( | 275 EXPECT_FALSE(process_map->Contains( |
| 276 chrome::GetWebContentsAt(browser(), 2)->GetRenderProcessHost()->GetID())); | 276 chrome::GetWebContentsAt(browser(), 2)->GetRenderProcessHost()->GetID())); |
| 277 EXPECT_FALSE(chrome::GetWebContentsAt(browser(), 2)->GetWebUI()); | 277 EXPECT_FALSE(chrome::GetWebContentsAt(browser(), 2)->GetWebUI()); |
| 278 | 278 |
| 279 // 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 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 contents->GetRenderProcessHost()->GetID())); | 379 contents->GetRenderProcessHost()->GetID())); |
| 380 | 380 |
| 381 // Disable app and navigate to the page. | 381 // Disable app and navigate to the page. |
| 382 DisableExtension(app->id()); | 382 DisableExtension(app->id()); |
| 383 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); | 383 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
| 384 EXPECT_FALSE(process_map->Contains( | 384 EXPECT_FALSE(process_map->Contains( |
| 385 contents->GetRenderProcessHost()->GetID())); | 385 contents->GetRenderProcessHost()->GetID())); |
| 386 | 386 |
| 387 // Enable app and reload the page. | 387 // Enable app and reload the page. |
| 388 EnableExtension(app->id()); | 388 EnableExtension(app->id()); |
| 389 ui_test_utils::WindowedNotificationObserver reload_observer( | 389 content::WindowedNotificationObserver reload_observer( |
| 390 content::NOTIFICATION_LOAD_STOP, | 390 content::NOTIFICATION_LOAD_STOP, |
| 391 content::Source<NavigationController>( | 391 content::Source<NavigationController>( |
| 392 &chrome::GetActiveWebContents(browser())->GetController())); | 392 &chrome::GetActiveWebContents(browser())->GetController())); |
| 393 chrome::Reload(browser(), CURRENT_TAB); | 393 chrome::Reload(browser(), CURRENT_TAB); |
| 394 reload_observer.Wait(); | 394 reload_observer.Wait(); |
| 395 EXPECT_TRUE(process_map->Contains( | 395 EXPECT_TRUE(process_map->Contains( |
| 396 contents->GetRenderProcessHost()->GetID())); | 396 contents->GetRenderProcessHost()->GetID())); |
| 397 | 397 |
| 398 // Disable app and reload the page. | 398 // Disable app and reload the page. |
| 399 DisableExtension(app->id()); | 399 DisableExtension(app->id()); |
| 400 ui_test_utils::WindowedNotificationObserver reload_observer2( | 400 content::WindowedNotificationObserver reload_observer2( |
| 401 content::NOTIFICATION_LOAD_STOP, | 401 content::NOTIFICATION_LOAD_STOP, |
| 402 content::Source<NavigationController>( | 402 content::Source<NavigationController>( |
| 403 &chrome::GetActiveWebContents(browser())->GetController())); | 403 &chrome::GetActiveWebContents(browser())->GetController())); |
| 404 chrome::Reload(browser(), CURRENT_TAB); | 404 chrome::Reload(browser(), CURRENT_TAB); |
| 405 reload_observer2.Wait(); | 405 reload_observer2.Wait(); |
| 406 EXPECT_FALSE(process_map->Contains( | 406 EXPECT_FALSE(process_map->Contains( |
| 407 contents->GetRenderProcessHost()->GetID())); | 407 contents->GetRenderProcessHost()->GetID())); |
| 408 | 408 |
| 409 // Enable app and reload via JavaScript. | 409 // Enable app and reload via JavaScript. |
| 410 EnableExtension(app->id()); | 410 EnableExtension(app->id()); |
| 411 ui_test_utils::WindowedNotificationObserver js_reload_observer( | 411 content::WindowedNotificationObserver js_reload_observer( |
| 412 content::NOTIFICATION_LOAD_STOP, | 412 content::NOTIFICATION_LOAD_STOP, |
| 413 content::Source<NavigationController>( | 413 content::Source<NavigationController>( |
| 414 &chrome::GetActiveWebContents(browser())->GetController())); | 414 &chrome::GetActiveWebContents(browser())->GetController())); |
| 415 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->GetRenderViewHost(), | 415 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->GetRenderViewHost(), |
| 416 L"", L"location.reload();")); | 416 L"", L"location.reload();")); |
| 417 js_reload_observer.Wait(); | 417 js_reload_observer.Wait(); |
| 418 EXPECT_TRUE(process_map->Contains( | 418 EXPECT_TRUE(process_map->Contains( |
| 419 contents->GetRenderProcessHost()->GetID())); | 419 contents->GetRenderProcessHost()->GetID())); |
| 420 | 420 |
| 421 // Disable app and reload via JavaScript. | 421 // Disable app and reload via JavaScript. |
| 422 DisableExtension(app->id()); | 422 DisableExtension(app->id()); |
| 423 ui_test_utils::WindowedNotificationObserver js_reload_observer2( | 423 content::WindowedNotificationObserver js_reload_observer2( |
| 424 content::NOTIFICATION_LOAD_STOP, | 424 content::NOTIFICATION_LOAD_STOP, |
| 425 content::Source<NavigationController>( | 425 content::Source<NavigationController>( |
| 426 &chrome::GetActiveWebContents(browser())->GetController())); | 426 &chrome::GetActiveWebContents(browser())->GetController())); |
| 427 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->GetRenderViewHost(), | 427 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->GetRenderViewHost(), |
| 428 L"", L"location = location;")); | 428 L"", L"location = location;")); |
| 429 js_reload_observer2.Wait(); | 429 js_reload_observer2.Wait(); |
| 430 EXPECT_FALSE(process_map->Contains( | 430 EXPECT_FALSE(process_map->Contains( |
| 431 contents->GetRenderProcessHost()->GetID())); | 431 contents->GetRenderProcessHost()->GetID())); |
| 432 } | 432 } |
| 433 | 433 |
| 434 // 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 |
| 435 // 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 |
| 436 // 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/ |
| 437 // empty.html) results in the new window being in an app process. See | 437 // empty.html) results in the new window being in an app process. See |
| 438 // http://crbug.com/89272 for more details. | 438 // http://crbug.com/89272 for more details. |
| 439 IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromIframe) { | 439 IN_PROC_BROWSER_TEST_F(AppApiTest, OpenAppFromIframe) { |
| 440 extensions::ProcessMap* process_map = | 440 extensions::ProcessMap* process_map = |
| 441 browser()->profile()->GetExtensionService()->process_map(); | 441 browser()->profile()->GetExtensionService()->process_map(); |
| 442 | 442 |
| 443 host_resolver()->AddRule("*", "127.0.0.1"); | 443 host_resolver()->AddRule("*", "127.0.0.1"); |
| 444 ASSERT_TRUE(test_server()->Start()); | 444 ASSERT_TRUE(test_server()->Start()); |
| 445 | 445 |
| 446 GURL base_url = GetTestBaseURL("app_process"); | 446 GURL base_url = GetTestBaseURL("app_process"); |
| 447 | 447 |
| 448 // Load app and start URL (not in the app). | 448 // Load app and start URL (not in the app). |
| 449 const Extension* app = | 449 const Extension* app = |
| 450 LoadExtension(test_data_dir_.AppendASCII("app_process")); | 450 LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 451 ASSERT_TRUE(app); | 451 ASSERT_TRUE(app); |
| 452 | 452 |
| 453 ui_test_utils::WindowedNotificationObserver popup_observer( | 453 content::WindowedNotificationObserver popup_observer( |
| 454 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, | 454 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, |
| 455 content::NotificationService::AllSources()); | 455 content::NotificationService::AllSources()); |
| 456 ui_test_utils::NavigateToURL(browser(), | 456 ui_test_utils::NavigateToURL(browser(), |
| 457 base_url.Resolve("path3/container.html")); | 457 base_url.Resolve("path3/container.html")); |
| 458 EXPECT_FALSE(process_map->Contains( | 458 EXPECT_FALSE(process_map->Contains( |
| 459 chrome::GetWebContentsAt(browser(), 0)->GetRenderProcessHost()->GetID())); | 459 chrome::GetWebContentsAt(browser(), 0)->GetRenderProcessHost()->GetID())); |
| 460 popup_observer.Wait(); | 460 popup_observer.Wait(); |
| 461 | 461 |
| 462 // Popup window should be in the app's process. | 462 // Popup window should be in the app's process. |
| 463 RenderViewHost* popup_host = | 463 RenderViewHost* popup_host = |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 host_resolver()->AddRule("*", "127.0.0.1"); | 521 host_resolver()->AddRule("*", "127.0.0.1"); |
| 522 ASSERT_TRUE(test_server()->Start()); | 522 ASSERT_TRUE(test_server()->Start()); |
| 523 | 523 |
| 524 GURL base_url = GetTestBaseURL("app_process"); | 524 GURL base_url = GetTestBaseURL("app_process"); |
| 525 | 525 |
| 526 // Load app and start URL (in the app). | 526 // Load app and start URL (in the app). |
| 527 const Extension* app = | 527 const Extension* app = |
| 528 LoadExtension(test_data_dir_.AppendASCII("app_process")); | 528 LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 529 ASSERT_TRUE(app); | 529 ASSERT_TRUE(app); |
| 530 | 530 |
| 531 ui_test_utils::WindowedNotificationObserver popup_observer( | 531 content::WindowedNotificationObserver popup_observer( |
| 532 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, | 532 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, |
| 533 content::NotificationService::AllSources()); | 533 content::NotificationService::AllSources()); |
| 534 ui_test_utils::NavigateToURL(browser(), | 534 ui_test_utils::NavigateToURL(browser(), |
| 535 base_url.Resolve("path1/container.html")); | 535 base_url.Resolve("path1/container.html")); |
| 536 content::RenderProcessHost* process = | 536 content::RenderProcessHost* process = |
| 537 chrome::GetWebContentsAt(browser(), 0)->GetRenderProcessHost(); | 537 chrome::GetWebContentsAt(browser(), 0)->GetRenderProcessHost(); |
| 538 EXPECT_TRUE(process_map->Contains(process->GetID())); | 538 EXPECT_TRUE(process_map->Contains(process->GetID())); |
| 539 | 539 |
| 540 // Wait for popup window to appear. | 540 // Wait for popup window to appear. |
| 541 popup_observer.Wait(); | 541 popup_observer.Wait(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 570 contents->GetRenderProcessHost()->GetID())); | 570 contents->GetRenderProcessHost()->GetID())); |
| 571 bool is_installed = false; | 571 bool is_installed = false; |
| 572 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 572 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 573 contents->GetRenderViewHost(), L"", | 573 contents->GetRenderViewHost(), L"", |
| 574 L"window.domAutomationController.send(chrome.app.isInstalled)", | 574 L"window.domAutomationController.send(chrome.app.isInstalled)", |
| 575 &is_installed)); | 575 &is_installed)); |
| 576 ASSERT_TRUE(is_installed); | 576 ASSERT_TRUE(is_installed); |
| 577 | 577 |
| 578 // 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. |
| 579 ui_test_utils::CrashTab(chrome::GetActiveWebContents(browser())); | 579 ui_test_utils::CrashTab(chrome::GetActiveWebContents(browser())); |
| 580 ui_test_utils::WindowedNotificationObserver observer( | 580 content::WindowedNotificationObserver observer( |
| 581 content::NOTIFICATION_LOAD_STOP, | 581 content::NOTIFICATION_LOAD_STOP, |
| 582 content::Source<NavigationController>( | 582 content::Source<NavigationController>( |
| 583 &chrome::GetActiveWebContents(browser())->GetController())); | 583 &chrome::GetActiveWebContents(browser())->GetController())); |
| 584 chrome::Reload(browser(), CURRENT_TAB); | 584 chrome::Reload(browser(), CURRENT_TAB); |
| 585 observer.Wait(); | 585 observer.Wait(); |
| 586 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 586 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 587 contents->GetRenderViewHost(), L"", | 587 contents->GetRenderViewHost(), L"", |
| 588 L"window.domAutomationController.send(chrome.app.isInstalled)", | 588 L"window.domAutomationController.send(chrome.app.isInstalled)", |
| 589 &is_installed)); | 589 &is_installed)); |
| 590 ASSERT_TRUE(is_installed); | 590 ASSERT_TRUE(is_installed); |
| 591 } | 591 } |
| OLD | NEW |