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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 | 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. |
68 // WebrtcTestBase-inheriting test cases do not run in parallel (if they did they | 68 void JavascriptErrorDetectingLogListener(int severity, |
69 // would race to look at the log, which is global to all tests). | 69 const char* file, |
70 bool JavascriptErrorDetectingLogHandler(int severity, | 70 int line, |
71 const char* file, | 71 size_t message_start, |
72 int line, | 72 const std::string& str) { |
73 size_t message_start, | |
74 const std::string& str) { | |
75 if (file == NULL || std::string("CONSOLE") != file) | 73 if (file == NULL || std::string("CONSOLE") != file) |
76 return false; | 74 return; |
77 | 75 |
78 bool contains_uncaught = str.find("\"Uncaught ") != std::string::npos; | 76 bool contains_uncaught = str.find("\"Uncaught ") != std::string::npos; |
79 if (severity == logging::LOG_ERROR || | 77 if (severity == logging::LOG_ERROR || |
80 (severity == logging::LOG_INFO && contains_uncaught)) { | 78 (severity == logging::LOG_INFO && contains_uncaught)) { |
81 hit_javascript_errors_.Get() = true; | 79 hit_javascript_errors_.Get() = true; |
82 } | 80 } |
83 | |
84 return false; | |
85 } | 81 } |
86 | 82 |
87 // PermissionRequestObserver --------------------------------------------------- | 83 // PermissionRequestObserver --------------------------------------------------- |
88 | 84 |
89 // Used to observe the creation of permission prompt without responding. | 85 // Used to observe the creation of permission prompt without responding. |
90 class PermissionRequestObserver : public PermissionBubbleManager::Observer { | 86 class PermissionRequestObserver : public PermissionBubbleManager::Observer { |
91 public: | 87 public: |
92 explicit PermissionRequestObserver(content::WebContents* web_contents) | 88 explicit PermissionRequestObserver(content::WebContents* web_contents) |
93 : bubble_manager_(PermissionBubbleManager::FromWebContents(web_contents)), | 89 : bubble_manager_(PermissionBubbleManager::FromWebContents(web_contents)), |
94 request_shown_(false), | 90 request_shown_(false), |
(...skipping 19 matching lines...) Expand all Loading... | |
114 | 110 |
115 PermissionBubbleManager* bubble_manager_; | 111 PermissionBubbleManager* bubble_manager_; |
116 bool request_shown_; | 112 bool request_shown_; |
117 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 113 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
118 | 114 |
119 DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver); | 115 DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver); |
120 }; | 116 }; |
121 | 117 |
122 } // namespace | 118 } // namespace |
123 | 119 |
124 WebRtcTestBase::WebRtcTestBase(): detect_errors_in_javascript_(false) { | 120 WebRtcTestBase::WebRtcTestBase() |
125 // The handler gets set for each test method, but that's fine since this | 121 : listener(JavascriptErrorDetectingLogListener), |
Dan Beam
2016/07/15 03:11:19
awesome
| |
126 // set operation is idempotent. | 122 detect_errors_in_javascript_(false) { |
127 logging::SetLogMessageHandler(&JavascriptErrorDetectingLogHandler); | |
128 hit_javascript_errors_.Get() = false; | 123 hit_javascript_errors_.Get() = false; |
129 | 124 |
130 EnablePixelOutput(); | 125 EnablePixelOutput(); |
131 } | 126 } |
132 | 127 |
133 WebRtcTestBase::~WebRtcTestBase() { | 128 WebRtcTestBase::~WebRtcTestBase() { |
134 if (detect_errors_in_javascript_) { | 129 if (detect_errors_in_javascript_) { |
135 EXPECT_FALSE(hit_javascript_errors_.Get()) | 130 EXPECT_FALSE(hit_javascript_errors_.Get()) |
136 << "Encountered javascript errors during test execution (Search " | 131 << "Encountered javascript errors during test execution (Search " |
137 << "for Uncaught or ERROR:CONSOLE in the test output)."; | 132 << "for Uncaught or ERROR:CONSOLE in the test output)."; |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
477 } | 472 } |
478 | 473 |
479 void WebRtcTestBase::GenerateAndCloneCertificate( | 474 void WebRtcTestBase::GenerateAndCloneCertificate( |
480 content::WebContents* tab, const std::string& keygen_algorithm) const { | 475 content::WebContents* tab, const std::string& keygen_algorithm) const { |
481 std::string javascript = base::StringPrintf( | 476 std::string javascript = base::StringPrintf( |
482 "generateAndCloneCertificate(%s)", keygen_algorithm.c_str()); | 477 "generateAndCloneCertificate(%s)", keygen_algorithm.c_str()); |
483 std::string response = ExecuteJavascript(javascript, tab); | 478 std::string response = ExecuteJavascript(javascript, tab); |
484 EXPECT_EQ("ok-generated-and-cloned", response) << "Failed to generate and " | 479 EXPECT_EQ("ok-generated-and-cloned", response) << "Failed to generate and " |
485 "clone certificate: " << response; | 480 "clone certificate: " << response; |
486 } | 481 } |
OLD | NEW |