Chromium Code Reviews| Index: chrome/browser/media/defer_background_media_browsertest.cc |
| diff --git a/chrome/browser/media/defer_background_media_browsertest.cc b/chrome/browser/media/defer_background_media_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9d1970b77adf378aa35c235140f1eca353f7f423 |
| --- /dev/null |
| +++ b/chrome/browser/media/defer_background_media_browsertest.cc |
| @@ -0,0 +1,58 @@ |
| +// Copyright 2015 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/strings/stringprintf.h" |
|
Lei Zhang
2015/08/14 02:21:18
not used
DaleCurtis
2015/08/18 18:19:12
Done.
|
| +#include "base/strings/utf_string_conversions.h" |
| +#include "build/build_config.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "chrome/test/base/in_process_browser_test.h" |
| +#include "chrome/test/base/ui_test_utils.h" |
| +#include "content/public/test/browser_test_utils.h" |
| +#include "media/base/test_data_util.h" |
| + |
| +// 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
|
| +#if !defined(OS_ANDROID) |
| +typedef InProcessBrowserTest MediaBrowserTest; |
| + |
| +IN_PROC_BROWSER_TEST_F(MediaBrowserTest, BackgroundMediaIsDeferred) { |
| + // Navigate to a video file, which would autoplay in the foreground, but won't |
| + // in the background due to deferred media loading for hidden tabs. |
| + ui_test_utils::NavigateToURLWithDisposition( |
| + browser(), content::GetFileUrlWithQuery( |
| + media::GetTestDataFilePath("bear-640x360.webm"), ""), |
| + NEW_BACKGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| + |
| + ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
| + 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.
|
| + browser()->tab_strip_model()->GetWebContentsAt(1); |
| + EXPECT_TRUE( |
| + content::WaitForRenderFrameReady(background_contents->GetMainFrame())); |
| + |
| + // If autoplay for background tabs isn't deferred the play event listener will |
| + // be attached too late to catch the event, and subsequently the test will hit |
| + // the ended event before the play event. |
| + EXPECT_TRUE( |
| + content::ExecuteScript(background_contents, |
| + "var video = document.querySelector('video');" |
| + "video.addEventListener('ended', function(event) {" |
| + " document.title = 'ended';" |
| + "}, false);" |
| + "video.addEventListener('play', function(event) {" |
| + " document.title = 'playing';" |
| + "}, false);")); |
| + |
| + // Make the background tab w/ our video the active tab. |
| + browser()->tab_strip_model()->SelectNextTab(); |
| + EXPECT_EQ(background_contents, |
| + browser()->tab_strip_model()->GetActiveWebContents()); |
| + |
| + // If everything worked, we should see "playing" and not "ended". |
| + const base::string16 playing_str = base::UTF8ToUTF16("playing"); |
| + const base::string16 ended_str = base::UTF8ToUTF16("ended"); |
| + content::TitleWatcher watcher(background_contents, playing_str); |
| + watcher.AlsoWaitForTitle(ended_str); |
| + EXPECT_EQ(playing_str, watcher.WaitAndGetTitle()); |
| +} |
| +#endif |
|
Lei Zhang
2015/08/14 02:21:18
// !defined(OS_ANDROID)
DaleCurtis
2015/08/18 18:19:12
Done.
|