| 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.tabmodel; | 5 package org.chromium.chrome.browser.tabmodel; |
| 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.annotation.TargetApi; | 9 import android.annotation.TargetApi; |
| 10 import android.app.Activity; | 10 import android.app.Activity; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 } | 148 } |
| 149 for (int i = 0; i < 3; i++) { | 149 for (int i = 0; i < 3; i++) { |
| 150 mMergeIntoActivity2ExpectedTabs[i] = | 150 mMergeIntoActivity2ExpectedTabs[i] = |
| 151 mActivity2.getTabModelSelector().getModel(false).getTabAt(i)
.getUrl(); | 151 mActivity2.getTabModelSelector().getModel(false).getTabAt(i)
.getUrl(); |
| 152 mMergeIntoActivity1ExpectedTabs[i + 4] = | 152 mMergeIntoActivity1ExpectedTabs[i + 4] = |
| 153 mActivity2.getTabModelSelector().getModel(false).getTabAt(i)
.getUrl(); | 153 mActivity2.getTabModelSelector().getModel(false).getTabAt(i)
.getUrl(); |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 | 156 |
| 157 private void mergeTabsAndAssert(final ChromeTabbedActivity activity, | 157 private void mergeTabsAndAssert(final ChromeTabbedActivity activity, |
| 158 final String[] expectedTabUrls) throws InterruptedException { | 158 final String[] expectedTabUrls) { |
| 159 String selectedTabUrl = activity.getTabModelSelector().getCurrentTab().g
etUrl(); | 159 String selectedTabUrl = activity.getTabModelSelector().getCurrentTab().g
etUrl(); |
| 160 mergeTabsAndAssert(activity, expectedTabUrls, expectedTabUrls.length, se
lectedTabUrl); | 160 mergeTabsAndAssert(activity, expectedTabUrls, expectedTabUrls.length, se
lectedTabUrl); |
| 161 } | 161 } |
| 162 | 162 |
| 163 /** | 163 /** |
| 164 * Merges tabs into the provided activity and asserts that the tab model loo
ks as expected. | 164 * Merges tabs into the provided activity and asserts that the tab model loo
ks as expected. |
| 165 * @param activity The activity to merge into. | 165 * @param activity The activity to merge into. |
| 166 * @param expectedTabUrls The expected ordering of normal tab URLs after the
merge. | 166 * @param expectedTabUrls The expected ordering of normal tab URLs after the
merge. |
| 167 * @param expectedNumberOfTabs The expected number of tabs after the merge. | 167 * @param expectedNumberOfTabs The expected number of tabs after the merge. |
| 168 * @param expectedSelectedTabUrl The expected URL of the selected tab after
the merge. | 168 * @param expectedSelectedTabUrl The expected URL of the selected tab after
the merge. |
| 169 */ | 169 */ |
| 170 private void mergeTabsAndAssert(final ChromeTabbedActivity activity, | 170 private void mergeTabsAndAssert(final ChromeTabbedActivity activity, |
| 171 final String[] expectedTabUrls, final int expectedNumberOfTabs, | 171 final String[] expectedTabUrls, final int expectedNumberOfTabs, |
| 172 String expectedSelectedTabUrl) throws InterruptedException { | 172 String expectedSelectedTabUrl) { |
| 173 // Merge tabs into the activity. | 173 // Merge tabs into the activity. |
| 174 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 174 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 175 @Override | 175 @Override |
| 176 public void run() { | 176 public void run() { |
| 177 activity.maybeMergeTabs(); | 177 activity.maybeMergeTabs(); |
| 178 } | 178 } |
| 179 }); | 179 }); |
| 180 | 180 |
| 181 // Wait for all tabs to be merged into the activity. | 181 // Wait for all tabs to be merged into the activity. |
| 182 CriteriaHelper.pollUiThread(new Criteria() { | 182 CriteriaHelper.pollUiThread(new Criteria() { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 201 } | 201 } |
| 202 | 202 |
| 203 /** | 203 /** |
| 204 * Starts a new ChromeTabbedActivity and asserts that the tab model looks as
expected. | 204 * Starts a new ChromeTabbedActivity and asserts that the tab model looks as
expected. |
| 205 * @param intent The intent to launch the new activity. | 205 * @param intent The intent to launch the new activity. |
| 206 * @param expectedSelectedTabUrl The URL of the tab that's expected to be se
lected. | 206 * @param expectedSelectedTabUrl The URL of the tab that's expected to be se
lected. |
| 207 * @param expectedTabUrls The expected ordering of tab URLs after the merge. | 207 * @param expectedTabUrls The expected ordering of tab URLs after the merge. |
| 208 * @return The newly created ChromeTabbedActivity. | 208 * @return The newly created ChromeTabbedActivity. |
| 209 */ | 209 */ |
| 210 private ChromeTabbedActivity startNewChromeTabbedActivityAndAssert(Intent in
tent, | 210 private ChromeTabbedActivity startNewChromeTabbedActivityAndAssert(Intent in
tent, |
| 211 String expectedSelectedTabUrl, String[] expectedTabUrls) | 211 String expectedSelectedTabUrl, String[] expectedTabUrls) { |
| 212 throws InterruptedException { | |
| 213 final ChromeTabbedActivity newActivity = | 212 final ChromeTabbedActivity newActivity = |
| 214 (ChromeTabbedActivity) getInstrumentation().startActivitySync(in
tent); | 213 (ChromeTabbedActivity) getInstrumentation().startActivitySync(in
tent); |
| 215 | 214 |
| 216 // Wait for the tab state to be initialized. | 215 // Wait for the tab state to be initialized. |
| 217 CriteriaHelper.pollUiThread(new Criteria() { | 216 CriteriaHelper.pollUiThread(new Criteria() { |
| 218 @Override | 217 @Override |
| 219 public boolean isSatisfied() { | 218 public boolean isSatisfied() { |
| 220 return newActivity.getTabModelSelector().isTabStateInitialized()
; | 219 return newActivity.getTabModelSelector().isTabStateInitialized()
; |
| 221 } | 220 } |
| 222 }); | 221 }); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 5, mActivity1.getTabModelSelector().getTotalTabCount()); | 387 5, mActivity1.getTabModelSelector().getTotalTabCount()); |
| 389 assertEquals("Wrong number of incognito tabs in ChromeTabbedActivity2", | 388 assertEquals("Wrong number of incognito tabs in ChromeTabbedActivity2", |
| 390 1, mActivity2.getTabModelSelector().getModel(true).getCount()); | 389 1, mActivity2.getTabModelSelector().getModel(true).getCount()); |
| 391 assertEquals("Wrong number of tabs in ChromeTabbedActivity2", | 390 assertEquals("Wrong number of tabs in ChromeTabbedActivity2", |
| 392 4, mActivity2.getTabModelSelector().getTotalTabCount()); | 391 4, mActivity2.getTabModelSelector().getTotalTabCount()); |
| 393 | 392 |
| 394 String selectedUrl = mActivity1.getTabModelSelector().getCurrentTab().ge
tUrl(); | 393 String selectedUrl = mActivity1.getTabModelSelector().getCurrentTab().ge
tUrl(); |
| 395 mergeTabsAndAssert(mActivity1, mMergeIntoActivity1ExpectedTabs, 9, selec
tedUrl); | 394 mergeTabsAndAssert(mActivity1, mMergeIntoActivity1ExpectedTabs, 9, selec
tedUrl); |
| 396 } | 395 } |
| 397 } | 396 } |
| OLD | NEW |