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 "chrome/browser/media/media_browsertest.h"
7 #include "base/path_service.h"
8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/common/chrome_paths.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/public/test/browser_test_utils.h"
16 // Common test results.
17 const char MediaBrowserTest::kEnded
[] = "ENDED";
18 const char MediaBrowserTest::kError
[] = "ERROR";
19 const char MediaBrowserTest::kFailed
[] = "FAILED";
21 MediaBrowserTest::MediaBrowserTest() {
24 MediaBrowserTest::~MediaBrowserTest() {
27 void MediaBrowserTest::RunMediaTestPage(
28 const char* html_page
, std::vector
<StringPair
>* query_params
,
29 const char* expected_title
, bool http
) {
31 std::string query
= "";
32 if (query_params
!= NULL
&& !query_params
->empty()) {
33 std::vector
<StringPair
>::const_iterator itr
= query_params
->begin();
34 query
= base::StringPrintf("%s=%s", itr
->first
, itr
->second
);
36 for (; itr
!= query_params
->end(); ++itr
) {
37 query
.append(base::StringPrintf("&%s=%s", itr
->first
, itr
->second
));
41 ASSERT_TRUE(test_server()->Start());
42 gurl
= test_server()->GetURL(
43 base::StringPrintf("files/media/%s?%s", html_page
, query
.c_str()));
45 base::FilePath test_file_path
;
46 PathService::Get(chrome::DIR_TEST_DATA
, &test_file_path
);
47 test_file_path
= test_file_path
.AppendASCII("media")
48 .AppendASCII(html_page
);
49 gurl
= content::GetFileUrlWithQuery(test_file_path
, query
);
52 base::string16 final_title
= RunTest(gurl
, expected_title
);
53 EXPECT_EQ(base::ASCIIToUTF16(expected_title
), final_title
);
56 base::string16
MediaBrowserTest::RunTest(const GURL
& gurl
,
57 const char* expected_title
) {
58 DVLOG(1) << "Running test URL: " << gurl
;
59 content::TitleWatcher
title_watcher(
60 browser()->tab_strip_model()->GetActiveWebContents(),
61 base::ASCIIToUTF16(expected_title
));
62 AddWaitForTitles(&title_watcher
);
63 ui_test_utils::NavigateToURL(browser(), gurl
);
65 return title_watcher
.WaitAndGetTitle();
68 void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher
* title_watcher
) {
69 title_watcher
->AlsoWaitForTitle(base::ASCIIToUTF16(kEnded
));
70 title_watcher
->AlsoWaitForTitle(base::ASCIIToUTF16(kError
));
71 title_watcher
->AlsoWaitForTitle(base::ASCIIToUTF16(kFailed
));