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 package org.chromium.chrome.browser.video; |
| 6 |
| 7 import android.test.FlakyTest; |
| 8 import android.view.KeyEvent; |
| 9 |
| 10 import org.chromium.base.ThreadUtils; |
| 11 import org.chromium.chrome.browser.ChromeActivity; |
| 12 import org.chromium.chrome.browser.EmptyTabObserver; |
| 13 import org.chromium.chrome.browser.Tab; |
| 14 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
| 15 import org.chromium.chrome.test.util.TestHttpServerClient; |
| 16 import org.chromium.content.browser.test.util.Criteria; |
| 17 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 18 import org.chromium.content.browser.test.util.TestTouchUtils; |
| 19 |
| 20 /** |
| 21 * Test suite for fullscreen video implementation. |
| 22 */ |
| 23 public class FullscreenVideoTest extends ChromeActivityTestCaseBase<ChromeActivi
ty> { |
| 24 private static final int TEST_TIMEOUT = 3000; |
| 25 private boolean mIsTabFullscreen = false; |
| 26 |
| 27 private class FullscreenTabObserver extends EmptyTabObserver { |
| 28 @Override |
| 29 public void onToggleFullscreenMode(Tab tab, boolean enable) { |
| 30 mIsTabFullscreen = enable; |
| 31 } |
| 32 } |
| 33 |
| 34 public FullscreenVideoTest() { |
| 35 super(ChromeActivity.class); |
| 36 } |
| 37 |
| 38 @Override |
| 39 public void startMainActivity() throws InterruptedException { |
| 40 startMainActivityOnBlankPage(); |
| 41 } |
| 42 |
| 43 /** |
| 44 * Test that when playing a fullscreen video, hitting the back button will l
et the tab |
| 45 * exit fullscreen mode without changing its URL. |
| 46 * |
| 47 * @MediumTest |
| 48 * crbug.com/458368. |
| 49 */ |
| 50 @FlakyTest |
| 51 public void testExitFullscreenNotifiesTabObservers() throws InterruptedExcep
tion { |
| 52 String url = TestHttpServerClient.getUrl( |
| 53 "chrome/test/data/android/media/video-fullscreen.html"); |
| 54 loadUrl(url); |
| 55 Tab tab = getActivity().getActivityTab(); |
| 56 FullscreenTabObserver observer = new FullscreenTabObserver(); |
| 57 tab.addObserver(observer); |
| 58 |
| 59 TestTouchUtils.singleClickView(getInstrumentation(), tab.getView(), 500,
500); |
| 60 waitForVideoToEnterFullscreen(); |
| 61 // Key events have to be dispached on UI thread. |
| 62 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 63 @Override |
| 64 public void run() { |
| 65 getActivity().dispatchKeyEvent( |
| 66 new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK
)); |
| 67 getActivity().dispatchKeyEvent( |
| 68 new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK))
; |
| 69 } |
| 70 }); |
| 71 |
| 72 waitForTabToExitFullscreen(); |
| 73 assertEquals("URL mismatch after exiting fullscreen video", |
| 74 url, getActivity().getActivityTab().getUrl()); |
| 75 } |
| 76 |
| 77 void waitForVideoToEnterFullscreen() throws InterruptedException { |
| 78 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
| 79 @Override |
| 80 public boolean isSatisfied() { |
| 81 return mIsTabFullscreen; |
| 82 } |
| 83 }, TEST_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL)); |
| 84 } |
| 85 |
| 86 void waitForTabToExitFullscreen() throws InterruptedException { |
| 87 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
| 88 @Override |
| 89 public boolean isSatisfied() { |
| 90 return !mIsTabFullscreen; |
| 91 } |
| 92 }, TEST_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL)); |
| 93 } |
| 94 } |
OLD | NEW |