Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: chrome/browser/media/media_browsertest.cc

Issue 408993002: Have media content and chrome browser tests load data from media/test/data (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/media/media_browsertest.h ('k') | chrome/test/data/media/eme_player.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/media/media_browsertest.h" 5 #include "chrome/browser/media/media_browsertest.h"
6 6
7 #include "base/path_service.h"
8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 9 #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" 10 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/public/browser/navigation_controller.h" 11 #include "content/public/browser/navigation_controller.h"
15 #include "content/public/browser/navigation_entry.h" 12 #include "content/public/browser/navigation_entry.h"
16 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
17 #include "content/public/test/browser_test_utils.h" 14 #include "content/public/test/browser_test_utils.h"
18 15
19 // Common test results. 16 // Common test results.
20 const char MediaBrowserTest::kEnded[] = "ENDED"; 17 const char MediaBrowserTest::kEnded[] = "ENDED";
21 const char MediaBrowserTest::kError[] = "ERROR"; 18 const char MediaBrowserTest::kError[] = "ERROR";
22 const char MediaBrowserTest::kFailed[] = "FAILED"; 19 const char MediaBrowserTest::kFailed[] = "FAILED";
23 const char MediaBrowserTest::kPluginCrashed[] = "PLUGIN_CRASHED"; 20 const char MediaBrowserTest::kPluginCrashed[] = "PLUGIN_CRASHED";
24 21
25 MediaBrowserTest::MediaBrowserTest() : ignore_plugin_crash_(false) { 22 MediaBrowserTest::MediaBrowserTest() : ignore_plugin_crash_(false) {
26 } 23 }
27 24
28 MediaBrowserTest::~MediaBrowserTest() { 25 MediaBrowserTest::~MediaBrowserTest() {
29 } 26 }
30 27
31 void MediaBrowserTest::RunMediaTestPage( 28 void MediaBrowserTest::RunMediaTestPage(const std::string& html_page,
32 const std::string& html_page, std::vector<StringPair>* query_params, 29 const media::QueryParams& query_params,
33 const std::string& expected_title, bool http) { 30 const std::string& expected_title,
31 bool http) {
34 GURL gurl; 32 GURL gurl;
35 std::string query = ""; 33 std::string query = media::GetURLQueryString(query_params);
36 if (query_params != NULL && !query_params->empty()) { 34 scoped_ptr<net::SpawnedTestServer> http_test_server;
37 std::vector<StringPair>::const_iterator itr = query_params->begin(); 35 if (http) {
38 query = itr->first + "=" + itr->second; 36 http_test_server = media::StartMediaHttpTestServer();
39 ++itr; 37 gurl = http_test_server->GetURL("files/" + html_page + "?" + query);
40 for (; itr != query_params->end(); ++itr) { 38 } else {
41 query.append("&" + itr->first + "=" + itr->second); 39 gurl = content::GetFileUrlWithQuery(media::GetTestDataFilePath(html_page),
42 } 40 query);
43 } 41 }
44 if (http) { 42 std::string final_title = RunTest(gurl, expected_title);
45 ASSERT_TRUE(test_server()->Start()); 43 EXPECT_EQ(expected_title, final_title);
46 gurl = test_server()->GetURL("files/media/" + html_page + "?" + query);
47 } else {
48 base::FilePath test_file_path;
49 PathService::Get(chrome::DIR_TEST_DATA, &test_file_path);
50 test_file_path = test_file_path.AppendASCII("media")
51 .AppendASCII(html_page);
52 gurl = content::GetFileUrlWithQuery(test_file_path, query);
53 }
54
55 base::string16 final_title = RunTest(gurl, expected_title);
56 EXPECT_EQ(base::ASCIIToUTF16(expected_title), final_title);
57 } 44 }
58 45
59 base::string16 MediaBrowserTest::RunTest(const GURL& gurl, 46 std::string MediaBrowserTest::RunTest(const GURL& gurl,
60 const std::string& expected_title) { 47 const std::string& expected_title) {
61 VLOG(0) << "Running test URL: " << gurl; 48 DVLOG(0) << "Running test URL: " << gurl;
62 // Observe the web contents for plugin crashes. 49 // Observe the web contents for plugin crashes.
63 Observe(browser()->tab_strip_model()->GetActiveWebContents()); 50 Observe(browser()->tab_strip_model()->GetActiveWebContents());
64 content::TitleWatcher title_watcher( 51 content::TitleWatcher title_watcher(
65 browser()->tab_strip_model()->GetActiveWebContents(), 52 browser()->tab_strip_model()->GetActiveWebContents(),
66 base::ASCIIToUTF16(expected_title)); 53 base::ASCIIToUTF16(expected_title));
67 AddWaitForTitles(&title_watcher); 54 AddWaitForTitles(&title_watcher);
68 ui_test_utils::NavigateToURL(browser(), gurl); 55 ui_test_utils::NavigateToURL(browser(), gurl);
69 56 base::string16 result = title_watcher.WaitAndGetTitle();
70 return title_watcher.WaitAndGetTitle(); 57 return base::UTF16ToASCII(result);
71 } 58 }
72 59
73 void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher* title_watcher) { 60 void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher* title_watcher) {
74 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEnded)); 61 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEnded));
75 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kError)); 62 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kError));
76 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kFailed)); 63 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kFailed));
77 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kPluginCrashed)); 64 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kPluginCrashed));
78 } 65 }
79 66
80 void MediaBrowserTest::PluginCrashed(const base::FilePath& plugin_path, 67 void MediaBrowserTest::PluginCrashed(const base::FilePath& plugin_path,
81 base::ProcessId plugin_pid) { 68 base::ProcessId plugin_pid) {
82 VLOG(0) << "Plugin crashed: " << plugin_path.value(); 69 VLOG(0) << "Plugin crashed: " << plugin_path.value();
83 if (ignore_plugin_crash_) 70 if (ignore_plugin_crash_)
84 return; 71 return;
85 // Update document title to quit TitleWatcher early. 72 // Update document title to quit TitleWatcher early.
86 web_contents()->GetController().GetActiveEntry() 73 web_contents()->GetController().GetActiveEntry()
87 ->SetTitle(base::ASCIIToUTF16(kPluginCrashed)); 74 ->SetTitle(base::ASCIIToUTF16(kPluginCrashed));
88 ADD_FAILURE() << "Failing test due to plugin crash."; 75 ADD_FAILURE() << "Failing test due to plugin crash.";
89 } 76 }
90 77
91 void MediaBrowserTest::IgnorePluginCrash() { 78 void MediaBrowserTest::IgnorePluginCrash() {
92 ignore_plugin_crash_ = true; 79 ignore_plugin_crash_ = true;
93 } 80 }
94 81
OLDNEW
« no previous file with comments | « chrome/browser/media/media_browsertest.h ('k') | chrome/test/data/media/eme_player.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698