diff options
author | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-31 17:57:19 +0000 |
---|---|---|
committer | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-31 17:57:19 +0000 |
commit | 9f55343057df8ce1942f3e05f0403fceb3ff026e (patch) | |
tree | 5268bf48fd1374afb1d4fb244d5593422de5cf9e | |
parent | 82a221dbd2df21739b877eca43c25bd0b6be4ccc (diff) | |
download | chromium_src-9f55343057df8ce1942f3e05f0403fceb3ff026e.zip chromium_src-9f55343057df8ce1942f3e05f0403fceb3ff026e.tar.gz chromium_src-9f55343057df8ce1942f3e05f0403fceb3ff026e.tar.bz2 |
Regression tests for two recently-fixed audio-related crashers.
This is a reboot of http://codereview.chromium.org/8418031/, using more robust
primitives to assemble the test.
BUG=101228, 101375
TEST=new tests pass locally, trybots
Review URL: https://chromiumcodereview.appspot.com/9113067
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119917 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/media/media_browsertest.cc | 155 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 1 | ||||
-rw-r--r-- | chrome/test/data/media/seek-jumper.html | 21 |
3 files changed, 177 insertions, 0 deletions
diff --git a/chrome/browser/media/media_browsertest.cc b/chrome/browser/media/media_browsertest.cc new file mode 100644 index 0000000..0fe6078 --- /dev/null +++ b/chrome/browser/media/media_browsertest.cc @@ -0,0 +1,155 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/string_util.h" +#include "base/test/test_timeouts.h" +#include "chrome/browser/tabs/tab_strip_model.h" +#include "chrome/browser/tabs/tab_strip_model_observer.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/ui_test_utils.h" +#include "content/browser/renderer_host/render_view_host.h" +#include "content/public/browser/web_contents.h" + +class MediaBrowserTest : public InProcessBrowserTest { + public: + MediaBrowserTest() + : seek_jumper_url_(ui_test_utils::GetTestUrl( + FilePath(FILE_PATH_LITERAL("media")), + FilePath(FILE_PATH_LITERAL("seek-jumper.html")))) { + } + + protected: + const GURL seek_jumper_url_; +}; + +class TabWatcher : public TabStripModelObserver { + public: + explicit TabWatcher(Browser* browser) + : browser_(browser), in_run_(false), + expected_title_tab_(-1), expected_tab_count_(-1) { + browser->tabstrip_model()->AddObserver(this); + } + + void WaitForTitleToBe(int tab_index, + const base::StringPiece& expected_title) { + DCHECK(expected_title_tab_ == -1 && expected_tab_count_ == -1); + expected_title_tab_ = tab_index; + expected_title_ = expected_title; + Run(); + } + + void WaitForTabCountToBe(int expected_tab_count) { + DCHECK(expected_title_tab_ == -1 && expected_tab_count_ == -1); + expected_tab_count_ = expected_tab_count; + Run(); + } + + virtual ~TabWatcher() { + if (browser_) + browser_->tabstrip_model()->RemoveObserver(this); + } + + private: + + void Run() { + CHECK(!in_run_); + in_run_ = true; + ui_test_utils::RunMessageLoop(); + in_run_ = false; + } + + void QuitIfExpectationReached() { + bool quit = false; + CHECK(browser_); + CHECK(in_run_); + if ((expected_tab_count_ >= 0) && + (browser_->tabstrip_model()->count() == expected_tab_count_)) { + quit = true; + } else if ((expected_title_tab_ >= 0) && EqualsASCII( + browser_->GetWebContentsAt(expected_title_tab_)->GetTitle(), + expected_title_)) { + quit = true; + } + if (quit) { + expected_title_tab_ = -1; + expected_tab_count_ = -1; + MessageLoopForUI::current()->Quit(); + } + } + + virtual void TabChangedAt(TabContentsWrapper*, int, TabChangeType) OVERRIDE { + QuitIfExpectationReached(); + } + virtual void TabInsertedAt(TabContentsWrapper*, int, bool) OVERRIDE { + QuitIfExpectationReached(); + } + virtual void TabClosingAt(TabStripModel*, TabContentsWrapper*, int) OVERRIDE { + QuitIfExpectationReached(); + } + virtual void TabStripEmpty() OVERRIDE { + browser_ = NULL; + } + virtual void TabStripModelDeleted() OVERRIDE { + browser_ = NULL; + } + + Browser* browser_; + bool in_run_; + int expected_title_tab_; // -1 if not waiting for a title. + base::StringPiece expected_title_; // Ignored if not waiting for a title. + int expected_tab_count_; // -1 if not waiting for a tab count. + +}; + +#if defined(OS_MACOSX) +// Mac still has bugs when it comes to lots of outstanding seeks +// http://crbug.com/102395 +#define MAYBE_SeekJumper_Alone DISABLED_SeekJumper_Alone +#else +#define MAYBE_SeekJumper_Alone SeekJumper_Alone +#endif + +// Regression test: pending seeks shouldn't crash the browser when the tab is +// closed. +IN_PROC_BROWSER_TEST_F(MediaBrowserTest, MAYBE_SeekJumper_Alone) { + TabWatcher watcher(browser()); + ui_test_utils::NavigateToURL(browser(), seek_jumper_url_); + watcher.WaitForTabCountToBe(1); + watcher.WaitForTitleToBe(0, "Done"); + ASSERT_TRUE(ui_test_utils::SendKeyPressSync( + browser(), ui::VKEY_W, true, false, false, false)); + watcher.WaitForTabCountToBe(0); + // Lack of crash is our SUCCESS. +} + +#if defined(OS_MACOSX) +// Mac still has bugs when it comes to lots of outstanding seeks +// http://crbug.com/102395 +#define MAYBE_SeekJumper_SharedRenderer DISABLED_SeekJumper_SharedRenderer +#else +#define MAYBE_SeekJumper_SharedRenderer SeekJumper_SharedRenderer +#endif + +// Regression test: pending seeks shouldn't crash a shared renderer when the tab +// containing the audio element is closed. +IN_PROC_BROWSER_TEST_F(MediaBrowserTest, MAYBE_SeekJumper_SharedRenderer) { + TabWatcher watcher(browser()); + ui_test_utils::NavigateToURL(browser(), seek_jumper_url_); + ui_test_utils::NavigateToURLWithDisposition( + browser(), seek_jumper_url_, NEW_BACKGROUND_TAB, + ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); + watcher.WaitForTabCountToBe(2); + watcher.WaitForTitleToBe(0, "Done"); + ASSERT_TRUE(ui_test_utils::SendKeyPressSync( + browser(), ui::VKEY_W, true, false, false, false)); + watcher.WaitForTabCountToBe(1); + watcher.WaitForTitleToBe(0, "Done"); + // Give the renderer a bit of time to crash. Sad but necessary. + MessageLoop::current()->PostDelayedTask( + FROM_HERE, MessageLoop::QuitClosure(), TestTimeouts::action_timeout()); + ui_test_utils::RunMessageLoop(); + ASSERT_TRUE(browser()->GetWebContentsAt(0)->GetRenderViewHost()-> + IsRenderViewLive()); +} diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index ff1a325..de50853 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -2658,6 +2658,7 @@ 'browser/infobars/infobar_extension_apitest.cc', 'browser/importer/toolbar_importer_utils_browsertest.cc', 'browser/magic_iframe_browsertest.cc', + 'browser/media/media_browsertest.cc', 'browser/net/cookie_policy_browsertest.cc', 'browser/net/ftp_browsertest.cc', 'browser/notifications/desktop_notifications_unittest.cc', diff --git a/chrome/test/data/media/seek-jumper.html b/chrome/test/data/media/seek-jumper.html new file mode 100644 index 0000000..3596924 --- /dev/null +++ b/chrome/test/data/media/seek-jumper.html @@ -0,0 +1,21 @@ +<html> +<head> +<script> +// Issue a bunch of seeks in a row, with some overlap. +var seekCount = 0; +function seeked() { + if (++seekCount == 100) + document.title = 'Done'; // Signals completion to the C++ side. + var a = document.querySelector('audio'); + a.currentTime = Math.random() * a.duration; + window.setTimeout(seeked, 1); // Overlaps the onseeked listener. +} +</script> +</head> +<body> + Test that rapid seeking fails to crash the browser. + + <audio controls autoplay src="bear_pcm.wav" + onseeked="seeked()" onplaying="seeked()" onended="seeked()"></audio> +</body> +</html> |