| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.content_shell; | 5 package org.chromium.content_shell; |
| 6 | 6 |
| 7 import android.content.ComponentName; | 7 import android.content.ComponentName; |
| 8 import android.content.Intent; | 8 import android.content.Intent; |
| 9 import android.net.Uri; | 9 import android.net.Uri; |
| 10 import android.test.ActivityInstrumentationTestCase2; | 10 import android.test.ActivityInstrumentationTestCase2; |
| 11 import android.text.TextUtils; | 11 import android.text.TextUtils; |
| 12 | 12 |
| 13 import java.util.concurrent.atomic.AtomicBoolean; | |
| 14 import java.util.concurrent.atomic.AtomicReference; | |
| 15 | |
| 16 import org.chromium.base.test.util.UrlUtils; | 13 import org.chromium.base.test.util.UrlUtils; |
| 17 import org.chromium.content.browser.ContentView; | 14 import org.chromium.content.browser.ContentView; |
| 18 import org.chromium.content.browser.ContentViewCore; | 15 import org.chromium.content.browser.ContentViewCore; |
| 16 import org.chromium.content.browser.LoadUrlParams; |
| 17 import org.chromium.content.browser.test.util.CallbackHelper; |
| 19 import org.chromium.content.browser.test.util.Criteria; | 18 import org.chromium.content.browser.test.util.Criteria; |
| 20 import org.chromium.content.browser.test.util.CriteriaHelper; | 19 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 20 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; |
| 21 |
| 22 import java.util.concurrent.TimeUnit; |
| 23 import java.util.concurrent.atomic.AtomicBoolean; |
| 21 | 24 |
| 22 /** | 25 /** |
| 23 * Base test class for all ContentShell based tests. | 26 * Base test class for all ContentShell based tests. |
| 24 */ | 27 */ |
| 25 public class ContentShellTestBase extends ActivityInstrumentationTestCase2<Conte
ntShellActivity> { | 28 public class ContentShellTestBase extends ActivityInstrumentationTestCase2<Conte
ntShellActivity> { |
| 26 | 29 |
| 27 /** The maximum time the waitForActiveShellToBeDoneLoading method will wait.
*/ | 30 /** The maximum time the waitForActiveShellToBeDoneLoading method will wait.
*/ |
| 28 private static final long WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT = 10000; | 31 private static final long WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT = 10000; |
| 29 | 32 |
| 33 protected static final int WAIT_PAGE_LOADING_TIMEOUT_SECONDS = 15; |
| 34 |
| 30 public ContentShellTestBase() { | 35 public ContentShellTestBase() { |
| 31 super(ContentShellActivity.class); | 36 super(ContentShellActivity.class); |
| 32 } | 37 } |
| 33 | 38 |
| 34 /** | 39 /** |
| 35 * Starts the ContentShell activity and loads the given URL. | 40 * Starts the ContentShell activity and loads the given URL. |
| 36 * The URL can be null, in which case will default to ContentShellActivity.D
EFAULT_SHELL_URL. | 41 * The URL can be null, in which case will default to ContentShellActivity.D
EFAULT_SHELL_URL. |
| 37 */ | 42 */ |
| 38 protected ContentShellActivity launchContentShellWithUrl(String url) { | 43 protected ContentShellActivity launchContentShellWithUrl(String url) { |
| 39 return launchContentShellWithUrlAndCommandLineArgs(url, null); | 44 return launchContentShellWithUrlAndCommandLineArgs(url, null); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 } | 142 } |
| 138 }); | 143 }); |
| 139 | 144 |
| 140 return isLoaded.get(); | 145 return isLoaded.get(); |
| 141 } catch (Throwable e) { | 146 } catch (Throwable e) { |
| 142 return false; | 147 return false; |
| 143 } | 148 } |
| 144 } | 149 } |
| 145 }, WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT, CriteriaHelper.DEFAULT_POLLING
_INTERVAL); | 150 }, WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT, CriteriaHelper.DEFAULT_POLLING
_INTERVAL); |
| 146 } | 151 } |
| 152 |
| 153 /** |
| 154 * Loads a URL in the specified content view. |
| 155 * |
| 156 * @param contentView The content view to load the URL in. |
| 157 * @param callbackHelperContainer The callback helper container used to moni
tor progress. |
| 158 * @param params The URL params to use. |
| 159 */ |
| 160 protected void loadUrl( |
| 161 final ContentView contentView, TestCallbackHelperContainer callbackH
elperContainer, |
| 162 final LoadUrlParams params) throws Throwable { |
| 163 handleBlockingCallbackAction( |
| 164 callbackHelperContainer.getOnPageFinishedHelper(), |
| 165 new Runnable() { |
| 166 @Override |
| 167 public void run() { |
| 168 contentView.loadUrl(params); |
| 169 } |
| 170 }); |
| 171 } |
| 172 |
| 173 /** |
| 174 * Handles performing an action on the UI thread that will return when the s
pecified callback |
| 175 * is incremented. |
| 176 * |
| 177 * @param callbackHelper The callback helper that will be blocked on. |
| 178 * @param action The action to be performed on the UI thread. |
| 179 */ |
| 180 protected void handleBlockingCallbackAction( |
| 181 CallbackHelper callbackHelper, Runnable action) throws Throwable { |
| 182 int currentCallCount = callbackHelper.getCallCount(); |
| 183 runTestOnUiThread(action); |
| 184 callbackHelper.waitForCallback( |
| 185 currentCallCount, 1, WAIT_PAGE_LOADING_TIMEOUT_SECONDS, TimeUnit
.SECONDS); |
| 186 } |
| 147 } | 187 } |
| OLD | NEW |