Rename GetIconID to GetIconId
[chromium-blink-merge.git] / chrome / browser / media / chrome_webrtc_perf_browsertest.cc
blob107c25fec4d224b67db24e623b33eb83d001f26d
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "base/files/file_util.h"
7 #include "base/json/json_reader.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string_split.h"
10 #include "base/strings/stringprintf.h"
11 #include "base/test/test_timeouts.h"
12 #include "base/time/time.h"
13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/media/webrtc_browsertest_base.h"
15 #include "chrome/browser/media/webrtc_browsertest_common.h"
16 #include "chrome/browser/media/webrtc_browsertest_perf.h"
17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_tabstrip.h"
19 #include "chrome/browser/ui/tabs/tab_strip_model.h"
20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/test/base/in_process_browser_test.h"
22 #include "chrome/test/base/ui_test_utils.h"
23 #include "content/public/test/browser_test_utils.h"
24 #include "media/base/media_switches.h"
25 #include "net/test/embedded_test_server/embedded_test_server.h"
26 #include "testing/perf/perf_test.h"
28 static const char kMainWebrtcTestHtmlPage[] =
29 "/webrtc/webrtc_jsep01_test.html";
31 // Performance browsertest for WebRTC. This test is manual since it takes long
32 // to execute and requires the reference files provided by the webrtc.DEPS
33 // solution (which is only available on WebRTC internal bots).
34 class WebRtcPerfBrowserTest : public WebRtcTestBase {
35 public:
36 void SetUpInProcessBrowserTestFixture() override {
37 DetectErrorsInJavaScript(); // Look for errors in our rather complex js.
40 void SetUpCommandLine(base::CommandLine* command_line) override {
41 // Ensure the infobar is enabled, since we expect that in this test.
42 EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream));
44 // Play a suitable, somewhat realistic video file.
45 base::FilePath input_video = test::GetReferenceFilesDir()
46 .Append(test::kReferenceFileName360p)
47 .AddExtension(test::kY4mFileExtension);
48 command_line->AppendSwitchPath(switches::kUseFileForFakeVideoCapture,
49 input_video);
50 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
53 // Tries to extract data from peerConnectionDataStore in the webrtc-internals
54 // tab. The caller owns the parsed data. Returns NULL on failure.
55 base::DictionaryValue* GetWebrtcInternalsData(
56 content::WebContents* webrtc_internals_tab) {
57 std::string all_stats_json = ExecuteJavascript(
58 "window.domAutomationController.send("
59 " JSON.stringify(peerConnectionDataStore));",
60 webrtc_internals_tab);
62 base::Value* parsed_json = base::JSONReader::DeprecatedRead(all_stats_json);
63 base::DictionaryValue* result;
64 if (parsed_json && parsed_json->GetAsDictionary(&result))
65 return result;
67 return NULL;
70 const base::DictionaryValue* GetDataOnPeerConnection(
71 const base::DictionaryValue* all_data,
72 int peer_connection_index) {
73 base::DictionaryValue::Iterator iterator(*all_data);
75 for (int i = 0; i < peer_connection_index && !iterator.IsAtEnd();
76 --peer_connection_index) {
77 iterator.Advance();
80 const base::DictionaryValue* result;
81 if (!iterator.IsAtEnd() && iterator.value().GetAsDictionary(&result))
82 return result;
84 return NULL;
87 scoped_ptr<base::DictionaryValue> MeasureWebRtcInternalsData(
88 int duration_msec) {
89 chrome::AddTabAt(browser(), GURL(), -1, true);
90 ui_test_utils::NavigateToURL(browser(), GURL("chrome://webrtc-internals"));
91 content::WebContents* webrtc_internals_tab =
92 browser()->tab_strip_model()->GetActiveWebContents();
94 test::SleepInJavascript(webrtc_internals_tab, duration_msec);
96 return scoped_ptr<base::DictionaryValue>(
97 GetWebrtcInternalsData(webrtc_internals_tab));
101 // This is manual for its long execution time.
102 IN_PROC_BROWSER_TEST_F(WebRtcPerfBrowserTest,
103 MANUAL_RunsAudioVideoCall60SecsAndLogsInternalMetrics) {
104 if (OnWinXp()) return;
106 ASSERT_TRUE(test::HasReferenceFilesInCheckout());
107 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
109 ASSERT_GE(TestTimeouts::action_max_timeout().InSeconds(), 100) <<
110 "This is a long-running test; you must specify "
111 "--ui-test-action-max-timeout to have a value of at least 100000.";
113 content::WebContents* left_tab =
114 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage);
115 content::WebContents* right_tab =
116 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage);
118 SetupPeerconnectionWithLocalStream(left_tab);
119 SetupPeerconnectionWithLocalStream(right_tab);
121 NegotiateCall(left_tab, right_tab);
123 StartDetectingVideo(left_tab, "remote-view");
124 StartDetectingVideo(right_tab, "remote-view");
126 WaitForVideoToPlay(left_tab);
127 WaitForVideoToPlay(right_tab);
129 // Let values stabilize, bandwidth ramp up, etc.
130 test::SleepInJavascript(left_tab, 60000);
132 // Start measurements.
133 scoped_ptr<base::DictionaryValue> all_data =
134 MeasureWebRtcInternalsData(10000);
135 ASSERT_TRUE(all_data.get() != NULL);
137 const base::DictionaryValue* first_pc_dict =
138 GetDataOnPeerConnection(all_data.get(), 0);
139 ASSERT_TRUE(first_pc_dict != NULL);
140 test::PrintBweForVideoMetrics(*first_pc_dict, "");
141 test::PrintMetricsForAllStreams(*first_pc_dict, "");
143 HangUp(left_tab);
144 HangUp(right_tab);
147 IN_PROC_BROWSER_TEST_F(WebRtcPerfBrowserTest,
148 MANUAL_RunsOneWayCall60SecsAndLogsInternalMetrics) {
149 if (OnWinXp()) return;
151 ASSERT_TRUE(test::HasReferenceFilesInCheckout());
152 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
154 ASSERT_GE(TestTimeouts::action_max_timeout().InSeconds(), 100) <<
155 "This is a long-running test; you must specify "
156 "--ui-test-action-max-timeout to have a value of at least 100000.";
158 content::WebContents* left_tab =
159 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage);
160 content::WebContents* right_tab =
161 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage);
163 SetupPeerconnectionWithLocalStream(left_tab);
164 SetupPeerconnectionWithoutLocalStream(right_tab);
166 NegotiateCall(left_tab, right_tab);
168 // Remote video will only play in one tab since the call is one-way.
169 StartDetectingVideo(right_tab, "remote-view");
170 WaitForVideoToPlay(right_tab);
172 // Let values stabilize, bandwidth ramp up, etc.
173 test::SleepInJavascript(left_tab, 60000);
175 scoped_ptr<base::DictionaryValue> all_data =
176 MeasureWebRtcInternalsData(10000);
177 ASSERT_TRUE(all_data.get() != NULL);
179 // This assumes the sending peer connection is always listed first in the
180 // data store, and the receiving second.
181 const base::DictionaryValue* first_pc_dict =
182 GetDataOnPeerConnection(all_data.get(), 0);
183 ASSERT_TRUE(first_pc_dict != NULL);
184 test::PrintBweForVideoMetrics(*first_pc_dict, "_sendonly");
185 test::PrintMetricsForAllStreams(*first_pc_dict, "_sendonly");
187 const base::DictionaryValue* second_pc_dict =
188 GetDataOnPeerConnection(all_data.get(), 1);
189 ASSERT_TRUE(second_pc_dict != NULL);
190 test::PrintBweForVideoMetrics(*second_pc_dict, "_recvonly");
191 test::PrintMetricsForAllStreams(*second_pc_dict, "_recvonly");
193 HangUp(left_tab);
194 HangUp(right_tab);