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

Side by Side Diff: chrome/test/base/web_ui_browser_test.cc

Issue 2034393004: Allow multiple logging::LogMessage{Handler,Listener}s Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 3 years, 11 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
« no previous file with comments | « chrome/test/base/web_ui_browser_test.h ('k') | chrome/test/chromedriver/logging.cc » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/test/base/web_ui_browser_test.h" 5 #include "chrome/test/base/web_ui_browser_test.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 using content::RenderViewHost; 46 using content::RenderViewHost;
47 using content::WebContents; 47 using content::WebContents;
48 using content::WebUIController; 48 using content::WebUIController;
49 using content::WebUIMessageHandler; 49 using content::WebUIMessageHandler;
50 50
51 namespace { 51 namespace {
52 52
53 base::LazyInstance<std::vector<std::string> > error_messages_ = 53 base::LazyInstance<std::vector<std::string> > error_messages_ =
54 LAZY_INSTANCE_INITIALIZER; 54 LAZY_INSTANCE_INITIALIZER;
55 55
56 // Intercepts all log messages.
57 bool LogHandler(int severity,
58 const char* file,
59 int line,
60 size_t message_start,
61 const std::string& str) {
62 if (severity == logging::LOG_ERROR && file &&
63 std::string("CONSOLE") == file) {
64 error_messages_.Get().push_back(str);
65 }
66
67 return false;
68 }
69
70 class WebUIJsInjectionReadyObserver : public content::WebContentsObserver { 56 class WebUIJsInjectionReadyObserver : public content::WebContentsObserver {
71 public: 57 public:
72 WebUIJsInjectionReadyObserver(content::WebContents* web_contents, 58 WebUIJsInjectionReadyObserver(content::WebContents* web_contents,
73 WebUIBrowserTest* browser_test, 59 WebUIBrowserTest* browser_test,
74 const std::string& preload_test_fixture, 60 const std::string& preload_test_fixture,
75 const std::string& preload_test_name) 61 const std::string& preload_test_name)
76 : content::WebContentsObserver(web_contents), 62 : content::WebContentsObserver(web_contents),
77 browser_test_(browser_test), 63 browser_test_(browser_test),
78 preload_test_fixture_(preload_test_fixture), 64 preload_test_fixture_(preload_test_fixture),
79 preload_test_name_(preload_test_name) {} 65 preload_test_name_(preload_test_name) {}
80 66
81 void RenderViewCreated(content::RenderViewHost* rvh) override { 67 void RenderViewCreated(content::RenderViewHost* rvh) override {
82 browser_test_->PreLoadJavascriptLibraries( 68 browser_test_->PreLoadJavascriptLibraries(
83 preload_test_fixture_, preload_test_name_, rvh); 69 preload_test_fixture_, preload_test_name_, rvh);
84 } 70 }
85 71
86 private: 72 private:
87 WebUIBrowserTest* browser_test_; 73 WebUIBrowserTest* browser_test_;
88 std::string preload_test_fixture_; 74 std::string preload_test_fixture_;
89 std::string preload_test_name_; 75 std::string preload_test_name_;
90 }; 76 };
91 77
92 } // namespace 78 } // namespace
93 79
80 // Intercepts all log messages.
81 void WebUILogMessageListener::OnMessage(int severity,
82 const char* file,
83 int line,
84 size_t message_start,
85 const std::string& str) {
86 if (severity == logging::LOG_ERROR && file &&
87 std::string("CONSOLE") == file) {
88 error_messages_.Get().push_back(str);
89 }
90 }
91
94 WebUIBrowserTest::~WebUIBrowserTest() { 92 WebUIBrowserTest::~WebUIBrowserTest() {
95 } 93 }
96 94
97 bool WebUIBrowserTest::RunJavascriptFunction(const std::string& function_name) { 95 bool WebUIBrowserTest::RunJavascriptFunction(const std::string& function_name) {
98 ConstValueVector empty_args; 96 ConstValueVector empty_args;
99 return RunJavascriptFunction(function_name, empty_args); 97 return RunJavascriptFunction(function_name, empty_args);
100 } 98 }
101 99
102 bool WebUIBrowserTest::RunJavascriptFunction(const std::string& function_name, 100 bool WebUIBrowserTest::RunJavascriptFunction(const std::string& function_name,
103 base::Value* arg) { 101 base::Value* arg) {
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 }; 374 };
377 375
378 base::LazyInstance<MockWebUIProvider> mock_provider_ = 376 base::LazyInstance<MockWebUIProvider> mock_provider_ =
379 LAZY_INSTANCE_INITIALIZER; 377 LAZY_INSTANCE_INITIALIZER;
380 378
381 } // namespace 379 } // namespace
382 380
383 void WebUIBrowserTest::SetUpOnMainThread() { 381 void WebUIBrowserTest::SetUpOnMainThread() {
384 JavaScriptBrowserTest::SetUpOnMainThread(); 382 JavaScriptBrowserTest::SetUpOnMainThread();
385 383
386 logging::SetLogMessageHandler(&LogHandler);
387
388 AddLibrary(base::FilePath(kA11yAuditLibraryJSPath)); 384 AddLibrary(base::FilePath(kA11yAuditLibraryJSPath));
389 385
390 content::WebUIControllerFactory::UnregisterFactoryForTesting( 386 content::WebUIControllerFactory::UnregisterFactoryForTesting(
391 ChromeWebUIControllerFactory::GetInstance()); 387 ChromeWebUIControllerFactory::GetInstance());
392 388
393 test_factory_.reset(new TestChromeWebUIControllerFactory); 389 test_factory_.reset(new TestChromeWebUIControllerFactory);
394 390
395 content::WebUIControllerFactory::RegisterFactory(test_factory_.get()); 391 content::WebUIControllerFactory::RegisterFactory(test_factory_.get());
396 392
397 test_factory_->AddFactoryOverride(GURL(kDummyURL).host(), 393 test_factory_->AddFactoryOverride(GURL(kDummyURL).host(),
398 mock_provider_.Pointer()); 394 mock_provider_.Pointer());
399 test_factory_->AddFactoryOverride(content::kChromeUIResourcesHost, 395 test_factory_->AddFactoryOverride(content::kChromeUIResourcesHost,
400 mock_provider_.Pointer()); 396 mock_provider_.Pointer());
401 } 397 }
402 398
403 void WebUIBrowserTest::TearDownOnMainThread() { 399 void WebUIBrowserTest::TearDownOnMainThread() {
404 logging::SetLogMessageHandler(NULL);
405
406 test_factory_->RemoveFactoryOverride(GURL(kDummyURL).host()); 400 test_factory_->RemoveFactoryOverride(GURL(kDummyURL).host());
407 content::WebUIControllerFactory::UnregisterFactoryForTesting( 401 content::WebUIControllerFactory::UnregisterFactoryForTesting(
408 test_factory_.get()); 402 test_factory_.get());
409 403
410 // This is needed to avoid a debug assert after the test completes, see stack 404 // This is needed to avoid a debug assert after the test completes, see stack
411 // trace in http://crrev.com/179347 405 // trace in http://crrev.com/179347
412 content::WebUIControllerFactory::RegisterFactory( 406 content::WebUIControllerFactory::RegisterFactory(
413 ChromeWebUIControllerFactory::GetInstance()); 407 ChromeWebUIControllerFactory::GetInstance());
414 408
415 test_factory_.reset(); 409 test_factory_.reset();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 } 493 }
500 494
501 GURL WebUIBrowserTest::WebUITestDataPathToURL( 495 GURL WebUIBrowserTest::WebUITestDataPathToURL(
502 const base::FilePath::StringType& path) { 496 const base::FilePath::StringType& path) {
503 base::FilePath dir_test_data; 497 base::FilePath dir_test_data;
504 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &dir_test_data)); 498 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &dir_test_data));
505 base::FilePath test_path(dir_test_data.Append(kWebUITestFolder).Append(path)); 499 base::FilePath test_path(dir_test_data.Append(kWebUITestFolder).Append(path));
506 EXPECT_TRUE(base::PathExists(test_path)); 500 EXPECT_TRUE(base::PathExists(test_path));
507 return net::FilePathToFileURL(test_path); 501 return net::FilePathToFileURL(test_path);
508 } 502 }
OLDNEW
« no previous file with comments | « chrome/test/base/web_ui_browser_test.h ('k') | chrome/test/chromedriver/logging.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698