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

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

Issue 8468032: Fix next_page_id_ in a NTP forced to share an existing WebUI process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Switch to UpdateAndSendMaxPageID Created 9 years, 1 month 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
« no previous file with comments | « no previous file | content/browser/renderer_host/browser_render_process_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/ui/browser.h" 5 #include "chrome/browser/ui/browser.h"
6 #include "chrome/common/url_constants.h"
6 #include "chrome/test/base/in_process_browser_test.h" 7 #include "chrome/test/base/in_process_browser_test.h"
7 #include "chrome/test/base/ui_test_utils.h" 8 #include "chrome/test/base/ui_test_utils.h"
8 #include "content/browser/tab_contents/tab_contents.h" 9 #include "content/browser/tab_contents/tab_contents.h"
10 #include "content/public/browser/notification_service.h"
11 #include "content/public/browser/notification_types.h"
9 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
10 13
11 class NewTabUIBrowserTest : public InProcessBrowserTest { 14 class NewTabUIBrowserTest : public InProcessBrowserTest {
12 public: 15 public:
13 NewTabUIBrowserTest() { 16 NewTabUIBrowserTest() {
14 EnableDOMAutomation(); 17 EnableDOMAutomation();
15 } 18 }
16 }; 19 };
17 20
18 // Ensure that chrome-internal: still loads the NTP. 21 // Ensure that chrome-internal: still loads the NTP.
19 // See http://crbug.com/6564. 22 // See http://crbug.com/6564.
20 IN_PROC_BROWSER_TEST_F(NewTabUIBrowserTest, ChromeInternalLoadsNTP) { 23 IN_PROC_BROWSER_TEST_F(NewTabUIBrowserTest, ChromeInternalLoadsNTP) {
21 // Go to the "new tab page" using its old url, rather than chrome://newtab. 24 // Go to the "new tab page" using its old url, rather than chrome://newtab.
22 // Ensure that we get there by checking for non-empty page content. 25 // Ensure that we get there by checking for non-empty page content.
23 ui_test_utils::NavigateToURL(browser(), GURL("chrome-internal:")); 26 ui_test_utils::NavigateToURL(browser(), GURL("chrome-internal:"));
24 bool empty_inner_html = false; 27 bool empty_inner_html = false;
25 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 28 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
26 browser()->GetTabContentsAt(0)->render_view_host(), L"", 29 browser()->GetTabContentsAt(0)->render_view_host(), L"",
27 L"window.domAutomationController.send(document.body.innerHTML == '')", 30 L"window.domAutomationController.send(document.body.innerHTML == '')",
28 &empty_inner_html)); 31 &empty_inner_html));
29 ASSERT_FALSE(empty_inner_html); 32 ASSERT_FALSE(empty_inner_html);
30 } 33 }
34
35 // Ensure loading a NTP with an existing SiteInstance in a reused process
36 // doesn't cause us to kill the process. See http://crbug.com/104258.
37 IN_PROC_BROWSER_TEST_F(NewTabUIBrowserTest, LoadNTPInExistingProcess) {
38 // Set max renderers to 1 to force running out of processes.
39 RenderProcessHost::SetMaxRendererProcessCountForTest(1);
40
41 // Start server for simple page.
42 ASSERT_TRUE(test_server()->Start());
43
44 // Load a NTP in a new tab.
45 ui_test_utils::NavigateToURLWithDisposition(
46 browser(), GURL(chrome::kChromeUINewTabURL), NEW_FOREGROUND_TAB,
47 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
48 EXPECT_EQ(1,
49 browser()->GetTabContentsAt(1)->GetSiteInstance()->max_page_id());
50
51 // Navigate that tab to another site. This allows the NTP process to exit,
52 // but it keeps the NTP SiteInstance (and its max_page_id) alive in history.
53 {
54 // Wait not just for the navigation to finish, but for the NTP process to
55 // exit as well.
56 ui_test_utils::WindowedNotificationObserver process_exited_observer(
57 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
58 content::NotificationService::AllSources());
59 browser()->OpenURL(test_server()->GetURL("files/title1.html"), GURL(),
60 CURRENT_TAB, content::PAGE_TRANSITION_TYPED);
61 process_exited_observer.Wait();
62 }
63
64 // Create and close another two NTPs to inflate the max_page_id.
65 ui_test_utils::NavigateToURLWithDisposition(
66 browser(), GURL(chrome::kChromeUINewTabURL), NEW_FOREGROUND_TAB,
67 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
68 EXPECT_EQ(2,
69 browser()->GetTabContentsAt(2)->GetSiteInstance()->max_page_id());
70 browser()->CloseTab();
71 ui_test_utils::NavigateToURLWithDisposition(
72 browser(), GURL(chrome::kChromeUINewTabURL), NEW_FOREGROUND_TAB,
73 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
74 EXPECT_EQ(3,
75 browser()->GetTabContentsAt(2)->GetSiteInstance()->max_page_id());
76 browser()->CloseTab();
77
78 // Open another Web UI page in a new tab.
79 ui_test_utils::NavigateToURLWithDisposition(
80 browser(), GURL(chrome::kChromeUISettingsURL), NEW_FOREGROUND_TAB,
81 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
82 EXPECT_EQ(1,
83 browser()->GetTabContentsAt(2)->GetSiteInstance()->max_page_id());
84
85 // At this point, opening another NTP will use the old SiteInstance (with a
86 // large max_page_id) in the existing Web UI process (with a small page ID).
87 // Make sure we don't confuse this as an existing navigation to an unknown
88 // entry.
89 ui_test_utils::NavigateToURLWithDisposition(
90 browser(), GURL(chrome::kChromeUINewTabURL), NEW_FOREGROUND_TAB,
91 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
92 EXPECT_EQ(4,
93 browser()->GetTabContentsAt(3)->GetSiteInstance()->max_page_id());
94 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/browser_render_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698