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

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

Issue 11028094: [android_webview] Use AwContents loadUrl method instead of ContentViewCore. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase yet again Created 8 years, 2 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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.FlakyTest; 7 import android.test.FlakyTest;
8 import android.test.suitebuilder.annotation.MediumTest; 8 import android.test.suitebuilder.annotation.MediumTest;
9 9
10 import org.chromium.android_webview.AwContents;
10 import org.chromium.android_webview.AndroidProtocolHandler; 11 import org.chromium.android_webview.AndroidProtocolHandler;
11 import org.chromium.android_webview.ErrorCodeConversionHelper; 12 import org.chromium.android_webview.ErrorCodeConversionHelper;
12 import org.chromium.base.test.util.DisabledTest; 13 import org.chromium.base.test.util.DisabledTest;
13 import org.chromium.base.test.util.Feature; 14 import org.chromium.base.test.util.Feature;
14 import org.chromium.content.browser.ContentViewCore; 15 import org.chromium.content.browser.ContentViewCore;
15 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; 16 import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
16 17
17 /** 18 /**
18 * Tests for the ContentViewClient.onReceivedError() method. 19 * Tests for the ContentViewClient.onReceivedError() method.
19 */ 20 */
20 public class ClientOnReceivedErrorTest extends AndroidWebViewTestBase { 21 public class ClientOnReceivedErrorTest extends AndroidWebViewTestBase {
21 22
22 private TestAwContentsClient mContentsClient; 23 private TestAwContentsClient mContentsClient;
23 private ContentViewCore mContentViewCore; 24 private AwContents mAwContents;
24 25
25 @Override 26 @Override
26 public void setUp() throws Exception { 27 public void setUp() throws Exception {
27 super.setUp(); 28 super.setUp();
28 mContentsClient = new TestAwContentsClient(); 29 mContentsClient = new TestAwContentsClient();
29 mContentViewCore = 30 final AwTestContainerView testContainerView =
30 createAwTestContainerViewOnMainSync(mContentsClient).getContentV iewCore(); 31 createAwTestContainerViewOnMainSync(mContentsClient);
32 mAwContents = testContainerView.getAwContents();
31 } 33 }
32 34
33 /*@MediumTest 35 /*@MediumTest
34 *@Feature({"Android-WebView"}) 36 *@Feature({"Android-WebView"})
35 * Bug crbug.com/152033 37 * Bug crbug.com/152033
36 */ 38 */
37 @FlakyTest 39 @FlakyTest
38 public void testOnReceivedErrorOnInvalidUrl() throws Throwable { 40 public void testOnReceivedErrorOnInvalidUrl() throws Throwable {
39 TestCallbackHelperContainer.OnReceivedErrorHelper onReceivedErrorHelper = 41 TestCallbackHelperContainer.OnReceivedErrorHelper onReceivedErrorHelper =
40 mContentsClient.getOnReceivedErrorHelper(); 42 mContentsClient.getOnReceivedErrorHelper();
41 43
42 String url = "http://man.id.be.really.surprised.if.this.address.existed. blah/"; 44 String url = "http://man.id.be.really.surprised.if.this.address.existed. blah/";
43 int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(); 45 int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount();
44 loadUrlAsync(mContentViewCore, url); 46 loadUrlAsync(mAwContents, url);
45 47
46 onReceivedErrorHelper.waitForCallback(onReceivedErrorCallCount); 48 onReceivedErrorHelper.waitForCallback(onReceivedErrorCallCount);
47 assertEquals(ErrorCodeConversionHelper.ERROR_HOST_LOOKUP, 49 assertEquals(ErrorCodeConversionHelper.ERROR_HOST_LOOKUP,
48 onReceivedErrorHelper.getErrorCode()); 50 onReceivedErrorHelper.getErrorCode());
49 assertEquals(url, onReceivedErrorHelper.getFailingUrl()); 51 assertEquals(url, onReceivedErrorHelper.getFailingUrl());
50 assertNotNull(onReceivedErrorHelper.getDescription()); 52 assertNotNull(onReceivedErrorHelper.getDescription());
51 } 53 }
52 54
53 /* 55 /*
54 @MediumTest 56 @MediumTest
55 @Feature({"Android-WebView"}) 57 @Feature({"Android-WebView"})
56 http://crbug.com/148369 58 http://crbug.com/148369
57 */ 59 */
58 @DisabledTest 60 @DisabledTest
59 public void testOnReceivedErrorOnInvalidScheme() throws Throwable { 61 public void testOnReceivedErrorOnInvalidScheme() throws Throwable {
60 TestCallbackHelperContainer.OnReceivedErrorHelper onReceivedErrorHelper = 62 TestCallbackHelperContainer.OnReceivedErrorHelper onReceivedErrorHelper =
61 mContentsClient.getOnReceivedErrorHelper(); 63 mContentsClient.getOnReceivedErrorHelper();
62 64
63 String url = "foo://some/resource"; 65 String url = "foo://some/resource";
64 int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(); 66 int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount();
65 loadUrlAsync(mContentViewCore, url); 67 loadUrlAsync(mAwContents, url);
66 68
67 onReceivedErrorHelper.waitForCallback(onReceivedErrorCallCount); 69 onReceivedErrorHelper.waitForCallback(onReceivedErrorCallCount);
68 assertEquals(ErrorCodeConversionHelper.ERROR_UNSUPPORTED_SCHEME, 70 assertEquals(ErrorCodeConversionHelper.ERROR_UNSUPPORTED_SCHEME,
69 onReceivedErrorHelper.getErrorCode()); 71 onReceivedErrorHelper.getErrorCode());
70 assertEquals(url, onReceivedErrorHelper.getFailingUrl()); 72 assertEquals(url, onReceivedErrorHelper.getFailingUrl());
71 assertNotNull(onReceivedErrorHelper.getDescription()); 73 assertNotNull(onReceivedErrorHelper.getDescription());
72 } 74 }
73 75
74 @MediumTest 76 @MediumTest
75 @Feature({"Android-WebView"}) 77 @Feature({"Android-WebView"})
76 public void testNoErrorOnFailedSubresourceLoad() throws Throwable { 78 public void testNoErrorOnFailedSubresourceLoad() throws Throwable {
77 TestCallbackHelperContainer.OnReceivedErrorHelper onReceivedErrorHelper = 79 TestCallbackHelperContainer.OnReceivedErrorHelper onReceivedErrorHelper =
78 mContentsClient.getOnReceivedErrorHelper(); 80 mContentsClient.getOnReceivedErrorHelper();
79 TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = 81 TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper =
80 mContentsClient.getOnPageFinishedHelper(); 82 mContentsClient.getOnPageFinishedHelper();
81 83
82 int currentCallCount = onPageFinishedHelper.getCallCount(); 84 int currentCallCount = onPageFinishedHelper.getCallCount();
83 loadDataAsync(mContentViewCore, 85 loadDataAsync(mAwContents,
84 "<html><iframe src=\"http//invalid.url.co/\" /></html>", 86 "<html><iframe src=\"http//invalid.url.co/\" /></html>",
85 "text/html", 87 "text/html",
86 false); 88 false);
87 89
88 onPageFinishedHelper.waitForCallback(currentCallCount); 90 onPageFinishedHelper.waitForCallback(currentCallCount);
89 assertEquals(0, onReceivedErrorHelper.getCallCount()); 91 assertEquals(0, onReceivedErrorHelper.getCallCount());
90 } 92 }
91 93
92 @MediumTest 94 @MediumTest
93 @Feature({"Android-WebView"}) 95 @Feature({"Android-WebView"})
94 public void testNonExistentAssetUrl() throws Throwable { 96 public void testNonExistentAssetUrl() throws Throwable {
95 TestCallbackHelperContainer.OnReceivedErrorHelper onReceivedErrorHelper = 97 TestCallbackHelperContainer.OnReceivedErrorHelper onReceivedErrorHelper =
96 mContentsClient.getOnReceivedErrorHelper(); 98 mContentsClient.getOnReceivedErrorHelper();
97 try { 99 try {
98 final String url = "file:///android_asset/does_not_exist.html"; 100 final String url = "file:///android_asset/does_not_exist.html";
99 int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(); 101 int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount();
100 useTestResourceContext(); 102 useTestResourceContext();
101 loadUrlAsync(mContentViewCore, url); 103 loadUrlAsync(mAwContents, url);
102 104
103 onReceivedErrorHelper.waitForCallback(onReceivedErrorCallCount); 105 onReceivedErrorHelper.waitForCallback(onReceivedErrorCallCount);
104 assertEquals(ErrorCodeConversionHelper.ERROR_UNKNOWN, 106 assertEquals(ErrorCodeConversionHelper.ERROR_UNKNOWN,
105 onReceivedErrorHelper.getErrorCode()); 107 onReceivedErrorHelper.getErrorCode());
106 assertEquals(url, onReceivedErrorHelper.getFailingUrl()); 108 assertEquals(url, onReceivedErrorHelper.getFailingUrl());
107 assertNotNull(onReceivedErrorHelper.getDescription()); 109 assertNotNull(onReceivedErrorHelper.getDescription());
108 } finally { 110 } finally {
109 resetResourceContext(); 111 resetResourceContext();
110 } 112 }
111 } 113 }
112 114
113 @MediumTest 115 @MediumTest
114 @Feature({"Android-WebView"}) 116 @Feature({"Android-WebView"})
115 public void testNonExistentResourceUrl() throws Throwable { 117 public void testNonExistentResourceUrl() throws Throwable {
116 TestCallbackHelperContainer.OnReceivedErrorHelper onReceivedErrorHelper = 118 TestCallbackHelperContainer.OnReceivedErrorHelper onReceivedErrorHelper =
117 mContentsClient.getOnReceivedErrorHelper(); 119 mContentsClient.getOnReceivedErrorHelper();
118 try { 120 try {
119 final String url = "file:///android_res/raw/does_not_exist.html"; 121 final String url = "file:///android_res/raw/does_not_exist.html";
120 int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(); 122 int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount();
121 useTestResourceContext(); 123 useTestResourceContext();
122 loadUrlAsync(mContentViewCore, url); 124 loadUrlAsync(mAwContents, url);
123 125
124 onReceivedErrorHelper.waitForCallback(onReceivedErrorCallCount); 126 onReceivedErrorHelper.waitForCallback(onReceivedErrorCallCount);
125 assertEquals(ErrorCodeConversionHelper.ERROR_UNKNOWN, 127 assertEquals(ErrorCodeConversionHelper.ERROR_UNKNOWN,
126 onReceivedErrorHelper.getErrorCode()); 128 onReceivedErrorHelper.getErrorCode());
127 assertEquals(url, onReceivedErrorHelper.getFailingUrl()); 129 assertEquals(url, onReceivedErrorHelper.getFailingUrl());
128 assertNotNull(onReceivedErrorHelper.getDescription()); 130 assertNotNull(onReceivedErrorHelper.getDescription());
129 } finally { 131 } finally {
130 resetResourceContext(); 132 resetResourceContext();
131 } 133 }
132 } 134 }
133 135
134 /** 136 /**
135 * Configure the browser to load resources from the test harness instead of the browser 137 * Configure the browser to load resources from the test harness instead of the browser
136 * application. 138 * application.
137 */ 139 */
138 private void useTestResourceContext() { 140 private void useTestResourceContext() {
139 AndroidProtocolHandler.setResourceContextForTesting(getInstrumentation() .getContext()); 141 AndroidProtocolHandler.setResourceContextForTesting(getInstrumentation() .getContext());
140 } 142 }
141 143
142 /** 144 /**
143 * Configure the browser to load resources from the browser application. 145 * Configure the browser to load resources from the browser application.
144 */ 146 */
145 private void resetResourceContext() { 147 private void resetResourceContext() {
146 AndroidProtocolHandler.setResourceContextForTesting(null); 148 AndroidProtocolHandler.setResourceContextForTesting(null);
147 } 149 }
148 } 150 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698