| 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" |
| 8 #include "base/strings/stringprintf.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 9 #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" |
| 10 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
| 11 #include "content/public/browser/navigation_controller.h" | 14 #include "content/public/browser/navigation_controller.h" |
| 12 #include "content/public/browser/navigation_entry.h" | 15 #include "content/public/browser/navigation_entry.h" |
| 13 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
| 15 | 18 |
| 16 // Common test results. | 19 // Common test results. |
| 17 const char MediaBrowserTest::kEnded[] = "ENDED"; | 20 const char MediaBrowserTest::kEnded[] = "ENDED"; |
| 18 const char MediaBrowserTest::kError[] = "ERROR"; | 21 const char MediaBrowserTest::kError[] = "ERROR"; |
| 19 const char MediaBrowserTest::kFailed[] = "FAILED"; | 22 const char MediaBrowserTest::kFailed[] = "FAILED"; |
| 20 const char MediaBrowserTest::kPluginCrashed[] = "PLUGIN_CRASHED"; | 23 const char MediaBrowserTest::kPluginCrashed[] = "PLUGIN_CRASHED"; |
| 21 | 24 |
| 22 MediaBrowserTest::MediaBrowserTest() : ignore_plugin_crash_(false) { | 25 MediaBrowserTest::MediaBrowserTest() : ignore_plugin_crash_(false) { |
| 23 } | 26 } |
| 24 | 27 |
| 25 MediaBrowserTest::~MediaBrowserTest() { | 28 MediaBrowserTest::~MediaBrowserTest() { |
| 26 } | 29 } |
| 27 | 30 |
| 28 void MediaBrowserTest::RunMediaTestPage(const std::string& html_page, | 31 void MediaBrowserTest::RunMediaTestPage( |
| 29 const media::QueryParams& query_params, | 32 const std::string& html_page, std::vector<StringPair>* query_params, |
| 30 const std::string& expected_title, | 33 const std::string& expected_title, bool http) { |
| 31 bool http) { | |
| 32 GURL gurl; | 34 GURL gurl; |
| 33 std::string query = media::GetURLQueryString(query_params); | 35 std::string query = ""; |
| 34 scoped_ptr<net::SpawnedTestServer> http_test_server; | 36 if (query_params != NULL && !query_params->empty()) { |
| 37 std::vector<StringPair>::const_iterator itr = query_params->begin(); |
| 38 query = itr->first + "=" + itr->second; |
| 39 ++itr; |
| 40 for (; itr != query_params->end(); ++itr) { |
| 41 query.append("&" + itr->first + "=" + itr->second); |
| 42 } |
| 43 } |
| 35 if (http) { | 44 if (http) { |
| 36 http_test_server = media::StartMediaHttpTestServer(); | 45 ASSERT_TRUE(test_server()->Start()); |
| 37 gurl = http_test_server->GetURL("files/" + html_page + "?" + query); | 46 gurl = test_server()->GetURL("files/media/" + html_page + "?" + query); |
| 38 } else { | 47 } else { |
| 39 gurl = content::GetFileUrlWithQuery(media::GetTestDataFilePath(html_page), | 48 base::FilePath test_file_path; |
| 40 query); | 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); |
| 41 } | 53 } |
| 42 std::string final_title = RunTest(gurl, expected_title); | 54 |
| 43 EXPECT_EQ(expected_title, final_title); | 55 base::string16 final_title = RunTest(gurl, expected_title); |
| 56 EXPECT_EQ(base::ASCIIToUTF16(expected_title), final_title); |
| 44 } | 57 } |
| 45 | 58 |
| 46 std::string MediaBrowserTest::RunTest(const GURL& gurl, | 59 base::string16 MediaBrowserTest::RunTest(const GURL& gurl, |
| 47 const std::string& expected_title) { | 60 const std::string& expected_title) { |
| 48 DVLOG(0) << "Running test URL: " << gurl; | 61 VLOG(0) << "Running test URL: " << gurl; |
| 49 // Observe the web contents for plugin crashes. | 62 // Observe the web contents for plugin crashes. |
| 50 Observe(browser()->tab_strip_model()->GetActiveWebContents()); | 63 Observe(browser()->tab_strip_model()->GetActiveWebContents()); |
| 51 content::TitleWatcher title_watcher( | 64 content::TitleWatcher title_watcher( |
| 52 browser()->tab_strip_model()->GetActiveWebContents(), | 65 browser()->tab_strip_model()->GetActiveWebContents(), |
| 53 base::ASCIIToUTF16(expected_title)); | 66 base::ASCIIToUTF16(expected_title)); |
| 54 AddWaitForTitles(&title_watcher); | 67 AddWaitForTitles(&title_watcher); |
| 55 ui_test_utils::NavigateToURL(browser(), gurl); | 68 ui_test_utils::NavigateToURL(browser(), gurl); |
| 56 base::string16 result = title_watcher.WaitAndGetTitle(); | 69 |
| 57 return base::UTF16ToASCII(result); | 70 return title_watcher.WaitAndGetTitle(); |
| 58 } | 71 } |
| 59 | 72 |
| 60 void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher* title_watcher) { | 73 void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher* title_watcher) { |
| 61 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEnded)); | 74 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEnded)); |
| 62 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kError)); | 75 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kError)); |
| 63 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kFailed)); | 76 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kFailed)); |
| 64 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kPluginCrashed)); | 77 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kPluginCrashed)); |
| 65 } | 78 } |
| 66 | 79 |
| 67 void MediaBrowserTest::PluginCrashed(const base::FilePath& plugin_path, | 80 void MediaBrowserTest::PluginCrashed(const base::FilePath& plugin_path, |
| 68 base::ProcessId plugin_pid) { | 81 base::ProcessId plugin_pid) { |
| 69 VLOG(0) << "Plugin crashed: " << plugin_path.value(); | 82 VLOG(0) << "Plugin crashed: " << plugin_path.value(); |
| 70 if (ignore_plugin_crash_) | 83 if (ignore_plugin_crash_) |
| 71 return; | 84 return; |
| 72 // Update document title to quit TitleWatcher early. | 85 // Update document title to quit TitleWatcher early. |
| 73 web_contents()->GetController().GetActiveEntry() | 86 web_contents()->GetController().GetActiveEntry() |
| 74 ->SetTitle(base::ASCIIToUTF16(kPluginCrashed)); | 87 ->SetTitle(base::ASCIIToUTF16(kPluginCrashed)); |
| 75 ADD_FAILURE() << "Failing test due to plugin crash."; | 88 ADD_FAILURE() << "Failing test due to plugin crash."; |
| 76 } | 89 } |
| 77 | 90 |
| 78 void MediaBrowserTest::IgnorePluginCrash() { | 91 void MediaBrowserTest::IgnorePluginCrash() { |
| 79 ignore_plugin_crash_ = true; | 92 ignore_plugin_crash_ = true; |
| 80 } | 93 } |
| 81 | 94 |
| OLD | NEW |