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

Side by Side Diff: chrome/browser/media/webrtc/webrtc_browsertest_base.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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/media/webrtc/webrtc_browsertest_base.h" 5 #include "chrome/browser/media/webrtc/webrtc_browsertest_base.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 " minHeight: 720, maxHeight: 720}}}"; 60 " minHeight: 720, maxHeight: 720}}}";
61 const char WebRtcTestBase::kUseDefaultCertKeygen[] = "null"; 61 const char WebRtcTestBase::kUseDefaultCertKeygen[] = "null";
62 const char WebRtcTestBase::kUseDefaultAudioCodec[] = ""; 62 const char WebRtcTestBase::kUseDefaultAudioCodec[] = "";
63 const char WebRtcTestBase::kUseDefaultVideoCodec[] = ""; 63 const char WebRtcTestBase::kUseDefaultVideoCodec[] = "";
64 64
65 namespace { 65 namespace {
66 66
67 base::LazyInstance<bool> hit_javascript_errors_ = 67 base::LazyInstance<bool> hit_javascript_errors_ =
68 LAZY_INSTANCE_INITIALIZER; 68 LAZY_INSTANCE_INITIALIZER;
69 69
70 // Intercepts all log messages. We always attach this handler but only look at
71 // the results if the test requests so. Note that this will only work if the
72 // WebrtcTestBase-inheriting test cases do not run in parallel (if they did they
73 // would race to look at the log, which is global to all tests).
74 bool JavascriptErrorDetectingLogHandler(int severity,
75 const char* file,
76 int line,
77 size_t message_start,
78 const std::string& str) {
79 if (file == NULL || std::string("CONSOLE") != file)
80 return false;
81
82 bool contains_uncaught = str.find("\"Uncaught ") != std::string::npos;
83 if (severity == logging::LOG_ERROR ||
84 (severity == logging::LOG_INFO && contains_uncaught)) {
85 hit_javascript_errors_.Get() = true;
86 }
87
88 return false;
89 }
90
91 // PermissionRequestObserver --------------------------------------------------- 70 // PermissionRequestObserver ---------------------------------------------------
92 71
93 // Used to observe the creation of permission prompt without responding. 72 // Used to observe the creation of permission prompt without responding.
94 class PermissionRequestObserver : public PermissionRequestManager::Observer { 73 class PermissionRequestObserver : public PermissionRequestManager::Observer {
95 public: 74 public:
96 explicit PermissionRequestObserver(content::WebContents* web_contents) 75 explicit PermissionRequestObserver(content::WebContents* web_contents)
97 : request_manager_( 76 : request_manager_(
98 PermissionRequestManager::FromWebContents(web_contents)), 77 PermissionRequestManager::FromWebContents(web_contents)),
99 request_shown_(false), 78 request_shown_(false),
100 message_loop_runner_(new content::MessageLoopRunner) { 79 message_loop_runner_(new content::MessageLoopRunner) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 EXPECT_TRUE(item->IsType(base::Value::Type::STRING)); 118 EXPECT_TRUE(item->IsType(base::Value::Type::STRING));
140 std::string item_str; 119 std::string item_str;
141 EXPECT_TRUE(item->GetAsString(&item_str)); 120 EXPECT_TRUE(item->GetAsString(&item_str));
142 vector.push_back(std::move(item_str)); 121 vector.push_back(std::move(item_str));
143 } 122 }
144 return vector; 123 return vector;
145 } 124 }
146 125
147 } // namespace 126 } // namespace
148 127
128 // Intercepts all log messages. We always attach this listener but only look at
129 // the results if the test requests so.
130 void JavascriptErrorDetectingListener::OnMessage(int severity,
131 const char* file,
132 int line,
133 size_t message_start,
134 const std::string& str) {
135 if (file == NULL || std::string("CONSOLE") != file)
136 return;
137
138 bool contains_uncaught = str.find("\"Uncaught ") != std::string::npos;
139 if (severity == logging::LOG_ERROR ||
140 (severity == logging::LOG_INFO && contains_uncaught)) {
141 hit_javascript_errors_.Get() = true;
142 }
143 }
144
149 WebRtcTestBase::WebRtcTestBase(): detect_errors_in_javascript_(false) { 145 WebRtcTestBase::WebRtcTestBase(): detect_errors_in_javascript_(false) {
150 // The handler gets set for each test method, but that's fine since this
151 // set operation is idempotent.
152 logging::SetLogMessageHandler(&JavascriptErrorDetectingLogHandler);
153 hit_javascript_errors_.Get() = false; 146 hit_javascript_errors_.Get() = false;
154 147
155 EnablePixelOutput(); 148 EnablePixelOutput();
156 } 149 }
157 150
158 WebRtcTestBase::~WebRtcTestBase() { 151 WebRtcTestBase::~WebRtcTestBase() {
159 if (detect_errors_in_javascript_) { 152 if (detect_errors_in_javascript_) {
160 EXPECT_FALSE(hit_javascript_errors_.Get()) 153 EXPECT_FALSE(hit_javascript_errors_.Get())
161 << "Encountered javascript errors during test execution (Search " 154 << "Encountered javascript errors during test execution (Search "
162 << "for Uncaught or ERROR:CONSOLE in the test output)."; 155 << "for Uncaught or ERROR:CONSOLE in the test output).";
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 void WebRtcTestBase::SetDefaultVideoCodec( 521 void WebRtcTestBase::SetDefaultVideoCodec(
529 content::WebContents* tab, 522 content::WebContents* tab,
530 const std::string& video_codec) const { 523 const std::string& video_codec) const {
531 EXPECT_EQ("ok", ExecuteJavascript( 524 EXPECT_EQ("ok", ExecuteJavascript(
532 "setDefaultVideoCodec('" + video_codec + "')", tab)); 525 "setDefaultVideoCodec('" + video_codec + "')", tab));
533 } 526 }
534 527
535 void WebRtcTestBase::EnableOpusDtx(content::WebContents* tab) const { 528 void WebRtcTestBase::EnableOpusDtx(content::WebContents* tab) const {
536 EXPECT_EQ("ok-forced", ExecuteJavascript("forceOpusDtx()", tab)); 529 EXPECT_EQ("ok-forced", ExecuteJavascript("forceOpusDtx()", tab));
537 } 530 }
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc/webrtc_browsertest_base.h ('k') | chrome/browser/safe_browsing/safe_browsing_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698