[safe-browsing] Database full hash matches like prefix match.
[chromium-blink-merge.git] / chrome / browser / media / chrome_webrtc_typing_detection_browsertest.cc
blob26d4c8704ee17727001a52c6029e685aa447f162
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.
5 #include <ctime>
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[] =
22 #if defined (OS_WIN)
23 FILE_PATH_LITERAL("pyauto_private/webrtc/human-voice-win.wav");
24 #else
25 FILE_PATH_LITERAL("pyauto_private/webrtc/human-voice-linux.wav");
26 #endif
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[] =
31 #if defined (OS_WIN)
32 "../pyauto_private/webrtc/human-voice-win.wav";
33 #else
34 "../pyauto_private/webrtc/human-voice-linux.wav";
35 #endif
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);
43 return 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 {
50 public:
51 // TODO(phoglund): clean up duplication from audio quality browser test when
52 // this test is complete and is proven to work.
53 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
54 test::PeerConnectionServerRunner::KillAllPeerConnectionServers();
57 bool HasAllRequiredResources() {
58 base::FilePath reference_file =
59 GetTestDataDir().Append(kReferenceFile);
60 if (!base::PathExists(reference_file)) {
61 LOG(ERROR) << "Cannot find the reference file to be used for audio "
62 << "quality comparison: " << reference_file.value();
63 return false;
65 return true;
68 void AddAudioFile(const std::string& input_file_relative_url,
69 content::WebContents* tab_contents) {
70 EXPECT_EQ("ok-added", ExecuteJavascript(
71 "addAudioFile('" + input_file_relative_url + "')", tab_contents));
74 void PlayAudioFile(content::WebContents* tab_contents) {
75 EXPECT_EQ("ok-playing", ExecuteJavascript("playAudioFile()", tab_contents));
78 void MixLocalStreamWithPreviouslyLoadedAudioFile(
79 content::WebContents* tab_contents) {
80 EXPECT_EQ("ok-mixed-in", ExecuteJavascript(
81 "mixLocalStreamWithPreviouslyLoadedAudioFile()", tab_contents));
84 void EstablishCall(content::WebContents* from_tab,
85 content::WebContents* to_tab) {
86 EXPECT_EQ("ok-negotiating",
87 ExecuteJavascript("negotiateCall()", from_tab));
89 // Ensure the call gets up on both sides.
90 EXPECT_TRUE(test::PollingWaitUntil("getPeerConnectionReadyState()",
91 "active", from_tab));
92 EXPECT_TRUE(test::PollingWaitUntil("getPeerConnectionReadyState()",
93 "active", to_tab));
96 test::PeerConnectionServerRunner peerconnection_server_;
99 // TODO(phoglund): enable when fully implemented.
100 IN_PROC_BROWSER_TEST_F(WebRtcTypingDetectionBrowserTest,
101 DISABLED_MANUAL_TestTypingDetection) {
102 // TODO(phoglund): make this use embedded_test_server when that test server
103 // can handle files > ~400Kb.
104 ASSERT_TRUE(test_server()->Start());
105 ASSERT_TRUE(peerconnection_server_.Start());
107 ui_test_utils::NavigateToURL(
108 browser(), test_server()->GetURL(kMainWebrtcTestHtmlPage));
109 content::WebContents* left_tab =
110 browser()->tab_strip_model()->GetActiveWebContents();
112 chrome::AddTabAt(browser(), GURL(), -1, true);
113 content::WebContents* right_tab =
114 browser()->tab_strip_model()->GetActiveWebContents();
115 ui_test_utils::NavigateToURL(
116 browser(), test_server()->GetURL(kMainWebrtcTestHtmlPage));
118 ConnectToPeerConnectionServer("peer 1", left_tab);
119 ConnectToPeerConnectionServer("peer 2", right_tab);
121 GetUserMediaWithSpecificConstraintsAndAccept(left_tab,
122 kAudioOnlyCallConstraints);
123 EXPECT_EQ("ok-peerconnection-created",
124 ExecuteJavascript("preparePeerConnection()", left_tab));
126 AddAudioFile(kReferenceFileRelativeUrl, left_tab);
127 MixLocalStreamWithPreviouslyLoadedAudioFile(left_tab);
129 EstablishCall(left_tab, right_tab);
131 // Note: the media flow isn't necessarily established on the connection just
132 // because the ready state is ok on both sides. We sleep a bit between call
133 // establishment and playing to avoid cutting of the beginning of the audio
134 // file.
135 test::SleepInJavascript(left_tab, 2000);
137 PlayAudioFile(left_tab);
139 // TODO(phoglund): simulate key presses, look for changes in typing detection
140 // state.
141 test::SleepInJavascript(left_tab, 10000);
143 HangUp(left_tab);
144 WaitUntilHangupVerified(left_tab);
145 WaitUntilHangupVerified(right_tab);
147 ASSERT_TRUE(peerconnection_server_.Stop());