| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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_apk; | 5 package org.chromium.content_shell_apk; |
| 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.ComponentName; | 9 import android.content.ComponentName; |
| 10 import android.content.Intent; | 10 import android.content.Intent; |
| 11 import android.net.Uri; | 11 import android.net.Uri; |
| 12 import android.test.ActivityInstrumentationTestCase2; | 12 import android.test.ActivityInstrumentationTestCase2; |
| 13 import android.text.TextUtils; | 13 import android.text.TextUtils; |
| 14 import android.view.ViewGroup; | 14 import android.view.ViewGroup; |
| 15 | 15 |
| 16 import org.chromium.base.ThreadUtils; | 16 import org.chromium.base.ThreadUtils; |
| 17 import org.chromium.base.test.util.UrlUtils; | 17 import org.chromium.base.test.util.UrlUtils; |
| 18 import org.chromium.content.browser.ContentView; | 18 import org.chromium.content.browser.ContentView; |
| 19 import org.chromium.content.browser.ContentViewCore; | 19 import org.chromium.content.browser.ContentViewCore; |
| 20 import org.chromium.content.browser.test.util.CallbackHelper; | 20 import org.chromium.content.browser.test.util.CallbackHelper; |
| 21 import org.chromium.content.browser.test.util.Criteria; | 21 import org.chromium.content.browser.test.util.Criteria; |
| 22 import org.chromium.content.browser.test.util.CriteriaHelper; | 22 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 23 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; | 23 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; |
| 24 import org.chromium.content_public.browser.LoadUrlParams; | 24 import org.chromium.content_public.browser.LoadUrlParams; |
| 25 import org.chromium.content_public.browser.NavigationController; |
| 26 import org.chromium.content_public.browser.WebContents; |
| 25 import org.chromium.content_shell.Shell; | 27 import org.chromium.content_shell.Shell; |
| 26 | 28 |
| 27 import java.lang.annotation.ElementType; | 29 import java.lang.annotation.ElementType; |
| 28 import java.lang.annotation.Retention; | 30 import java.lang.annotation.Retention; |
| 29 import java.lang.annotation.RetentionPolicy; | 31 import java.lang.annotation.RetentionPolicy; |
| 30 import java.lang.annotation.Target; | 32 import java.lang.annotation.Target; |
| 31 import java.lang.reflect.Method; | 33 import java.lang.reflect.Method; |
| 32 import java.util.concurrent.TimeUnit; | 34 import java.util.concurrent.TimeUnit; |
| 33 import java.util.concurrent.atomic.AtomicBoolean; | 35 import java.util.concurrent.atomic.AtomicBoolean; |
| 34 | 36 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 107 } |
| 106 | 108 |
| 107 /** | 109 /** |
| 108 * Returns the current ContentViewCore or null if there is no ContentView. | 110 * Returns the current ContentViewCore or null if there is no ContentView. |
| 109 */ | 111 */ |
| 110 protected ContentViewCore getContentViewCore() { | 112 protected ContentViewCore getContentViewCore() { |
| 111 return getActivity().getActiveShell().getContentViewCore(); | 113 return getActivity().getActiveShell().getContentViewCore(); |
| 112 } | 114 } |
| 113 | 115 |
| 114 /** | 116 /** |
| 117 * Returns the WebContents of this Shell. |
| 118 */ |
| 119 protected WebContents getWebContents() { |
| 120 return getActivity().getActiveShell().getWebContents(); |
| 121 } |
| 122 |
| 123 /** |
| 115 * Waits for the Active shell to finish loading. This times out after | 124 * Waits for the Active shell to finish loading. This times out after |
| 116 * WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT milliseconds and it shouldn't be us
ed for long | 125 * WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT milliseconds and it shouldn't be us
ed for long |
| 117 * loading pages. Instead it should be used more for test initialization. Th
e proper way | 126 * loading pages. Instead it should be used more for test initialization. Th
e proper way |
| 118 * to wait is to use a TestCallbackHelperContainer after the initial load is
completed. | 127 * to wait is to use a TestCallbackHelperContainer after the initial load is
completed. |
| 119 * @return Whether or not the Shell was actually finished loading. | 128 * @return Whether or not the Shell was actually finished loading. |
| 120 * @throws InterruptedException | 129 * @throws InterruptedException |
| 121 */ | 130 */ |
| 122 protected boolean waitForActiveShellToBeDoneLoading() throws InterruptedExce
ption { | 131 protected boolean waitForActiveShellToBeDoneLoading() throws InterruptedExce
ption { |
| 123 final ContentShellActivity activity = getActivity(); | 132 final ContentShellActivity activity = getActivity(); |
| 124 | 133 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 155 } | 164 } |
| 156 | 165 |
| 157 /** | 166 /** |
| 158 * Loads a URL in the specified content view. | 167 * Loads a URL in the specified content view. |
| 159 * | 168 * |
| 160 * @param viewCore The content view core to load the URL in. | 169 * @param viewCore The content view core to load the URL in. |
| 161 * @param callbackHelperContainer The callback helper container used to moni
tor progress. | 170 * @param callbackHelperContainer The callback helper container used to moni
tor progress. |
| 162 * @param params The URL params to use. | 171 * @param params The URL params to use. |
| 163 */ | 172 */ |
| 164 protected void loadUrl( | 173 protected void loadUrl( |
| 165 final ContentViewCore viewCore, TestCallbackHelperContainer callback
HelperContainer, | 174 final NavigationController navigationController, |
| 175 TestCallbackHelperContainer callbackHelperContainer, |
| 166 final LoadUrlParams params) throws Throwable { | 176 final LoadUrlParams params) throws Throwable { |
| 167 handleBlockingCallbackAction( | 177 handleBlockingCallbackAction( |
| 168 callbackHelperContainer.getOnPageFinishedHelper(), | 178 callbackHelperContainer.getOnPageFinishedHelper(), |
| 169 new Runnable() { | 179 new Runnable() { |
| 170 @Override | 180 @Override |
| 171 public void run() { | 181 public void run() { |
| 172 viewCore.getWebContents().getNavigationController().load
Url(params); | 182 navigationController.loadUrl(params); |
| 173 } | 183 } |
| 174 }); | 184 }); |
| 175 } | 185 } |
| 176 | 186 |
| 177 /** | 187 /** |
| 178 * Handles performing an action on the UI thread that will return when the s
pecified callback | 188 * Handles performing an action on the UI thread that will return when the s
pecified callback |
| 179 * is incremented. | 189 * is incremented. |
| 180 * | 190 * |
| 181 * @param callbackHelper The callback helper that will be blocked on. | 191 * @param callbackHelper The callback helper that will be blocked on. |
| 182 * @param action The action to be performed on the UI thread. | 192 * @param action The action to be performed on the UI thread. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 * the ContentViewCore's container view (see {@link #runTest()}). | 253 * the ContentViewCore's container view (see {@link #runTest()}). |
| 244 * | 254 * |
| 245 * <p>Please note that {@link #setUp()} is only invoked once before both run
s, | 255 * <p>Please note that {@link #setUp()} is only invoked once before both run
s, |
| 246 * and that any state changes produced by the first run are visible to the s
econd run. | 256 * and that any state changes produced by the first run are visible to the s
econd run. |
| 247 */ | 257 */ |
| 248 @Target(ElementType.METHOD) | 258 @Target(ElementType.METHOD) |
| 249 @Retention(RetentionPolicy.RUNTIME) | 259 @Retention(RetentionPolicy.RUNTIME) |
| 250 public @interface RerunWithUpdatedContainerView { | 260 public @interface RerunWithUpdatedContainerView { |
| 251 } | 261 } |
| 252 } | 262 } |
| OLD | NEW |