| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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.compositor.layouts; | 5 package org.chromium.chrome.browser.compositor.layouts; |
| 6 | 6 |
| 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E
ND_DEVICE; | 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E
ND_DEVICE; |
| 8 | 8 |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.graphics.PointF; | 10 import android.graphics.PointF; |
| 11 import android.support.test.InstrumentationRegistry; |
| 12 import android.support.test.annotation.UiThreadTest; |
| 11 import android.support.test.filters.SmallTest; | 13 import android.support.test.filters.SmallTest; |
| 12 import android.test.InstrumentationTestCase; | 14 import android.support.test.rule.UiThreadTestRule; |
| 13 import android.util.Log; | 15 import android.util.Log; |
| 14 import android.view.MotionEvent; | 16 import android.view.MotionEvent; |
| 15 import android.view.MotionEvent.PointerCoords; | 17 import android.view.MotionEvent.PointerCoords; |
| 16 import android.view.MotionEvent.PointerProperties; | 18 import android.view.MotionEvent.PointerProperties; |
| 17 import android.widget.FrameLayout; | 19 import android.widget.FrameLayout; |
| 18 | 20 |
| 21 import org.junit.Assert; |
| 22 import org.junit.Before; |
| 23 import org.junit.Rule; |
| 24 import org.junit.Test; |
| 25 import org.junit.runner.RunWith; |
| 26 |
| 19 import org.chromium.base.ThreadUtils; | 27 import org.chromium.base.ThreadUtils; |
| 20 import org.chromium.base.library_loader.ProcessInitException; | 28 import org.chromium.base.library_loader.ProcessInitException; |
| 21 import org.chromium.base.test.util.Feature; | 29 import org.chromium.base.test.util.Feature; |
| 22 import org.chromium.base.test.util.Restriction; | 30 import org.chromium.base.test.util.Restriction; |
| 23 import org.chromium.chrome.browser.compositor.layouts.components.LayoutTab; | 31 import org.chromium.chrome.browser.compositor.layouts.components.LayoutTab; |
| 24 import org.chromium.chrome.browser.compositor.layouts.eventfilter.EdgeSwipeEvent
Filter.ScrollDirection; | 32 import org.chromium.chrome.browser.compositor.layouts.eventfilter.EdgeSwipeEvent
Filter.ScrollDirection; |
| 25 import org.chromium.chrome.browser.compositor.layouts.eventfilter.EdgeSwipeHandl
er; | 33 import org.chromium.chrome.browser.compositor.layouts.eventfilter.EdgeSwipeHandl
er; |
| 26 import org.chromium.chrome.browser.compositor.layouts.eventfilter.EventFilter; | 34 import org.chromium.chrome.browser.compositor.layouts.eventfilter.EventFilter; |
| 27 import org.chromium.chrome.browser.compositor.layouts.phone.StackLayout; | 35 import org.chromium.chrome.browser.compositor.layouts.phone.StackLayout; |
| 28 import org.chromium.chrome.browser.compositor.layouts.phone.stack.Stack; | 36 import org.chromium.chrome.browser.compositor.layouts.phone.stack.Stack; |
| 29 import org.chromium.chrome.browser.compositor.layouts.phone.stack.StackTab; | 37 import org.chromium.chrome.browser.compositor.layouts.phone.stack.StackTab; |
| 30 import org.chromium.chrome.browser.init.ChromeBrowserInitializer; | 38 import org.chromium.chrome.browser.init.ChromeBrowserInitializer; |
| 31 import org.chromium.chrome.browser.tab.Tab; | 39 import org.chromium.chrome.browser.tab.Tab; |
| 32 import org.chromium.chrome.browser.tabmodel.TabModel; | 40 import org.chromium.chrome.browser.tabmodel.TabModel; |
| 33 import org.chromium.chrome.browser.tabmodel.TabModelSelector; | 41 import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
| 34 import org.chromium.chrome.browser.tabmodel.TabModelUtils; | 42 import org.chromium.chrome.browser.tabmodel.TabModelUtils; |
| 35 import org.chromium.chrome.browser.util.MathUtils; | 43 import org.chromium.chrome.browser.util.MathUtils; |
| 44 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
| 36 import org.chromium.chrome.test.util.ChromeRestriction; | 45 import org.chromium.chrome.test.util.ChromeRestriction; |
| 37 import org.chromium.chrome.test.util.browser.tabmodel.MockTabModel.MockTabModelD
elegate; | 46 import org.chromium.chrome.test.util.browser.tabmodel.MockTabModel.MockTabModelD
elegate; |
| 38 import org.chromium.chrome.test.util.browser.tabmodel.MockTabModelSelector; | 47 import org.chromium.chrome.test.util.browser.tabmodel.MockTabModelSelector; |
| 39 | 48 |
| 40 /** | 49 /** |
| 41 * Unit tests for {@link org.chromium.chrome.browser.compositor.layouts.LayoutMa
nagerChrome} | 50 * Unit tests for {@link org.chromium.chrome.browser.compositor.layouts.LayoutMa
nagerChrome} |
| 42 */ | 51 */ |
| 43 public class LayoutManagerTest extends InstrumentationTestCase | 52 @RunWith(ChromeJUnit4ClassRunner.class) |
| 44 implements MockTabModelDelegate { | 53 public class LayoutManagerTest implements MockTabModelDelegate { |
| 45 private static final String TAG = "LayoutManagerTest"; | 54 private static final String TAG = "LayoutManagerTest"; |
| 46 | 55 |
| 47 private long mLastDownTime = 0; | 56 private long mLastDownTime = 0; |
| 48 | 57 |
| 49 private TabModelSelector mTabModelSelector; | 58 private TabModelSelector mTabModelSelector; |
| 50 private LayoutManagerChrome mManager; | 59 private LayoutManagerChrome mManager; |
| 51 private LayoutManagerChromePhone mManagerPhone; | 60 private LayoutManagerChromePhone mManagerPhone; |
| 52 | 61 |
| 53 private final PointerProperties[] mProperties = new PointerProperties[2]; | 62 private final PointerProperties[] mProperties = new PointerProperties[2]; |
| 54 private final PointerCoords[] mPointerCoords = new PointerCoords[2]; | 63 private final PointerCoords[] mPointerCoords = new PointerCoords[2]; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 68 mPointerCoords[0].y = 0; | 77 mPointerCoords[0].y = 0; |
| 69 mPointerCoords[0].pressure = 1; | 78 mPointerCoords[0].pressure = 1; |
| 70 mPointerCoords[0].size = 1; | 79 mPointerCoords[0].size = 1; |
| 71 mPointerCoords[1] = new PointerCoords(); | 80 mPointerCoords[1] = new PointerCoords(); |
| 72 mPointerCoords[1].x = 0; | 81 mPointerCoords[1].x = 0; |
| 73 mPointerCoords[1].y = 0; | 82 mPointerCoords[1].y = 0; |
| 74 mPointerCoords[1].pressure = 1; | 83 mPointerCoords[1].pressure = 1; |
| 75 mPointerCoords[1].size = 1; | 84 mPointerCoords[1].size = 1; |
| 76 } | 85 } |
| 77 | 86 |
| 87 @Rule |
| 88 public UiThreadTestRule mRule = new UiThreadTestRule(); |
| 89 |
| 78 /** | 90 /** |
| 79 * Simulates time so the animation updates. | 91 * Simulates time so the animation updates. |
| 80 * @param layoutManager The {@link LayoutManagerChrome} to update. | 92 * @param layoutManager The {@link LayoutManagerChrome} to update. |
| 81 * @param maxFrameCount The maximum number of frames to simulate before the
motion ends. | 93 * @param maxFrameCount The maximum number of frames to simulate before the
motion ends. |
| 82 * @return Whether the maximum number of frames was enough for
the | 94 * @return Whether the maximum number of frames was enough for
the |
| 83 * {@link LayoutManagerChrome} to reach the end of the
animations. | 95 * {@link LayoutManagerChrome} to reach the end of the
animations. |
| 84 */ | 96 */ |
| 85 private static boolean simulateTime(LayoutManagerChrome layoutManager, int m
axFrameCount) { | 97 private static boolean simulateTime(LayoutManagerChrome layoutManager, int m
axFrameCount) { |
| 86 // Simulating time | 98 // Simulating time |
| 87 int frame = 0; | 99 int frame = 0; |
| 88 long time = 0; | 100 long time = 0; |
| 89 final long dt = 16; | 101 final long dt = 16; |
| 90 while (layoutManager.onUpdate(time, dt) && frame < maxFrameCount) { | 102 while (layoutManager.onUpdate(time, dt) && frame < maxFrameCount) { |
| 91 time += dt; | 103 time += dt; |
| 92 frame++; | 104 frame++; |
| 93 } | 105 } |
| 94 Log.w(TAG, "simulateTime frame " + frame); | 106 Log.w(TAG, "simulateTime frame " + frame); |
| 95 return frame < maxFrameCount; | 107 return frame < maxFrameCount; |
| 96 } | 108 } |
| 97 | 109 |
| 98 private void initializeLayoutManagerPhone(int standardTabCount, int incognit
oTabCount) { | 110 private void initializeLayoutManagerPhone(int standardTabCount, int incognit
oTabCount) { |
| 99 initializeLayoutManagerPhone(standardTabCount, incognitoTabCount, | 111 initializeLayoutManagerPhone(standardTabCount, incognitoTabCount, |
| 100 TabModel.INVALID_TAB_INDEX, TabModel.INVALID_TAB_INDEX, false); | 112 TabModel.INVALID_TAB_INDEX, TabModel.INVALID_TAB_INDEX, false); |
| 101 } | 113 } |
| 102 | 114 |
| 103 private void initializeLayoutManagerPhone(int standardTabCount, int incognit
oTabCount, | 115 private void initializeLayoutManagerPhone(int standardTabCount, int incognit
oTabCount, |
| 104 int standardIndexSelected, int incognitoIndexSelected, boolean incog
nitoSelected) { | 116 int standardIndexSelected, int incognitoIndexSelected, boolean incog
nitoSelected) { |
| 105 Context context = new MockContextForLayout(getInstrumentation().getConte
xt()); | 117 Context context = |
| 118 new MockContextForLayout(InstrumentationRegistry.getInstrumentat
ion().getContext()); |
| 106 | 119 |
| 107 mDpToPx = context.getResources().getDisplayMetrics().density; | 120 mDpToPx = context.getResources().getDisplayMetrics().density; |
| 108 | 121 |
| 109 mTabModelSelector = new MockTabModelSelector(standardTabCount, incognito
TabCount, this); | 122 mTabModelSelector = new MockTabModelSelector(standardTabCount, incognito
TabCount, this); |
| 110 if (standardIndexSelected != TabModel.INVALID_TAB_INDEX) { | 123 if (standardIndexSelected != TabModel.INVALID_TAB_INDEX) { |
| 111 TabModelUtils.setIndex(mTabModelSelector.getModel(false), standardIn
dexSelected); | 124 TabModelUtils.setIndex(mTabModelSelector.getModel(false), standardIn
dexSelected); |
| 112 } | 125 } |
| 113 if (incognitoIndexSelected != TabModel.INVALID_TAB_INDEX) { | 126 if (incognitoIndexSelected != TabModel.INVALID_TAB_INDEX) { |
| 114 TabModelUtils.setIndex(mTabModelSelector.getModel(true), incognitoIn
dexSelected); | 127 TabModelUtils.setIndex(mTabModelSelector.getModel(true), incognitoIn
dexSelected); |
| 115 } | 128 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 135 } | 148 } |
| 136 | 149 |
| 137 private void eventDown(long time, PointF p) { | 150 private void eventDown(long time, PointF p) { |
| 138 mLastDownTime = time; | 151 mLastDownTime = time; |
| 139 | 152 |
| 140 mPointerCoords[0].x = p.x * mDpToPx; | 153 mPointerCoords[0].x = p.x * mDpToPx; |
| 141 mPointerCoords[0].y = p.y * mDpToPx; | 154 mPointerCoords[0].y = p.y * mDpToPx; |
| 142 | 155 |
| 143 MotionEvent event = MotionEvent.obtain(mLastDownTime, time, MotionEvent.
ACTION_DOWN, | 156 MotionEvent event = MotionEvent.obtain(mLastDownTime, time, MotionEvent.
ACTION_DOWN, |
| 144 1, mProperties, mPointerCoords, 0, 0, 1, 1, 0, 0, 0, 0); | 157 1, mProperties, mPointerCoords, 0, 0, 1, 1, 0, 0, 0, 0); |
| 145 assertTrue("Down event not intercepted", mManager.onInterceptTouchEvent(
event, false)); | 158 Assert.assertTrue( |
| 146 assertTrue("Down event not handled", mManager.onTouchEvent(event)); | 159 "Down event not intercepted", mManager.onInterceptTouchEvent(eve
nt, false)); |
| 160 Assert.assertTrue("Down event not handled", mManager.onTouchEvent(event)
); |
| 147 } | 161 } |
| 148 | 162 |
| 149 private void eventDown1(long time, PointF p) { | 163 private void eventDown1(long time, PointF p) { |
| 150 mPointerCoords[1].x = p.x * mDpToPx; | 164 mPointerCoords[1].x = p.x * mDpToPx; |
| 151 mPointerCoords[1].y = p.y * mDpToPx; | 165 mPointerCoords[1].y = p.y * mDpToPx; |
| 152 | 166 |
| 153 assertTrue("Down_1 event not handled", mManager.onTouchEvent( | 167 Assert.assertTrue("Down_1 event not handled", |
| 154 MotionEvent.obtain(mLastDownTime, time, | 168 mManager.onTouchEvent(MotionEvent.obtain(mLastDownTime, time, |
| 155 MotionEvent.ACTION_POINTER_DOWN | (0x1 << MotionEvent.ACTION_POI
NTER_INDEX_SHIFT), | 169 MotionEvent.ACTION_POINTER_DOWN |
| 156 2, mProperties, mPointerCoords, 0, 0, 1, 1, 0, 0, 0, 0))); | 170 | (0x1 << MotionEvent.ACTION_POINTER_INDEX_SHIFT
), |
| 171 2, mProperties, mPointerCoords, 0, 0, 1, 1, 0, 0, 0, 0))
); |
| 157 } | 172 } |
| 158 | 173 |
| 159 private void eventMove(long time, PointF p) { | 174 private void eventMove(long time, PointF p) { |
| 160 mPointerCoords[0].x = p.x * mDpToPx; | 175 mPointerCoords[0].x = p.x * mDpToPx; |
| 161 mPointerCoords[0].y = p.y * mDpToPx; | 176 mPointerCoords[0].y = p.y * mDpToPx; |
| 162 | 177 |
| 163 assertTrue("Move event not handled", mManager.onTouchEvent( | 178 Assert.assertTrue("Move event not handled", |
| 164 MotionEvent.obtain(mLastDownTime, time, MotionEvent.ACTION_MOVE, | 179 mManager.onTouchEvent( |
| 165 1, mProperties, mPointerCoords, 0, 0, 1, 1, 0, 0, 0, 0))); | 180 MotionEvent.obtain(mLastDownTime, time, MotionEvent.ACTI
ON_MOVE, 1, |
| 181 mProperties, mPointerCoords, 0, 0, 1, 1, 0, 0, 0
, 0))); |
| 166 } | 182 } |
| 167 | 183 |
| 168 private void eventUp(long time, PointF p) { | 184 private void eventUp(long time, PointF p) { |
| 169 mPointerCoords[0].x = p.x * mDpToPx; | 185 mPointerCoords[0].x = p.x * mDpToPx; |
| 170 mPointerCoords[0].y = p.y * mDpToPx; | 186 mPointerCoords[0].y = p.y * mDpToPx; |
| 171 | 187 |
| 172 assertTrue("Up event not handled", mManager.onTouchEvent( | 188 Assert.assertTrue("Up event not handled", |
| 173 MotionEvent.obtain(mLastDownTime, time, MotionEvent.ACTION_UP, | 189 mManager.onTouchEvent(MotionEvent.obtain(mLastDownTime, time, Mo
tionEvent.ACTION_UP, |
| 174 1, mProperties, mPointerCoords, 0, 0, 1, 1, 0, 0, 0, 0))); | 190 1, mProperties, mPointerCoords, 0, 0, 1, 1, 0, 0, 0, 0))
); |
| 175 } | 191 } |
| 176 | 192 |
| 177 private void eventUp1(long time, PointF p) { | 193 private void eventUp1(long time, PointF p) { |
| 178 mPointerCoords[1].x = p.x * mDpToPx; | 194 mPointerCoords[1].x = p.x * mDpToPx; |
| 179 mPointerCoords[1].y = p.y * mDpToPx; | 195 mPointerCoords[1].y = p.y * mDpToPx; |
| 180 | 196 |
| 181 assertTrue("Up_1 event not handled", mManager.onTouchEvent( | 197 Assert.assertTrue("Up_1 event not handled", |
| 182 MotionEvent.obtain(mLastDownTime, time, | 198 mManager.onTouchEvent(MotionEvent.obtain(mLastDownTime, time, |
| 183 MotionEvent.ACTION_POINTER_UP | (0x1 << MotionEvent.ACTION_POINT
ER_INDEX_SHIFT), | 199 MotionEvent.ACTION_POINTER_UP |
| 184 2, mProperties, mPointerCoords, 0, 0, 1, 1, 0, 0, 0, 0))); | 200 | (0x1 << MotionEvent.ACTION_POINTER_INDEX_SHIFT
), |
| 201 2, mProperties, mPointerCoords, 0, 0, 1, 1, 0, 0, 0, 0))
); |
| 185 } | 202 } |
| 186 | 203 |
| 187 private void eventMoveBoth(long time, PointF p0, PointF p1) { | 204 private void eventMoveBoth(long time, PointF p0, PointF p1) { |
| 188 mPointerCoords[0].x = p0.x * mDpToPx; | 205 mPointerCoords[0].x = p0.x * mDpToPx; |
| 189 mPointerCoords[0].y = p0.y * mDpToPx; | 206 mPointerCoords[0].y = p0.y * mDpToPx; |
| 190 mPointerCoords[1].x = p1.x * mDpToPx; | 207 mPointerCoords[1].x = p1.x * mDpToPx; |
| 191 mPointerCoords[1].y = p1.y * mDpToPx; | 208 mPointerCoords[1].y = p1.y * mDpToPx; |
| 192 | 209 |
| 193 assertTrue("Move event not handled", mManager.onTouchEvent( | 210 Assert.assertTrue("Move event not handled", |
| 194 MotionEvent.obtain(mLastDownTime, time, MotionEvent.ACTION_MOVE,
2, | 211 mManager.onTouchEvent( |
| 195 mProperties, mPointerCoords, 0, 0, 1, 1, 0, 0, 0, 0))); | 212 MotionEvent.obtain(mLastDownTime, time, MotionEvent.ACTI
ON_MOVE, 2, |
| 213 mProperties, mPointerCoords, 0, 0, 1, 1, 0, 0, 0
, 0))); |
| 196 } | 214 } |
| 197 | 215 |
| 216 @Test |
| 198 @SmallTest | 217 @SmallTest |
| 199 @Feature({"Android-TabSwitcher"}) | 218 @Feature({"Android-TabSwitcher"}) |
| 219 @UiThreadTest |
| 200 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) | 220 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) |
| 201 public void testCreation() { | 221 public void testCreation() { |
| 202 initializeLayoutManagerPhone(0, 0); | 222 initializeLayoutManagerPhone(0, 0); |
| 203 } | 223 } |
| 204 | 224 |
| 225 @Test |
| 205 @SmallTest | 226 @SmallTest |
| 206 @Feature({"Android-TabSwitcher"}) | 227 @Feature({"Android-TabSwitcher"}) |
| 228 @UiThreadTest |
| 207 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) | 229 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) |
| 208 public void testStack() throws Exception { | 230 public void testStack() throws Exception { |
| 209 initializeLayoutManagerPhone(3, 0); | 231 initializeLayoutManagerPhone(3, 0); |
| 210 mManagerPhone.showOverview(true); | 232 mManagerPhone.showOverview(true); |
| 211 assertTrue("layoutManager is way too long to end motion", simulateTime(m
Manager, 1000)); | 233 Assert.assertTrue( |
| 212 assertTrue("The activate layout type is expected to be StackLayout", | 234 "layoutManager is way too long to end motion", simulateTime(mMan
ager, 1000)); |
| 235 Assert.assertTrue("The activate layout type is expected to be StackLayou
t", |
| 213 mManager.getActiveLayout() instanceof StackLayout); | 236 mManager.getActiveLayout() instanceof StackLayout); |
| 214 mManagerPhone.hideOverview(true); | 237 mManagerPhone.hideOverview(true); |
| 215 assertTrue("layoutManager is way too long to end motion", simulateTime(m
Manager, 1000)); | 238 Assert.assertTrue( |
| 239 "layoutManager is way too long to end motion", simulateTime(mMan
ager, 1000)); |
| 216 } | 240 } |
| 217 | 241 |
| 242 @Test |
| 218 @SmallTest | 243 @SmallTest |
| 219 @Feature({"Android-TabSwitcher"}) | 244 @Feature({"Android-TabSwitcher"}) |
| 245 @UiThreadTest |
| 220 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) | 246 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) |
| 221 public void testStackNoAnimation() throws Exception { | 247 public void testStackNoAnimation() throws Exception { |
| 222 initializeLayoutManagerPhone(1, 0); | 248 initializeLayoutManagerPhone(1, 0); |
| 223 mManagerPhone.showOverview(false); | 249 mManagerPhone.showOverview(false); |
| 224 assertTrue("The activate layout type is expected to be StackLayout", | 250 Assert.assertTrue("The activate layout type is expected to be StackLayou
t", |
| 225 mManager.getActiveLayout() instanceof StackLayout); | 251 mManager.getActiveLayout() instanceof StackLayout); |
| 226 mManagerPhone.hideOverview(false); | 252 mManagerPhone.hideOverview(false); |
| 227 } | 253 } |
| 228 | 254 |
| 229 /** | 255 /** |
| 230 * Tests the tab pinching behavior with two finger. | 256 * Tests the tab pinching behavior with two finger. |
| 231 * This test is still under development. | 257 * This test is still under development. |
| 232 */ | 258 */ |
| 259 @Test |
| 233 @SmallTest | 260 @SmallTest |
| 234 @Feature({"Android-TabSwitcher"}) | 261 @Feature({"Android-TabSwitcher"}) |
| 262 @UiThreadTest |
| 235 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) | 263 @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON
_LOW_END_DEVICE}) |
| 236 public void testStackPinch() throws Exception { | 264 public void testStackPinch() throws Exception { |
| 237 initializeLayoutManagerPhone(5, 0); | 265 initializeLayoutManagerPhone(5, 0); |
| 238 // Setting the index to the second to last element ensure the stack can
be scrolled in both | 266 // Setting the index to the second to last element ensure the stack can
be scrolled in both |
| 239 // directions. | 267 // directions. |
| 240 mManager.tabSelected(mTabModelSelector.getCurrentModel().getTabAt(3).get
Id(), | 268 mManager.tabSelected(mTabModelSelector.getCurrentModel().getTabAt(3).get
Id(), |
| 241 Tab.INVALID_TAB_ID, false); | 269 Tab.INVALID_TAB_ID, false); |
| 242 | 270 |
| 243 mManagerPhone.showOverview(false); | 271 mManagerPhone.showOverview(false); |
| 244 // Basic verifications | 272 // Basic verifications |
| 245 assertTrue("The activate layout type is expected to be StackLayout", | 273 Assert.assertTrue("The activate layout type is expected to be StackLayou
t", |
| 246 mManager.getActiveLayout() instanceof StackLayout); | 274 mManager.getActiveLayout() instanceof StackLayout); |
| 247 | 275 |
| 248 StackLayout layout = (StackLayout) mManager.getActiveLayout(); | 276 StackLayout layout = (StackLayout) mManager.getActiveLayout(); |
| 249 Stack stack = layout.getTabStack(false); | 277 Stack stack = layout.getTabStack(false); |
| 250 StackTab[] tabs = stack.getTabs(); | 278 StackTab[] tabs = stack.getTabs(); |
| 251 | 279 |
| 252 long time = 0; | 280 long time = 0; |
| 253 // At least one update is necessary to get updated positioning of Layout
Tabs. | 281 // At least one update is necessary to get updated positioning of Layout
Tabs. |
| 254 mManager.onUpdate(time, 16); | 282 mManager.onUpdate(time, 16); |
| 255 time++; | 283 time++; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 285 float expectedTab1Y = tab1.getY(); | 313 float expectedTab1Y = tab1.getY(); |
| 286 | 314 |
| 287 // Initiate the pinch with finger 1 | 315 // Initiate the pinch with finger 1 |
| 288 PointF finger1 = new PointF(tab3.getX() + tab3.getFinalContentWidth() /
2, | 316 PointF finger1 = new PointF(tab3.getX() + tab3.getFinalContentWidth() /
2, |
| 289 tab3.getY() + fingerOffset); | 317 tab3.getY() + fingerOffset); |
| 290 eventDown1(time, finger1); | 318 eventDown1(time, finger1); |
| 291 mManager.onUpdate(time, 16); | 319 mManager.onUpdate(time, 16); |
| 292 time++; | 320 time++; |
| 293 | 321 |
| 294 final float delta = 0.001f; | 322 final float delta = 0.001f; |
| 295 assertEquals("Wrong x offset for tab 1", expectedTab1X, tab1.getX(), del
ta); | 323 Assert.assertEquals("Wrong x offset for tab 1", expectedTab1X, tab1.getX
(), delta); |
| 296 assertEquals("Wrong y offset for tab 1", expectedTab1Y, tab1.getY(), del
ta); | 324 Assert.assertEquals("Wrong y offset for tab 1", expectedTab1Y, tab1.getY
(), delta); |
| 297 float expectedTab3X = tab3.getX(); | 325 float expectedTab3X = tab3.getX(); |
| 298 float expectedTab3Y = tab3.getY(); | 326 float expectedTab3Y = tab3.getY(); |
| 299 | 327 |
| 300 // Move Finger 0: Y only | 328 // Move Finger 0: Y only |
| 301 finger0.y += scrollOffset1; | 329 finger0.y += scrollOffset1; |
| 302 expectedTab1Y += scrollOffset1; | 330 expectedTab1Y += scrollOffset1; |
| 303 | 331 |
| 304 eventMoveBoth(time, finger0, finger1); | 332 eventMoveBoth(time, finger0, finger1); |
| 305 mManager.onUpdate(time, 16); | 333 mManager.onUpdate(time, 16); |
| 306 time++; | 334 time++; |
| 307 | 335 |
| 308 assertEquals("Wrong x offset for tab 1", expectedTab1X, tab1.getX(), del
ta); | 336 Assert.assertEquals("Wrong x offset for tab 1", expectedTab1X, tab1.getX
(), delta); |
| 309 assertEquals("Wrong y offset for tab 1", expectedTab1Y, tab1.getY(), del
ta); | 337 Assert.assertEquals("Wrong y offset for tab 1", expectedTab1Y, tab1.getY
(), delta); |
| 310 assertEquals("Wrong x offset for tab 3", expectedTab3X, tab3.getX(), del
ta); | 338 Assert.assertEquals("Wrong x offset for tab 3", expectedTab3X, tab3.getX
(), delta); |
| 311 assertEquals("Wrong y offset for tab 3", expectedTab3Y, tab3.getY(), del
ta); | 339 Assert.assertEquals("Wrong y offset for tab 3", expectedTab3Y, tab3.getY
(), delta); |
| 312 | 340 |
| 313 // Move finger 0: Y and X | 341 // Move finger 0: Y and X |
| 314 finger0.y += scrollOffset1; | 342 finger0.y += scrollOffset1; |
| 315 finger0.x += tab1.getFinalContentWidth() / 8.0f; | 343 finger0.x += tab1.getFinalContentWidth() / 8.0f; |
| 316 expectedTab1Y += scrollOffset1; | 344 expectedTab1Y += scrollOffset1; |
| 317 | 345 |
| 318 eventMoveBoth(time, finger0, finger1); | 346 eventMoveBoth(time, finger0, finger1); |
| 319 mManager.onUpdate(time, 16); | 347 mManager.onUpdate(time, 16); |
| 320 time++; | 348 time++; |
| 321 | 349 |
| 322 assertEquals("Wrong x offset for tab 1", expectedTab1X, tab1.getX(), del
ta); | 350 Assert.assertEquals("Wrong x offset for tab 1", expectedTab1X, tab1.getX
(), delta); |
| 323 assertEquals("Wrong y offset for tab 1", expectedTab1Y, tab1.getY(), del
ta); | 351 Assert.assertEquals("Wrong y offset for tab 1", expectedTab1Y, tab1.getY
(), delta); |
| 324 assertEquals("Wrong x offset for tab 3", expectedTab3X, tab3.getX(), del
ta); | 352 Assert.assertEquals("Wrong x offset for tab 3", expectedTab3X, tab3.getX
(), delta); |
| 325 assertEquals("Wrong y offset for tab 3", expectedTab3Y, tab3.getY(), del
ta); | 353 Assert.assertEquals("Wrong y offset for tab 3", expectedTab3Y, tab3.getY
(), delta); |
| 326 | 354 |
| 327 // Move finger 1: Y and X | 355 // Move finger 1: Y and X |
| 328 final float scrollOffset3 = (tab3.getY() - layout.getHeight()) / 8.0f; | 356 final float scrollOffset3 = (tab3.getY() - layout.getHeight()) / 8.0f; |
| 329 finger1.y += scrollOffset3; | 357 finger1.y += scrollOffset3; |
| 330 finger1.x += tab3.getFinalContentWidth() / 8.0f; | 358 finger1.x += tab3.getFinalContentWidth() / 8.0f; |
| 331 expectedTab3Y += scrollOffset3; | 359 expectedTab3Y += scrollOffset3; |
| 332 | 360 |
| 333 eventMoveBoth(time, finger0, finger1); | 361 eventMoveBoth(time, finger0, finger1); |
| 334 mManager.onUpdate(time, 16); | 362 mManager.onUpdate(time, 16); |
| 335 time++; | 363 time++; |
| 336 | 364 |
| 337 assertEquals("Wrong x offset for tab 1", expectedTab1X, tab1.getX(), del
ta); | 365 Assert.assertEquals("Wrong x offset for tab 1", expectedTab1X, tab1.getX
(), delta); |
| 338 assertEquals("Wrong y offset for tab 1", expectedTab1Y, tab1.getY(), del
ta); | 366 Assert.assertEquals("Wrong y offset for tab 1", expectedTab1Y, tab1.getY
(), delta); |
| 339 assertEquals("Wrong x offset for tab 3", expectedTab3X, tab3.getX(), del
ta); | 367 Assert.assertEquals("Wrong x offset for tab 3", expectedTab3X, tab3.getX
(), delta); |
| 340 assertEquals("Wrong y offset for tab 3", expectedTab3Y, tab3.getY(), del
ta); | 368 Assert.assertEquals("Wrong y offset for tab 3", expectedTab3Y, tab3.getY
(), delta); |
| 341 | 369 |
| 342 // Move finger 0 and 1: Y and X | 370 // Move finger 0 and 1: Y and X |
| 343 finger0.y += scrollOffset1; | 371 finger0.y += scrollOffset1; |
| 344 finger0.x += tab1.getFinalContentWidth() / 8.0f; | 372 finger0.x += tab1.getFinalContentWidth() / 8.0f; |
| 345 expectedTab1Y += scrollOffset1; | 373 expectedTab1Y += scrollOffset1; |
| 346 finger1.y += scrollOffset3; | 374 finger1.y += scrollOffset3; |
| 347 finger1.x += tab3.getFinalContentWidth() / 8.0f; | 375 finger1.x += tab3.getFinalContentWidth() / 8.0f; |
| 348 expectedTab3Y += scrollOffset3; | 376 expectedTab3Y += scrollOffset3; |
| 349 | 377 |
| 350 eventMoveBoth(time, finger0, finger1); | 378 eventMoveBoth(time, finger0, finger1); |
| 351 mManager.onUpdate(time, 16); | 379 mManager.onUpdate(time, 16); |
| 352 time++; | 380 time++; |
| 353 | 381 |
| 354 assertEquals("Wrong x offset for tab 1", expectedTab1X, tab1.getX(), del
ta); | 382 Assert.assertEquals("Wrong x offset for tab 1", expectedTab1X, tab1.getX
(), delta); |
| 355 assertEquals("Wrong y offset for tab 1", expectedTab1Y, tab1.getY(), del
ta); | 383 Assert.assertEquals("Wrong y offset for tab 1", expectedTab1Y, tab1.getY
(), delta); |
| 356 assertEquals("Wrong x offset for tab 3", expectedTab3X, tab3.getX(), del
ta); | 384 Assert.assertEquals("Wrong x offset for tab 3", expectedTab3X, tab3.getX
(), delta); |
| 357 assertEquals("Wrong y offset for tab 3", expectedTab3Y, tab3.getY(), del
ta); | 385 Assert.assertEquals("Wrong y offset for tab 3", expectedTab3Y, tab3.getY
(), delta); |
| 358 | 386 |
| 359 // Done | 387 // Done |
| 360 eventUp1(time, finger1); | 388 eventUp1(time, finger1); |
| 361 eventUp(time, finger0); | 389 eventUp(time, finger0); |
| 362 | 390 |
| 363 assertEquals("Wrong x offset for tab 1", expectedTab1X, tab1.getX(), del
ta); | 391 Assert.assertEquals("Wrong x offset for tab 1", expectedTab1X, tab1.getX
(), delta); |
| 364 assertEquals("Wrong y offset for tab 1", expectedTab1Y, tab1.getY(), del
ta); | 392 Assert.assertEquals("Wrong y offset for tab 1", expectedTab1Y, tab1.getY
(), delta); |
| 365 assertEquals("Wrong x offset for tab 3", expectedTab3X, tab3.getX(), del
ta); | 393 Assert.assertEquals("Wrong x offset for tab 3", expectedTab3X, tab3.getX
(), delta); |
| 366 assertEquals("Wrong y offset for tab 3", expectedTab3Y, tab3.getY(), del
ta); | 394 Assert.assertEquals("Wrong y offset for tab 3", expectedTab3Y, tab3.getY
(), delta); |
| 367 | 395 |
| 368 mManagerPhone.hideOverview(false); | 396 mManagerPhone.hideOverview(false); |
| 369 } | 397 } |
| 370 | 398 |
| 399 @Test |
| 371 @SmallTest | 400 @SmallTest |
| 372 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 401 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
| 373 @Feature({"Android-TabSwitcher"}) | 402 @Feature({"Android-TabSwitcher"}) |
| 403 @UiThreadTest |
| 374 public void testToolbarSideSwipeOnlyTab() throws Exception { | 404 public void testToolbarSideSwipeOnlyTab() throws Exception { |
| 375 initializeLayoutManagerPhone(1, 0, 0, TabModel.INVALID_TAB_INDEX, false)
; | 405 initializeLayoutManagerPhone(1, 0, 0, TabModel.INVALID_TAB_INDEX, false)
; |
| 376 assertEquals(mTabModelSelector.getModel(false).index(), 0); | 406 Assert.assertEquals(mTabModelSelector.getModel(false).index(), 0); |
| 377 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.LEFT, 0); | 407 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.LEFT, 0); |
| 378 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.RIGHT, 0); | 408 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.RIGHT, 0); |
| 379 } | 409 } |
| 380 | 410 |
| 411 @Test |
| 381 @SmallTest | 412 @SmallTest |
| 382 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 413 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
| 383 @Feature({"Android-TabSwitcher"}) | 414 @Feature({"Android-TabSwitcher"}) |
| 415 @UiThreadTest |
| 384 public void testToolbarSideSwipeOnlyTabIncognito() throws Exception { | 416 public void testToolbarSideSwipeOnlyTabIncognito() throws Exception { |
| 385 initializeLayoutManagerPhone(0, 1, TabModel.INVALID_TAB_INDEX, 0, true); | 417 initializeLayoutManagerPhone(0, 1, TabModel.INVALID_TAB_INDEX, 0, true); |
| 386 assertEquals(mTabModelSelector.getModel(true).index(), 0); | 418 Assert.assertEquals(mTabModelSelector.getModel(true).index(), 0); |
| 387 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.LEFT, 0); | 419 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.LEFT, 0); |
| 388 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.RIGHT, 0); | 420 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.RIGHT, 0); |
| 389 } | 421 } |
| 390 | 422 |
| 423 @Test |
| 391 @SmallTest | 424 @SmallTest |
| 392 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 425 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
| 393 @Feature({"Android-TabSwitcher"}) | 426 @Feature({"Android-TabSwitcher"}) |
| 427 @UiThreadTest |
| 394 public void testToolbarSideSwipeNextTab() throws Exception { | 428 public void testToolbarSideSwipeNextTab() throws Exception { |
| 395 initializeLayoutManagerPhone(2, 0, 0, TabModel.INVALID_TAB_INDEX, false)
; | 429 initializeLayoutManagerPhone(2, 0, 0, TabModel.INVALID_TAB_INDEX, false)
; |
| 396 assertEquals(mTabModelSelector.getModel(false).index(), 0); | 430 Assert.assertEquals(mTabModelSelector.getModel(false).index(), 0); |
| 397 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.LEFT, 1); | 431 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.LEFT, 1); |
| 398 } | 432 } |
| 399 | 433 |
| 434 @Test |
| 400 @SmallTest | 435 @SmallTest |
| 401 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 436 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
| 402 @Feature({"Android-TabSwitcher"}) | 437 @Feature({"Android-TabSwitcher"}) |
| 438 @UiThreadTest |
| 403 public void testToolbarSideSwipePrevTab() throws Exception { | 439 public void testToolbarSideSwipePrevTab() throws Exception { |
| 404 initializeLayoutManagerPhone(2, 0, 1, TabModel.INVALID_TAB_INDEX, false)
; | 440 initializeLayoutManagerPhone(2, 0, 1, TabModel.INVALID_TAB_INDEX, false)
; |
| 405 assertEquals(mTabModelSelector.getModel(false).index(), 1); | 441 Assert.assertEquals(mTabModelSelector.getModel(false).index(), 1); |
| 406 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.RIGHT, 0); | 442 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.RIGHT, 0); |
| 407 } | 443 } |
| 408 | 444 |
| 445 @Test |
| 409 @SmallTest | 446 @SmallTest |
| 410 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 447 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
| 411 @Feature({"Android-TabSwitcher"}) | 448 @Feature({"Android-TabSwitcher"}) |
| 449 @UiThreadTest |
| 412 public void testToolbarSideSwipeNextTabNone() throws Exception { | 450 public void testToolbarSideSwipeNextTabNone() throws Exception { |
| 413 initializeLayoutManagerPhone(2, 0, 1, TabModel.INVALID_TAB_INDEX, false)
; | 451 initializeLayoutManagerPhone(2, 0, 1, TabModel.INVALID_TAB_INDEX, false)
; |
| 414 assertEquals(mTabModelSelector.getModel(false).index(), 1); | 452 Assert.assertEquals(mTabModelSelector.getModel(false).index(), 1); |
| 415 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.LEFT, 1); | 453 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.LEFT, 1); |
| 416 } | 454 } |
| 417 | 455 |
| 456 @Test |
| 418 @SmallTest | 457 @SmallTest |
| 419 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 458 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
| 420 @Feature({"Android-TabSwitcher"}) | 459 @Feature({"Android-TabSwitcher"}) |
| 460 @UiThreadTest |
| 421 public void testToolbarSideSwipePrevTabNone() throws Exception { | 461 public void testToolbarSideSwipePrevTabNone() throws Exception { |
| 422 initializeLayoutManagerPhone(2, 0, 0, TabModel.INVALID_TAB_INDEX, false)
; | 462 initializeLayoutManagerPhone(2, 0, 0, TabModel.INVALID_TAB_INDEX, false)
; |
| 423 assertEquals(mTabModelSelector.getModel(false).index(), 0); | 463 Assert.assertEquals(mTabModelSelector.getModel(false).index(), 0); |
| 424 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.RIGHT, 0); | 464 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.RIGHT, 0); |
| 425 } | 465 } |
| 426 | 466 |
| 467 @Test |
| 427 @SmallTest | 468 @SmallTest |
| 428 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 469 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
| 429 @Feature({"Android-TabSwitcher"}) | 470 @Feature({"Android-TabSwitcher"}) |
| 471 @UiThreadTest |
| 430 public void testToolbarSideSwipeNextTabIncognito() throws Exception { | 472 public void testToolbarSideSwipeNextTabIncognito() throws Exception { |
| 431 initializeLayoutManagerPhone(0, 2, TabModel.INVALID_TAB_INDEX, 0, true); | 473 initializeLayoutManagerPhone(0, 2, TabModel.INVALID_TAB_INDEX, 0, true); |
| 432 assertEquals(mTabModelSelector.getModel(true).index(), 0); | 474 Assert.assertEquals(mTabModelSelector.getModel(true).index(), 0); |
| 433 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.LEFT, 1); | 475 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.LEFT, 1); |
| 434 } | 476 } |
| 435 | 477 |
| 478 @Test |
| 436 @SmallTest | 479 @SmallTest |
| 437 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 480 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
| 438 @Feature({"Android-TabSwitcher"}) | 481 @Feature({"Android-TabSwitcher"}) |
| 482 @UiThreadTest |
| 439 public void testToolbarSideSwipePrevTabIncognito() throws Exception { | 483 public void testToolbarSideSwipePrevTabIncognito() throws Exception { |
| 440 initializeLayoutManagerPhone(0, 2, TabModel.INVALID_TAB_INDEX, 1, true); | 484 initializeLayoutManagerPhone(0, 2, TabModel.INVALID_TAB_INDEX, 1, true); |
| 441 assertEquals(mTabModelSelector.getModel(true).index(), 1); | 485 Assert.assertEquals(mTabModelSelector.getModel(true).index(), 1); |
| 442 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.RIGHT, 0); | 486 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.RIGHT, 0); |
| 443 } | 487 } |
| 444 | 488 |
| 489 @Test |
| 445 @SmallTest | 490 @SmallTest |
| 446 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 491 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
| 447 @Feature({"Android-TabSwitcher"}) | 492 @Feature({"Android-TabSwitcher"}) |
| 493 @UiThreadTest |
| 448 public void testToolbarSideSwipeNextTabNoneIncognito() throws Exception { | 494 public void testToolbarSideSwipeNextTabNoneIncognito() throws Exception { |
| 449 initializeLayoutManagerPhone(0, 2, TabModel.INVALID_TAB_INDEX, 1, true); | 495 initializeLayoutManagerPhone(0, 2, TabModel.INVALID_TAB_INDEX, 1, true); |
| 450 assertEquals(mTabModelSelector.getModel(true).index(), 1); | 496 Assert.assertEquals(mTabModelSelector.getModel(true).index(), 1); |
| 451 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.LEFT, 1); | 497 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.LEFT, 1); |
| 452 } | 498 } |
| 453 | 499 |
| 500 @Test |
| 454 @SmallTest | 501 @SmallTest |
| 455 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) | 502 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
| 456 @Feature({"Android-TabSwitcher"}) | 503 @Feature({"Android-TabSwitcher"}) |
| 504 @UiThreadTest |
| 457 public void testToolbarSideSwipePrevTabNoneIncognito() throws Exception { | 505 public void testToolbarSideSwipePrevTabNoneIncognito() throws Exception { |
| 458 initializeLayoutManagerPhone(0, 2, TabModel.INVALID_TAB_INDEX, 0, true); | 506 initializeLayoutManagerPhone(0, 2, TabModel.INVALID_TAB_INDEX, 0, true); |
| 459 assertEquals(mTabModelSelector.getModel(true).index(), 0); | 507 Assert.assertEquals(mTabModelSelector.getModel(true).index(), 0); |
| 460 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.RIGHT, 0); | 508 runToolbarSideSwipeTestOnCurrentModel(ScrollDirection.RIGHT, 0); |
| 461 } | 509 } |
| 462 | 510 |
| 463 @Override | 511 @Before |
| 464 protected void setUp() throws Exception { | 512 public void setUp() throws Exception { |
| 465 super.setUp(); | |
| 466 | |
| 467 // Load the browser process. | 513 // Load the browser process. |
| 468 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 514 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 469 @Override | 515 @Override |
| 470 public void run() { | 516 public void run() { |
| 471 try { | 517 try { |
| 472 ChromeBrowserInitializer.getInstance( | 518 ChromeBrowserInitializer |
| 473 getInstrumentation().getTargetContext()).handleSynch
ronousStartup(); | 519 .getInstance( |
| 520 InstrumentationRegistry.getInstrumentation()
.getTargetContext()) |
| 521 .handleSynchronousStartup(); |
| 474 } catch (ProcessInitException e) { | 522 } catch (ProcessInitException e) { |
| 475 fail("Failed to load browser"); | 523 Assert.fail("Failed to load browser"); |
| 476 } | 524 } |
| 477 } | 525 } |
| 478 }); | 526 }); |
| 479 } | 527 } |
| 480 | 528 |
| 481 private void runToolbarSideSwipeTestOnCurrentModel(ScrollDirection direction
, int finalIndex) { | 529 private void runToolbarSideSwipeTestOnCurrentModel(ScrollDirection direction
, int finalIndex) { |
| 482 final TabModel model = mTabModelSelector.getCurrentModel(); | 530 final TabModel model = mTabModelSelector.getCurrentModel(); |
| 483 final int finalId = model.getTabAt(finalIndex).getId(); | 531 final int finalId = model.getTabAt(finalIndex).getId(); |
| 484 | 532 |
| 485 performToolbarSideSwipe(direction); | 533 performToolbarSideSwipe(direction); |
| 486 | 534 |
| 487 assertEquals("Unexpected model change after side swipe", model.isIncogni
to(), | 535 Assert.assertEquals("Unexpected model change after side swipe", model.is
Incognito(), |
| 488 mTabModelSelector.isIncognitoSelected()); | 536 mTabModelSelector.isIncognitoSelected()); |
| 489 | 537 |
| 490 assertEquals("Wrong index after side swipe", finalIndex, model.index()); | 538 Assert.assertEquals("Wrong index after side swipe", finalIndex, model.in
dex()); |
| 491 assertEquals("Wrong current tab id", finalId, TabModelUtils.getCurrentTa
b(model).getId()); | 539 Assert.assertEquals( |
| 492 assertTrue("LayoutManager#getActiveLayout() should be StaticLayout", | 540 "Wrong current tab id", finalId, TabModelUtils.getCurrentTab(mod
el).getId()); |
| 541 Assert.assertTrue("LayoutManager#getActiveLayout() should be StaticLayou
t", |
| 493 mManager.getActiveLayout() instanceof StaticLayout); | 542 mManager.getActiveLayout() instanceof StaticLayout); |
| 494 } | 543 } |
| 495 | 544 |
| 496 private void performToolbarSideSwipe(ScrollDirection direction) { | 545 private void performToolbarSideSwipe(ScrollDirection direction) { |
| 497 assertTrue("Unexpected direction for side swipe " + direction, | 546 Assert.assertTrue("Unexpected direction for side swipe " + direction, |
| 498 direction == ScrollDirection.LEFT || direction == ScrollDirectio
n.RIGHT); | 547 direction == ScrollDirection.LEFT || direction == ScrollDirectio
n.RIGHT); |
| 499 | 548 |
| 500 final Layout layout = mManager.getActiveLayout(); | 549 final Layout layout = mManager.getActiveLayout(); |
| 501 final EdgeSwipeHandler eventHandler = mManager.getTopSwipeHandler(); | 550 final EdgeSwipeHandler eventHandler = mManager.getTopSwipeHandler(); |
| 502 | 551 |
| 503 assertNotNull("LayoutManager#getTopSwipeHandler() returned null", eventH
andler); | 552 Assert.assertNotNull("LayoutManager#getTopSwipeHandler() returned null",
eventHandler); |
| 504 assertNotNull("LayoutManager#getActiveLayout() returned null", layout); | 553 Assert.assertNotNull("LayoutManager#getActiveLayout() returned null", la
yout); |
| 505 | 554 |
| 506 final float layoutWidth = layout.getWidth(); | 555 final float layoutWidth = layout.getWidth(); |
| 507 final boolean scrollLeft = direction == ScrollDirection.LEFT; | 556 final boolean scrollLeft = direction == ScrollDirection.LEFT; |
| 508 final float deltaX = MathUtils.flipSignIf(layoutWidth / 2.f, scrollLeft)
; | 557 final float deltaX = MathUtils.flipSignIf(layoutWidth / 2.f, scrollLeft)
; |
| 509 | 558 |
| 510 eventHandler.swipeStarted(direction, layoutWidth, 0); | 559 eventHandler.swipeStarted(direction, layoutWidth, 0); |
| 511 eventHandler.swipeUpdated(deltaX, 0.f, deltaX, 0.f, deltaX, 0.f); | 560 eventHandler.swipeUpdated(deltaX, 0.f, deltaX, 0.f, deltaX, 0.f); |
| 512 eventHandler.swipeFinished(); | 561 eventHandler.swipeFinished(); |
| 513 | 562 |
| 514 assertTrue("LayoutManager#getActiveLayout() should be ToolbarSwipeLayout
", | 563 Assert.assertTrue("LayoutManager#getActiveLayout() should be ToolbarSwip
eLayout", |
| 515 mManager.getActiveLayout() instanceof ToolbarSwipeLayout); | 564 mManager.getActiveLayout() instanceof ToolbarSwipeLayout); |
| 516 assertTrue("LayoutManager took too long to finish the animations", | 565 Assert.assertTrue("LayoutManager took too long to finish the animations"
, |
| 517 simulateTime(mManager, 1000)); | 566 simulateTime(mManager, 1000)); |
| 518 } | 567 } |
| 519 | 568 |
| 520 @Override | 569 @Override |
| 521 public Tab createTab(int id, boolean incognito) { | 570 public Tab createTab(int id, boolean incognito) { |
| 522 return new Tab(id, incognito, null); | 571 return new Tab(id, incognito, null); |
| 523 } | 572 } |
| 524 } | 573 } |
| OLD | NEW |