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(FILE_PATH_LITERAL("media")), | |
18 FilePath(FILE_PATH_LITERAL("seek-jumper.html")))) { | |
19 EnableDOMAutomation(); | |
20 } | |
21 | |
22 protected: | |
23 // Loop until |closure| returns true, CHECK-failing if | |
24 // this fails to happen within a reasonable amount of time. | |
25 void WaitForSuccess(const base::Callback<bool(void)>& closure) { | |
Paweł Hajdan Jr.
2011/11/02 08:43:27
Sorry, no way. Please wait for an event, this kind
Ami GONE FROM CHROMIUM
2011/11/02 16:32:48
The events I need to await for are "JS expression
Paweł Hajdan Jr.
2011/11/02 18:18:15
This is non-trivial, but I think extensions and We
| |
26 const int kLoopIntervalMs = 250; | |
27 const int kNumIntervals = | |
28 TestTimeouts::action_timeout_ms() / kLoopIntervalMs; | |
29 for (int i = 0; i < kNumIntervals; ++i) { | |
30 if (closure.Run()) | |
31 return; | |
32 MessageLoop::current()->PostDelayedTask( | |
33 FROM_HERE, new MessageLoop::QuitTask(), kLoopIntervalMs); | |
34 ui_test_utils::RunMessageLoop(); | |
35 } | |
36 LOG(FATAL) << "Timed out."; | |
37 } | |
38 | |
39 const GURL seek_jumper_url_; | |
40 }; | |
41 | |
42 // Helper that executes |js_expr| in |tab| and returns its evaluated value as a | |
43 // bool. | |
44 static bool ExecuteJavaScriptAsBool(TabContents* tab, | |
45 const std::wstring& js_expr) { | |
46 bool result = false; | |
47 CHECK(ui_test_utils::ExecuteJavaScriptAndExtractBool( | |
Paweł Hajdan Jr.
2011/11/02 08:43:27
Please avoid CHECK, on any failures the test would
Ami GONE FROM CHROMIUM
2011/11/02 16:32:48
1) Why does a CHECK (as opposed to propagating a g
Paweł Hajdan Jr.
2011/11/02 18:18:15
That's true. Now here's the catch: we still want t
| |
48 tab->render_view_host(), L"", js_expr, &result)); | |
49 return result; | |
50 } | |
51 | |
52 // Helper that returns true iff |browser| has |expected_tab_count| tabs. | |
53 static bool IsTabCount(Browser* browser, int expected_tab_count) { | |
54 return browser->tab_count() == expected_tab_count; | |
55 } | |
56 | |
57 // Regression test: pending seeks shouldn't crash the browser when the tab is | |
58 // closed. | |
59 IN_PROC_BROWSER_TEST_F(MediaBrowserTest, SeekJumper_Alone) { | |
60 ui_test_utils::NavigateToURL(browser(), seek_jumper_url_); | |
61 WaitForSuccess(base::Bind( | |
62 &ExecuteJavaScriptAsBool, | |
63 browser()->GetTabContentsAt(0), | |
64 L"window.domAutomationController.send(seekCount > 100)")); | |
65 CHECK(ui_test_utils::SendKeyPressSync( | |
Paweł Hajdan Jr.
2011/11/02 08:43:27
Same here.
| |
66 browser(), ui::VKEY_W, true, false, false, false)); | |
67 // Lack of crash is our SUCCESS. | |
68 } | |
69 | |
70 // Regression test: pending seeks shouldn't crash a shared renderer when the tab | |
71 // containing the audio element is closed. | |
72 IN_PROC_BROWSER_TEST_F(MediaBrowserTest, SeekJumper_SharedRenderer) { | |
73 ui_test_utils::NavigateToURL(browser(), seek_jumper_url_); | |
74 ui_test_utils::NavigateToURLWithDisposition( | |
75 browser(), seek_jumper_url_, NEW_BACKGROUND_TAB, | |
76 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
77 WaitForSuccess(base::Bind(&IsTabCount, browser(), 2)); | |
78 WaitForSuccess(base::Bind( | |
79 &ExecuteJavaScriptAsBool, | |
80 browser()->GetTabContentsAt(0), | |
81 L"window.domAutomationController.send(seekCount > 100)")); | |
82 CHECK(ui_test_utils::SendKeyPressSync( | |
83 browser(), ui::VKEY_W, true, false, false, false)); | |
84 WaitForSuccess(base::Bind(&IsTabCount, browser(), 1)); | |
85 // Give the renderer a bit of time to crash. Sad but necessary. | |
Paweł Hajdan Jr.
2011/11/02 08:43:27
Not true, at least on POSIX. On Windows it's a kno
Ami GONE FROM CHROMIUM
2011/11/02 16:32:48
I feel like you have a magic cure but you're holdi
Paweł Hajdan Jr.
2011/11/02 18:18:15
Not exactly, but yeah, I was working on this issue
| |
86 MessageLoop::current()->PostDelayedTask( | |
87 FROM_HERE, new MessageLoop::QuitTask(), 2000); | |
Paweł Hajdan Jr.
2011/11/02 08:43:27
No hardcoded timeouts please.
Ami GONE FROM CHROMIUM
2011/11/02 16:32:48
Have you looked at the bugs that these tests are r
Paweł Hajdan Jr.
2011/11/02 18:18:15
I've read the bugs now. I think my comment about t
| |
88 ui_test_utils::RunMessageLoop(); | |
89 ASSERT_FALSE(browser()->GetTabContentsAt(0)->is_crashed()); | |
90 } | |
OLD | NEW |