Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / content / browser / media / webrtc_aecdump_browsertest.cc
1 // Copyright (c) 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.
4
5 #include "base/command_line.h"
6 #include "base/file_util.h"
7 #include "base/json/json_reader.h"
8 #include "base/platform_file.h"
9 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "base/test/trace_event_analyzer.h"
12 #include "content/public/common/content_switches.h"
13 #include "content/public/test/browser_test_utils.h"
14 #include "content/public/test/content_browser_test_utils.h"
15 #include "content/shell/browser/shell.h"
16 #include "content/test/webrtc_content_browsertest_base.h"
17 #include "net/test/embedded_test_server/embedded_test_server.h"
18
19 namespace content {
20
21 // This tests AEC dump enabled using the command line flag. It does not test AEC
22 // dump enabled using webrtc-internals (that's tested in webrtc_browsertest.cc).
23 class WebRtcAecDumpBrowserTest : public WebRtcContentBrowserTest,
24                                  public testing::WithParamInterface<bool> {
25  public:
26   WebRtcAecDumpBrowserTest() {}
27   virtual ~WebRtcAecDumpBrowserTest() {}
28
29   virtual void SetUp() OVERRIDE {
30     // Find a safe place to write the dump to.
31     ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
32     ASSERT_TRUE(CreateTemporaryFileInDir(temp_dir_.path(), &dump_file_));
33
34     EnablePixelOutput();
35     ContentBrowserTest::SetUp();
36   }
37
38   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
39     WebRtcContentBrowserTest::SetUpCommandLine(command_line);
40
41     // Enable AEC dump with the command line flag.
42     command_line->AppendSwitchPath(switches::kEnableWebRtcAecRecordings,
43                                    dump_file_);
44
45     bool enable_audio_track_processing = GetParam();
46     if (enable_audio_track_processing)
47       command_line->AppendSwitch(switches::kEnableAudioTrackProcessing);
48   }
49
50  protected:
51   base::ScopedTempDir temp_dir_;
52   base::FilePath dump_file_;
53
54  private:
55   DISALLOW_COPY_AND_ASSIGN(WebRtcAecDumpBrowserTest);
56 };
57
58 static const bool kRunTestsWithFlag[] = { false, true };
59 INSTANTIATE_TEST_CASE_P(WebRtcAecDumpBrowserTests,
60                         WebRtcAecDumpBrowserTest,
61                         testing::ValuesIn(kRunTestsWithFlag));
62
63 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
64 // Timing out on ARM linux bot: http://crbug.com/238490
65 #define MAYBE_CallWithAecDump DISABLED_CallWithAecDump
66 #else
67 #define MAYBE_CallWithAecDump CallWithAecDump
68 #endif
69
70 // This tests will make a complete PeerConnection-based call, verify that
71 // video is playing for the call, and verify that a non-empty AEC dump file
72 // exists.
73 IN_PROC_BROWSER_TEST_P(WebRtcAecDumpBrowserTest, MAYBE_CallWithAecDump) {
74   ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
75
76   GURL url(embedded_test_server()->GetURL("/media/peerconnection-call.html"));
77   NavigateToURL(shell(), url);
78
79 #if defined (OS_ANDROID)
80   // Always force iSAC 16K on Android for now (Opus is broken).
81   EXPECT_EQ("isac-forced",
82             ExecuteJavascriptAndReturnResult("forceIsac16KInSdp();"));
83 #endif
84
85   ExecuteJavascriptAndWaitForOk("call({video: true, audio: true});");
86
87   EXPECT_TRUE(base::PathExists(dump_file_));
88   int64 file_size = 0;
89   EXPECT_TRUE(base::GetFileSize(dump_file_, &file_size));
90   EXPECT_GT(file_size, 0);
91 }
92
93 }  // namespace content