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.util; |
| 6 |
| 7 import android.annotation.TargetApi; |
| 8 import android.os.Build; |
| 9 |
| 10 import org.chromium.chrome.browser.Tab; |
| 11 import org.chromium.chrome.browser.ntp.IncognitoNewTabPage; |
| 12 import org.chromium.chrome.browser.ntp.NewTabPage; |
| 13 import org.chromium.chrome.browser.util.FeatureUtilities; |
| 14 import org.chromium.content.browser.test.util.Criteria; |
| 15 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 16 |
| 17 /** |
| 18 * Utilities for testing the NTP. |
| 19 */ |
| 20 public class NewTabPageTestUtils { |
| 21 |
| 22 /** |
| 23 * Waits for the NTP owned by the passed in tab to be fully loaded. |
| 24 * |
| 25 * @param tab The tab to be monitored for NTP loading. |
| 26 * @return Whether the NTP has fully loaded. |
| 27 */ |
| 28 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
| 29 public static boolean waitForNtpLoaded(final Tab tab) throws InterruptedExce
ption { |
| 30 return CriteriaHelper.pollForUIThreadCriteria(new Criteria() { |
| 31 @Override |
| 32 public boolean isSatisfied() { |
| 33 if (!tab.isIncognito()) { |
| 34 // TODO(tedchoc): Make MostVisitedPage also have a isLoaded(
) concept. |
| 35 if (FeatureUtilities.isDocumentMode( |
| 36 tab.getWindowAndroid().getApplicationContext())) { |
| 37 return tab.getView().isAttachedToWindow(); |
| 38 } |
| 39 if (!(tab.getNativePage() instanceof NewTabPage)) { |
| 40 return false; |
| 41 } |
| 42 return ((NewTabPage) tab.getNativePage()).isLoadedForTests()
; |
| 43 } else { |
| 44 if (!(tab.getNativePage() instanceof IncognitoNewTabPage)) { |
| 45 return false; |
| 46 } |
| 47 return ((IncognitoNewTabPage) tab.getNativePage()).isLoadedF
orTests(); |
| 48 } |
| 49 } |
| 50 }); |
| 51 } |
| 52 |
| 53 } |
OLD | NEW |