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

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

Issue 139493008: [android_webview] Call onPageFinished for anchor navigations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix indent Created 6 years, 10 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 | Annotate | Revision Log
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; 7 import android.graphics.Bitmap;
8 import android.test.suitebuilder.annotation.SmallTest; 8 import android.test.suitebuilder.annotation.SmallTest;
9 9
10 import org.chromium.android_webview.AwContents; 10 import org.chromium.android_webview.AwContents;
11 import org.chromium.android_webview.AwSettings; 11 import org.chromium.android_webview.AwSettings;
12 import org.chromium.android_webview.test.util.CommonResources; 12 import org.chromium.android_webview.test.util.CommonResources;
13 import org.chromium.base.test.util.DisabledTest; 13 import org.chromium.base.test.util.DisabledTest;
14 import org.chromium.base.test.util.Feature; 14 import org.chromium.base.test.util.Feature;
15 import org.chromium.content.browser.ContentViewCore; 15 import org.chromium.content.browser.ContentViewCore;
16 import org.chromium.content.browser.LoadUrlParams;
17 import org.chromium.content.browser.test.util.HistoryUtils; 16 import org.chromium.content.browser.test.util.HistoryUtils;
18 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; 17 import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
19 import org.chromium.net.test.util.TestWebServer; 18 import org.chromium.net.test.util.TestWebServer;
20 19
21 import java.io.File; 20 import java.io.File;
22 import java.io.FileOutputStream; 21 import java.io.FileOutputStream;
23 import java.util.concurrent.Callable; 22 import java.util.concurrent.Callable;
24 import java.util.concurrent.TimeUnit;
25 23
26 /** 24 /**
27 * Tests for the {@link android.webkit.WebView#loadDataWithBaseURL(String, Strin g, String, String, 25 * Tests for the {@link android.webkit.WebView#loadDataWithBaseURL(String, Strin g, String, String,
28 * String)} method. 26 * String)} method.
29 */ 27 */
30 public class LoadDataWithBaseUrlTest extends AwTestBase { 28 public class LoadDataWithBaseUrlTest extends AwTestBase {
31 29
32 private TestAwContentsClient mContentsClient; 30 private TestAwContentsClient mContentsClient;
33 private AwContents mAwContents; 31 private AwContents mAwContents;
34 private ContentViewCore mContentViewCore; 32 private ContentViewCore mContentViewCore;
35 33
36 @Override 34 @Override
37 public void setUp() throws Exception { 35 public void setUp() throws Exception {
38 super.setUp(); 36 super.setUp();
39 mContentsClient = new TestAwContentsClient(); 37 mContentsClient = new TestAwContentsClient();
40 final AwTestContainerView testContainerView = 38 final AwTestContainerView testContainerView =
41 createAwTestContainerViewOnMainSync(mContentsClient); 39 createAwTestContainerViewOnMainSync(mContentsClient);
42 mAwContents = testContainerView.getAwContents(); 40 mAwContents = testContainerView.getAwContents();
43 mContentViewCore = testContainerView.getContentViewCore(); 41 mContentViewCore = testContainerView.getContentViewCore();
44 } 42 }
45 43
46 protected void loadDataWithBaseUrlSync( 44 protected void loadDataWithBaseUrlSync(
47 final String data, final String mimeType, final boolean isBase64Encoded, 45 final String data, final String mimeType, final boolean isBase64Encoded,
48 final String baseUrl, final String historyUrl) throws Throwable { 46 final String baseUrl, final String historyUrl) throws Throwable {
49 TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = 47 loadDataWithBaseUrlSync(mAwContents, mContentsClient.getOnPageFinishedHe lper(),
50 mContentsClient.getOnPageFinishedHelper(); 48 data, mimeType, isBase64Encoded, baseUrl, historyUrl);
51 int currentCallCount = onPageFinishedHelper.getCallCount();
52 loadDataWithBaseUrlAsync(data, mimeType, isBase64Encoded, baseUrl, histo ryUrl);
53 onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_M S,
54 TimeUnit.MILLISECONDS);
55 }
56
57 protected void loadDataWithBaseUrlAsync(
58 final String data, final String mimeType, final boolean isBase64Encoded,
59 final String baseUrl, final String historyUrl) throws Throwable {
60 runTestOnUiThread(new Runnable() {
61 @Override
62 public void run() {
63 mAwContents.loadUrl(LoadUrlParams.createLoadDataParamsWithBaseUr l(
64 data, mimeType, isBase64Encoded, baseUrl, historyUrl));
65 }
66 });
67 } 49 }
68 50
69 private static final String SCRIPT_FILE = "/script.js"; 51 private static final String SCRIPT_FILE = "/script.js";
70 private static final String SCRIPT_LOADED = "Loaded"; 52 private static final String SCRIPT_LOADED = "Loaded";
71 private static final String SCRIPT_NOT_LOADED = "Not loaded"; 53 private static final String SCRIPT_NOT_LOADED = "Not loaded";
72 private static final String SCRIPT_JS = "script_was_loaded = true;"; 54 private static final String SCRIPT_JS = "script_was_loaded = true;";
73 55
74 private String getScriptFileTestPageHtml(final String scriptUrl) { 56 private String getScriptFileTestPageHtml(final String scriptUrl) {
75 return "<html>" + 57 return "<html>" +
76 " <head>" + 58 " <head>" +
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 assertEquals("about:blank", getTitleOnUiThread(mAwContents)); 178 assertEquals("about:blank", getTitleOnUiThread(mAwContents));
197 } 179 }
198 180
199 @SmallTest 181 @SmallTest
200 @Feature({"AndroidWebView"}) 182 @Feature({"AndroidWebView"})
201 public void testloadDataWithBaseUrlCallsOnPageStarted() throws Throwable { 183 public void testloadDataWithBaseUrlCallsOnPageStarted() throws Throwable {
202 final String baseUrl = "http://base.com/"; 184 final String baseUrl = "http://base.com/";
203 TestCallbackHelperContainer.OnPageStartedHelper onPageStartedHelper = 185 TestCallbackHelperContainer.OnPageStartedHelper onPageStartedHelper =
204 mContentsClient.getOnPageStartedHelper(); 186 mContentsClient.getOnPageStartedHelper();
205 final int callCount = onPageStartedHelper.getCallCount(); 187 final int callCount = onPageStartedHelper.getCallCount();
206 loadDataWithBaseUrlAsync(CommonResources.ABOUT_HTML, "text/html", false, baseUrl, 188 loadDataWithBaseUrlAsync(mAwContents, CommonResources.ABOUT_HTML, "text/ html", false,
207 "about:blank"); 189 baseUrl, "about:blank");
208 onPageStartedHelper.waitForCallback(callCount); 190 onPageStartedHelper.waitForCallback(callCount);
209 assertEquals(baseUrl, onPageStartedHelper.getUrl()); 191 assertEquals(baseUrl, onPageStartedHelper.getUrl());
210 } 192 }
211 193
212 @SmallTest 194 @SmallTest
213 @Feature({"AndroidWebView"}) 195 @Feature({"AndroidWebView"})
214 public void testHistoryUrl() throws Throwable { 196 public void testHistoryUrl() throws Throwable {
215 197
216 final String pageHtml = "<html><body>Hello, world!</body></html>"; 198 final String pageHtml = "<html><body>Hello, world!</body></html>";
217 final String baseUrl = "http://example.com"; 199 final String baseUrl = "http://example.com";
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 "file:///android_asset/asset_icon.png?" + token)); 350 "file:///android_asset/asset_icon.png?" + token));
369 assertTrue(canAccessFileFromData(NON_DATA_BASE_URL, 351 assertTrue(canAccessFileFromData(NON_DATA_BASE_URL,
370 "file:///android_res/raw/resource_icon.png?" + token)); 352 "file:///android_res/raw/resource_icon.png?" + token));
371 assertTrue(canAccessFileFromData(NON_DATA_BASE_URL, 353 assertTrue(canAccessFileFromData(NON_DATA_BASE_URL,
372 "file://" + imagePath + "?" + token)); 354 "file://" + imagePath + "?" + token));
373 } finally { 355 } finally {
374 if (!tempImage.delete()) throw new AssertionError(); 356 if (!tempImage.delete()) throw new AssertionError();
375 } 357 }
376 } 358 }
377 } 359 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698