Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(464)

Side by Side Diff: chrome/browser/extensions/app_process_apitest.cc

Issue 9015022: Replace most of Browser::GetSelectedTabContents calls into Browser::GetSelectedWebContents. I've ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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::WebContents;
28
27 class AppApiTest : public ExtensionApiTest { 29 class AppApiTest : public ExtensionApiTest {
28 protected: 30 protected:
29 // Gets the base URL for files for a specific test, making sure that it uses 31 // Gets the base URL for files for a specific test, making sure that it uses
30 // "localhost" as the hostname, since that is what the extent is declared 32 // "localhost" as the hostname, since that is what the extent is declared
31 // as in the test apps manifests. 33 // as in the test apps manifests.
32 GURL GetTestBaseURL(std::string test_directory) { 34 GURL GetTestBaseURL(std::string test_directory) {
33 GURL::Replacements replace_host; 35 GURL::Replacements replace_host;
34 std::string host_str("localhost"); // must stay in scope with replace_host 36 std::string host_str("localhost"); // must stay in scope with replace_host
35 replace_host.SetHostStr(host_str); 37 replace_host.SetHostStr(host_str);
36 GURL base_url = test_server()->GetURL( 38 GURL base_url = test_server()->GetURL(
(...skipping 11 matching lines...) Expand all
48 content::NOTIFICATION_LOAD_STOP, 50 content::NOTIFICATION_LOAD_STOP,
49 content::NotificationService::AllSources()); 51 content::NotificationService::AllSources());
50 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( 52 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
51 opener_host, L"", L"window.open('" + UTF8ToWide(url.spec()) + L"');")); 53 opener_host, L"", L"window.open('" + UTF8ToWide(url.spec()) + L"');"));
52 54
53 // The above window.open call is not user-initiated, it will create 55 // The above window.open call is not user-initiated, it will create
54 // a popup window instead of a new tab in current window. 56 // a popup window instead of a new tab in current window.
55 // Now the active tab in last active window should be the new tab. 57 // Now the active tab in last active window should be the new tab.
56 Browser* last_active_browser = BrowserList::GetLastActive(); 58 Browser* last_active_browser = BrowserList::GetLastActive();
57 EXPECT_TRUE(last_active_browser); 59 EXPECT_TRUE(last_active_browser);
58 TabContents* newtab = last_active_browser->GetSelectedTabContents(); 60 WebContents* newtab = last_active_browser->GetSelectedWebContents();
59 EXPECT_TRUE(newtab); 61 EXPECT_TRUE(newtab);
60 observer.Wait(); 62 observer.Wait();
61 EXPECT_EQ(url, newtab->GetController().GetLastCommittedEntry()->GetURL()); 63 EXPECT_EQ(url, newtab->GetController().GetLastCommittedEntry()->GetURL());
62 if (newtab_process_should_equal_opener) 64 if (newtab_process_should_equal_opener)
63 EXPECT_EQ(opener_host->process(), newtab->GetRenderProcessHost()); 65 EXPECT_EQ(opener_host->process(), newtab->GetRenderProcessHost());
64 else 66 else
65 EXPECT_NE(opener_host->process(), newtab->GetRenderProcessHost()); 67 EXPECT_NE(opener_host->process(), newtab->GetRenderProcessHost());
66 } 68 }
67 69
68 // Simulates a page navigating itself to an URL, and waits for the navigation. 70 // Simulates a page navigating itself to an URL, and waits for the navigation.
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION | 500 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION |
499 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); 501 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
500 EXPECT_FALSE(process_map->Contains( 502 EXPECT_FALSE(process_map->Contains(
501 browser()->GetTabContentsAt(0)->GetRenderProcessHost()->GetID())); 503 browser()->GetTabContentsAt(0)->GetRenderProcessHost()->GetID()));
502 504
503 // Wait for popup window to appear. 505 // Wait for popup window to appear.
504 GURL app_url = base_url.Resolve("path1/empty.html"); 506 GURL app_url = base_url.Resolve("path1/empty.html");
505 Browser* last_active_browser = BrowserList::GetLastActive(); 507 Browser* last_active_browser = BrowserList::GetLastActive();
506 EXPECT_TRUE(last_active_browser); 508 EXPECT_TRUE(last_active_browser);
507 ASSERT_NE(browser(), last_active_browser); 509 ASSERT_NE(browser(), last_active_browser);
508 TabContents* newtab = last_active_browser->GetSelectedTabContents(); 510 WebContents* newtab = last_active_browser->GetSelectedWebContents();
509 EXPECT_TRUE(newtab); 511 EXPECT_TRUE(newtab);
510 if (!newtab->GetController().GetLastCommittedEntry() || 512 if (!newtab->GetController().GetLastCommittedEntry() ||
511 newtab->GetController().GetLastCommittedEntry()->GetURL() != app_url) { 513 newtab->GetController().GetLastCommittedEntry()->GetURL() != app_url) {
512 // TODO(gbillock): This still looks racy. Need to make a custom 514 // TODO(gbillock): This still looks racy. Need to make a custom
513 // observer to intercept new window creation and then look for 515 // observer to intercept new window creation and then look for
514 // NAV_ENTRY_COMMITTED on the new tab there. 516 // NAV_ENTRY_COMMITTED on the new tab there.
515 ui_test_utils::WindowedNotificationObserver observer( 517 ui_test_utils::WindowedNotificationObserver observer(
516 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 518 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
517 content::Source<NavigationController>(&(newtab->GetController()))); 519 content::Source<NavigationController>(&(newtab->GetController())));
518 observer.Wait(); 520 observer.Wait();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 555
554 // Wait for app tab to be created and loaded. 556 // Wait for app tab to be created and loaded.
555 test_navigation_observer.WaitForObservation( 557 test_navigation_observer.WaitForObservation(
556 base::Bind(&ui_test_utils::RunMessageLoop), 558 base::Bind(&ui_test_utils::RunMessageLoop),
557 base::Bind(&MessageLoop::Quit, 559 base::Bind(&MessageLoop::Quit,
558 base::Unretained(MessageLoopForUI::current()))); 560 base::Unretained(MessageLoopForUI::current())));
559 561
560 // App has loaded, and chrome.app.isInstalled should be true. 562 // App has loaded, and chrome.app.isInstalled should be true.
561 bool is_installed = false; 563 bool is_installed = false;
562 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 564 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
563 browser()->GetSelectedTabContents()->GetRenderViewHost(), L"", 565 browser()->GetSelectedWebContents()->GetRenderViewHost(), L"",
564 L"window.domAutomationController.send(chrome.app.isInstalled)", 566 L"window.domAutomationController.send(chrome.app.isInstalled)",
565 &is_installed)); 567 &is_installed));
566 ASSERT_TRUE(is_installed); 568 ASSERT_TRUE(is_installed);
567 } 569 }
568 570
569 // Tests that if we have an app process (path1/container.html) with a non-app 571 // Tests that if we have an app process (path1/container.html) with a non-app
570 // iframe (path3/iframe.html), then opening a link from that iframe to a new 572 // iframe (path3/iframe.html), then opening a link from that iframe to a new
571 // window to a same-origin non-app URL (path3/empty.html) should keep the window 573 // window to a same-origin non-app URL (path3/empty.html) should keep the window
572 // in the app process. 574 // in the app process.
573 // This is in contrast to OpenAppFromIframe, since here the popup will not be 575 // This is in contrast to OpenAppFromIframe, since here the popup will not be
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 // This is necessary for popup windows without a cross-site transition. 609 // This is necessary for popup windows without a cross-site transition.
608 if (browser() == BrowserList::GetLastActive()) { 610 if (browser() == BrowserList::GetLastActive()) {
609 // Grab the second window and show it. 611 // Grab the second window and show it.
610 ASSERT_TRUE(BrowserList::size() == 2); 612 ASSERT_TRUE(BrowserList::size() == 2);
611 Browser* popup_browser = *(++BrowserList::begin()); 613 Browser* popup_browser = *(++BrowserList::begin());
612 popup_browser->window()->Show(); 614 popup_browser->window()->Show();
613 } 615 }
614 Browser* last_active_browser = BrowserList::GetLastActive(); 616 Browser* last_active_browser = BrowserList::GetLastActive();
615 EXPECT_TRUE(last_active_browser); 617 EXPECT_TRUE(last_active_browser);
616 ASSERT_NE(browser(), last_active_browser); 618 ASSERT_NE(browser(), last_active_browser);
617 TabContents* newtab = last_active_browser->GetSelectedTabContents(); 619 WebContents* newtab = last_active_browser->GetSelectedWebContents();
618 EXPECT_TRUE(newtab); 620 EXPECT_TRUE(newtab);
619 GURL non_app_url = base_url.Resolve("path3/empty.html"); 621 GURL non_app_url = base_url.Resolve("path3/empty.html");
620 observer.Wait(); 622 observer.Wait();
621 623
622 // Popup window should be in the app's process. 624 // Popup window should be in the app's process.
623 content::RenderProcessHost* popup_process = 625 content::RenderProcessHost* popup_process =
624 last_active_browser->GetTabContentsAt(0)->GetRenderProcessHost(); 626 last_active_browser->GetTabContentsAt(0)->GetRenderProcessHost();
625 EXPECT_EQ(process, popup_process); 627 EXPECT_EQ(process, popup_process);
626 } 628 }
627 629
(...skipping 14 matching lines...) Expand all
642 EXPECT_TRUE(process_map->Contains( 644 EXPECT_TRUE(process_map->Contains(
643 contents->GetRenderProcessHost()->GetID())); 645 contents->GetRenderProcessHost()->GetID()));
644 bool is_installed = false; 646 bool is_installed = false;
645 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 647 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
646 contents->GetRenderViewHost(), L"", 648 contents->GetRenderViewHost(), L"",
647 L"window.domAutomationController.send(chrome.app.isInstalled)", 649 L"window.domAutomationController.send(chrome.app.isInstalled)",
648 &is_installed)); 650 &is_installed));
649 ASSERT_TRUE(is_installed); 651 ASSERT_TRUE(is_installed);
650 652
651 // Crash the tab and reload it, chrome.app.isInstalled should still be true. 653 // Crash the tab and reload it, chrome.app.isInstalled should still be true.
652 ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); 654 ui_test_utils::CrashTab(browser()->GetSelectedWebContents());
653 ui_test_utils::WindowedNotificationObserver observer( 655 ui_test_utils::WindowedNotificationObserver observer(
654 content::NOTIFICATION_LOAD_STOP, 656 content::NOTIFICATION_LOAD_STOP,
655 content::Source<NavigationController>( 657 content::Source<NavigationController>(
656 &browser()->GetSelectedTabContentsWrapper()->tab_contents()-> 658 &browser()->GetSelectedTabContentsWrapper()->tab_contents()->
657 GetController())); 659 GetController()));
658 browser()->Reload(CURRENT_TAB); 660 browser()->Reload(CURRENT_TAB);
659 observer.Wait(); 661 observer.Wait();
660 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 662 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
661 contents->GetRenderViewHost(), L"", 663 contents->GetRenderViewHost(), L"",
662 L"window.domAutomationController.send(chrome.app.isInstalled)", 664 L"window.domAutomationController.send(chrome.app.isInstalled)",
663 &is_installed)); 665 &is_installed));
664 ASSERT_TRUE(is_installed); 666 ASSERT_TRUE(is_installed);
665 } 667 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_browsertest.cc ('k') | chrome/browser/extensions/browser_action_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698