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.graphics.Bitmap; | |
8 import android.graphics.Canvas; | |
9 import android.graphics.Color; | |
7 import android.test.suitebuilder.annotation.SmallTest; | 10 import android.test.suitebuilder.annotation.SmallTest; |
8 import android.util.Pair; | 11 import android.util.Pair; |
9 | 12 |
10 import org.chromium.android_webview.AwContents; | 13 import org.chromium.android_webview.AwContents; |
11 import org.chromium.android_webview.AwContentsClient.ShouldInterceptRequestParam s; | 14 import org.chromium.android_webview.AwContentsClient.ShouldInterceptRequestParam s; |
12 import org.chromium.android_webview.AwWebResourceResponse; | 15 import org.chromium.android_webview.AwWebResourceResponse; |
16 import org.chromium.android_webview.test.util.AwTestTouchUtils; | |
13 import org.chromium.android_webview.test.util.CommonResources; | 17 import org.chromium.android_webview.test.util.CommonResources; |
14 import org.chromium.android_webview.test.util.JSUtils; | 18 import org.chromium.android_webview.test.util.JSUtils; |
15 import org.chromium.base.test.util.Feature; | 19 import org.chromium.base.test.util.Feature; |
16 import org.chromium.base.test.util.TestFileUtil; | 20 import org.chromium.base.test.util.TestFileUtil; |
17 import org.chromium.content.browser.test.util.CallbackHelper; | 21 import org.chromium.content.browser.test.util.CallbackHelper; |
18 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnRece ivedErrorHelper; | 22 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnRece ivedErrorHelper; |
19 import org.chromium.net.test.util.TestWebServer; | 23 import org.chromium.net.test.util.TestWebServer; |
20 | 24 |
21 import java.io.ByteArrayInputStream; | 25 import java.io.ByteArrayInputStream; |
22 import java.io.IOException; | 26 import java.io.IOException; |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 final String pageWithLinkUrl = addPageToTestServer(mWebServer, "/page_wi th_link.html", | 233 final String pageWithLinkUrl = addPageToTestServer(mWebServer, "/page_wi th_link.html", |
230 CommonResources.makeHtmlPageWithSimpleLinkTo(aboutPageUrl)); | 234 CommonResources.makeHtmlPageWithSimpleLinkTo(aboutPageUrl)); |
231 enableJavaScriptOnUiThread(mAwContents); | 235 enableJavaScriptOnUiThread(mAwContents); |
232 | 236 |
233 int callCount = mShouldInterceptRequestHelper.getCallCount(); | 237 int callCount = mShouldInterceptRequestHelper.getCallCount(); |
234 loadUrlAsync(mAwContents, pageWithLinkUrl); | 238 loadUrlAsync(mAwContents, pageWithLinkUrl); |
235 mShouldInterceptRequestHelper.waitForCallback(callCount); | 239 mShouldInterceptRequestHelper.waitForCallback(callCount); |
236 assertEquals(false, | 240 assertEquals(false, |
237 mShouldInterceptRequestHelper.getParamsForUrl(pageWithLinkUrl).h asUserGesture); | 241 mShouldInterceptRequestHelper.getParamsForUrl(pageWithLinkUrl).h asUserGesture); |
238 | 242 |
243 // TODO(mkosiba): Remove this once we have a real API to wait for the pa ge to load and | |
244 // display. | |
245 // http://crbug.com/364612 | |
246 pollOnUiThread(new Callable<Boolean>() { | |
247 @Override | |
248 public Boolean call() throws Exception { | |
249 Bitmap bitmap = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_888 8); | |
250 Canvas canvas = new Canvas(bitmap); | |
251 canvas.translate(-mTestContainerView.getWidth() / 2, | |
252 -mTestContainerView.getHeight() / 2); | |
253 mAwContents.onDraw(canvas); | |
254 return bitmap.getPixel(0, 0) == Color.BLUE; | |
boliu
2014/09/08 16:02:55
That looks *super* brittle. What if text rendering
mkosiba (inactive)
2014/09/08 16:54:36
This is not checking the text to be blue. The "lin
boliu
2014/09/08 17:02:10
Meh, badly named function then.
side note, why em
| |
255 } | |
256 }); | |
239 callCount = mShouldInterceptRequestHelper.getCallCount(); | 257 callCount = mShouldInterceptRequestHelper.getCallCount(); |
240 JSUtils.clickOnLinkUsingJs(this, mAwContents, | 258 AwTestTouchUtils.simulateTouchCenterOfView(mTestContainerView); |
241 mContentsClient.getOnEvaluateJavaScriptResultHelper(), "link"); | |
242 mShouldInterceptRequestHelper.waitForCallback(callCount); | 259 mShouldInterceptRequestHelper.waitForCallback(callCount); |
243 assertEquals(true, | 260 assertEquals(true, |
244 mShouldInterceptRequestHelper.getParamsForUrl(aboutPageUrl).hasU serGesture); | 261 mShouldInterceptRequestHelper.getParamsForUrl(aboutPageUrl).hasU serGesture); |
245 } | 262 } |
246 | 263 |
247 @SmallTest | 264 @SmallTest |
248 @Feature({"AndroidWebView"}) | 265 @Feature({"AndroidWebView"}) |
249 public void testCalledWithCorrectHeadersParam() throws Throwable { | 266 public void testCalledWithCorrectHeadersParam() throws Throwable { |
250 final String headerName = "X-Test-Header-Name"; | 267 final String headerName = "X-Test-Header-Name"; |
251 final String headerValue = "TestHeaderValue"; | 268 final String headerValue = "TestHeaderValue"; |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
780 getInstrumentation().getTargetContext(), contentResourceName); | 797 getInstrumentation().getTargetContext(), contentResourceName); |
781 assertEquals(1, contentRequestCount); | 798 assertEquals(1, contentRequestCount); |
782 } | 799 } |
783 | 800 |
784 @SmallTest | 801 @SmallTest |
785 @Feature({"AndroidWebView"}) | 802 @Feature({"AndroidWebView"}) |
786 public void testCalledForNonexistentContentUrl() throws Throwable { | 803 public void testCalledForNonexistentContentUrl() throws Throwable { |
787 calledForUrlTemplate("content://org.chromium.webview.NoSuchProvider/foo" ); | 804 calledForUrlTemplate("content://org.chromium.webview.NoSuchProvider/foo" ); |
788 } | 805 } |
789 } | 806 } |
OLD | NEW |