Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/bind.h" | |
| 6 #include "base/callback.h" | |
| 7 #include "base/test/test_timeouts.h" | |
| 8 #include "chrome/browser/ui/browser.h" | |
| 9 #include "chrome/test/base/in_process_browser_test.h" | |
| 10 #include "chrome/test/base/ui_test_utils.h" | |
| 11 #include "content/browser/tab_contents/tab_contents.h" | |
| 12 | |
| 13 class MediaBrowserTest : public InProcessBrowserTest { | |
| 14 public: | |
| 15 MediaBrowserTest() | |
| 16 : seek_jumper_url_(ui_test_utils::GetTestUrl( | |
| 17 FilePath("media"), FilePath("seek-jumper.html"))) {} | |
|
scherkus (not reviewing)
2011/10/28 21:03:13
indent +2
pedantic nit 'o mine: if entire ctor/dt
scherkus (not reviewing)
2011/10/28 21:03:13
fix file path literals
Ami GONE FROM CHROMIUM
2011/10/28 21:54:28
I don't think so - as a continuation line it inden
| |
| 18 | |
| 19 virtual void SetUp() OVERRIDE { | |
| 20 EnableDOMAutomation(); | |
|
scherkus (not reviewing)
2011/10/28 21:03:13
sanity check: can we not move this to ctor then av
Ami GONE FROM CHROMIUM
2011/10/28 21:54:28
Done.
| |
| 21 InProcessBrowserTest::SetUp(); | |
| 22 } | |
| 23 | |
| 24 protected: | |
| 25 // Loop until |closure| returns true, CHECK-failing if | |
| 26 // this fails to happen within a reasonable amount of time. | |
| 27 void WaitForSuccess(const base::Callback<bool(void)>& closure) { | |
| 28 const int kLoopIntervalMs = 250; | |
| 29 const int kNumIntervals = | |
| 30 TestTimeouts::action_timeout_ms() / kLoopIntervalMs; | |
| 31 for (int i = 0; i < kNumIntervals; ++i) { | |
| 32 if (closure.Run()) | |
| 33 return; | |
| 34 MessageLoop::current()->PostDelayedTask( | |
| 35 FROM_HERE, new MessageLoop::QuitTask(), kLoopIntervalMs); | |
| 36 ui_test_utils::RunMessageLoop(); | |
| 37 } | |
| 38 LOG(FATAL) << "Timed out."; | |
| 39 } | |
| 40 | |
| 41 const GURL seek_jumper_url_; | |
| 42 }; | |
| 43 | |
| 44 // Helper that executes |js_expr| in |tab| and returns its evaluated value as a | |
| 45 // bool. | |
| 46 static bool ExecuteJavaScriptAsBool(TabContents* tab, | |
| 47 const std::wstring& js_expr) { | |
| 48 bool result = false; | |
| 49 CHECK(ui_test_utils::ExecuteJavaScriptAndExtractBool( | |
| 50 tab->render_view_host(), L"", js_expr, &result)); | |
| 51 return result; | |
| 52 } | |
| 53 | |
| 54 // Helper that returns true iff |browser| has |expected_tab_count| tabs. | |
| 55 static bool IsTabCount(Browser* browser, int expected_tab_count) { | |
| 56 return browser->tab_count() == expected_tab_count; | |
| 57 } | |
| 58 | |
| 59 // Regression test: pending seeks shouldn't crash the browser when the tab is | |
| 60 // closed. | |
| 61 IN_PROC_BROWSER_TEST_F(MediaBrowserTest, SeekJumperAlone) { | |
|
scherkus (not reviewing)
2011/10/28 21:03:13
nit: for prefixed test names we've typically added
Ami GONE FROM CHROMIUM
2011/10/28 21:54:28
Done.
| |
| 62 ui_test_utils::NavigateToURL(browser(), seek_jumper_url_); | |
| 63 WaitForSuccess(base::Bind( | |
| 64 &ExecuteJavaScriptAsBool, | |
| 65 browser()->GetTabContentsAt(0), | |
| 66 L"window.domAutomationController.send(seekCount > 100)")); | |
| 67 CHECK(ui_test_utils::SendKeyPressSync( | |
| 68 browser(), ui::VKEY_W, true, false, false, false)); | |
| 69 // Lack of crash is our SUCCESS. | |
| 70 } | |
| 71 | |
|
scherkus (not reviewing)
2011/10/28 21:03:13
remove blank line
Ami GONE FROM CHROMIUM
2011/10/28 21:54:28
Done.
| |
| 72 | |
| 73 // Regression test: pending seeks shouldn't crash a shared renderer when the tab | |
| 74 // containing the audio element is closed. | |
| 75 IN_PROC_BROWSER_TEST_F(MediaBrowserTest, SeekJumperSharedRenderer) { | |
| 76 | |
|
scherkus (not reviewing)
2011/10/28 21:03:13
remove blank line
Ami GONE FROM CHROMIUM
2011/10/28 21:54:28
Done.
| |
| 77 ui_test_utils::NavigateToURL(browser(), seek_jumper_url_); | |
| 78 ui_test_utils::NavigateToURLWithDisposition( | |
| 79 browser(), seek_jumper_url_, NEW_BACKGROUND_TAB, | |
| 80 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 81 WaitForSuccess(base::Bind(&IsTabCount, browser(), 2)); | |
| 82 WaitForSuccess(base::Bind( | |
| 83 &ExecuteJavaScriptAsBool, | |
| 84 browser()->GetTabContentsAt(0), | |
| 85 L"window.domAutomationController.send(seekCount > 100)")); | |
| 86 CHECK(ui_test_utils::SendKeyPressSync( | |
| 87 browser(), ui::VKEY_W, true, false, false, false)); | |
| 88 WaitForSuccess(base::Bind(&IsTabCount, browser(), 1)); | |
| 89 // Give the renderer a bit of time to crash. Sad but necessary. | |
| 90 MessageLoop::current()->PostDelayedTask( | |
| 91 FROM_HERE, new MessageLoop::QuitTask(), 2000); | |
|
scherkus (not reviewing)
2011/10/28 21:03:13
test timeouts?
Ami GONE FROM CHROMIUM
2011/10/28 21:54:28
I don't think so; none of them are a good fit. No
| |
| 92 ui_test_utils::RunMessageLoop(); | |
| 93 ASSERT_FALSE(browser()->GetTabContentsAt(0)->is_crashed()); | |
| 94 } | |
| OLD | NEW |