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

Side by Side Diff: chrome/browser/ui/webui/ntp/new_tab_ui_browsertest.cc

Issue 10702029: Move tab functions off Browser into browser_tabstrip and browser_tabrestore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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) 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "chrome/browser/ui/browser.h" 6 #include "chrome/browser/ui/browser.h"
7 #include "chrome/browser/ui/browser_commands.h" 7 #include "chrome/browser/ui/browser_commands.h"
8 #include "chrome/browser/ui/browser_tabstrip.h"
8 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
9 #include "chrome/common/url_constants.h" 10 #include "chrome/common/url_constants.h"
10 #include "chrome/test/base/in_process_browser_test.h" 11 #include "chrome/test/base/in_process_browser_test.h"
11 #include "chrome/test/base/ui_test_utils.h" 12 #include "chrome/test/base/ui_test_utils.h"
12 #include "content/public/browser/notification_service.h" 13 #include "content/public/browser/notification_service.h"
13 #include "content/public/browser/notification_types.h" 14 #include "content/public/browser/notification_types.h"
14 #include "content/public/browser/render_process_host.h" 15 #include "content/public/browser/render_process_host.h"
15 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
16 #include "content/public/test/test_navigation_observer.h" 17 #include "content/public/test/test_navigation_observer.h"
17 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
18 19
19 using content::OpenURLParams; 20 using content::OpenURLParams;
20 using content::Referrer; 21 using content::Referrer;
21 22
22 class NewTabUIBrowserTest : public InProcessBrowserTest { 23 class NewTabUIBrowserTest : public InProcessBrowserTest {
23 public: 24 public:
24 NewTabUIBrowserTest() { 25 NewTabUIBrowserTest() {
25 EnableDOMAutomation(); 26 EnableDOMAutomation();
26 } 27 }
27 }; 28 };
28 29
29 // Ensure that chrome-internal: still loads the NTP. 30 // Ensure that chrome-internal: still loads the NTP.
30 // See http://crbug.com/6564. 31 // See http://crbug.com/6564.
31 IN_PROC_BROWSER_TEST_F(NewTabUIBrowserTest, ChromeInternalLoadsNTP) { 32 IN_PROC_BROWSER_TEST_F(NewTabUIBrowserTest, ChromeInternalLoadsNTP) {
32 // Go to the "new tab page" using its old url, rather than chrome://newtab. 33 // Go to the "new tab page" using its old url, rather than chrome://newtab.
33 // Ensure that we get there by checking for non-empty page content. 34 // Ensure that we get there by checking for non-empty page content.
34 ui_test_utils::NavigateToURL(browser(), GURL("chrome-internal:")); 35 ui_test_utils::NavigateToURL(browser(), GURL("chrome-internal:"));
35 bool empty_inner_html = false; 36 bool empty_inner_html = false;
36 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 37 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
37 browser()->GetWebContentsAt(0)->GetRenderViewHost(), L"", 38 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(), L"",
38 L"window.domAutomationController.send(document.body.innerHTML == '')", 39 L"window.domAutomationController.send(document.body.innerHTML == '')",
39 &empty_inner_html)); 40 &empty_inner_html));
40 ASSERT_FALSE(empty_inner_html); 41 ASSERT_FALSE(empty_inner_html);
41 } 42 }
42 43
43 // Ensure loading a NTP with an existing SiteInstance in a reused process 44 // Ensure loading a NTP with an existing SiteInstance in a reused process
44 // doesn't cause us to kill the process. See http://crbug.com/104258. 45 // doesn't cause us to kill the process. See http://crbug.com/104258.
45 IN_PROC_BROWSER_TEST_F(NewTabUIBrowserTest, LoadNTPInExistingProcess) { 46 IN_PROC_BROWSER_TEST_F(NewTabUIBrowserTest, LoadNTPInExistingProcess) {
46 // Set max renderers to 1 to force running out of processes. 47 // Set max renderers to 1 to force running out of processes.
47 content::RenderProcessHost::SetMaxRendererProcessCount(1); 48 content::RenderProcessHost::SetMaxRendererProcessCount(1);
48 49
49 // Start server for simple page. 50 // Start server for simple page.
50 ASSERT_TRUE(test_server()->Start()); 51 ASSERT_TRUE(test_server()->Start());
51 52
52 // Load a NTP in a new tab. 53 // Load a NTP in a new tab.
53 ui_test_utils::NavigateToURLWithDisposition( 54 ui_test_utils::NavigateToURLWithDisposition(
54 browser(), GURL(chrome::kChromeUINewTabURL), NEW_FOREGROUND_TAB, 55 browser(), GURL(chrome::kChromeUINewTabURL), NEW_FOREGROUND_TAB,
55 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 56 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
56 EXPECT_EQ(1, browser()->GetWebContentsAt(1)->GetMaxPageID()); 57 EXPECT_EQ(1, chrome::GetWebContentsAt(browser(), 1)->GetMaxPageID());
57 58
58 // Navigate that tab to another site. This allows the NTP process to exit, 59 // Navigate that tab to another site. This allows the NTP process to exit,
59 // but it keeps the NTP SiteInstance (and its max_page_id) alive in history. 60 // but it keeps the NTP SiteInstance (and its max_page_id) alive in history.
60 { 61 {
61 // Wait not just for the navigation to finish, but for the NTP process to 62 // Wait not just for the navigation to finish, but for the NTP process to
62 // exit as well. 63 // exit as well.
63 ui_test_utils::WindowedNotificationObserver process_exited_observer( 64 ui_test_utils::WindowedNotificationObserver process_exited_observer(
64 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 65 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
65 content::NotificationService::AllSources()); 66 content::NotificationService::AllSources());
66 browser()->OpenURL(OpenURLParams( 67 browser()->OpenURL(OpenURLParams(
67 test_server()->GetURL("files/title1.html"), Referrer(), CURRENT_TAB, 68 test_server()->GetURL("files/title1.html"), Referrer(), CURRENT_TAB,
68 content::PAGE_TRANSITION_TYPED, false)); 69 content::PAGE_TRANSITION_TYPED, false));
69 process_exited_observer.Wait(); 70 process_exited_observer.Wait();
70 } 71 }
71 72
72 // Creating a NTP in another tab should not be affected, since page IDs 73 // Creating a NTP in another tab should not be affected, since page IDs
73 // are now specific to a tab. 74 // are now specific to a tab.
74 ui_test_utils::NavigateToURLWithDisposition( 75 ui_test_utils::NavigateToURLWithDisposition(
75 browser(), GURL(chrome::kChromeUINewTabURL), NEW_FOREGROUND_TAB, 76 browser(), GURL(chrome::kChromeUINewTabURL), NEW_FOREGROUND_TAB,
76 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 77 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
77 EXPECT_EQ(1, browser()->GetWebContentsAt(2)->GetMaxPageID()); 78 EXPECT_EQ(1, chrome::GetWebContentsAt(browser(), 2)->GetMaxPageID());
78 chrome::CloseTab(browser()); 79 chrome::CloseTab(browser());
79 80
80 // Open another Web UI page in a new tab. 81 // Open another Web UI page in a new tab.
81 ui_test_utils::NavigateToURLWithDisposition( 82 ui_test_utils::NavigateToURLWithDisposition(
82 browser(), GURL(chrome::kChromeUISettingsURL), NEW_FOREGROUND_TAB, 83 browser(), GURL(chrome::kChromeUISettingsURL), NEW_FOREGROUND_TAB,
83 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 84 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
84 EXPECT_EQ(1, browser()->GetWebContentsAt(2)->GetMaxPageID()); 85 EXPECT_EQ(1, chrome::GetWebContentsAt(browser(), 2)->GetMaxPageID());
85 86
86 // At this point, opening another NTP will use the existing WebUI process 87 // At this point, opening another NTP will use the existing WebUI process
87 // but its own SiteInstance, so the page IDs shouldn't affect each other. 88 // but its own SiteInstance, so the page IDs shouldn't affect each other.
88 ui_test_utils::NavigateToURLWithDisposition( 89 ui_test_utils::NavigateToURLWithDisposition(
89 browser(), GURL(chrome::kChromeUINewTabURL), NEW_FOREGROUND_TAB, 90 browser(), GURL(chrome::kChromeUINewTabURL), NEW_FOREGROUND_TAB,
90 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 91 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
91 EXPECT_EQ(1, browser()->GetWebContentsAt(3)->GetMaxPageID()); 92 EXPECT_EQ(1, chrome::GetWebContentsAt(browser(), 3)->GetMaxPageID());
92 93
93 // Navigating to the NTP in the original tab causes a BrowsingInstance 94 // Navigating to the NTP in the original tab causes a BrowsingInstance
94 // swap, so it gets a new SiteInstance starting with page ID 1 again. 95 // swap, so it gets a new SiteInstance starting with page ID 1 again.
95 browser()->ActivateTabAt(1, true); 96 chrome::ActivateTabAt(browser(), 1, true);
96 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); 97 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL));
97 EXPECT_EQ(1, browser()->GetWebContentsAt(1)->GetMaxPageID()); 98 EXPECT_EQ(1, chrome::GetWebContentsAt(browser(), 1)->GetMaxPageID());
98 } 99 }
99 100
100 // Loads chrome://hang/ into two NTP tabs, ensuring we don't crash. 101 // Loads chrome://hang/ into two NTP tabs, ensuring we don't crash.
101 // See http://crbug.com/59859. 102 // See http://crbug.com/59859.
102 // If this flakes, use http://crbug.com/87200. 103 // If this flakes, use http://crbug.com/87200.
103 IN_PROC_BROWSER_TEST_F(NewTabUIBrowserTest, ChromeHangInNTP) { 104 IN_PROC_BROWSER_TEST_F(NewTabUIBrowserTest, ChromeHangInNTP) {
104 // Bring up a new tab page. 105 // Bring up a new tab page.
105 ui_test_utils::NavigateToURLWithDisposition( 106 ui_test_utils::NavigateToURLWithDisposition(
106 browser(), GURL(chrome::kChromeUINewTabURL), NEW_FOREGROUND_TAB, 107 browser(), GURL(chrome::kChromeUINewTabURL), NEW_FOREGROUND_TAB,
107 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 108 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 146
146 // We don't use ui_test_utils::NavigateToURLWithDisposition because that waits 147 // We don't use ui_test_utils::NavigateToURLWithDisposition because that waits
147 // for current loading to stop. 148 // for current loading to stop.
148 content::TestNavigationObserver observer( 149 content::TestNavigationObserver observer(
149 content::NotificationService::AllSources()); 150 content::NotificationService::AllSources());
150 browser()->OpenURL(OpenURLParams( 151 browser()->OpenURL(OpenURLParams(
151 GURL("data:text/html,hello world"), Referrer(), CURRENT_TAB, 152 GURL("data:text/html,hello world"), Referrer(), CURRENT_TAB,
152 content::PAGE_TRANSITION_TYPED, false)); 153 content::PAGE_TRANSITION_TYPED, false));
153 observer.Wait(); 154 observer.Wait();
154 } 155 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/app_launcher_handler.cc ('k') | chrome/browser/ui/webui/ntp/suggestions_combiner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698