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_browsertest_base.h" | 5 #include "chrome/browser/media/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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 "{audio: true, video: {mandatory: {minWidth: 1280, maxWidth: 1280, " | 56 "{audio: true, video: {mandatory: {minWidth: 1280, maxWidth: 1280, " |
57 " minHeight: 720, maxHeight: 720}}}"; | 57 " minHeight: 720, maxHeight: 720}}}"; |
58 const char WebRtcTestBase::kUseDefaultCertKeygen[] = "null"; | 58 const char WebRtcTestBase::kUseDefaultCertKeygen[] = "null"; |
59 const char WebRtcTestBase::kUseDefaultVideoCodec[] = ""; | 59 const char WebRtcTestBase::kUseDefaultVideoCodec[] = ""; |
60 | 60 |
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 | |
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 | |
69 // would race to look at the log, which is global to all tests). | |
70 bool JavascriptErrorDetectingLogHandler(int severity, | |
71 const char* file, | |
72 int line, | |
73 size_t message_start, | |
74 const std::string& str) { | |
75 if (file == NULL || std::string("CONSOLE") != file) | |
76 return false; | |
77 | |
78 bool contains_uncaught = str.find("\"Uncaught ") != std::string::npos; | |
79 if (severity == logging::LOG_ERROR || | |
80 (severity == logging::LOG_INFO && contains_uncaught)) { | |
81 hit_javascript_errors_.Get() = true; | |
82 } | |
83 | |
84 return false; | |
85 } | |
86 | |
87 // PermissionRequestObserver --------------------------------------------------- | 66 // PermissionRequestObserver --------------------------------------------------- |
88 | 67 |
89 // Used to observe the creation of permission prompt without responding. | 68 // Used to observe the creation of permission prompt without responding. |
90 class PermissionRequestObserver : public PermissionRequestManager::Observer { | 69 class PermissionRequestObserver : public PermissionRequestManager::Observer { |
91 public: | 70 public: |
92 explicit PermissionRequestObserver(content::WebContents* web_contents) | 71 explicit PermissionRequestObserver(content::WebContents* web_contents) |
93 : request_manager_( | 72 : request_manager_( |
94 PermissionRequestManager::FromWebContents(web_contents)), | 73 PermissionRequestManager::FromWebContents(web_contents)), |
95 request_shown_(false), | 74 request_shown_(false), |
96 message_loop_runner_(new content::MessageLoopRunner) { | 75 message_loop_runner_(new content::MessageLoopRunner) { |
(...skipping 18 matching lines...) Expand all Loading... |
115 | 94 |
116 PermissionRequestManager* request_manager_; | 95 PermissionRequestManager* request_manager_; |
117 bool request_shown_; | 96 bool request_shown_; |
118 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 97 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
119 | 98 |
120 DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver); | 99 DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver); |
121 }; | 100 }; |
122 | 101 |
123 } // namespace | 102 } // namespace |
124 | 103 |
| 104 // Intercepts all log messages. We always attach this listener but only look at |
| 105 // the results if the test requests so. |
| 106 void JavascriptErrorDetectingListener::OnMessage(int severity, |
| 107 const char* file, |
| 108 int line, |
| 109 size_t message_start, |
| 110 const std::string& str) { |
| 111 if (file == NULL || std::string("CONSOLE") != file) |
| 112 return; |
| 113 |
| 114 bool contains_uncaught = str.find("\"Uncaught ") != std::string::npos; |
| 115 if (severity == logging::LOG_ERROR || |
| 116 (severity == logging::LOG_INFO && contains_uncaught)) { |
| 117 hit_javascript_errors_.Get() = true; |
| 118 } |
| 119 } |
| 120 |
125 WebRtcTestBase::WebRtcTestBase(): detect_errors_in_javascript_(false) { | 121 WebRtcTestBase::WebRtcTestBase(): detect_errors_in_javascript_(false) { |
126 // The handler gets set for each test method, but that's fine since this | |
127 // set operation is idempotent. | |
128 logging::SetLogMessageHandler(&JavascriptErrorDetectingLogHandler); | |
129 hit_javascript_errors_.Get() = false; | 122 hit_javascript_errors_.Get() = false; |
130 | 123 |
131 EnablePixelOutput(); | 124 EnablePixelOutput(); |
132 } | 125 } |
133 | 126 |
134 WebRtcTestBase::~WebRtcTestBase() { | 127 WebRtcTestBase::~WebRtcTestBase() { |
135 if (detect_errors_in_javascript_) { | 128 if (detect_errors_in_javascript_) { |
136 EXPECT_FALSE(hit_javascript_errors_.Get()) | 129 EXPECT_FALSE(hit_javascript_errors_.Get()) |
137 << "Encountered javascript errors during test execution (Search " | 130 << "Encountered javascript errors during test execution (Search " |
138 << "for Uncaught or ERROR:CONSOLE in the test output)."; | 131 << "for Uncaught or ERROR:CONSOLE in the test output)."; |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 void WebRtcTestBase::SetDefaultVideoCodec( | 466 void WebRtcTestBase::SetDefaultVideoCodec( |
474 content::WebContents* tab, | 467 content::WebContents* tab, |
475 const std::string& video_codec) const { | 468 const std::string& video_codec) const { |
476 EXPECT_EQ("ok-forced", | 469 EXPECT_EQ("ok-forced", |
477 ExecuteJavascript("forceVideoCodec('" + video_codec + "')", tab)); | 470 ExecuteJavascript("forceVideoCodec('" + video_codec + "')", tab)); |
478 } | 471 } |
479 | 472 |
480 void WebRtcTestBase::EnableOpusDtx(content::WebContents* tab) const { | 473 void WebRtcTestBase::EnableOpusDtx(content::WebContents* tab) const { |
481 EXPECT_EQ("ok-forced", ExecuteJavascript("forceOpusDtx()", tab)); | 474 EXPECT_EQ("ok-forced", ExecuteJavascript("forceOpusDtx()", tab)); |
482 } | 475 } |
OLD | NEW |