| 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/json/json_reader.h" |
| 9 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 14 #include "chrome/browser/media/webrtc/webrtc_browsertest_common.h" | 15 #include "chrome/browser/media/webrtc/webrtc_browsertest_common.h" |
| 15 #include "chrome/browser/permissions/permission_request_manager.h" | 16 #include "chrome/browser/permissions/permission_request_manager.h" |
| 16 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_tabstrip.h" | 18 #include "chrome/browser/ui/browser_tabstrip.h" |
| 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 message_loop_runner_->Quit(); | 114 message_loop_runner_->Quit(); |
| 114 } | 115 } |
| 115 | 116 |
| 116 PermissionRequestManager* request_manager_; | 117 PermissionRequestManager* request_manager_; |
| 117 bool request_shown_; | 118 bool request_shown_; |
| 118 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 119 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 119 | 120 |
| 120 DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver); | 121 DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver); |
| 121 }; | 122 }; |
| 122 | 123 |
| 124 std::vector<std::string> JsonArrayToVectorOfStrings( |
| 125 const std::string& json_array) { |
| 126 std::unique_ptr<base::Value> value = base::JSONReader::Read(json_array); |
| 127 EXPECT_TRUE(value); |
| 128 EXPECT_TRUE(value->IsType(base::Value::TYPE_LIST)); |
| 129 std::unique_ptr<base::ListValue> list = |
| 130 base::ListValue::From(std::move(value)); |
| 131 std::vector<std::string> vector; |
| 132 vector.reserve(list->GetSize()); |
| 133 for (size_t i = 0; i < list->GetSize(); ++i) { |
| 134 base::Value* item; |
| 135 EXPECT_TRUE(list->Get(i, &item)); |
| 136 EXPECT_TRUE(item->IsType(base::Value::TYPE_STRING)); |
| 137 std::string item_str; |
| 138 EXPECT_TRUE(item->GetAsString(&item_str)); |
| 139 vector.push_back(std::move(item_str)); |
| 140 } |
| 141 return vector; |
| 142 } |
| 143 |
| 123 } // namespace | 144 } // namespace |
| 124 | 145 |
| 125 WebRtcTestBase::WebRtcTestBase(): detect_errors_in_javascript_(false) { | 146 WebRtcTestBase::WebRtcTestBase(): detect_errors_in_javascript_(false) { |
| 126 // The handler gets set for each test method, but that's fine since this | 147 // The handler gets set for each test method, but that's fine since this |
| 127 // set operation is idempotent. | 148 // set operation is idempotent. |
| 128 logging::SetLogMessageHandler(&JavascriptErrorDetectingLogHandler); | 149 logging::SetLogMessageHandler(&JavascriptErrorDetectingLogHandler); |
| 129 hit_javascript_errors_.Get() = false; | 150 hit_javascript_errors_.Get() = false; |
| 130 | 151 |
| 131 EnablePixelOutput(); | 152 EnablePixelOutput(); |
| 132 } | 153 } |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 std::string javascript = base::StringPrintf( | 474 std::string javascript = base::StringPrintf( |
| 454 "generateAndCloneCertificate(%s)", keygen_algorithm.c_str()); | 475 "generateAndCloneCertificate(%s)", keygen_algorithm.c_str()); |
| 455 EXPECT_EQ("ok-generated-and-cloned", ExecuteJavascript(javascript, tab)); | 476 EXPECT_EQ("ok-generated-and-cloned", ExecuteJavascript(javascript, tab)); |
| 456 } | 477 } |
| 457 | 478 |
| 458 void WebRtcTestBase::VerifyStatsGeneratedCallback( | 479 void WebRtcTestBase::VerifyStatsGeneratedCallback( |
| 459 content::WebContents* tab) const { | 480 content::WebContents* tab) const { |
| 460 EXPECT_EQ("ok-got-stats", ExecuteJavascript("verifyStatsGenerated()", tab)); | 481 EXPECT_EQ("ok-got-stats", ExecuteJavascript("verifyStatsGenerated()", tab)); |
| 461 } | 482 } |
| 462 | 483 |
| 463 void WebRtcTestBase::VerifyStatsGeneratedPromise( | 484 std::vector<std::string> WebRtcTestBase::VerifyStatsGeneratedPromise( |
| 464 content::WebContents* tab) const { | 485 content::WebContents* tab) const { |
| 465 EXPECT_EQ("ok-got-stats", | 486 std::string result = ExecuteJavascript("verifyStatsGeneratedPromise()", tab); |
| 466 ExecuteJavascript("verifyStatsGeneratedPromise()", tab)); | 487 EXPECT_TRUE(base::StartsWith(result, "ok-", base::CompareCase::SENSITIVE)); |
| 488 return JsonArrayToVectorOfStrings(result.substr(3)); |
| 489 } |
| 490 |
| 491 std::vector<std::string> WebRtcTestBase::GetWhitelistedStatsTypes( |
| 492 content::WebContents* tab) const { |
| 493 return JsonArrayToVectorOfStrings( |
| 494 ExecuteJavascript("getWhitelistedStatsTypes()", tab)); |
| 467 } | 495 } |
| 468 | 496 |
| 469 void WebRtcTestBase::SetDefaultVideoCodec( | 497 void WebRtcTestBase::SetDefaultVideoCodec( |
| 470 content::WebContents* tab, | 498 content::WebContents* tab, |
| 471 const std::string& video_codec) const { | 499 const std::string& video_codec) const { |
| 472 EXPECT_EQ("ok-forced", | 500 EXPECT_EQ("ok-forced", |
| 473 ExecuteJavascript("forceVideoCodec('" + video_codec + "')", tab)); | 501 ExecuteJavascript("forceVideoCodec('" + video_codec + "')", tab)); |
| 474 } | 502 } |
| 475 | 503 |
| 476 void WebRtcTestBase::EnableOpusDtx(content::WebContents* tab) const { | 504 void WebRtcTestBase::EnableOpusDtx(content::WebContents* tab) const { |
| 477 EXPECT_EQ("ok-forced", ExecuteJavascript("forceOpusDtx()", tab)); | 505 EXPECT_EQ("ok-forced", ExecuteJavascript("forceOpusDtx()", tab)); |
| 478 } | 506 } |
| OLD | NEW |