Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(681)

Side by Side Diff: android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldInterceptRequestTest.java

Issue 552813002: [android_webview] Use a MotionEvent to trigger ShouldInterceptRequest tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | android_webview/javatests/src/org/chromium/android_webview/test/WebKitHitTestTest.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 //
247 // The code here is waiting for the "link" (which is a full-screen blue div) to appear on
248 // screen.
249 pollOnUiThread(new Callable<Boolean>() {
250 @Override
251 public Boolean call() throws Exception {
252 Bitmap bitmap = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_888 8);
253 Canvas canvas = new Canvas(bitmap);
254 canvas.translate(-(float)mTestContainerView.getWidth() / 2,
255 -(float)mTestContainerView.getHeight() / 2);
256 mAwContents.onDraw(canvas);
257 return bitmap.getPixel(0, 0) == Color.BLUE;
258 }
259 });
239 callCount = mShouldInterceptRequestHelper.getCallCount(); 260 callCount = mShouldInterceptRequestHelper.getCallCount();
240 JSUtils.clickOnLinkUsingJs(this, mAwContents, 261 AwTestTouchUtils.simulateTouchCenterOfView(mTestContainerView);
241 mContentsClient.getOnEvaluateJavaScriptResultHelper(), "link");
242 mShouldInterceptRequestHelper.waitForCallback(callCount); 262 mShouldInterceptRequestHelper.waitForCallback(callCount);
243 assertEquals(true, 263 assertEquals(true,
244 mShouldInterceptRequestHelper.getParamsForUrl(aboutPageUrl).hasU serGesture); 264 mShouldInterceptRequestHelper.getParamsForUrl(aboutPageUrl).hasU serGesture);
245 } 265 }
246 266
247 @SmallTest 267 @SmallTest
248 @Feature({"AndroidWebView"}) 268 @Feature({"AndroidWebView"})
249 public void testCalledWithCorrectHeadersParam() throws Throwable { 269 public void testCalledWithCorrectHeadersParam() throws Throwable {
250 final String headerName = "X-Test-Header-Name"; 270 final String headerName = "X-Test-Header-Name";
251 final String headerValue = "TestHeaderValue"; 271 final String headerValue = "TestHeaderValue";
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 getInstrumentation().getTargetContext(), contentResourceName); 800 getInstrumentation().getTargetContext(), contentResourceName);
781 assertEquals(1, contentRequestCount); 801 assertEquals(1, contentRequestCount);
782 } 802 }
783 803
784 @SmallTest 804 @SmallTest
785 @Feature({"AndroidWebView"}) 805 @Feature({"AndroidWebView"})
786 public void testCalledForNonexistentContentUrl() throws Throwable { 806 public void testCalledForNonexistentContentUrl() throws Throwable {
787 calledForUrlTemplate("content://org.chromium.webview.NoSuchProvider/foo" ); 807 calledForUrlTemplate("content://org.chromium.webview.NoSuchProvider/foo" );
788 } 808 }
789 } 809 }
OLDNEW
« no previous file with comments | « no previous file | android_webview/javatests/src/org/chromium/android_webview/test/WebKitHitTestTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698