OLD | NEW |
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.test.util.TestWebServer; | 11 import org.chromium.android_webview.test.util.TestWebServer; |
11 import org.chromium.base.test.util.Feature; | 12 import org.chromium.base.test.util.Feature; |
12 import org.chromium.content.browser.ContentViewCore; | |
13 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; | 13 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; |
14 | 14 |
15 /** | 15 /** |
16 * Tests for the ContentViewClient.onPageFinished() method. | 16 * Tests for the ContentViewClient.onPageFinished() method. |
17 */ | 17 */ |
18 public class ClientOnPageFinishedTest extends AndroidWebViewTestBase { | 18 public class ClientOnPageFinishedTest extends AndroidWebViewTestBase { |
19 | 19 |
20 private TestAwContentsClient mContentsClient; | 20 private TestAwContentsClient mContentsClient; |
21 private ContentViewCore mContentViewCore; | 21 private AwContents mAwContents; |
22 | 22 |
23 @Override | 23 @Override |
24 public void setUp() throws Exception { | 24 public void setUp() throws Exception { |
25 super.setUp(); | 25 super.setUp(); |
26 mContentsClient = new TestAwContentsClient(); | 26 mContentsClient = new TestAwContentsClient(); |
27 mContentViewCore = | 27 final AwTestContainerView testContainerView = |
28 createAwTestContainerViewOnMainSync(mContentsClient).getContentV
iewCore(); | 28 createAwTestContainerViewOnMainSync(mContentsClient); |
| 29 mAwContents = testContainerView.getAwContents(); |
29 } | 30 } |
30 | 31 |
31 @MediumTest | 32 @MediumTest |
32 @Feature({"Android-WebView"}) | 33 @Feature({"Android-WebView"}) |
33 public void testOnPageFinishedPassesCorrectUrl() throws Throwable { | 34 public void testOnPageFinishedPassesCorrectUrl() throws Throwable { |
34 TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = | 35 TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = |
35 mContentsClient.getOnPageFinishedHelper(); | 36 mContentsClient.getOnPageFinishedHelper(); |
36 | 37 |
37 String html = "<html><body>Simple page.</body></html>"; | 38 String html = "<html><body>Simple page.</body></html>"; |
38 int currentCallCount = onPageFinishedHelper.getCallCount(); | 39 int currentCallCount = onPageFinishedHelper.getCallCount(); |
39 loadDataAsync(mContentViewCore, html, "text/html", false); | 40 loadDataAsync(mAwContents, html, "text/html", false); |
40 | 41 |
41 onPageFinishedHelper.waitForCallback(currentCallCount); | 42 onPageFinishedHelper.waitForCallback(currentCallCount); |
42 assertEquals("data:text/html," + html, onPageFinishedHelper.getUrl()); | 43 assertEquals("data:text/html," + html, onPageFinishedHelper.getUrl()); |
43 } | 44 } |
44 | 45 |
45 //@MediumTest | 46 //@MediumTest |
46 //@Feature({"Android-WebView"}) | 47 //@Feature({"Android-WebView"}) |
47 // See crbug.com/148917 | 48 // See crbug.com/148917 |
48 @FlakyTest | 49 @FlakyTest |
49 public void testOnPageFinishedCalledAfterError() throws Throwable { | 50 public void testOnPageFinishedCalledAfterError() throws Throwable { |
50 TestCallbackHelperContainer.OnReceivedErrorHelper onReceivedErrorHelper
= | 51 TestCallbackHelperContainer.OnReceivedErrorHelper onReceivedErrorHelper
= |
51 mContentsClient.getOnReceivedErrorHelper(); | 52 mContentsClient.getOnReceivedErrorHelper(); |
52 TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = | 53 TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = |
53 mContentsClient.getOnPageFinishedHelper(); | 54 mContentsClient.getOnPageFinishedHelper(); |
54 | 55 |
55 assertEquals(0, onReceivedErrorHelper.getCallCount()); | 56 assertEquals(0, onReceivedErrorHelper.getCallCount()); |
56 | 57 |
57 String url = "http://man.id.be.really.surprised.if.this.address.existed.
blah/"; | 58 String url = "http://man.id.be.really.surprised.if.this.address.existed.
blah/"; |
58 int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(); | 59 int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(); |
59 int onPageFinishedCallCount = onPageFinishedHelper.getCallCount(); | 60 int onPageFinishedCallCount = onPageFinishedHelper.getCallCount(); |
60 loadUrlAsync(mContentViewCore, url); | 61 loadUrlAsync(mAwContents, url); |
61 | 62 |
62 onReceivedErrorHelper.waitForCallback(onReceivedErrorCallCount); | 63 onReceivedErrorHelper.waitForCallback(onReceivedErrorCallCount); |
63 onPageFinishedHelper.waitForCallback(onPageFinishedCallCount); | 64 onPageFinishedHelper.waitForCallback(onPageFinishedCallCount); |
64 assertEquals(1, onReceivedErrorHelper.getCallCount()); | 65 assertEquals(1, onReceivedErrorHelper.getCallCount()); |
65 } | 66 } |
66 | 67 |
67 @MediumTest | 68 @MediumTest |
68 @Feature({"Android-WebView"}) | 69 @Feature({"Android-WebView"}) |
69 public void testOnPageFinishedNotCalledForValidSubresources() throws Throwab
le { | 70 public void testOnPageFinishedNotCalledForValidSubresources() throws Throwab
le { |
70 TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = | 71 TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = |
71 mContentsClient.getOnPageFinishedHelper(); | 72 mContentsClient.getOnPageFinishedHelper(); |
72 | 73 |
73 TestWebServer webServer = null; | 74 TestWebServer webServer = null; |
74 try { | 75 try { |
75 webServer = new TestWebServer(false); | 76 webServer = new TestWebServer(false); |
76 | 77 |
77 final String testHtml = "<html><head>Header</head><body>Body</body><
/html>"; | 78 final String testHtml = "<html><head>Header</head><body>Body</body><
/html>"; |
78 final String testPath = "/test.html"; | 79 final String testPath = "/test.html"; |
79 final String syncPath = "/sync.html"; | 80 final String syncPath = "/sync.html"; |
80 | 81 |
81 final String testUrl = webServer.setResponse(testPath, testHtml, nul
l); | 82 final String testUrl = webServer.setResponse(testPath, testHtml, nul
l); |
82 final String syncUrl = webServer.setResponse(syncPath, testHtml, nul
l); | 83 final String syncUrl = webServer.setResponse(syncPath, testHtml, nul
l); |
83 | 84 |
84 assertEquals(0, onPageFinishedHelper.getCallCount()); | 85 assertEquals(0, onPageFinishedHelper.getCallCount()); |
85 final int pageWithSubresourcesCallCount = onPageFinishedHelper.getCa
llCount(); | 86 final int pageWithSubresourcesCallCount = onPageFinishedHelper.getCa
llCount(); |
86 loadDataAsync(mContentViewCore, | 87 loadDataAsync(mAwContents, |
87 "<html><iframe src=\"" + testPath + "\" /></html>", | 88 "<html><iframe src=\"" + testPath + "\" /></html>", |
88 "text/html", | 89 "text/html", |
89 false); | 90 false); |
90 | 91 |
91 onPageFinishedHelper.waitForCallback(pageWithSubresourcesCallCount); | 92 onPageFinishedHelper.waitForCallback(pageWithSubresourcesCallCount); |
92 | 93 |
93 // Rather than wait a fixed time to see that an onPageFinished callb
ack isn't issued | 94 // Rather than wait a fixed time to see that an onPageFinished callb
ack isn't issued |
94 // we load another valid page. Since callbacks arrive sequentially i
f the next callback | 95 // we load another valid page. Since callbacks arrive sequentially i
f the next callback |
95 // we get is for the synchronizationUrl we know that the previous lo
ad did not schedule | 96 // we get is for the synchronizationUrl we know that the previous lo
ad did not schedule |
96 // a callback for the iframe. | 97 // a callback for the iframe. |
97 final int synchronizationPageCallCount = onPageFinishedHelper.getCal
lCount(); | 98 final int synchronizationPageCallCount = onPageFinishedHelper.getCal
lCount(); |
98 loadUrlAsync(mContentViewCore, syncUrl); | 99 loadUrlAsync(mAwContents, syncUrl); |
99 | 100 |
100 onPageFinishedHelper.waitForCallback(synchronizationPageCallCount); | 101 onPageFinishedHelper.waitForCallback(synchronizationPageCallCount); |
101 assertEquals(syncUrl, onPageFinishedHelper.getUrl()); | 102 assertEquals(syncUrl, onPageFinishedHelper.getUrl()); |
102 assertEquals(2, onPageFinishedHelper.getCallCount()); | 103 assertEquals(2, onPageFinishedHelper.getCallCount()); |
103 | 104 |
104 } finally { | 105 } finally { |
105 if (webServer != null) webServer.shutdown(); | 106 if (webServer != null) webServer.shutdown(); |
106 } | 107 } |
107 } | 108 } |
108 } | 109 } |
OLD | NEW |