| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.webapps; | 5 package org.chromium.chrome.browser.webapps; |
| 6 | 6 |
| 7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; | 7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; |
| 8 | 8 |
| 9 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.net.Uri; | 10 import android.net.Uri; |
| 11 import android.view.ViewGroup; | 11 import android.view.ViewGroup; |
| 12 | 12 |
| 13 import org.junit.Assert; | 13 import org.junit.Assert; |
| 14 import org.junit.runner.Description; | 14 import org.junit.runner.Description; |
| 15 import org.junit.runners.model.Statement; | 15 import org.junit.runners.model.Statement; |
| 16 | 16 |
| 17 import org.chromium.base.test.util.UrlUtils; | 17 import org.chromium.base.test.util.UrlUtils; |
| 18 import org.chromium.chrome.browser.ChromeActivity; |
| 18 import org.chromium.chrome.browser.ShortcutHelper; | 19 import org.chromium.chrome.browser.ShortcutHelper; |
| 19 import org.chromium.chrome.test.ChromeActivityTestRule; | 20 import org.chromium.chrome.test.ChromeActivityTestRule; |
| 20 import org.chromium.content.browser.test.util.Criteria; | 21 import org.chromium.content.browser.test.util.Criteria; |
| 21 import org.chromium.content.browser.test.util.CriteriaHelper; | 22 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 22 | 23 |
| 23 /** | 24 /** |
| 24 * Custom {@link ChromeActivityTestRule} for tests using {@link WebappActivity}. | 25 * Custom {@link ChromeActivityTestRule} for tests using {@link WebappActivity}. |
| 25 */ | 26 */ |
| 26 public class WebappActivityTestRule extends ChromeActivityTestRule<WebappActivit
y0> { | 27 public class WebappActivityTestRule extends ChromeActivityTestRule<WebappActivit
y0> { |
| 27 public static final String WEBAPP_ID = "webapp_id"; | 28 public static final String WEBAPP_ID = "webapp_id"; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 110 |
| 110 /** | 111 /** |
| 111 * Starts up the WebappActivity with a specific Intent and sets up the test
observer. | 112 * Starts up the WebappActivity with a specific Intent and sets up the test
observer. |
| 112 */ | 113 */ |
| 113 public final void startWebappActivity(Intent intent) throws Exception { | 114 public final void startWebappActivity(Intent intent) throws Exception { |
| 114 launchActivity(intent); | 115 launchActivity(intent); |
| 115 waitUntilIdle(); | 116 waitUntilIdle(); |
| 116 } | 117 } |
| 117 | 118 |
| 118 /** | 119 /** |
| 119 * Waits until any loads in progress have completed. | 120 * Waits until any loads in progress of the activity under test have complet
ed. |
| 120 */ | 121 */ |
| 121 public void waitUntilIdle() { | 122 protected void waitUntilIdle() { |
| 123 waitUntilIdle(getActivity()); |
| 124 } |
| 125 |
| 126 /** |
| 127 * Waits until any loads in progress of a selected activity have completed. |
| 128 */ |
| 129 protected void waitUntilIdle(final ChromeActivity activity) { |
| 122 getInstrumentation().waitForIdleSync(); | 130 getInstrumentation().waitForIdleSync(); |
| 123 CriteriaHelper.pollInstrumentationThread(new Criteria() { | 131 CriteriaHelper.pollInstrumentationThread(new Criteria() { |
| 124 @Override | 132 @Override |
| 125 public boolean isSatisfied() { | 133 public boolean isSatisfied() { |
| 126 return getActivity().getActivityTab() != null | 134 return activity.getActivityTab() != null && !activity.getActivit
yTab().isLoading(); |
| 127 && !getActivity().getActivityTab().isLoading(); | |
| 128 } | 135 } |
| 129 }, STARTUP_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL); | 136 }, STARTUP_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL); |
| 130 | 137 |
| 131 getInstrumentation().waitForIdleSync(); | 138 getInstrumentation().waitForIdleSync(); |
| 132 } | 139 } |
| 133 | 140 |
| 134 /** | 141 /** |
| 135 * Waits for the splash screen to be hidden. | 142 * Waits for the splash screen to be hidden. |
| 136 */ | 143 */ |
| 137 public void waitUntilSplashscreenHides() { | 144 public void waitUntilSplashscreenHides() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 151 } | 158 } |
| 152 }); | 159 }); |
| 153 | 160 |
| 154 ViewGroup splashScreen = getActivity().getSplashScreenForTests(); | 161 ViewGroup splashScreen = getActivity().getSplashScreenForTests(); |
| 155 if (splashScreen == null) { | 162 if (splashScreen == null) { |
| 156 Assert.fail("No splash screen available."); | 163 Assert.fail("No splash screen available."); |
| 157 } | 164 } |
| 158 return splashScreen; | 165 return splashScreen; |
| 159 } | 166 } |
| 160 } | 167 } |
| OLD | NEW |