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_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" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.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_wrapper.h" |
15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
17 #include "chrome/common/extensions/extension_file_util.h" | 17 #include "chrome/common/extensions/extension_file_util.h" |
18 #include "chrome/common/string_ordinal.h" | 18 #include "chrome/common/string_ordinal.h" |
19 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
20 #include "content/browser/renderer_host/render_view_host.h" | 20 #include "content/browser/renderer_host/render_view_host.h" |
21 #include "content/browser/tab_contents/tab_contents.h" | 21 #include "content/browser/tab_contents/tab_contents.h" |
22 #include "content/public/browser/navigation_entry.h" | 22 #include "content/public/browser/navigation_entry.h" |
23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
24 #include "content/test/test_navigation_observer.h" | 24 #include "content/test/test_navigation_observer.h" |
25 #include "net/base/mock_host_resolver.h" | 25 #include "net/base/mock_host_resolver.h" |
26 | 26 |
| 27 using content::NavigationController; |
27 using content::WebContents; | 28 using content::WebContents; |
28 | 29 |
29 class AppApiTest : public ExtensionApiTest { | 30 class AppApiTest : public ExtensionApiTest { |
30 protected: | 31 protected: |
31 // Gets the base URL for files for a specific test, making sure that it uses | 32 // Gets the base URL for files for a specific test, making sure that it uses |
32 // "localhost" as the hostname, since that is what the extent is declared | 33 // "localhost" as the hostname, since that is what the extent is declared |
33 // as in the test apps manifests. | 34 // as in the test apps manifests. |
34 GURL GetTestBaseURL(std::string test_directory) { | 35 GURL GetTestBaseURL(std::string test_directory) { |
35 GURL::Replacements replace_host; | 36 GURL::Replacements replace_host; |
36 std::string host_str("localhost"); // must stay in scope with replace_host | 37 std::string host_str("localhost"); // must stay in scope with replace_host |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 // Disable app and navigate to the page. | 419 // Disable app and navigate to the page. |
419 DisableExtension(app->id()); | 420 DisableExtension(app->id()); |
420 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); | 421 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
421 EXPECT_FALSE(process_map->Contains( | 422 EXPECT_FALSE(process_map->Contains( |
422 contents->GetRenderProcessHost()->GetID())); | 423 contents->GetRenderProcessHost()->GetID())); |
423 | 424 |
424 // Enable app and reload the page. | 425 // Enable app and reload the page. |
425 EnableExtension(app->id()); | 426 EnableExtension(app->id()); |
426 ui_test_utils::WindowedNotificationObserver reload_observer( | 427 ui_test_utils::WindowedNotificationObserver reload_observer( |
427 content::NOTIFICATION_LOAD_STOP, | 428 content::NOTIFICATION_LOAD_STOP, |
428 content::Source<content::NavigationController>( | 429 content::Source<NavigationController>( |
429 &browser()->GetSelectedTabContentsWrapper()->tab_contents()-> | 430 &browser()->GetSelectedTabContentsWrapper()->tab_contents()-> |
430 GetController())); | 431 GetController())); |
431 browser()->Reload(CURRENT_TAB); | 432 browser()->Reload(CURRENT_TAB); |
432 reload_observer.Wait(); | 433 reload_observer.Wait(); |
433 EXPECT_TRUE(process_map->Contains( | 434 EXPECT_TRUE(process_map->Contains( |
434 contents->GetRenderProcessHost()->GetID())); | 435 contents->GetRenderProcessHost()->GetID())); |
435 | 436 |
436 // Disable app and reload the page. | 437 // Disable app and reload the page. |
437 DisableExtension(app->id()); | 438 DisableExtension(app->id()); |
438 ui_test_utils::WindowedNotificationObserver reload_observer2( | 439 ui_test_utils::WindowedNotificationObserver reload_observer2( |
439 content::NOTIFICATION_LOAD_STOP, | 440 content::NOTIFICATION_LOAD_STOP, |
440 content::Source<content::NavigationController>( | 441 content::Source<NavigationController>( |
441 &browser()->GetSelectedTabContentsWrapper()->tab_contents()-> | 442 &browser()->GetSelectedTabContentsWrapper()->tab_contents()-> |
442 GetController())); | 443 GetController())); |
443 browser()->Reload(CURRENT_TAB); | 444 browser()->Reload(CURRENT_TAB); |
444 reload_observer2.Wait(); | 445 reload_observer2.Wait(); |
445 EXPECT_FALSE(process_map->Contains( | 446 EXPECT_FALSE(process_map->Contains( |
446 contents->GetRenderProcessHost()->GetID())); | 447 contents->GetRenderProcessHost()->GetID())); |
447 | 448 |
448 // Enable app and reload via JavaScript. | 449 // Enable app and reload via JavaScript. |
449 EnableExtension(app->id()); | 450 EnableExtension(app->id()); |
450 ui_test_utils::WindowedNotificationObserver js_reload_observer( | 451 ui_test_utils::WindowedNotificationObserver js_reload_observer( |
451 content::NOTIFICATION_LOAD_STOP, | 452 content::NOTIFICATION_LOAD_STOP, |
452 content::Source<content::NavigationController>( | 453 content::Source<NavigationController>( |
453 &browser()->GetSelectedTabContentsWrapper()->tab_contents()-> | 454 &browser()->GetSelectedTabContentsWrapper()->tab_contents()-> |
454 GetController())); | 455 GetController())); |
455 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->GetRenderViewHost(), | 456 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->GetRenderViewHost(), |
456 L"", L"location.reload();")); | 457 L"", L"location.reload();")); |
457 js_reload_observer.Wait(); | 458 js_reload_observer.Wait(); |
458 EXPECT_TRUE(process_map->Contains( | 459 EXPECT_TRUE(process_map->Contains( |
459 contents->GetRenderProcessHost()->GetID())); | 460 contents->GetRenderProcessHost()->GetID())); |
460 | 461 |
461 // Disable app and reload via JavaScript. | 462 // Disable app and reload via JavaScript. |
462 DisableExtension(app->id()); | 463 DisableExtension(app->id()); |
463 ui_test_utils::WindowedNotificationObserver js_reload_observer2( | 464 ui_test_utils::WindowedNotificationObserver js_reload_observer2( |
464 content::NOTIFICATION_LOAD_STOP, | 465 content::NOTIFICATION_LOAD_STOP, |
465 content::Source<content::NavigationController>( | 466 content::Source<NavigationController>( |
466 &browser()->GetSelectedTabContentsWrapper()->tab_contents()-> | 467 &browser()->GetSelectedTabContentsWrapper()->tab_contents()-> |
467 GetController())); | 468 GetController())); |
468 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->GetRenderViewHost(), | 469 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(contents->GetRenderViewHost(), |
469 L"", L"location.reload();")); | 470 L"", L"location.reload();")); |
470 js_reload_observer2.Wait(); | 471 js_reload_observer2.Wait(); |
471 EXPECT_FALSE(process_map->Contains( | 472 EXPECT_FALSE(process_map->Contains( |
472 contents->GetRenderProcessHost()->GetID())); | 473 contents->GetRenderProcessHost()->GetID())); |
473 } | 474 } |
474 | 475 |
475 // Tests that if we have a non-app process (path3/container.html) that has an | 476 // Tests that if we have a non-app process (path3/container.html) that has an |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 ASSERT_NE(browser(), last_active_browser); | 510 ASSERT_NE(browser(), last_active_browser); |
510 WebContents* newtab = last_active_browser->GetSelectedWebContents(); | 511 WebContents* newtab = last_active_browser->GetSelectedWebContents(); |
511 EXPECT_TRUE(newtab); | 512 EXPECT_TRUE(newtab); |
512 if (!newtab->GetController().GetLastCommittedEntry() || | 513 if (!newtab->GetController().GetLastCommittedEntry() || |
513 newtab->GetController().GetLastCommittedEntry()->GetURL() != app_url) { | 514 newtab->GetController().GetLastCommittedEntry()->GetURL() != app_url) { |
514 // TODO(gbillock): This still looks racy. Need to make a custom | 515 // TODO(gbillock): This still looks racy. Need to make a custom |
515 // observer to intercept new window creation and then look for | 516 // observer to intercept new window creation and then look for |
516 // NAV_ENTRY_COMMITTED on the new tab there. | 517 // NAV_ENTRY_COMMITTED on the new tab there. |
517 ui_test_utils::WindowedNotificationObserver observer( | 518 ui_test_utils::WindowedNotificationObserver observer( |
518 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 519 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
519 content::Source<content::NavigationController>( | 520 content::Source<NavigationController>(&(newtab->GetController()))); |
520 &(newtab->GetController()))); | |
521 observer.Wait(); | 521 observer.Wait(); |
522 } | 522 } |
523 | 523 |
524 // Popup window should be in the app's process. | 524 // Popup window should be in the app's process. |
525 EXPECT_TRUE(process_map->Contains( | 525 EXPECT_TRUE(process_map->Contains( |
526 last_active_browser->GetTabContentsAt(0)->GetRenderProcessHost()-> | 526 last_active_browser->GetTabContentsAt(0)->GetRenderProcessHost()-> |
527 GetID())); | 527 GetID())); |
528 } | 528 } |
529 | 529 |
530 // Tests that if an extension launches an app via chrome.tabs.create with an URL | 530 // Tests that if an extension launches an app via chrome.tabs.create with an URL |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 648 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
649 contents->GetRenderViewHost(), L"", | 649 contents->GetRenderViewHost(), L"", |
650 L"window.domAutomationController.send(chrome.app.isInstalled)", | 650 L"window.domAutomationController.send(chrome.app.isInstalled)", |
651 &is_installed)); | 651 &is_installed)); |
652 ASSERT_TRUE(is_installed); | 652 ASSERT_TRUE(is_installed); |
653 | 653 |
654 // Crash the tab and reload it, chrome.app.isInstalled should still be true. | 654 // Crash the tab and reload it, chrome.app.isInstalled should still be true. |
655 ui_test_utils::CrashTab(browser()->GetSelectedWebContents()); | 655 ui_test_utils::CrashTab(browser()->GetSelectedWebContents()); |
656 ui_test_utils::WindowedNotificationObserver observer( | 656 ui_test_utils::WindowedNotificationObserver observer( |
657 content::NOTIFICATION_LOAD_STOP, | 657 content::NOTIFICATION_LOAD_STOP, |
658 content::Source<content::NavigationController>( | 658 content::Source<NavigationController>( |
659 &browser()->GetSelectedTabContentsWrapper()->tab_contents()-> | 659 &browser()->GetSelectedTabContentsWrapper()->tab_contents()-> |
660 GetController())); | 660 GetController())); |
661 browser()->Reload(CURRENT_TAB); | 661 browser()->Reload(CURRENT_TAB); |
662 observer.Wait(); | 662 observer.Wait(); |
663 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 663 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
664 contents->GetRenderViewHost(), L"", | 664 contents->GetRenderViewHost(), L"", |
665 L"window.domAutomationController.send(chrome.app.isInstalled)", | 665 L"window.domAutomationController.send(chrome.app.isInstalled)", |
666 &is_installed)); | 666 &is_installed)); |
667 ASSERT_TRUE(is_installed); | 667 ASSERT_TRUE(is_installed); |
668 } | 668 } |
OLD | NEW |