| 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_finder.h" | 11 #include "chrome/browser/ui/browser_finder.h" |
| 12 #include "chrome/browser/ui/browser_list.h" | 12 #include "chrome/browser/ui/browser_list.h" |
| 13 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
| 18 #include "chrome/common/extensions/extension_file_util.h" | 18 #include "chrome/common/extensions/extension_file_util.h" |
| 19 #include "chrome/common/string_ordinal.h" | 19 #include "chrome/common/string_ordinal.h" |
| 20 #include "chrome/test/base/ui_test_utils.h" | 20 #include "chrome/test/base/ui_test_utils.h" |
| 21 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
| 22 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 23 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
| 24 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 DisableExtension(app->id()); | 379 DisableExtension(app->id()); |
| 380 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); | 380 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
| 381 EXPECT_FALSE(process_map->Contains( | 381 EXPECT_FALSE(process_map->Contains( |
| 382 contents->GetRenderProcessHost()->GetID())); | 382 contents->GetRenderProcessHost()->GetID())); |
| 383 | 383 |
| 384 // Enable app and reload the page. | 384 // Enable app and reload the page. |
| 385 EnableExtension(app->id()); | 385 EnableExtension(app->id()); |
| 386 ui_test_utils::WindowedNotificationObserver reload_observer( | 386 ui_test_utils::WindowedNotificationObserver reload_observer( |
| 387 content::NOTIFICATION_LOAD_STOP, | 387 content::NOTIFICATION_LOAD_STOP, |
| 388 content::Source<NavigationController>( | 388 content::Source<NavigationController>( |
| 389 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> | 389 &browser()->GetActiveWebContents()->GetController())); |
| 390 GetController())); | |
| 391 browser()->Reload(CURRENT_TAB); | 390 browser()->Reload(CURRENT_TAB); |
| 392 reload_observer.Wait(); | 391 reload_observer.Wait(); |
| 393 EXPECT_TRUE(process_map->Contains( | 392 EXPECT_TRUE(process_map->Contains( |
| 394 contents->GetRenderProcessHost()->GetID())); | 393 contents->GetRenderProcessHost()->GetID())); |
| 395 | 394 |
| 396 // Disable app and reload the page. | 395 // Disable app and reload the page. |
| 397 DisableExtension(app->id()); | 396 DisableExtension(app->id()); |
| 398 ui_test_utils::WindowedNotificationObserver reload_observer2( | 397 ui_test_utils::WindowedNotificationObserver reload_observer2( |
| 399 content::NOTIFICATION_LOAD_STOP, | 398 content::NOTIFICATION_LOAD_STOP, |
| 400 content::Source<NavigationController>( | 399 content::Source<NavigationController>( |
| 401 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> | 400 &browser()->GetActiveWebContents()->GetController())); |
| 402 GetController())); | |
| 403 browser()->Reload(CURRENT_TAB); | 401 browser()->Reload(CURRENT_TAB); |
| 404 reload_observer2.Wait(); | 402 reload_observer2.Wait(); |
| 405 EXPECT_FALSE(process_map->Contains( | 403 EXPECT_FALSE(process_map->Contains( |
| 406 contents->GetRenderProcessHost()->GetID())); | 404 contents->GetRenderProcessHost()->GetID())); |
| 407 | 405 |
| 408 // Enable app and reload via JavaScript. | 406 // Enable app and reload via JavaScript. |
| 409 EnableExtension(app->id()); | 407 EnableExtension(app->id()); |
| 410 ui_test_utils::WindowedNotificationObserver js_reload_observer( | 408 ui_test_utils::WindowedNotificationObserver js_reload_observer( |
| 411 content::NOTIFICATION_LOAD_STOP, | 409 content::NOTIFICATION_LOAD_STOP, |
| 412 content::Source<NavigationController>( | 410 content::Source<NavigationController>( |
| 413 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> | 411 &browser()->GetActiveWebContents()->GetController())); |
| 414 GetController())); | |
| 415 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->GetRenderViewHost(), | 412 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->GetRenderViewHost(), |
| 416 L"", L"location.reload();")); | 413 L"", L"location.reload();")); |
| 417 js_reload_observer.Wait(); | 414 js_reload_observer.Wait(); |
| 418 EXPECT_TRUE(process_map->Contains( | 415 EXPECT_TRUE(process_map->Contains( |
| 419 contents->GetRenderProcessHost()->GetID())); | 416 contents->GetRenderProcessHost()->GetID())); |
| 420 | 417 |
| 421 // Disable app and reload via JavaScript. | 418 // Disable app and reload via JavaScript. |
| 422 DisableExtension(app->id()); | 419 DisableExtension(app->id()); |
| 423 ui_test_utils::WindowedNotificationObserver js_reload_observer2( | 420 ui_test_utils::WindowedNotificationObserver js_reload_observer2( |
| 424 content::NOTIFICATION_LOAD_STOP, | 421 content::NOTIFICATION_LOAD_STOP, |
| 425 content::Source<NavigationController>( | 422 content::Source<NavigationController>( |
| 426 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> | 423 &browser()->GetActiveWebContents()->GetController())); |
| 427 GetController())); | |
| 428 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->GetRenderViewHost(), | 424 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->GetRenderViewHost(), |
| 429 L"", L"location = location;")); | 425 L"", L"location = location;")); |
| 430 js_reload_observer2.Wait(); | 426 js_reload_observer2.Wait(); |
| 431 EXPECT_FALSE(process_map->Contains( | 427 EXPECT_FALSE(process_map->Contains( |
| 432 contents->GetRenderProcessHost()->GetID())); | 428 contents->GetRenderProcessHost()->GetID())); |
| 433 } | 429 } |
| 434 | 430 |
| 435 // Tests that if we have a non-app process (path3/container.html) that has an | 431 // Tests that if we have a non-app process (path3/container.html) that has an |
| 436 // iframe with a URL in the app's extent (path1/iframe.html), then opening a | 432 // iframe with a URL in the app's extent (path1/iframe.html), then opening a |
| 437 // link from that iframe to a new window to a URL in the app's extent (path1/ | 433 // link from that iframe to a new window to a URL in the app's extent (path1/ |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 | 491 |
| 496 // Wait for app tab to be created and loaded. | 492 // Wait for app tab to be created and loaded. |
| 497 test_navigation_observer.WaitForObservation( | 493 test_navigation_observer.WaitForObservation( |
| 498 base::Bind(&ui_test_utils::RunMessageLoop), | 494 base::Bind(&ui_test_utils::RunMessageLoop), |
| 499 base::Bind(&MessageLoop::Quit, | 495 base::Bind(&MessageLoop::Quit, |
| 500 base::Unretained(MessageLoopForUI::current()))); | 496 base::Unretained(MessageLoopForUI::current()))); |
| 501 | 497 |
| 502 // App has loaded, and chrome.app.isInstalled should be true. | 498 // App has loaded, and chrome.app.isInstalled should be true. |
| 503 bool is_installed = false; | 499 bool is_installed = false; |
| 504 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 500 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 505 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"", | 501 browser()->GetActiveWebContents()->GetRenderViewHost(), L"", |
| 506 L"window.domAutomationController.send(chrome.app.isInstalled)", | 502 L"window.domAutomationController.send(chrome.app.isInstalled)", |
| 507 &is_installed)); | 503 &is_installed)); |
| 508 ASSERT_TRUE(is_installed); | 504 ASSERT_TRUE(is_installed); |
| 509 } | 505 } |
| 510 | 506 |
| 511 // Tests that if we have an app process (path1/container.html) with a non-app | 507 // Tests that if we have an app process (path1/container.html) with a non-app |
| 512 // iframe (path3/iframe.html), then opening a link from that iframe to a new | 508 // iframe (path3/iframe.html), then opening a link from that iframe to a new |
| 513 // window to a same-origin non-app URL (path3/empty.html) should keep the window | 509 // window to a same-origin non-app URL (path3/empty.html) should keep the window |
| 514 // in the app process. | 510 // in the app process. |
| 515 // This is in contrast to OpenAppFromIframe, since here the popup will not be | 511 // This is in contrast to OpenAppFromIframe, since here the popup will not be |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 EXPECT_TRUE(process_map->Contains( | 566 EXPECT_TRUE(process_map->Contains( |
| 571 contents->GetRenderProcessHost()->GetID())); | 567 contents->GetRenderProcessHost()->GetID())); |
| 572 bool is_installed = false; | 568 bool is_installed = false; |
| 573 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 569 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 574 contents->GetRenderViewHost(), L"", | 570 contents->GetRenderViewHost(), L"", |
| 575 L"window.domAutomationController.send(chrome.app.isInstalled)", | 571 L"window.domAutomationController.send(chrome.app.isInstalled)", |
| 576 &is_installed)); | 572 &is_installed)); |
| 577 ASSERT_TRUE(is_installed); | 573 ASSERT_TRUE(is_installed); |
| 578 | 574 |
| 579 // Crash the tab and reload it, chrome.app.isInstalled should still be true. | 575 // Crash the tab and reload it, chrome.app.isInstalled should still be true. |
| 580 ui_test_utils::CrashTab(browser()->GetSelectedWebContents()); | 576 ui_test_utils::CrashTab(browser()->GetActiveWebContents()); |
| 581 ui_test_utils::WindowedNotificationObserver observer( | 577 ui_test_utils::WindowedNotificationObserver observer( |
| 582 content::NOTIFICATION_LOAD_STOP, | 578 content::NOTIFICATION_LOAD_STOP, |
| 583 content::Source<NavigationController>( | 579 content::Source<NavigationController>( |
| 584 &browser()->GetSelectedTabContentsWrapper()->web_contents()-> | 580 &browser()->GetActiveWebContents()->GetController())); |
| 585 GetController())); | |
| 586 browser()->Reload(CURRENT_TAB); | 581 browser()->Reload(CURRENT_TAB); |
| 587 observer.Wait(); | 582 observer.Wait(); |
| 588 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 583 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 589 contents->GetRenderViewHost(), L"", | 584 contents->GetRenderViewHost(), L"", |
| 590 L"window.domAutomationController.send(chrome.app.isInstalled)", | 585 L"window.domAutomationController.send(chrome.app.isInstalled)", |
| 591 &is_installed)); | 586 &is_installed)); |
| 592 ASSERT_TRUE(is_installed); | 587 ASSERT_TRUE(is_installed); |
| 593 } | 588 } |
| OLD | NEW |