OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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/strings/stringprintf.h" | |
Lei Zhang
2015/08/14 02:21:18
not used
DaleCurtis
2015/08/18 18:19:12
Done.
| |
6 #include "base/strings/utf_string_conversions.h" | |
7 #include "build/build_config.h" | |
8 #include "chrome/browser/ui/browser.h" | |
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
10 #include "chrome/test/base/in_process_browser_test.h" | |
11 #include "chrome/test/base/ui_test_utils.h" | |
12 #include "content/public/test/browser_test_utils.h" | |
13 #include "media/base/test_data_util.h" | |
14 | |
15 // Android does not support deferred media loading. | |
Lei Zhang
2015/08/14 02:21:18
Add bug # if there is one
mmenke
2015/08/14 14:57:35
Does this mean if we prerender on android, we'll p
DaleCurtis
2015/08/14 17:37:35
The DeferMediaLoad() call is unused on Android (se
mmenke
2015/08/18 17:36:04
I believe prerendering is enabled on Android, or a
DaleCurtis
2015/08/18 18:19:12
Hmm, that's broken for Media Source on Android the
| |
16 #if !defined(OS_ANDROID) | |
17 typedef InProcessBrowserTest MediaBrowserTest; | |
18 | |
19 IN_PROC_BROWSER_TEST_F(MediaBrowserTest, BackgroundMediaIsDeferred) { | |
20 // Navigate to a video file, which would autoplay in the foreground, but won't | |
21 // in the background due to deferred media loading for hidden tabs. | |
22 ui_test_utils::NavigateToURLWithDisposition( | |
23 browser(), content::GetFileUrlWithQuery( | |
24 media::GetTestDataFilePath("bear-640x360.webm"), ""), | |
25 NEW_BACKGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
26 | |
27 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | |
28 content::WebContents* background_contents = | |
Lei Zhang
2015/08/14 02:21:18
Also get the current tab via GetActiveWebContents(
DaleCurtis
2015/08/18 18:19:12
Done.
| |
29 browser()->tab_strip_model()->GetWebContentsAt(1); | |
30 EXPECT_TRUE( | |
31 content::WaitForRenderFrameReady(background_contents->GetMainFrame())); | |
32 | |
33 // If autoplay for background tabs isn't deferred the play event listener will | |
34 // be attached too late to catch the event, and subsequently the test will hit | |
35 // the ended event before the play event. | |
36 EXPECT_TRUE( | |
37 content::ExecuteScript(background_contents, | |
38 "var video = document.querySelector('video');" | |
39 "video.addEventListener('ended', function(event) {" | |
40 " document.title = 'ended';" | |
41 "}, false);" | |
42 "video.addEventListener('play', function(event) {" | |
43 " document.title = 'playing';" | |
44 "}, false);")); | |
45 | |
46 // Make the background tab w/ our video the active tab. | |
47 browser()->tab_strip_model()->SelectNextTab(); | |
48 EXPECT_EQ(background_contents, | |
49 browser()->tab_strip_model()->GetActiveWebContents()); | |
50 | |
51 // If everything worked, we should see "playing" and not "ended". | |
52 const base::string16 playing_str = base::UTF8ToUTF16("playing"); | |
53 const base::string16 ended_str = base::UTF8ToUTF16("ended"); | |
54 content::TitleWatcher watcher(background_contents, playing_str); | |
55 watcher.AlsoWaitForTitle(ended_str); | |
56 EXPECT_EQ(playing_str, watcher.WaitAndGetTitle()); | |
57 } | |
58 #endif | |
Lei Zhang
2015/08/14 02:21:18
// !defined(OS_ANDROID)
DaleCurtis
2015/08/18 18:19:12
Done.
| |
OLD | NEW |