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