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

Side by Side Diff: chrome/browser/media/webrtc/webrtc_browsertest_base.cc

Issue 2489673003: RTCPeerConnection.getStats: Whitelist of stats in unittest. (Closed)
Patch Set: Created 4 years, 1 month 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/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 message_loop_runner_->Quit(); 113 message_loop_runner_->Quit();
114 } 114 }
115 115
116 PermissionRequestManager* request_manager_; 116 PermissionRequestManager* request_manager_;
117 bool request_shown_; 117 bool request_shown_;
118 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 118 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
119 119
120 DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver); 120 DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver);
121 }; 121 };
122 122
123 std::vector<std::string> SemicolonListToVector(
124 const std::string str, size_t start_index = 0) {
125 std::vector<std::string> vector;
126 for (size_t begin = start_index, end = begin; begin <= str.length(); ++end) {
127 if (end >= str.length() || str[end] == ';') {
128 vector.push_back(str.substr(begin, end - begin));
129 begin = end + 1;
130 }
131 }
132 return vector;
133 }
134
123 } // namespace 135 } // namespace
124 136
125 WebRtcTestBase::WebRtcTestBase(): detect_errors_in_javascript_(false) { 137 WebRtcTestBase::WebRtcTestBase(): detect_errors_in_javascript_(false) {
126 // The handler gets set for each test method, but that's fine since this 138 // The handler gets set for each test method, but that's fine since this
127 // set operation is idempotent. 139 // set operation is idempotent.
128 logging::SetLogMessageHandler(&JavascriptErrorDetectingLogHandler); 140 logging::SetLogMessageHandler(&JavascriptErrorDetectingLogHandler);
129 hit_javascript_errors_.Get() = false; 141 hit_javascript_errors_.Get() = false;
130 142
131 EnablePixelOutput(); 143 EnablePixelOutput();
132 } 144 }
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 std::string javascript = base::StringPrintf( 465 std::string javascript = base::StringPrintf(
454 "generateAndCloneCertificate(%s)", keygen_algorithm.c_str()); 466 "generateAndCloneCertificate(%s)", keygen_algorithm.c_str());
455 EXPECT_EQ("ok-generated-and-cloned", ExecuteJavascript(javascript, tab)); 467 EXPECT_EQ("ok-generated-and-cloned", ExecuteJavascript(javascript, tab));
456 } 468 }
457 469
458 void WebRtcTestBase::VerifyStatsGeneratedCallback( 470 void WebRtcTestBase::VerifyStatsGeneratedCallback(
459 content::WebContents* tab) const { 471 content::WebContents* tab) const {
460 EXPECT_EQ("ok-got-stats", ExecuteJavascript("verifyStatsGenerated()", tab)); 472 EXPECT_EQ("ok-got-stats", ExecuteJavascript("verifyStatsGenerated()", tab));
461 } 473 }
462 474
463 void WebRtcTestBase::VerifyStatsGeneratedPromise( 475 std::vector<std::string> WebRtcTestBase::VerifyStatsGeneratedPromise(
464 content::WebContents* tab) const { 476 content::WebContents* tab) const {
465 EXPECT_EQ("ok-got-stats", 477 std::string result = ExecuteJavascript("verifyStatsGeneratedPromise()", tab);
466 ExecuteJavascript("verifyStatsGeneratedPromise()", tab)); 478 EXPECT_TRUE(base::StartsWith(result, "ok-", base::CompareCase::SENSITIVE));
479 return SemicolonListToVector(result, 3);
480 }
481
482 std::vector<std::string> WebRtcTestBase::GetWhitelistedStatsTypes(
483 content::WebContents* tab) const {
484 return SemicolonListToVector(
485 ExecuteJavascript("getWhitelistedStatsTypes()", tab));
467 } 486 }
468 487
469 void WebRtcTestBase::SetDefaultVideoCodec( 488 void WebRtcTestBase::SetDefaultVideoCodec(
470 content::WebContents* tab, 489 content::WebContents* tab,
471 const std::string& video_codec) const { 490 const std::string& video_codec) const {
472 EXPECT_EQ("ok-forced", 491 EXPECT_EQ("ok-forced",
473 ExecuteJavascript("forceVideoCodec('" + video_codec + "')", tab)); 492 ExecuteJavascript("forceVideoCodec('" + video_codec + "')", tab));
474 } 493 }
475 494
476 void WebRtcTestBase::EnableOpusDtx(content::WebContents* tab) const { 495 void WebRtcTestBase::EnableOpusDtx(content::WebContents* tab) const {
477 EXPECT_EQ("ok-forced", ExecuteJavascript("forceOpusDtx()", tab)); 496 EXPECT_EQ("ok-forced", ExecuteJavascript("forceOpusDtx()", tab));
478 } 497 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698