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.test; |
| 6 |
| 7 import android.app.Activity; |
| 8 import android.content.Context; |
| 9 import android.os.Build; |
| 10 import android.test.suitebuilder.annotation.MediumTest; |
| 11 |
| 12 import org.chromium.base.ApplicationStatus; |
| 13 import org.chromium.base.ThreadUtils; |
| 14 import org.chromium.base.test.util.MinAndroidSdkLevel; |
| 15 import org.chromium.base.test.util.Restriction; |
| 16 import org.chromium.chrome.browser.ChromeTabbedActivity; |
| 17 import org.chromium.chrome.browser.document.ChromeLauncherActivity; |
| 18 import org.chromium.chrome.browser.document.DocumentActivity; |
| 19 import org.chromium.chrome.browser.document.DocumentMetricIds; |
| 20 import org.chromium.chrome.browser.util.FeatureUtilities; |
| 21 import org.chromium.chrome.test.util.ActivityUtils; |
| 22 import org.chromium.content.browser.test.util.Criteria; |
| 23 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 24 |
| 25 import java.lang.ref.WeakReference; |
| 26 import java.util.List; |
| 27 |
| 28 /** |
| 29 * Tests for ChromeTabbedActivity that need to run on L+ devices. |
| 30 */ |
| 31 @MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP) |
| 32 public class ChromeTabbedActivityLollipopAndAboveTest extends ChromeTabbedActivi
tyTestBase { |
| 33 /** |
| 34 * Confirm that you can't start DocumentActivity while the user is running i
n tabbed mode. |
| 35 */ |
| 36 @Restriction(Restriction.RESTRICTION_TYPE_PHONE) |
| 37 @MediumTest |
| 38 public void testDontKeepDocumentActivityInTabbedMode() throws Exception { |
| 39 // Make sure that ChromeTabbedActivity started up. |
| 40 Context context = getInstrumentation().getTargetContext(); |
| 41 assertFalse(FeatureUtilities.isDocumentMode(context)); |
| 42 assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() { |
| 43 @Override |
| 44 public boolean isSatisfied() { |
| 45 Activity lastActivity = ApplicationStatus.getLastTrackedFocusedA
ctivity(); |
| 46 return lastActivity instanceof ChromeTabbedActivity; |
| 47 } |
| 48 })); |
| 49 |
| 50 // Try launching a DocumentActivity. |
| 51 Runnable runnable = new Runnable() { |
| 52 @Override |
| 53 public void run() { |
| 54 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 55 @Override |
| 56 public void run() { |
| 57 ChromeLauncherActivity.launchDocumentInstance(null, fals
e, |
| 58 ChromeLauncherActivity.LAUNCH_MODE_FOREGROUND, "
about:blank", |
| 59 DocumentMetricIds.STARTED_BY_UNKNOWN, 0, false,
null); |
| 60 } |
| 61 }); |
| 62 } |
| 63 }; |
| 64 final Activity documentActivity = ActivityUtils.waitForActivity( |
| 65 getInstrumentation(), DocumentActivity.class, runnable); |
| 66 |
| 67 // ApplicationStatus should note that the DocumentActivity isn't running
anymore. |
| 68 assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() { |
| 69 @Override |
| 70 public boolean isSatisfied() { |
| 71 List<WeakReference<Activity>> activities = ApplicationStatus.get
RunningActivities(); |
| 72 for (WeakReference<Activity> activity : activities) { |
| 73 if (activity.get() == documentActivity) return false; |
| 74 } |
| 75 return true; |
| 76 } |
| 77 })); |
| 78 } |
| 79 |
| 80 @Override |
| 81 public void startMainActivity() throws InterruptedException { |
| 82 startMainActivityOnBlankPage(); |
| 83 } |
| 84 } |
OLD | NEW |