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
3 // found in the LICENSE file.
7 #include "base/path_service.h"
8 #include "base/strings/stringprintf.h"
9 #include "chrome/browser/media/webrtc_browsertest_base.h"
10 #include "chrome/browser/media/webrtc_browsertest_common.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_tabstrip.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/common/chrome_paths.h"
16 #include "chrome/test/base/ui_test_utils.h"
17 #include "content/public/test/browser_test_utils.h"
18 #include "net/test/embedded_test_server/embedded_test_server.h"
19 #include "testing/perf/perf_test.h"
21 static const base::FilePath::CharType kReferenceFile
[] =
23 FILE_PATH_LITERAL("pyauto_private/webrtc/human-voice-win.wav");
25 FILE_PATH_LITERAL("pyauto_private/webrtc/human-voice-linux.wav");
28 // The javascript will load the reference file relative to its location,
29 // which is in /webrtc on the web server. Therefore, prepend a '..' traversal.
30 static const char kReferenceFileRelativeUrl
[] =
32 "../pyauto_private/webrtc/human-voice-win.wav";
34 "../pyauto_private/webrtc/human-voice-linux.wav";
37 static const char kMainWebrtcTestHtmlPage
[] =
38 "files/webrtc/webrtc_audio_quality_test.html";
40 static base::FilePath
GetTestDataDir() {
41 base::FilePath source_dir
;
42 PathService::Get(chrome::DIR_TEST_DATA
, &source_dir
);
46 // Test that the typing detection feature works.
47 // You must have the src-internal solution in your .gclient to put the required
48 // pyauto_private directory into chrome/test/data/.
49 class WebRtcTypingDetectionBrowserTest
: public WebRtcTestBase
{
51 // TODO(phoglund): clean up duplication from audio quality browser test when
52 // this test is complete and is proven to work.
53 bool HasAllRequiredResources() {
54 base::FilePath reference_file
=
55 GetTestDataDir().Append(kReferenceFile
);
56 if (!base::PathExists(reference_file
)) {
57 LOG(ERROR
) << "Cannot find the reference file to be used for audio "
58 << "quality comparison: " << reference_file
.value();
64 void AddAudioFile(const std::string
& input_file_relative_url
,
65 content::WebContents
* tab_contents
) {
66 EXPECT_EQ("ok-added", ExecuteJavascript(
67 "addAudioFile('" + input_file_relative_url
+ "')", tab_contents
));
70 void PlayAudioFile(content::WebContents
* tab_contents
) {
71 EXPECT_EQ("ok-playing", ExecuteJavascript("playAudioFile()", tab_contents
));
74 void MixLocalStreamWithPreviouslyLoadedAudioFile(
75 content::WebContents
* tab_contents
) {
76 EXPECT_EQ("ok-mixed-in", ExecuteJavascript(
77 "mixLocalStreamWithPreviouslyLoadedAudioFile()", tab_contents
));
80 void EstablishCall(content::WebContents
* from_tab
,
81 content::WebContents
* to_tab
) {
82 EXPECT_EQ("ok-negotiating",
83 ExecuteJavascript("negotiateCall()", from_tab
));
85 // Ensure the call gets up on both sides.
86 EXPECT_TRUE(test::PollingWaitUntil("getPeerConnectionReadyState()",
88 EXPECT_TRUE(test::PollingWaitUntil("getPeerConnectionReadyState()",
93 // TODO(phoglund): enable when fully implemented.
94 IN_PROC_BROWSER_TEST_F(WebRtcTypingDetectionBrowserTest
,
95 DISABLED_MANUAL_TestTypingDetection
) {
96 // TODO(phoglund): make this use embedded_test_server when that test server
97 // can handle files > ~400Kb.
98 ASSERT_TRUE(test_server()->Start());
100 ui_test_utils::NavigateToURL(
101 browser(), test_server()->GetURL(kMainWebrtcTestHtmlPage
));
102 content::WebContents
* left_tab
=
103 browser()->tab_strip_model()->GetActiveWebContents();
105 chrome::AddTabAt(browser(), GURL(), -1, true);
106 content::WebContents
* right_tab
=
107 browser()->tab_strip_model()->GetActiveWebContents();
108 ui_test_utils::NavigateToURL(
109 browser(), test_server()->GetURL(kMainWebrtcTestHtmlPage
));
111 GetUserMediaWithSpecificConstraintsAndAccept(left_tab
,
112 kAudioOnlyCallConstraints
);
113 EXPECT_EQ("ok-peerconnection-created",
114 ExecuteJavascript("preparePeerConnection()", left_tab
));
116 AddAudioFile(kReferenceFileRelativeUrl
, left_tab
);
117 MixLocalStreamWithPreviouslyLoadedAudioFile(left_tab
);
119 SetupPeerconnectionWithLocalStream(left_tab
);
120 SetupPeerconnectionWithLocalStream(right_tab
);
122 NegotiateCall(left_tab
, right_tab
);
124 // Note: the media flow isn't necessarily established on the connection just
125 // because the ready state is ok on both sides. We sleep a bit between call
126 // establishment and playing to avoid cutting of the beginning of the audio
128 test::SleepInJavascript(left_tab
, 2000);
130 PlayAudioFile(left_tab
);
132 // TODO(phoglund): simulate key presses, look for changes in typing detection
134 test::SleepInJavascript(left_tab
, 10000);