| 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.android_webview.test; | 5 package org.chromium.android_webview.test; |
| 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.app.Instrumentation; | 9 import android.app.Instrumentation; |
| 10 import android.content.Context; | 10 import android.content.Context; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 import org.chromium.content_public.browser.LoadUrlParams; | 35 import org.chromium.content_public.browser.LoadUrlParams; |
| 36 import org.chromium.net.test.util.TestWebServer; | 36 import org.chromium.net.test.util.TestWebServer; |
| 37 | 37 |
| 38 import java.lang.annotation.Annotation; | 38 import java.lang.annotation.Annotation; |
| 39 import java.lang.reflect.AnnotatedElement; | 39 import java.lang.reflect.AnnotatedElement; |
| 40 import java.lang.reflect.Method; | 40 import java.lang.reflect.Method; |
| 41 import java.util.Map; | 41 import java.util.Map; |
| 42 import java.util.concurrent.Callable; | 42 import java.util.concurrent.Callable; |
| 43 import java.util.concurrent.FutureTask; | 43 import java.util.concurrent.FutureTask; |
| 44 import java.util.concurrent.TimeUnit; | 44 import java.util.concurrent.TimeUnit; |
| 45 import java.util.regex.Matcher; |
| 46 import java.util.regex.Pattern; |
| 45 | 47 |
| 46 /** | 48 /** |
| 47 * A base class for android_webview tests. WebView only runs on KitKat and later
, | 49 * A base class for android_webview tests. WebView only runs on KitKat and later
, |
| 48 * so make sure no one attempts to run the tests on earlier OS releases. | 50 * so make sure no one attempts to run the tests on earlier OS releases. |
| 49 * | 51 * |
| 50 * By default, all tests run both in single-process mode, and with sandboxed ren
derer. | 52 * By default, all tests run both in single-process mode, and with sandboxed ren
derer. |
| 51 * If a test doesn't yet work with sandboxed renderer, an entire class, or an in
dividual test | 53 * If a test doesn't yet work with sandboxed renderer, an entire class, or an in
dividual test |
| 52 * method can be marked for single-process testing only by adding the following
annotation: | 54 * method can be marked for single-process testing only by adding the following
annotation: |
| 53 * | 55 * |
| 54 * @ParameterizedTest.Set | 56 * @ParameterizedTest.Set |
| 55 */ | 57 */ |
| 56 @MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT) | 58 @MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT) |
| 57 @ParameterizedTest.Set(tests = { | 59 @ParameterizedTest.Set(tests = { |
| 58 @ParameterizedTest(parameters = { | 60 @ParameterizedTest(parameters = { |
| 59 @Parameter( | 61 @Parameter( |
| 60 tag = CommandLineFlags.Parameter.PARAMETER_TAG)}
), | 62 tag = CommandLineFlags.Parameter.PARAMETER_TAG)}
), |
| 61 @ParameterizedTest(parameters = { | 63 @ParameterizedTest(parameters = { |
| 62 @Parameter( | 64 @Parameter( |
| 63 tag = CommandLineFlags.Parameter.PARAMETER_TAG, | 65 tag = CommandLineFlags.Parameter.PARAMETER_TAG, |
| 64 arguments = { | 66 arguments = { |
| 65 @Parameter.Argument( | 67 @Parameter.Argument( |
| 66 name = CommandLineFlags.Parameter.ADD_AR
G, | 68 name = CommandLineFlags.Parameter.ADD_AR
G, |
| 67 stringArray = {AwSwitches.WEBVIEW_SANDBO
XED_RENDERER}) | 69 stringArray = {AwSwitches.WEBVIEW_SANDBO
XED_RENDERER}) |
| 68 })})}) | 70 })})}) |
| 69 public class AwTestBase | 71 public class AwTestBase |
| 70 extends BaseActivityInstrumentationTestCase<AwTestRunnerActivity> { | 72 extends BaseActivityInstrumentationTestCase<AwTestRunnerActivity> { |
| 71 public static final long WAIT_TIMEOUT_MS = scaleTimeout(15000); | 73 public static final long WAIT_TIMEOUT_MS = scaleTimeout(15000); |
| 72 public static final int CHECK_INTERVAL = 100; | 74 public static final int CHECK_INTERVAL = 100; |
| 73 private static final String TAG = "AwTestBase"; | 75 private static final String TAG = "AwTestBase"; |
| 76 private static final Pattern MAYBE_QUOTED_STRING = Pattern.compile("^(\"?)(.
*)\\1$"); |
| 74 | 77 |
| 75 // The browser context needs to be a process-wide singleton. | 78 // The browser context needs to be a process-wide singleton. |
| 76 private AwBrowserContext mBrowserContext; | 79 private AwBrowserContext mBrowserContext; |
| 77 | 80 |
| 78 public AwTestBase() { | 81 public AwTestBase() { |
| 79 super(AwTestRunnerActivity.class); | 82 super(AwTestRunnerActivity.class); |
| 80 } | 83 } |
| 81 | 84 |
| 82 @Override | 85 @Override |
| 83 protected void setUp() throws Exception { | 86 protected void setUp() throws Exception { |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 final AwContents awContents) throws Exception { | 500 final AwContents awContents) throws Exception { |
| 498 return runTestOnUiThreadAndGetResult(new Callable<AwSettings>() { | 501 return runTestOnUiThreadAndGetResult(new Callable<AwSettings>() { |
| 499 @Override | 502 @Override |
| 500 public AwSettings call() throws Exception { | 503 public AwSettings call() throws Exception { |
| 501 return awContents.getSettings(); | 504 return awContents.getSettings(); |
| 502 } | 505 } |
| 503 }); | 506 }); |
| 504 } | 507 } |
| 505 | 508 |
| 506 /** | 509 /** |
| 510 * Verify double quotes in both sides of the raw string. Strip the double qu
otes and |
| 511 * returns rest of the string. |
| 512 */ |
| 513 protected String maybeStripDoubleQuotes(String raw) { |
| 514 assertNotNull(raw); |
| 515 Matcher m = MAYBE_QUOTED_STRING.matcher(raw); |
| 516 assertTrue(m.matches()); |
| 517 return m.group(2); |
| 518 } |
| 519 |
| 520 /** |
| 507 * Executes the given snippet of JavaScript code within the given ContentVie
w. Returns the | 521 * Executes the given snippet of JavaScript code within the given ContentVie
w. Returns the |
| 508 * result of its execution in JSON format. | 522 * result of its execution in JSON format. |
| 509 */ | 523 */ |
| 510 public String executeJavaScriptAndWaitForResult(final AwContents awContents, | 524 public String executeJavaScriptAndWaitForResult(final AwContents awContents, |
| 511 TestAwContentsClient viewClient, final String code) throws Exception
{ | 525 TestAwContentsClient viewClient, final String code) throws Exception
{ |
| 512 return JSUtils.executeJavaScriptAndWaitForResult(this, awContents, | 526 return JSUtils.executeJavaScriptAndWaitForResult(this, awContents, |
| 513 viewClient.getOnEvaluateJavaScriptResultHelper(), | 527 viewClient.getOnEvaluateJavaScriptResultHelper(), |
| 514 code); | 528 code); |
| 515 } | 529 } |
| 516 | 530 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 int titleCallCount = onReceivedTitleHelper.getCallCount(); | 697 int titleCallCount = onReceivedTitleHelper.getCallCount(); |
| 684 | 698 |
| 685 onPageFinishedHelper.waitForCallback(finishCallCount, 1, WAIT_TIMEOUT_MS
, | 699 onPageFinishedHelper.waitForCallback(finishCallCount, 1, WAIT_TIMEOUT_MS
, |
| 686 TimeUnit.MILLISECONDS); | 700 TimeUnit.MILLISECONDS); |
| 687 onReceivedTitleHelper.waitForCallback(titleCallCount, 1, WAIT_TIMEOUT_MS
, | 701 onReceivedTitleHelper.waitForCallback(titleCallCount, 1, WAIT_TIMEOUT_MS
, |
| 688 TimeUnit.MILLISECONDS); | 702 TimeUnit.MILLISECONDS); |
| 689 | 703 |
| 690 return new PopupInfo(popupContentsClient, popupContainerView, popupConte
nts); | 704 return new PopupInfo(popupContentsClient, popupContainerView, popupConte
nts); |
| 691 } | 705 } |
| 692 } | 706 } |
| OLD | NEW |