media_uitest.cc revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1// Copyright (c) 2009 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/basictypes.h"
6#include "base/file_path.h"
7#include "base/platform_thread.h"
8#include "base/string_util.h"
9#include "chrome/test/ui/ui_layout_test.h"
10#include "chrome/test/ui/ui_test.h"
11#include "net/base/net_util.h"
12
13class MediaTest : public UITest {
14 protected:
15  void PlayMedia(const char* tag, const char* media_file) {
16    FilePath test_file(test_data_directory_);
17    test_file = test_file.AppendASCII("media/player.html");
18
19    GURL player_gurl = net::FilePathToFileURL(test_file);
20    std::string url = StringPrintf("%s?%s=%s",
21                                   player_gurl.spec().c_str(),
22                                   tag,
23                                   media_file);
24
25    NavigateToURL(GURL(url));
26
27    // Allow the media file to be loaded.
28    const std::wstring kPlaying = L"PLAYING";
29    const std::wstring kFailed = L"FAILED";
30    const std::wstring kError = L"ERROR";
31    for (int i = 0; i < 10; ++i) {
32      PlatformThread::Sleep(sleep_timeout_ms());
33      const std::wstring& title = GetActiveTabTitle();
34      if (title == kPlaying || title == kFailed ||
35          StartsWith(title, kError, true))
36        break;
37    }
38
39    EXPECT_EQ(kPlaying, GetActiveTabTitle());
40  }
41
42  void PlayAudio(const char* url) {
43    PlayMedia("audio", url);
44  }
45
46  void PlayVideo(const char* url) {
47    PlayMedia("video", url);
48  }
49};
50
51#if defined(OS_WIN)
52
53// Tests always fail on windows:  http://crbug.com/55477
54#define MAYBE_VideoBearTheora DISABLED_VideoBearTheora
55#define MAYBE_VideoBearSilentTheora DISABLED_VideoBearSilentTheora
56#define MAYBE_VideoBearWebm DISABLED_VideoBearWebm
57#define MAYBE_VideoBearSilentWebm DISABLED_VideoBearSilentWebm
58#define MAYBE_VideoBearMp4 DISABLED_VideoBearMp4
59#define MAYBE_VideoBearSilentMp4 DISABLED_VideoBearSilentMp4
60#define MAYBE_MediaUILayoutTest DISABLED_MediaUILayoutTest
61
62#else
63
64#define MAYBE_VideoBearTheora VideoBearTheora
65#define MAYBE_VideoBearSilentTheora VideoBearSilentTheora
66#define MAYBE_VideoBearWebm VideoBearWebm
67#define MAYBE_VideoBearSilentWebm VideoBearSilentWebm
68#define MAYBE_VideoBearMp4 VideoBearMp4
69#define MAYBE_VideoBearSilentMp4 VideoBearSilentMp4
70
71#if defined(OS_LINUX)
72// Test fails on linux: http://crbug.com/56364
73#define MAYBE_MediaUILayoutTest DISABLED_MediaUILayoutTest
74#else
75#define MAYBE_MediaUILayoutTest MediaUILayoutTest
76#endif
77
78#endif
79
80TEST_F(MediaTest, MAYBE_VideoBearTheora) {
81  PlayVideo("bear.ogv");
82}
83
84TEST_F(MediaTest, MAYBE_VideoBearSilentTheora) {
85  PlayVideo("bear_silent.ogv");
86}
87
88TEST_F(MediaTest, MAYBE_VideoBearWebm) {
89  PlayVideo("bear.webm");
90}
91
92TEST_F(MediaTest, MAYBE_VideoBearSilentWebm) {
93  PlayVideo("bear_silent.webm");
94}
95
96#if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
97TEST_F(MediaTest, MAYBE_VideoBearMp4) {
98  PlayVideo("bear.mp4");
99}
100
101TEST_F(MediaTest, MAYBE_VideoBearSilentMp4) {
102  PlayVideo("bear_silent.mp4");
103}
104#endif
105
106TEST_F(UILayoutTest, MAYBE_MediaUILayoutTest) {
107  static const char* kResources[] = {
108    "content",
109    "media-file.js",
110    "media-fullscreen.js",
111    "video-paint-test.js",
112    "video-played.js",
113    "video-test.js",
114  };
115
116  static const char* kMediaTests[] = {
117    "video-autoplay.html",
118    // "video-loop.html", disabled due to 52887.
119    "video-no-autoplay.html",
120    // TODO(sergeyu): Add more tests here.
121  };
122
123  FilePath test_dir;
124  FilePath media_test_dir;
125  media_test_dir = media_test_dir.AppendASCII("media");
126  InitializeForLayoutTest(test_dir, media_test_dir, kNoHttpPort);
127
128  // Copy resources first.
129  for (size_t i = 0; i < arraysize(kResources); ++i)
130    AddResourceForLayoutTest(
131        test_dir, media_test_dir.AppendASCII(kResources[i]));
132
133  for (size_t i = 0; i < arraysize(kMediaTests); ++i)
134    RunLayoutTest(kMediaTests[i], kNoHttpPort);
135}
136