OLD | NEW |
---|---|
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" | 7 #include "base/path_service.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
12 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
13 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
14 #include "content/public/browser/navigation_controller.h" | 14 #include "content/public/browser/navigation_controller.h" |
15 #include "content/public/browser/navigation_entry.h" | 15 #include "content/public/browser/navigation_entry.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
18 #include "media/base/test_data_util.h" | |
18 | 19 |
19 // Common test results. | 20 // Common test results. |
20 const char MediaBrowserTest::kEnded[] = "ENDED"; | 21 const char MediaBrowserTest::kEnded[] = "ENDED"; |
21 const char MediaBrowserTest::kError[] = "ERROR"; | 22 const char MediaBrowserTest::kError[] = "ERROR"; |
22 const char MediaBrowserTest::kFailed[] = "FAILED"; | 23 const char MediaBrowserTest::kFailed[] = "FAILED"; |
23 const char MediaBrowserTest::kPluginCrashed[] = "PLUGIN_CRASHED"; | 24 const char MediaBrowserTest::kPluginCrashed[] = "PLUGIN_CRASHED"; |
24 | 25 |
25 MediaBrowserTest::MediaBrowserTest() : ignore_plugin_crash_(false) { | 26 MediaBrowserTest::MediaBrowserTest() : ignore_plugin_crash_(false) { |
26 } | 27 } |
27 | 28 |
28 MediaBrowserTest::~MediaBrowserTest() { | 29 MediaBrowserTest::~MediaBrowserTest() { |
29 } | 30 } |
30 | 31 |
31 void MediaBrowserTest::RunMediaTestPage( | 32 void MediaBrowserTest::RunMediaTestPage( |
32 const std::string& html_page, std::vector<StringPair>* query_params, | 33 const std::string& html_page, |
33 const std::string& expected_title, bool http) { | 34 std::vector<StringPair>* query_params, |
35 const std::string& expected_title, | |
36 bool http) { | |
34 GURL gurl; | 37 GURL gurl; |
35 std::string query = ""; | 38 std::string query = ""; |
36 if (query_params != NULL && !query_params->empty()) { | 39 if (query_params != NULL && !query_params->empty()) { |
37 std::vector<StringPair>::const_iterator itr = query_params->begin(); | 40 std::vector<StringPair>::const_iterator itr = query_params->begin(); |
38 query = itr->first + "=" + itr->second; | 41 query = itr->first + "=" + itr->second; |
39 ++itr; | 42 ++itr; |
40 for (; itr != query_params->end(); ++itr) { | 43 for (; itr != query_params->end(); ++itr) { |
41 query.append("&" + itr->first + "=" + itr->second); | 44 query.append("&" + itr->first + "=" + itr->second); |
42 } | 45 } |
43 } | 46 } |
47 scoped_ptr<net::SpawnedTestServer> http_test_server_; | |
44 if (http) { | 48 if (http) { |
45 ASSERT_TRUE(test_server()->Start()); | 49 http_test_server_.reset(new net::SpawnedTestServer( |
46 gurl = test_server()->GetURL("files/media/" + html_page + "?" + query); | 50 net::SpawnedTestServer::TYPE_HTTP, |
51 net::SpawnedTestServer::kLocalhost, | |
52 media::GetTestDataPath())); | |
53 ASSERT_TRUE(http_test_server_.get()->Start()); | |
jrummell
2014/07/02 00:33:40
nit: you don't need .get() here and next line.
shadi
2014/07/02 19:23:36
Done.
| |
54 gurl = http_test_server_.get()->GetURL("files/" + html_page + "?" + query); | |
47 } else { | 55 } else { |
48 base::FilePath test_file_path; | 56 gurl = content::GetFileUrlWithQuery(media::GetTestDataFilePath(html_page), |
49 PathService::Get(chrome::DIR_TEST_DATA, &test_file_path); | 57 query); |
50 test_file_path = test_file_path.AppendASCII("media") | |
51 .AppendASCII(html_page); | |
52 gurl = content::GetFileUrlWithQuery(test_file_path, query); | |
53 } | 58 } |
54 | |
55 base::string16 final_title = RunTest(gurl, expected_title); | 59 base::string16 final_title = RunTest(gurl, expected_title); |
56 EXPECT_EQ(base::ASCIIToUTF16(expected_title), final_title); | 60 EXPECT_EQ(base::ASCIIToUTF16(expected_title), final_title); |
57 } | 61 } |
58 | 62 |
59 base::string16 MediaBrowserTest::RunTest(const GURL& gurl, | 63 base::string16 MediaBrowserTest::RunTest(const GURL& gurl, |
60 const std::string& expected_title) { | 64 const std::string& expected_title) { |
61 VLOG(0) << "Running test URL: " << gurl; | 65 DVLOG(0) << "Running test URL: " << gurl; |
62 // Observe the web contents for plugin crashes. | 66 // Observe the web contents for plugin crashes. |
63 Observe(browser()->tab_strip_model()->GetActiveWebContents()); | 67 Observe(browser()->tab_strip_model()->GetActiveWebContents()); |
64 content::TitleWatcher title_watcher( | 68 content::TitleWatcher title_watcher( |
65 browser()->tab_strip_model()->GetActiveWebContents(), | 69 browser()->tab_strip_model()->GetActiveWebContents(), |
66 base::ASCIIToUTF16(expected_title)); | 70 base::ASCIIToUTF16(expected_title)); |
67 AddWaitForTitles(&title_watcher); | 71 AddWaitForTitles(&title_watcher); |
68 ui_test_utils::NavigateToURL(browser(), gurl); | 72 ui_test_utils::NavigateToURL(browser(), gurl); |
69 | 73 |
70 return title_watcher.WaitAndGetTitle(); | 74 return title_watcher.WaitAndGetTitle(); |
71 } | 75 } |
(...skipping 13 matching lines...) Expand all Loading... | |
85 // Update document title to quit TitleWatcher early. | 89 // Update document title to quit TitleWatcher early. |
86 web_contents()->GetController().GetActiveEntry() | 90 web_contents()->GetController().GetActiveEntry() |
87 ->SetTitle(base::ASCIIToUTF16(kPluginCrashed)); | 91 ->SetTitle(base::ASCIIToUTF16(kPluginCrashed)); |
88 ADD_FAILURE() << "Failing test due to plugin crash."; | 92 ADD_FAILURE() << "Failing test due to plugin crash."; |
89 } | 93 } |
90 | 94 |
91 void MediaBrowserTest::IgnorePluginCrash() { | 95 void MediaBrowserTest::IgnorePluginCrash() { |
92 ignore_plugin_crash_ = true; | 96 ignore_plugin_crash_ = true; |
93 } | 97 } |
94 | 98 |
OLD | NEW |