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; |
| 6 |
| 7 import android.test.suitebuilder.annotation.MediumTest; |
| 8 |
| 9 import org.chromium.base.ThreadUtils; |
| 10 import org.chromium.chrome.browser.tabmodel.ChromeTabCreator; |
| 11 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
| 12 import org.chromium.chrome.test.ChromeTabbedActivityTestBase; |
| 13 import org.chromium.chrome.test.util.TestHttpServerClient; |
| 14 import org.chromium.content_public.browser.LoadUrlParams; |
| 15 |
| 16 /** |
| 17 * Instrumentation tests for ChromeActivity. |
| 18 */ |
| 19 public class ChromeActivityTest extends ChromeTabbedActivityTestBase { |
| 20 private static final String FILE_PATH = "chrome/test/data/android/test.html"
; |
| 21 |
| 22 /** |
| 23 * Verifies that the front tab receives the hide() call when the activity is
stopped (hidden); |
| 24 * and that it receives the show() call when the activity is started again.
This is a regression |
| 25 * test for http://crbug.com/319804 . |
| 26 */ |
| 27 @MediumTest |
| 28 public void testTabVisibility() { |
| 29 // Create two tabs - tab[0] in the foreground and tab[1] in the backgrou
nd. |
| 30 final Tab[] tabs = new Tab[2]; |
| 31 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 32 @Override |
| 33 public void run() { |
| 34 // Foreground tab. |
| 35 ChromeTabCreator tabCreator = getActivity().getCurrentTabCreator
(); |
| 36 tabs[0] = tabCreator.createNewTab( |
| 37 new LoadUrlParams(TestHttpServerClient.getUrl(FILE_PATH)
), |
| 38 TabLaunchType.FROM_KEYBOARD, null); |
| 39 // Background tab. |
| 40 tabs[1] = tabCreator.createNewTab( |
| 41 new LoadUrlParams(TestHttpServerClient.getUrl(FILE_PATH)
), |
| 42 TabLaunchType.FROM_LONGPRESS_BACKGROUND, null); |
| 43 } |
| 44 }); |
| 45 |
| 46 // Verify that the front tab is in the 'visible' state. |
| 47 assertFalse(tabs[0].isHidden()); |
| 48 assertTrue(tabs[1].isHidden()); |
| 49 |
| 50 // Fake sending the activity to background. |
| 51 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 52 @Override |
| 53 public void run() { |
| 54 getActivity().onPause(); |
| 55 } |
| 56 }); |
| 57 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 58 @Override |
| 59 public void run() { |
| 60 getActivity().onStop(); |
| 61 } |
| 62 }); |
| 63 // TODO(jdduke): Ensure the Tab's WebContents is hidden despite the |
| 64 // Tab itself remaining visible. This prevents visual artifacts during |
| 65 // activity transitions. |
| 66 assertFalse(tabs[0].isHidden()); |
| 67 assertTrue(tabs[1].isHidden()); |
| 68 |
| 69 // Fake bringing the activity back to foreground. |
| 70 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 71 @Override |
| 72 public void run() { |
| 73 getActivity().onStart(); |
| 74 } |
| 75 }); |
| 76 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 77 @Override |
| 78 public void run() { |
| 79 getActivity().onResume(); |
| 80 } |
| 81 }); |
| 82 // Verify that the front tab is in the 'visible' state. |
| 83 assertFalse(tabs[0].isHidden()); |
| 84 assertTrue(tabs[1].isHidden()); |
| 85 } |
| 86 |
| 87 @Override |
| 88 public void startMainActivity() throws InterruptedException { |
| 89 startMainActivityOnBlankPage(); |
| 90 } |
| 91 } |
OLD | NEW |