OLD | NEW |
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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
14 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
15 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
16 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
19 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
20 #include "content/public/test/test_navigation_observer.h" | 20 #include "content/public/test/test_navigation_observer.h" |
21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
22 | 22 |
23 using content::OpenURLParams; | 23 using content::OpenURLParams; |
24 using content::Referrer; | 24 using content::Referrer; |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 static bool had_console_errors = false; | 28 static bool had_console_errors = false; |
29 | 29 |
30 bool HandleMessage(int severity, | 30 class MessageListener : logging::LogMessageListener { |
31 const char* file, | 31 public: |
32 int line, | 32 void OnMessage(int severity, |
33 size_t message_start, | 33 const char* file, |
34 const std::string& str) { | 34 int line, |
35 if (severity == logging::LOG_ERROR && file && file == std::string("CONSOLE")) | 35 size_t message_start, |
36 had_console_errors = true; | 36 const std::string& str) override { |
37 return false; | 37 if (severity == logging::LOG_ERROR && file && |
38 } | 38 file == std::string("CONSOLE")) |
| 39 had_console_errors = true; |
| 40 } |
| 41 }; |
39 | 42 |
40 } // namespace | 43 } // namespace |
41 | 44 |
42 class NewTabUIBrowserTest : public InProcessBrowserTest { | 45 class NewTabUIBrowserTest : public InProcessBrowserTest { |
43 public: | 46 public: |
44 NewTabUIBrowserTest() { | 47 NewTabUIBrowserTest() {} |
45 logging::SetLogMessageHandler(&HandleMessage); | |
46 } | |
47 | |
48 ~NewTabUIBrowserTest() override { logging::SetLogMessageHandler(NULL); } | |
49 | 48 |
50 void TearDown() override { | 49 void TearDown() override { |
51 InProcessBrowserTest::TearDown(); | 50 InProcessBrowserTest::TearDown(); |
52 ASSERT_FALSE(had_console_errors); | 51 ASSERT_FALSE(had_console_errors); |
53 } | 52 } |
| 53 |
| 54 private: |
| 55 MessageListener log_listener_; |
54 }; | 56 }; |
55 | 57 |
56 // Navigate to incognito NTP. Fails if there are console errors. | 58 // Navigate to incognito NTP. Fails if there are console errors. |
57 IN_PROC_BROWSER_TEST_F(NewTabUIBrowserTest, ShowIncognito) { | 59 IN_PROC_BROWSER_TEST_F(NewTabUIBrowserTest, ShowIncognito) { |
58 ui_test_utils::NavigateToURL(CreateIncognitoBrowser(), | 60 ui_test_utils::NavigateToURL(CreateIncognitoBrowser(), |
59 GURL(chrome::kChromeUINewTabURL)); | 61 GURL(chrome::kChromeUINewTabURL)); |
60 } | 62 } |
61 | 63 |
62 class NewTabUIProcessPerTabTest : public NewTabUIBrowserTest { | 64 class NewTabUIProcessPerTabTest : public NewTabUIBrowserTest { |
63 public: | 65 public: |
(...skipping 24 matching lines...) Expand all Loading... |
88 | 90 |
89 // We don't use ui_test_utils::NavigateToURLWithDisposition because that waits | 91 // We don't use ui_test_utils::NavigateToURLWithDisposition because that waits |
90 // for current loading to stop. | 92 // for current loading to stop. |
91 content::TestNavigationObserver observer( | 93 content::TestNavigationObserver observer( |
92 browser()->tab_strip_model()->GetActiveWebContents()); | 94 browser()->tab_strip_model()->GetActiveWebContents()); |
93 browser()->OpenURL(OpenURLParams( | 95 browser()->OpenURL(OpenURLParams( |
94 GURL("data:text/html,hello world"), Referrer(), | 96 GURL("data:text/html,hello world"), Referrer(), |
95 WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); | 97 WindowOpenDisposition::CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); |
96 observer.Wait(); | 98 observer.Wait(); |
97 } | 99 } |
OLD | NEW |