Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / webui / ntp / new_tab_ui_browsertest.cc
blob6dd5606cb479ee093d0910e6758dcb0d222fddda
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
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "base/logging.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/url_constants.h"
12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/public/browser/render_process_host.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/test/browser_test_utils.h"
17 #include "content/public/test/test_navigation_observer.h"
18 #include "url/gurl.h"
20 using content::OpenURLParams;
21 using content::Referrer;
23 namespace {
25 static bool had_console_errors = false;
27 bool HandleMessage(int severity,
28 const char* file,
29 int line,
30 size_t message_start,
31 const std::string& str) {
32 if (severity == logging::LOG_ERROR && file && file == std::string("CONSOLE"))
33 had_console_errors = true;
34 return false;
37 } // namespace
39 class NewTabUIBrowserTest : public InProcessBrowserTest {
40 public:
41 NewTabUIBrowserTest() {
42 logging::SetLogMessageHandler(&HandleMessage);
45 ~NewTabUIBrowserTest() override { logging::SetLogMessageHandler(NULL); }
47 void TearDown() override {
48 InProcessBrowserTest::TearDown();
49 ASSERT_FALSE(had_console_errors);
53 // TODO(samarth): delete along with rest of NTP4 code.
54 // Loads chrome://hang/ into two NTP tabs, ensuring we don't crash.
55 // See http://crbug.com/59859.
56 // If this flakes, use http://crbug.com/87200.
57 IN_PROC_BROWSER_TEST_F(NewTabUIBrowserTest, DISABLED_ChromeHangInNTP) {
58 // Bring up a new tab page.
59 ui_test_utils::NavigateToURLWithDisposition(
60 browser(), GURL(chrome::kChromeUINewTabURL), NEW_FOREGROUND_TAB,
61 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
63 // Navigate to chrome://hang/ to stall the process.
64 ui_test_utils::NavigateToURLWithDisposition(
65 browser(), GURL(content::kChromeUIHangURL), CURRENT_TAB, 0);
67 // Visit chrome://hang/ again in another NTP. Don't bother waiting for the
68 // NTP to load, because it's hung.
69 chrome::NewTab(browser());
70 browser()->OpenURL(OpenURLParams(
71 GURL(content::kChromeUIHangURL), Referrer(), CURRENT_TAB,
72 ui::PAGE_TRANSITION_TYPED, false));
75 // Navigate to incognito NTP. Fails if there are console errors.
76 IN_PROC_BROWSER_TEST_F(NewTabUIBrowserTest, ShowIncognito) {
77 ui_test_utils::NavigateToURL(CreateIncognitoBrowser(),
78 GURL(chrome::kChromeUINewTabURL));
81 class NewTabUIProcessPerTabTest : public NewTabUIBrowserTest {
82 public:
83 NewTabUIProcessPerTabTest() {}
85 void SetUpCommandLine(base::CommandLine* command_line) override {
86 command_line->AppendSwitch(switches::kProcessPerTab);
90 // Navigates away from NTP before it commits, in process-per-tab mode.
91 // Ensures that we don't load the normal page in the NTP process (and thus
92 // crash), as in http://crbug.com/69224.
93 // If this flakes, use http://crbug.com/87200
94 IN_PROC_BROWSER_TEST_F(NewTabUIProcessPerTabTest, NavBeforeNTPCommits) {
95 // Bring up a new tab page.
96 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL));
98 // Navigate to chrome://hang/ to stall the process.
99 ui_test_utils::NavigateToURLWithDisposition(
100 browser(), GURL(content::kChromeUIHangURL), CURRENT_TAB, 0);
102 // Visit a normal URL in another NTP that hasn't committed.
103 ui_test_utils::NavigateToURLWithDisposition(
104 browser(), GURL(chrome::kChromeUINewTabURL), NEW_FOREGROUND_TAB, 0);
106 // We don't use ui_test_utils::NavigateToURLWithDisposition because that waits
107 // for current loading to stop.
108 content::TestNavigationObserver observer(
109 browser()->tab_strip_model()->GetActiveWebContents());
110 browser()->OpenURL(OpenURLParams(
111 GURL("data:text/html,hello world"), Referrer(), CURRENT_TAB,
112 ui::PAGE_TRANSITION_TYPED, false));
113 observer.Wait();