Chromium Code Reviews| 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" | |
| 15 #include "content/public/browser/navigation_entry.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"; |
| 23 const char MediaBrowserTest::kPluginCrashed[] = "PLUGIN_CRASHED"; | |
| 20 | 24 |
| 21 MediaBrowserTest::MediaBrowserTest() { | 25 MediaBrowserTest::MediaBrowserTest() : ignore_plugin_crash_(false) { |
| 22 } | 26 } |
| 23 | 27 |
| 24 MediaBrowserTest::~MediaBrowserTest() { | 28 MediaBrowserTest::~MediaBrowserTest() { |
| 25 } | 29 } |
| 26 | 30 |
| 27 void MediaBrowserTest::RunMediaTestPage( | 31 void MediaBrowserTest::RunMediaTestPage( |
| 28 const std::string& html_page, std::vector<StringPair>* query_params, | 32 const std::string& html_page, std::vector<StringPair>* query_params, |
| 29 const std::string& expected_title, bool http) { | 33 const std::string& expected_title, bool http) { |
| 30 GURL gurl; | 34 GURL gurl; |
| 31 std::string query = ""; | 35 std::string query = ""; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 48 gurl = content::GetFileUrlWithQuery(test_file_path, query); | 52 gurl = content::GetFileUrlWithQuery(test_file_path, query); |
| 49 } | 53 } |
| 50 | 54 |
| 51 base::string16 final_title = RunTest(gurl, expected_title); | 55 base::string16 final_title = RunTest(gurl, expected_title); |
| 52 EXPECT_EQ(base::ASCIIToUTF16(expected_title), final_title); | 56 EXPECT_EQ(base::ASCIIToUTF16(expected_title), final_title); |
| 53 } | 57 } |
| 54 | 58 |
| 55 base::string16 MediaBrowserTest::RunTest(const GURL& gurl, | 59 base::string16 MediaBrowserTest::RunTest(const GURL& gurl, |
| 56 const std::string& expected_title) { | 60 const std::string& expected_title) { |
| 57 DVLOG(1) << "Running test URL: " << gurl; | 61 DVLOG(1) << "Running test URL: " << gurl; |
| 62 // Observe the web contents for plugin crashes. | |
| 63 Observe(browser()->tab_strip_model()->GetActiveWebContents()); | |
| 58 content::TitleWatcher title_watcher( | 64 content::TitleWatcher title_watcher( |
| 59 browser()->tab_strip_model()->GetActiveWebContents(), | 65 browser()->tab_strip_model()->GetActiveWebContents(), |
| 60 base::ASCIIToUTF16(expected_title)); | 66 base::ASCIIToUTF16(expected_title)); |
| 61 AddWaitForTitles(&title_watcher); | 67 AddWaitForTitles(&title_watcher); |
| 62 ui_test_utils::NavigateToURL(browser(), gurl); | 68 ui_test_utils::NavigateToURL(browser(), gurl); |
| 63 | 69 |
| 64 return title_watcher.WaitAndGetTitle(); | 70 return title_watcher.WaitAndGetTitle(); |
| 65 } | 71 } |
| 66 | 72 |
| 67 void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher* title_watcher) { | 73 void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher* title_watcher) { |
| 68 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEnded)); | 74 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEnded)); |
| 69 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kError)); | 75 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kError)); |
| 70 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kFailed)); | 76 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kFailed)); |
| 77 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kPluginCrashed)); | |
| 71 } | 78 } |
| 79 | |
| 80 void MediaBrowserTest::PluginCrashed(const base::FilePath& plugin_path, | |
| 81 base::ProcessId plugin_pid) { | |
| 82 VLOG(0) << "Plugin crashed: " << plugin_path.value(); | |
| 83 if (ignore_plugin_crash_) | |
| 84 return; | |
| 85 // Update document title to quit TitleWatcher early. | |
| 86 web_contents()->GetController().GetActiveEntry() | |
| 87 ->SetTitle(base::ASCIIToUTF16(kPluginCrashed)); | |
| 88 // Force test to fail. | |
| 89 EXPECT_TRUE(ignore_plugin_crash_) << "Failing test due to plugin crash."; | |
|
ddorwin
2014/03/21 17:06:29
You don't actually expect ignore_plugin_crash_ to
shadi1
2014/03/21 18:43:54
Done.
| |
| 90 } | |
| 91 | |
| 92 void MediaBrowserTest::IgnorePluginCrash(bool ignore_plugin_crash) { | |
| 93 ignore_plugin_crash_ = ignore_plugin_crash; | |
| 94 } | |
| 95 | |
| OLD | NEW |