| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.multiwindow; | 5 package org.chromium.chrome.browser.multiwindow; |
| 6 | 6 |
| 7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
| 8 import android.app.Activity; | 8 import android.app.Activity; |
| 9 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.os.Build; | 10 import android.os.Build; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 startMainActivityOnBlankPage(); | 37 startMainActivityOnBlankPage(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 /** | 40 /** |
| 41 * Tests that ChromeTabbedActivity2 is used for intents when EXTRA_WINDOW_ID
is set to 2. | 41 * Tests that ChromeTabbedActivity2 is used for intents when EXTRA_WINDOW_ID
is set to 2. |
| 42 */ | 42 */ |
| 43 @SmallTest | 43 @SmallTest |
| 44 @Feature("MultiWindow") | 44 @Feature("MultiWindow") |
| 45 public void testTabbedActivityForIntentWithExtraWindowId() throws Interrupte
dException { | 45 public void testTabbedActivityForIntentWithExtraWindowId() throws Interrupte
dException { |
| 46 ChromeTabbedActivity activity1 = getActivity(); | 46 ChromeTabbedActivity activity1 = getActivity(); |
| 47 createSecondChromeTabbedActivity(); | 47 createSecondChromeTabbedActivity(activity1); |
| 48 | 48 |
| 49 Intent intent = activity1.getIntent(); | 49 Intent intent = activity1.getIntent(); |
| 50 intent.putExtra(IntentHandler.EXTRA_WINDOW_ID, 2); | 50 intent.putExtra(IntentHandler.EXTRA_WINDOW_ID, 2); |
| 51 | 51 |
| 52 assertEquals("ChromeTabbedActivity2 should be used when EXTRA_WINDOW_ID
is set to 2.", | 52 assertEquals("ChromeTabbedActivity2 should be used when EXTRA_WINDOW_ID
is set to 2.", |
| 53 ChromeTabbedActivity2.class, | 53 ChromeTabbedActivity2.class, |
| 54 MultiWindowUtils.getInstance().getTabbedActivityForIntent( | 54 MultiWindowUtils.getInstance().getTabbedActivityForIntent( |
| 55 intent, activity1)); | 55 intent, activity1)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * Tests that if two ChromeTabbedActivities are running the one that was res
umed most recently | 59 * Tests that if two ChromeTabbedActivities are running the one that was res
umed most recently |
| 60 * is used as the class name for new intents. | 60 * is used as the class name for new intents. |
| 61 */ | 61 */ |
| 62 @SmallTest | 62 @SmallTest |
| 63 @Feature("MultiWindow") | 63 @Feature("MultiWindow") |
| 64 public void testTabbedActivityForIntentLastResumedActivity() throws Interrup
tedException { | 64 public void testTabbedActivityForIntentLastResumedActivity() throws Interrup
tedException { |
| 65 ChromeTabbedActivity activity1 = getActivity(); | 65 ChromeTabbedActivity activity1 = getActivity(); |
| 66 final ChromeTabbedActivity2 activity2 = createSecondChromeTabbedActivity
(); | 66 final ChromeTabbedActivity2 activity2 = createSecondChromeTabbedActivity
(activity1); |
| 67 | 67 |
| 68 assertFalse("ChromeTabbedActivity should not be resumed", | 68 assertFalse("ChromeTabbedActivity should not be resumed", |
| 69 ApplicationStatus.getStateForActivity(activity1) == ActivityStat
e.RESUMED); | 69 ApplicationStatus.getStateForActivity(activity1) == ActivityStat
e.RESUMED); |
| 70 assertTrue("ChromeTabbedActivity2 should be resumed", | 70 assertTrue("ChromeTabbedActivity2 should be resumed", |
| 71 ApplicationStatus.getStateForActivity(activity2) == ActivityStat
e.RESUMED); | 71 ApplicationStatus.getStateForActivity(activity2) == ActivityStat
e.RESUMED); |
| 72 | 72 |
| 73 // Open settings and wait for ChromeTabbedActivity2 to pause. | 73 // Open settings and wait for ChromeTabbedActivity2 to pause. |
| 74 activity2.onMenuOrKeyboardAction(R.id.preferences_id, true); | 74 activity2.onMenuOrKeyboardAction(R.id.preferences_id, true); |
| 75 int expected = ActivityState.PAUSED; | 75 int expected = ActivityState.PAUSED; |
| 76 CriteriaHelper.pollUiThread(Criteria.equals(expected, new Callable<Integ
er>() { | 76 CriteriaHelper.pollUiThread(Criteria.equals(expected, new Callable<Integ
er>() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 88 | 88 |
| 89 /** | 89 /** |
| 90 * Tests that if only ChromeTabbedActivity is running it is used as the clas
s name for intents. | 90 * Tests that if only ChromeTabbedActivity is running it is used as the clas
s name for intents. |
| 91 */ | 91 */ |
| 92 @SmallTest | 92 @SmallTest |
| 93 @Feature("MultiWindow") | 93 @Feature("MultiWindow") |
| 94 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 94 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
| 95 public void testTabbedActivityForIntentOnlyActivity1IsRunning() | 95 public void testTabbedActivityForIntentOnlyActivity1IsRunning() |
| 96 throws InterruptedException { | 96 throws InterruptedException { |
| 97 ChromeTabbedActivity activity1 = getActivity(); | 97 ChromeTabbedActivity activity1 = getActivity(); |
| 98 ChromeTabbedActivity2 activity2 = createSecondChromeTabbedActivity(); | 98 ChromeTabbedActivity2 activity2 = createSecondChromeTabbedActivity(activ
ity1); |
| 99 activity2.finishAndRemoveTask(); | 99 activity2.finishAndRemoveTask(); |
| 100 | 100 |
| 101 assertEquals("ChromeTabbedActivity should be used for intents if ChromeT
abbedActivity2 is " | 101 assertEquals("ChromeTabbedActivity should be used for intents if ChromeT
abbedActivity2 is " |
| 102 + "not running.", | 102 + "not running.", |
| 103 ChromeTabbedActivity.class, | 103 ChromeTabbedActivity.class, |
| 104 MultiWindowUtils.getInstance().getTabbedActivityForIntent( | 104 MultiWindowUtils.getInstance().getTabbedActivityForIntent( |
| 105 activity1.getIntent(), activity1)); | 105 activity1.getIntent(), activity1)); |
| 106 } | 106 } |
| 107 | 107 |
| 108 /** | 108 /** |
| 109 * Tests that if only ChromeTabbedActivity2 is running it is used as the cla
ss name for intents. | 109 * Tests that if only ChromeTabbedActivity2 is running it is used as the cla
ss name for intents. |
| 110 */ | 110 */ |
| 111 @SmallTest | 111 @SmallTest |
| 112 @Feature("MultiWindow") | 112 @Feature("MultiWindow") |
| 113 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 113 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
| 114 public void testTabbedActivityForIntentOnlyActivity2IsRunning() | 114 public void testTabbedActivityForIntentOnlyActivity2IsRunning() |
| 115 throws InterruptedException { | 115 throws InterruptedException { |
| 116 ChromeTabbedActivity activity1 = getActivity(); | 116 ChromeTabbedActivity activity1 = getActivity(); |
| 117 createSecondChromeTabbedActivity(); | 117 createSecondChromeTabbedActivity(activity1); |
| 118 activity1.finishAndRemoveTask(); | 118 activity1.finishAndRemoveTask(); |
| 119 | 119 |
| 120 assertEquals("ChromeTabbedActivity2 should be used for intents if Chrome
TabbedActivity is " | 120 assertEquals("ChromeTabbedActivity2 should be used for intents if Chrome
TabbedActivity is " |
| 121 + "not running.", | 121 + "not running.", |
| 122 ChromeTabbedActivity2.class, | 122 ChromeTabbedActivity2.class, |
| 123 MultiWindowUtils.getInstance().getTabbedActivityForIntent( | 123 MultiWindowUtils.getInstance().getTabbedActivityForIntent( |
| 124 activity1.getIntent(), activity1)); | 124 activity1.getIntent(), activity1)); |
| 125 } | 125 } |
| 126 | 126 |
| 127 /** | 127 /** |
| (...skipping 13 matching lines...) Expand all Loading... |
| 141 activity1.getIntent(), activity1)); | 141 activity1.getIntent(), activity1)); |
| 142 } | 142 } |
| 143 | 143 |
| 144 /** | 144 /** |
| 145 * Tests that MultiWindowUtils properly tracks whether ChromeTabbedActivity2
is running. | 145 * Tests that MultiWindowUtils properly tracks whether ChromeTabbedActivity2
is running. |
| 146 */ | 146 */ |
| 147 @SmallTest | 147 @SmallTest |
| 148 @Feature("MultiWindow") | 148 @Feature("MultiWindow") |
| 149 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 149 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
| 150 public void testTabbedActivity2TaskRunning() throws InterruptedException { | 150 public void testTabbedActivity2TaskRunning() throws InterruptedException { |
| 151 ChromeTabbedActivity activity2 = createSecondChromeTabbedActivity(); | 151 ChromeTabbedActivity activity2 = createSecondChromeTabbedActivity(getAct
ivity()); |
| 152 assertTrue(MultiWindowUtils.getInstance().getTabbedActivity2TaskRunning(
)); | 152 assertTrue(MultiWindowUtils.getInstance().getTabbedActivity2TaskRunning(
)); |
| 153 | 153 |
| 154 activity2.finishAndRemoveTask(); | 154 activity2.finishAndRemoveTask(); |
| 155 MultiWindowUtils.getInstance().getTabbedActivityForIntent( | 155 MultiWindowUtils.getInstance().getTabbedActivityForIntent( |
| 156 getActivity().getIntent(), getActivity()); | 156 getActivity().getIntent(), getActivity()); |
| 157 assertFalse(MultiWindowUtils.getInstance().getTabbedActivity2TaskRunning
()); | 157 assertFalse(MultiWindowUtils.getInstance().getTabbedActivity2TaskRunning
()); |
| 158 } | 158 } |
| 159 | 159 |
| 160 private ChromeTabbedActivity2 createSecondChromeTabbedActivity() throws Inte
rruptedException { | 160 public static ChromeTabbedActivity2 createSecondChromeTabbedActivity(Activit
y activity) |
| 161 throws InterruptedException { |
| 161 // TODO(twellington): after there is test support for putting an activit
y into multi-window | 162 // TODO(twellington): after there is test support for putting an activit
y into multi-window |
| 162 // mode, this should be changed to use the menu item for opening a new w
indow. | 163 // mode, this should be changed to use the menu item for opening a new w
indow. |
| 163 | 164 |
| 164 // Number of expected activities after the second ChromeTabbedActivity i
s created. | 165 // Number of expected activities after the second ChromeTabbedActivity i
s created. |
| 165 int numExpectedActivities = ApplicationStatus.getRunningActivities().siz
e() + 1; | 166 int numExpectedActivities = ApplicationStatus.getRunningActivities().siz
e() + 1; |
| 166 | 167 |
| 167 // Get the class name to use for the second ChromeTabbedActivity. This s
tep is important | 168 // Get the class name to use for the second ChromeTabbedActivity. This s
tep is important |
| 168 // for initializing things in MultiWindowUtils.java. | 169 // for initializing things in MultiWindowUtils.java. |
| 169 ChromeTabbedActivity activity = getActivity(); | |
| 170 Class<? extends Activity> secondActivityClass = | 170 Class<? extends Activity> secondActivityClass = |
| 171 MultiWindowUtils.getInstance().getOpenInOtherWindowActivity(acti
vity); | 171 MultiWindowUtils.getInstance().getOpenInOtherWindowActivity(acti
vity); |
| 172 assertEquals("ChromeTabbedActivity2 should be used as the 'open in other
window' activity.", | 172 assertEquals("ChromeTabbedActivity2 should be used as the 'open in other
window' activity.", |
| 173 ChromeTabbedActivity2.class, secondActivityClass); | 173 ChromeTabbedActivity2.class, secondActivityClass); |
| 174 | 174 |
| 175 // Create an intent and start the second ChromeTabbedActivity. | 175 // Create an intent and start the second ChromeTabbedActivity. |
| 176 Intent intent = new Intent(activity.getIntent()); | 176 Intent intent = new Intent(activity.getIntent()); |
| 177 intent.setClass(activity, secondActivityClass); | 177 intent.setClass(activity, secondActivityClass); |
| 178 activity.startActivity(intent); | 178 activity.startActivity(intent); |
| 179 | 179 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 191 Activity runningActivity = reference.get(); | 191 Activity runningActivity = reference.get(); |
| 192 if (runningActivity == null) continue; | 192 if (runningActivity == null) continue; |
| 193 if (runningActivity.getClass().equals(ChromeTabbedActivity2.class))
{ | 193 if (runningActivity.getClass().equals(ChromeTabbedActivity2.class))
{ |
| 194 returnActivity = (ChromeTabbedActivity2) runningActivity; | 194 returnActivity = (ChromeTabbedActivity2) runningActivity; |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 assertTrue(returnActivity != null); | 197 assertTrue(returnActivity != null); |
| 198 return returnActivity; | 198 return returnActivity; |
| 199 } | 199 } |
| 200 } | 200 } |
| OLD | NEW |