| 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 android.test.suitebuilder.annotation.SmallTest; | 7 import android.test.suitebuilder.annotation.SmallTest; |
| 8 import android.util.Pair; | 8 import android.util.Pair; |
| 9 | 9 |
| 10 import org.chromium.android_webview.AwContents; | 10 import org.chromium.android_webview.AwContents; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * Tests for the WebViewClient.shouldOverrideUrlLoading() method. | 26 * Tests for the WebViewClient.shouldOverrideUrlLoading() method. |
| 27 */ | 27 */ |
| 28 public class AwContentsClientShouldOverrideUrlLoadingTest extends AwTestBase { | 28 public class AwContentsClientShouldOverrideUrlLoadingTest extends AwTestBase { |
| 29 private static final String ABOUT_BLANK_URL = "about:blank"; | 29 private static final String ABOUT_BLANK_URL = "about:blank"; |
| 30 private static final String DATA_URL = "data:text/html,<div/>"; | 30 private static final String DATA_URL = "data:text/html,<div/>"; |
| 31 private static final String REDIRECT_TARGET_PATH = "/redirect_target.html"; | 31 private static final String REDIRECT_TARGET_PATH = "/redirect_target.html"; |
| 32 private static final String TITLE = "TITLE"; | 32 private static final String TITLE = "TITLE"; |
| 33 | 33 |
| 34 private static class TestAwContentsClient | |
| 35 extends org.chromium.android_webview.test.TestAwContentsClient { | |
| 36 | |
| 37 public static class ShouldOverrideUrlLoadingHelper extends CallbackHelpe
r { | |
| 38 private String mShouldOverrideUrlLoadingUrl; | |
| 39 private String mPreviousShouldOverrideUrlLoadingUrl; | |
| 40 private boolean mShouldOverrideUrlLoadingReturnValue = false; | |
| 41 void setShouldOverrideUrlLoadingUrl(String url) { | |
| 42 mShouldOverrideUrlLoadingUrl = url; | |
| 43 } | |
| 44 void setPreviousShouldOverrideUrlLoadingUrl(String url) { | |
| 45 mPreviousShouldOverrideUrlLoadingUrl = url; | |
| 46 } | |
| 47 void setShouldOverrideUrlLoadingReturnValue(boolean value) { | |
| 48 mShouldOverrideUrlLoadingReturnValue = value; | |
| 49 } | |
| 50 public String getShouldOverrideUrlLoadingUrl() { | |
| 51 assert getCallCount() > 0; | |
| 52 return mShouldOverrideUrlLoadingUrl; | |
| 53 } | |
| 54 public String getPreviousShouldOverrideUrlLoadingUrl() { | |
| 55 assert getCallCount() > 1; | |
| 56 return mPreviousShouldOverrideUrlLoadingUrl; | |
| 57 } | |
| 58 public boolean getShouldOverrideUrlLoadingReturnValue() { | |
| 59 return mShouldOverrideUrlLoadingReturnValue; | |
| 60 } | |
| 61 public void notifyCalled(String url) { | |
| 62 mPreviousShouldOverrideUrlLoadingUrl = mShouldOverrideUrlLoading
Url; | |
| 63 mShouldOverrideUrlLoadingUrl = url; | |
| 64 notifyCalled(); | |
| 65 } | |
| 66 } | |
| 67 | |
| 68 @Override | |
| 69 public boolean shouldOverrideUrlLoading(String url) { | |
| 70 super.shouldOverrideUrlLoading(url); | |
| 71 boolean returnValue = | |
| 72 mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingRetur
nValue(); | |
| 73 mShouldOverrideUrlLoadingHelper.notifyCalled(url); | |
| 74 return returnValue; | |
| 75 } | |
| 76 | |
| 77 private ShouldOverrideUrlLoadingHelper mShouldOverrideUrlLoadingHelper; | |
| 78 | |
| 79 public TestAwContentsClient() { | |
| 80 mShouldOverrideUrlLoadingHelper = new ShouldOverrideUrlLoadingHelper
(); | |
| 81 } | |
| 82 | |
| 83 public ShouldOverrideUrlLoadingHelper getShouldOverrideUrlLoadingHelper(
) { | |
| 84 return mShouldOverrideUrlLoadingHelper; | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 private TestWebServer mWebServer; | 34 private TestWebServer mWebServer; |
| 89 | 35 |
| 90 @Override | 36 @Override |
| 91 protected void setUp() throws Exception { | 37 protected void setUp() throws Exception { |
| 92 super.setUp(); | 38 super.setUp(); |
| 93 mWebServer = new TestWebServer(false); | 39 mWebServer = new TestWebServer(false); |
| 94 } | 40 } |
| 95 | 41 |
| 96 @Override | 42 @Override |
| 97 protected void tearDown() throws Exception { | 43 protected void tearDown() throws Exception { |
| (...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", f
alse)); | 816 getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", f
alse)); |
| 871 awContents.loadUrl(new LoadUrlParams(jsUrl)); | 817 awContents.loadUrl(new LoadUrlParams(jsUrl)); |
| 872 } | 818 } |
| 873 }); | 819 }); |
| 874 contentsClient.getOnPageFinishedHelper().waitForCallback(currentCallCoun
t, 1, | 820 contentsClient.getOnPageFinishedHelper().waitForCallback(currentCallCoun
t, 1, |
| 875 WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS); | 821 WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS); |
| 876 | 822 |
| 877 assertEquals(0, shouldOverrideUrlLoadingHelper.getCallCount()); | 823 assertEquals(0, shouldOverrideUrlLoadingHelper.getCallCount()); |
| 878 } | 824 } |
| 879 } | 825 } |
| OLD | NEW |