diff options
author | mnaganov <mnaganov@chromium.org> | 2015-06-22 08:50:27 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-22 15:50:57 +0000 |
commit | c4c75cdc4114a5c259bab77b8cf74d683c741bc6 (patch) | |
tree | 82c27edebe434055421d968da210b966e0579901 /android_webview/javatests | |
parent | 5aa3f26c3a738ad4a320b767cbf7d565101573de (diff) | |
download | chromium_src-c4c75cdc4114a5c259bab77b8cf74d683c741bc6.zip chromium_src-c4c75cdc4114a5c259bab77b8cf74d683c741bc6.tar.gz chromium_src-c4c75cdc4114a5c259bab77b8cf74d683c741bc6.tar.bz2 |
[Android WebView] Convert some more callbacks into embedder to be async
Callbacks in WebContentsObserver are called synchronously from Navigator
(via WebContents), thus it is safer to post them to embedders
asynchronously.
OnFormResubmission is called synchronously from inside
NavigationControllerImpl::ReloadInternal.
Fix tests that started failing because they were relying on callbacks
being synchronous.
BUG=495234
Review URL: https://codereview.chromium.org/1192933003
Cr-Commit-Position: refs/heads/master@{#335507}
Diffstat (limited to 'android_webview/javatests')
-rw-r--r-- | android_webview/javatests/src/org/chromium/android_webview/test/AwWebContentsObserverTest.java | 100 |
1 files changed, 69 insertions, 31 deletions
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwWebContentsObserverTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwWebContentsObserverTest.java index db0e1e3..460fc4c 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/AwWebContentsObserverTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwWebContentsObserverTest.java @@ -11,6 +11,7 @@ import org.chromium.android_webview.AwContentsStatics; import org.chromium.android_webview.AwWebContentsObserver; import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.MinAndroidSdkLevel; +import org.chromium.content.browser.test.util.TestCallbackHelperContainer; /** * Tests for the AwWebContentsObserver class. @@ -22,6 +23,7 @@ public class AwWebContentsObserverTest extends AwTestBase { private AwWebContentsObserver mWebContentsObserver; private static final String EXAMPLE_URL = "http://www.example.com/"; + private static final String SYNC_URL = "http://example.org/"; private static final String ERROR_DESCRIPTION = "description"; private String mUnreachableWebDataUrl; @@ -44,66 +46,102 @@ public class AwWebContentsObserverTest extends AwTestBase { @SmallTest @Feature({"AndroidWebView"}) - public void testOnPageFinished() { + public void testOnPageFinished() throws Throwable { int frameId = 0; boolean mainFrame = true; boolean subFrame = false; + final TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = + mContentsClient.getOnPageFinishedHelper(); - int callCount = mContentsClient.getOnPageFinishedHelper().getCallCount(); - mWebContentsObserver.didFinishLoad(frameId, EXAMPLE_URL, subFrame); - assertEquals("onPageFinished should only be called for the main frame.", callCount, - mContentsClient.getOnPageFinishedHelper().getCallCount()); - - callCount = mContentsClient.getOnPageFinishedHelper().getCallCount(); - mWebContentsObserver.didFinishLoad(frameId, mUnreachableWebDataUrl, mainFrame); - assertEquals("onPageFinished should not be called for the error url.", callCount, - mContentsClient.getOnPageFinishedHelper().getCallCount()); - - callCount = mContentsClient.getOnPageFinishedHelper().getCallCount(); + int callCount = onPageFinishedHelper.getCallCount(); mWebContentsObserver.didFinishLoad(frameId, EXAMPLE_URL, mainFrame); + onPageFinishedHelper.waitForCallback(callCount); assertEquals("onPageFinished should be called for main frame navigations.", callCount + 1, - mContentsClient.getOnPageFinishedHelper().getCallCount()); + onPageFinishedHelper.getCallCount()); + assertEquals("onPageFinished should be called for main frame navigations.", EXAMPLE_URL, + onPageFinishedHelper.getUrl()); + + // In order to check that callbacks are *not* firing, first we execute code + // that shoudn't emit callbacks, then code that emits a callback, and check that we + // have got only one callback, and that its URL is from the last call. Since + // callbacks are serialized, that means we didn't have a callback for the first call. + callCount = onPageFinishedHelper.getCallCount(); + mWebContentsObserver.didFinishLoad(frameId, EXAMPLE_URL, subFrame); + mWebContentsObserver.didFinishLoad(frameId, SYNC_URL, mainFrame); + onPageFinishedHelper.waitForCallback(callCount); + assertEquals("onPageFinished should only be called for the main frame.", callCount + 1, + onPageFinishedHelper.getCallCount()); + assertEquals("onPageFinished should only be called for the main frame.", SYNC_URL, + onPageFinishedHelper.getUrl()); + + callCount = onPageFinishedHelper.getCallCount(); + mWebContentsObserver.didFinishLoad(frameId, mUnreachableWebDataUrl, mainFrame); + mWebContentsObserver.didFinishLoad(frameId, SYNC_URL, mainFrame); + onPageFinishedHelper.waitForCallback(callCount); + assertEquals("onPageFinished should not be called for the error url.", callCount + 1, + onPageFinishedHelper.getCallCount()); + assertEquals("onPageFinished should not be called for the error url.", SYNC_URL, + onPageFinishedHelper.getUrl()); String baseUrl = null; boolean navigationToDifferentPage = true; boolean fragmentNavigation = true; int httpStatusCode = 200; - callCount = mContentsClient.getOnPageFinishedHelper().getCallCount(); + callCount = onPageFinishedHelper.getCallCount(); mWebContentsObserver.didNavigateMainFrame(EXAMPLE_URL, baseUrl, !navigationToDifferentPage, fragmentNavigation, httpStatusCode); + onPageFinishedHelper.waitForCallback(callCount); + assertEquals("onPageFinished should be called for main frame fragment navigations.", + callCount + 1, onPageFinishedHelper.getCallCount()); assertEquals("onPageFinished should be called for main frame fragment navigations.", - callCount + 1, mContentsClient.getOnPageFinishedHelper().getCallCount()); + EXAMPLE_URL, onPageFinishedHelper.getUrl()); - callCount = mContentsClient.getOnPageFinishedHelper().getCallCount(); + callCount = onPageFinishedHelper.getCallCount(); mWebContentsObserver.didNavigateMainFrame(EXAMPLE_URL, baseUrl, !navigationToDifferentPage, !fragmentNavigation, httpStatusCode); + mWebContentsObserver.didFinishLoad(frameId, SYNC_URL, mainFrame); + onPageFinishedHelper.waitForCallback(callCount); + onPageFinishedHelper.waitForCallback(callCount); + assertEquals("onPageFinished should be called only for main frame fragment navigations.", + callCount + 1, onPageFinishedHelper.getCallCount()); assertEquals("onPageFinished should be called only for main frame fragment navigations.", - callCount, mContentsClient.getOnPageFinishedHelper().getCallCount()); + SYNC_URL, onPageFinishedHelper.getUrl()); } @SmallTest @Feature({"AndroidWebView"}) - public void testDidNavigateMainFrame() { + public void testDidNavigateMainFrame() throws Throwable { String nullUrl = null; String baseUrl = null; boolean reload = true; + TestAwContentsClient.DoUpdateVisitedHistoryHelper doUpdateVisitedHistoryHelper = + mContentsClient.getDoUpdateVisitedHistoryHelper(); - int callCount = mContentsClient.getDoUpdateVisitedHistoryHelper().getCallCount(); + int callCount = doUpdateVisitedHistoryHelper.getCallCount(); mWebContentsObserver.didNavigateAnyFrame(nullUrl, baseUrl, !reload); - assertEquals("doUpdateVisitedHistory should only be called for any url.", callCount + 1, - mContentsClient.getDoUpdateVisitedHistoryHelper().getCallCount()); - assertEquals(!reload, mContentsClient.getDoUpdateVisitedHistoryHelper().getIsReload()); - - callCount = mContentsClient.getDoUpdateVisitedHistoryHelper().getCallCount(); + doUpdateVisitedHistoryHelper.waitForCallback(callCount); + assertEquals("doUpdateVisitedHistory should be called for any url.", callCount + 1, + doUpdateVisitedHistoryHelper.getCallCount()); + assertEquals("doUpdateVisitedHistory should be called for any url.", nullUrl, + doUpdateVisitedHistoryHelper.getUrl()); + assertEquals(!reload, doUpdateVisitedHistoryHelper.getIsReload()); + + callCount = doUpdateVisitedHistoryHelper.getCallCount(); mWebContentsObserver.didNavigateAnyFrame(EXAMPLE_URL, baseUrl, !reload); - assertEquals("doUpdateVisitedHistory should only be called for any url.", callCount + 1, - mContentsClient.getDoUpdateVisitedHistoryHelper().getCallCount()); - assertEquals(!reload, mContentsClient.getDoUpdateVisitedHistoryHelper().getIsReload()); - - callCount = mContentsClient.getDoUpdateVisitedHistoryHelper().getCallCount(); + doUpdateVisitedHistoryHelper.waitForCallback(callCount); + assertEquals("doUpdateVisitedHistory should be called for any url.", callCount + 1, + doUpdateVisitedHistoryHelper.getCallCount()); + assertEquals("doUpdateVisitedHistory should be called for any url.", EXAMPLE_URL, + doUpdateVisitedHistoryHelper.getUrl()); + assertEquals(!reload, doUpdateVisitedHistoryHelper.getIsReload()); + + callCount = doUpdateVisitedHistoryHelper.getCallCount(); mWebContentsObserver.didNavigateAnyFrame(EXAMPLE_URL, baseUrl, reload); + doUpdateVisitedHistoryHelper.waitForCallback(callCount); assertEquals("doUpdateVisitedHistory should be called for reloads.", callCount + 1, - mContentsClient.getDoUpdateVisitedHistoryHelper().getCallCount()); - assertEquals(reload, mContentsClient.getDoUpdateVisitedHistoryHelper().getIsReload()); + doUpdateVisitedHistoryHelper.getCallCount()); + assertEquals("doUpdateVisitedHistory should be called for reloads.", EXAMPLE_URL, + doUpdateVisitedHistoryHelper.getUrl()); + assertEquals(reload, doUpdateVisitedHistoryHelper.getIsReload()); } } |