diff options
-rw-r--r-- | chrome/browser/media_uitest.cc | 52 | ||||
-rw-r--r-- | chrome/chrome.gyp | 2 | ||||
-rw-r--r-- | chrome/test/data/media/bear.mp4 | bin | 0 -> 134641 bytes | |||
-rw-r--r-- | chrome/test/data/media/player.html | 46 |
4 files changed, 100 insertions, 0 deletions
diff --git a/chrome/browser/media_uitest.cc b/chrome/browser/media_uitest.cc new file mode 100644 index 0000000..faa8d15 --- /dev/null +++ b/chrome/browser/media_uitest.cc @@ -0,0 +1,52 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/basictypes.h" +#include "base/file_path.h" +#include "base/platform_thread.h" +#include "base/string_util.h" +#include "chrome/test/ui/ui_test.h" +#include "net/base/net_util.h" + +class MediaTest : public UITest { + protected: + void PlayMedia(const char* tag, const char* media_file) { + FilePath test_file(test_data_directory_); + test_file = test_file.AppendASCII("/media/player.html"); + + GURL player_gurl = net::FilePathToFileURL(test_file); + std::string url = StringPrintf("%s?%s=%s", + player_gurl.spec().c_str(), + tag, + media_file); + + NavigateToURL(GURL(url)); + + // Allow the media file to be loaded. + const std::wstring kPlaying = L"PLAYING"; + const std::wstring kFailed = L"FAILED"; + const std::wstring kError = L"ERROR"; + for (int i = 0; i < 10; ++i) { + PlatformThread::Sleep(sleep_timeout_ms()); + const std::wstring& title = GetActiveTabTitle(); + if (title == kPlaying || title == kFailed || + StartsWith(title, kError, true)) + break; + } + + EXPECT_EQ(kPlaying, GetActiveTabTitle()); + } + + void PlayAudio(const char* url) { + PlayMedia("audio", url); + } + + void PlayVideo(const char* url) { + PlayMedia("video", url); + } +}; + +TEST_F(MediaTest, VideoBearH264) { + PlayVideo("bear.mp4"); +} diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index ef48b56..a407299 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -3098,6 +3098,7 @@ 'browser/images_uitest.cc', 'browser/locale_tests_uitest.cc', 'browser/login_prompt_uitest.cc', + 'browser/media_uitest.cc', 'browser/metrics/metrics_service_uitest.cc', 'browser/printing/printing_layout_uitest.cc', 'browser/printing/printing_test.h', @@ -3210,6 +3211,7 @@ 'sources!': [ # TODO(port)? (Most of these include windows.h or similar.) 'browser/extensions/extension_uitest.cc', + 'browser/media_uitest.cc', 'browser/printing/printing_layout_uitest.cc', 'browser/ssl/ssl_uitest.cc', 'browser/views/find_bar_win_uitest.cc', diff --git a/chrome/test/data/media/bear.mp4 b/chrome/test/data/media/bear.mp4 Binary files differnew file mode 100644 index 0000000..f0b4707 --- /dev/null +++ b/chrome/test/data/media/bear.mp4 diff --git a/chrome/test/data/media/player.html b/chrome/test/data/media/player.html new file mode 100644 index 0000000..3b8fd9b --- /dev/null +++ b/chrome/test/data/media/player.html @@ -0,0 +1,46 @@ +<html> +<body> +<div id="player_container"></div> +<script> +var player = null; +function InstallEventHandler(event, action) { + player.addEventListener(event, function(e) { + eval(action); + }, false); +} + +// Parse the location and load the media file accordingly. +var url = window.location.href; +var url_parts = url.split('?'); + +// Make sure the URL is of the form "player.html?query". +var ok = false; +if (url_parts.length > 1) { + var query = url_parts[1]; + var query_parts = query.split('='); + if (query_parts.length == 2) { + var tag = query_parts[0]; + var media_url = query_parts[1]; + if (tag == 'audio' || tag == 'video') { + ok = true; + var container = document.getElementById('player_container'); + container.innerHTML = '<' + tag + ' controls id="player"></' + tag + '>'; + player = document.getElementById('player'); + + // Install event handlers. + InstallEventHandler('error', + 'document.title = "ERROR = " + player.error.code'); + InstallEventHandler('playing', 'document.title = "PLAYING"'); + + // Starts the player. + player.src = media_url; + player.play(); + } + } +} +if (!ok) { + document.title = 'FAILED'; +} +</script> +</body> +</html> |