OLD | NEW |
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/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 namespace { | 61 namespace { |
62 | 62 |
63 base::LazyInstance<bool> hit_javascript_errors_ = | 63 base::LazyInstance<bool> hit_javascript_errors_ = |
64 LAZY_INSTANCE_INITIALIZER; | 64 LAZY_INSTANCE_INITIALIZER; |
65 | 65 |
66 // Intercepts all log messages. We always attach this handler but only look at | 66 // Intercepts all log messages. We always attach this handler but only look at |
67 // the results if the test requests so. Note that this will only work if the | 67 // the results if the test requests so. Note that this will only work if the |
68 // WebrtcTestBase-inheriting test cases do not run in parallel (if they did they | 68 // WebrtcTestBase-inheriting test cases do not run in parallel (if they did they |
69 // would race to look at the log, which is global to all tests). | 69 // would race to look at the log, which is global to all tests). |
70 bool JavascriptErrorDetectingLogHandler(int severity, | 70 bool JavascriptErrorDetectingLogHandler(int severity, |
71 const char* file, | 71 const std::string& file, |
72 int line, | 72 int line, |
73 size_t message_start, | |
74 const std::string& str) { | 73 const std::string& str) { |
75 if (file == NULL || std::string("CONSOLE") != file) | 74 if (std::string("CONSOLE") != file) |
76 return false; | 75 return false; |
77 | 76 |
78 bool contains_uncaught = str.find("\"Uncaught ") != std::string::npos; | 77 bool contains_uncaught = str.find("\"Uncaught ") != std::string::npos; |
79 if (severity == logging::LOG_ERROR || | 78 if (severity == logging::LOG_ERROR || |
80 (severity == logging::LOG_INFO && contains_uncaught)) { | 79 (severity == logging::LOG_INFO && contains_uncaught)) { |
81 hit_javascript_errors_.Get() = true; | 80 hit_javascript_errors_.Get() = true; |
82 } | 81 } |
83 | 82 |
84 return false; | 83 return false; |
85 } | 84 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 117 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
119 | 118 |
120 DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver); | 119 DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver); |
121 }; | 120 }; |
122 | 121 |
123 } // namespace | 122 } // namespace |
124 | 123 |
125 WebRtcTestBase::WebRtcTestBase(): detect_errors_in_javascript_(false) { | 124 WebRtcTestBase::WebRtcTestBase(): detect_errors_in_javascript_(false) { |
126 // The handler gets set for each test method, but that's fine since this | 125 // The handler gets set for each test method, but that's fine since this |
127 // set operation is idempotent. | 126 // set operation is idempotent. |
128 logging::SetLogMessageHandler(&JavascriptErrorDetectingLogHandler); | 127 logging::AddLogMessageHandler(&JavascriptErrorDetectingLogHandler); |
129 hit_javascript_errors_.Get() = false; | 128 hit_javascript_errors_.Get() = false; |
130 | 129 |
131 EnablePixelOutput(); | 130 EnablePixelOutput(); |
132 } | 131 } |
133 | 132 |
134 WebRtcTestBase::~WebRtcTestBase() { | 133 WebRtcTestBase::~WebRtcTestBase() { |
135 if (detect_errors_in_javascript_) { | 134 if (detect_errors_in_javascript_) { |
136 EXPECT_FALSE(hit_javascript_errors_.Get()) | 135 EXPECT_FALSE(hit_javascript_errors_.Get()) |
137 << "Encountered javascript errors during test execution (Search " | 136 << "Encountered javascript errors during test execution (Search " |
138 << "for Uncaught or ERROR:CONSOLE in the test output)."; | 137 << "for Uncaught or ERROR:CONSOLE in the test output)."; |
139 } | 138 } |
| 139 logging::RemoveLogMessageHandler(&JavascriptErrorDetectingLogHandler); |
140 } | 140 } |
141 | 141 |
142 bool WebRtcTestBase::GetUserMediaAndAccept( | 142 bool WebRtcTestBase::GetUserMediaAndAccept( |
143 content::WebContents* tab_contents) const { | 143 content::WebContents* tab_contents) const { |
144 return GetUserMediaWithSpecificConstraintsAndAccept( | 144 return GetUserMediaWithSpecificConstraintsAndAccept( |
145 tab_contents, kAudioVideoCallConstraints); | 145 tab_contents, kAudioVideoCallConstraints); |
146 } | 146 } |
147 | 147 |
148 bool WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( | 148 bool WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( |
149 content::WebContents* tab_contents, | 149 content::WebContents* tab_contents, |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 void WebRtcTestBase::SetDefaultVideoCodec( | 469 void WebRtcTestBase::SetDefaultVideoCodec( |
470 content::WebContents* tab, | 470 content::WebContents* tab, |
471 const std::string& video_codec) const { | 471 const std::string& video_codec) const { |
472 EXPECT_EQ("ok-forced", | 472 EXPECT_EQ("ok-forced", |
473 ExecuteJavascript("forceVideoCodec('" + video_codec + "')", tab)); | 473 ExecuteJavascript("forceVideoCodec('" + video_codec + "')", tab)); |
474 } | 474 } |
475 | 475 |
476 void WebRtcTestBase::EnableOpusDtx(content::WebContents* tab) const { | 476 void WebRtcTestBase::EnableOpusDtx(content::WebContents* tab) const { |
477 EXPECT_EQ("ok-forced", ExecuteJavascript("forceOpusDtx()", tab)); | 477 EXPECT_EQ("ok-forced", ExecuteJavascript("forceOpusDtx()", tab)); |
478 } | 478 } |
OLD | NEW |