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 void MessageListener(int severity, |
31 const char* file, | 31 const char* file, |
32 int line, | 32 int line, |
33 size_t message_start, | 33 size_t message_start, |
34 const std::string& str) { | 34 const std::string& str) { |
35 if (severity == logging::LOG_ERROR && file && file == std::string("CONSOLE")) | 35 if (severity == logging::LOG_ERROR && file && file == std::string("CONSOLE")) |
36 had_console_errors = true; | 36 had_console_errors = true; |
37 return false; | |
38 } | 37 } |
39 | 38 |
40 } // namespace | 39 } // namespace |
41 | 40 |
42 class NewTabUIBrowserTest : public InProcessBrowserTest { | 41 class NewTabUIBrowserTest : public InProcessBrowserTest { |
43 public: | 42 public: |
44 NewTabUIBrowserTest() { | 43 NewTabUIBrowserTest(): listener(MessageListener) {} |
45 logging::SetLogMessageHandler(&HandleMessage); | |
46 } | |
47 | |
48 ~NewTabUIBrowserTest() override { logging::SetLogMessageHandler(NULL); } | |
49 | 44 |
50 void TearDown() override { | 45 void TearDown() override { |
51 InProcessBrowserTest::TearDown(); | 46 InProcessBrowserTest::TearDown(); |
52 ASSERT_FALSE(had_console_errors); | 47 ASSERT_FALSE(had_console_errors); |
53 } | 48 } |
49 private: | |
50 logging::ScopedLogMessageListener listener; | |
Dan Beam
2016/07/15 03:11:19
all of these should be log_listener_ IMO or at lea
wychen
2016/07/18 15:44:12
Oops.
| |
54 }; | 51 }; |
55 | 52 |
56 // Navigate to incognito NTP. Fails if there are console errors. | 53 // Navigate to incognito NTP. Fails if there are console errors. |
57 IN_PROC_BROWSER_TEST_F(NewTabUIBrowserTest, ShowIncognito) { | 54 IN_PROC_BROWSER_TEST_F(NewTabUIBrowserTest, ShowIncognito) { |
58 ui_test_utils::NavigateToURL(CreateIncognitoBrowser(), | 55 ui_test_utils::NavigateToURL(CreateIncognitoBrowser(), |
59 GURL(chrome::kChromeUINewTabURL)); | 56 GURL(chrome::kChromeUINewTabURL)); |
60 } | 57 } |
61 | 58 |
62 class NewTabUIProcessPerTabTest : public NewTabUIBrowserTest { | 59 class NewTabUIProcessPerTabTest : public NewTabUIBrowserTest { |
63 public: | 60 public: |
(...skipping 22 matching lines...) Expand all Loading... | |
86 | 83 |
87 // We don't use ui_test_utils::NavigateToURLWithDisposition because that waits | 84 // We don't use ui_test_utils::NavigateToURLWithDisposition because that waits |
88 // for current loading to stop. | 85 // for current loading to stop. |
89 content::TestNavigationObserver observer( | 86 content::TestNavigationObserver observer( |
90 browser()->tab_strip_model()->GetActiveWebContents()); | 87 browser()->tab_strip_model()->GetActiveWebContents()); |
91 browser()->OpenURL(OpenURLParams( | 88 browser()->OpenURL(OpenURLParams( |
92 GURL("data:text/html,hello world"), Referrer(), CURRENT_TAB, | 89 GURL("data:text/html,hello world"), Referrer(), CURRENT_TAB, |
93 ui::PAGE_TRANSITION_TYPED, false)); | 90 ui::PAGE_TRANSITION_TYPED, false)); |
94 observer.Wait(); | 91 observer.Wait(); |
95 } | 92 } |
OLD | NEW |