Commit f14516de authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

AW: fix and renable onPageFinished test

No change to production logic.

This fixes a bad test and reenables it. In the test, the server and test
were deadlocked: the server was waiting for the test to finish, while
the test couldn't finish because the server wouldn't serve the second
page.

Instead, let the server complete the request shortly after we invoke
stopLoading(). This unblocks the server, but still guarantees the load
will still be provisional at the time we invoke stopLoading().

  --num_retries=0 --break-on-failure --repeat=1000 \
  -f ClientOnPageFinishedTest#testCalledAfterRedirectedUrlIsOverridden

Bug: 683384
Test: run_webview_instrumentation_test_apk \
Change-Id: I21be548fb1fd57724351fd372cc78d00062489b2
Reviewed-on: https://chromium-review.googlesource.com/1100547Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567840}
parent 2c1c1bd3
...@@ -18,7 +18,6 @@ import org.junit.runner.RunWith; ...@@ -18,7 +18,6 @@ import org.junit.runner.RunWith;
import org.chromium.android_webview.AwContents; import org.chromium.android_webview.AwContents;
import org.chromium.android_webview.test.util.CommonResources; import org.chromium.android_webview.test.util.CommonResources;
import org.chromium.android_webview.test.util.JSUtils; import org.chromium.android_webview.test.util.JSUtils;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.FlakyTest; import org.chromium.base.test.util.FlakyTest;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer; import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
...@@ -472,18 +471,19 @@ public class ClientOnPageFinishedTest { ...@@ -472,18 +471,19 @@ public class ClientOnPageFinishedTest {
* Ensure onPageFinished is called when a provisional load is cancelled. * Ensure onPageFinished is called when a provisional load is cancelled.
*/ */
@Test @Test
//@MediumTest @MediumTest
//@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
@DisabledTest(message = "crbug.com/683384")
public void testCalledOnCancelingProvisionalLoad() throws Throwable { public void testCalledOnCancelingProvisionalLoad() throws Throwable {
TestWebServer webServer = TestWebServer.start(); TestWebServer webServer = TestWebServer.start();
final CountDownLatch testDoneLatch = new CountDownLatch(1); final CountDownLatch firstUrlLatch = new CountDownLatch(1);
try { try {
final String url = webServer.setResponseWithRunnableAction( final String url = webServer.setResponseWithRunnableAction(
"/slow_page.html", "", null /* headers */, () -> { "/slow_page.html", "", null /* headers */, () -> {
try { try {
Assert.assertTrue(testDoneLatch.await(WAIT_TIMEOUT_MS, // Delay the server response so that we guarantee stopLoading() comes
java.util.concurrent.TimeUnit.MILLISECONDS)); // before the server response.
Assert.assertTrue(firstUrlLatch.await(
WAIT_TIMEOUT_MS, java.util.concurrent.TimeUnit.MILLISECONDS));
} catch (InterruptedException e) { } catch (InterruptedException e) {
Assert.fail("Caught InterruptedException " + e); Assert.fail("Caught InterruptedException " + e);
} }
...@@ -498,17 +498,16 @@ public class ClientOnPageFinishedTest { ...@@ -498,17 +498,16 @@ public class ClientOnPageFinishedTest {
onPageFinishedHelper.waitForCallback(initialCallCount); onPageFinishedHelper.waitForCallback(initialCallCount);
Assert.assertEquals(url, onPageFinishedHelper.getUrl()); Assert.assertEquals(url, onPageFinishedHelper.getUrl());
firstUrlLatch.countDown();
// Load another page to ensure onPageFinished isn't called several times. // Load another page to ensure onPageFinished isn't called several times.
final String syncUrl = webServer.setResponse("/sync.html", "", null); final String syncUrl = webServer.setResponse("/sync.html", "", null /* headers */);
final int synchronizationPageCallCount = onPageFinishedHelper.getCallCount(); mActivityTestRule.loadUrlSync(mAwContents, onPageFinishedHelper, syncUrl);
Assert.assertEquals(initialCallCount + 1, synchronizationPageCallCount);
mActivityTestRule.loadUrlAsync(mAwContents, syncUrl);
onPageFinishedHelper.waitForCallback(synchronizationPageCallCount);
Assert.assertEquals(syncUrl, onPageFinishedHelper.getUrl()); Assert.assertEquals(syncUrl, onPageFinishedHelper.getUrl());
final int finalCallCount = onPageFinishedHelper.getCallCount();
Assert.assertEquals(
"onPageFinished should be called twice", initialCallCount + 2, finalCallCount);
} finally { } finally {
testDoneLatch.countDown();
webServer.shutdown(); webServer.shutdown();
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment