Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.android_webview.test; | |
| 6 | |
| 7 import android.test.UiThreadTest; | |
| 8 import android.test.suitebuilder.annotation.SmallTest; | |
| 9 | |
| 10 import org.chromium.android_webview.AwContentsStatics; | |
| 11 import org.chromium.android_webview.AwWebContentsObserver; | |
| 12 import org.chromium.base.test.util.Feature; | |
| 13 import org.chromium.net.NetError; | |
| 14 | |
| 15 /** | |
| 16 * Tests for the AwWebContentsObserver class. | |
| 17 */ | |
| 18 public class AwWebContentsObserverTest extends AwTestBase { | |
| 19 private TestAwContentsClient mContentsClient; | |
| 20 private AwTestContainerView mTestContainerView; | |
| 21 private AwWebContentsObserver mWebContentsObserver; | |
| 22 | |
| 23 private static final String EXAMPLE_URL = "http://www.example.com/"; | |
| 24 private static final String ERROR_DESCRIPTION = "description"; | |
| 25 private static String mUnreachableWebDataUrl; | |
| 26 | |
| 27 @Override | |
| 28 public void setUp() throws Exception { | |
| 29 super.setUp(); | |
| 30 mContentsClient = new TestAwContentsClient(); | |
| 31 mTestContainerView = createAwTestContainerViewOnMainSync(mContentsClient ); | |
| 32 mUnreachableWebDataUrl = AwContentsStatics.getUnreachableWebDataUrl(); | |
| 33 getInstrumentation().runOnMainSync(new Runnable() { | |
|
boliu
2014/08/07 16:01:29
Is runOnMainSync here necessary? Test won't start
mkosiba (inactive)
2014/08/08 10:58:44
The constructor DCHECKS when it's not run on the U
| |
| 34 @Override | |
| 35 public void run() { | |
| 36 mWebContentsObserver = new AwWebContentsObserver( | |
| 37 mTestContainerView.getContentViewCore().getWebContents() , mContentsClient); | |
| 38 } | |
| 39 }); | |
| 40 } | |
| 41 | |
| 42 @SmallTest | |
| 43 @UiThreadTest | |
| 44 @Feature({"AndroidWebView"}) | |
| 45 public void testOnPageFinished() { | |
| 46 int callCount = mContentsClient.getOnPageFinishedHelper().getCallCount() ; | |
| 47 mWebContentsObserver.didFinishLoad(/*frameId=*/0, EXAMPLE_URL, /*isMainF rame=*/false); | |
|
boliu
2014/08/07 16:01:29
nit: Not sure what the java style is, but in chrom
mkosiba (inactive)
2014/08/08 10:58:44
Done.
| |
| 48 assertEquals("onPageFinished should only be called for the main frame.", callCount, | |
| 49 mContentsClient.getOnPageFinishedHelper().getCallCount()); | |
| 50 | |
| 51 callCount = mContentsClient.getOnPageFinishedHelper().getCallCount(); | |
| 52 mWebContentsObserver.didFinishLoad( | |
| 53 /*frameId=*/0, mUnreachableWebDataUrl, /*isMainFrame=*/true); | |
| 54 assertEquals("onPageFinished should not be called for the error url.", c allCount, | |
| 55 mContentsClient.getOnPageFinishedHelper().getCallCount()); | |
| 56 | |
| 57 callCount = mContentsClient.getOnPageFinishedHelper().getCallCount(); | |
| 58 mWebContentsObserver.didFinishLoad(/*frameId=*/0, EXAMPLE_URL, /*isMainF rame=*/true); | |
| 59 assertEquals("onPageFinished should be called for main frame navigations .", callCount + 1, | |
| 60 mContentsClient.getOnPageFinishedHelper().getCallCount()); | |
| 61 | |
| 62 callCount = mContentsClient.getOnPageFinishedHelper().getCallCount(); | |
| 63 mWebContentsObserver.didFailLoad(/*isProvisionaLoad=*/false, /*isMainFra me=*/true, | |
| 64 NetError.ERR_ABORTED, ERROR_DESCRIPTION, EXAMPLE_URL); | |
| 65 assertEquals("onPageFinished should be called for main frame errors.", c allCount + 1, | |
| 66 mContentsClient.getOnPageFinishedHelper().getCallCount()); | |
| 67 | |
| 68 callCount = mContentsClient.getOnPageFinishedHelper().getCallCount(); | |
| 69 mWebContentsObserver.didFailLoad(/*isProvisionaLoad=*/false, /*isMainFra me=*/false, | |
| 70 NetError.ERR_ABORTED, ERROR_DESCRIPTION, EXAMPLE_URL); | |
| 71 assertEquals("onPageFinished should only be called for main frame errors .", callCount, | |
| 72 mContentsClient.getOnPageFinishedHelper().getCallCount()); | |
| 73 | |
| 74 callCount = mContentsClient.getOnPageFinishedHelper().getCallCount(); | |
| 75 mWebContentsObserver.didFailLoad(/*isProvisionaLoad=*/false, /*isMainFra me=*/true, | |
| 76 NetError.ERR_ABORTED, ERROR_DESCRIPTION, mUnreachableWebDataUrl) ; | |
| 77 assertEquals("onPageFinished should not be called on unrechable url erro rs.", callCount, | |
| 78 mContentsClient.getOnPageFinishedHelper().getCallCount()); | |
| 79 | |
| 80 callCount = mContentsClient.getOnPageFinishedHelper().getCallCount(); | |
| 81 mWebContentsObserver.didNavigateMainFrame(/*url=*/EXAMPLE_URL, /*baseUrl =*/null, | |
| 82 /*isNavigationToDifferentPage*/false, /*isFragmentNavigation*/tr ue); | |
| 83 assertEquals("onPageFinished should be called for main frame fragment na vigations.", | |
| 84 callCount + 1, mContentsClient.getOnPageFinishedHelper().getCall Count()); | |
| 85 | |
| 86 callCount = mContentsClient.getOnPageFinishedHelper().getCallCount(); | |
| 87 mWebContentsObserver.didNavigateMainFrame(/*url=*/EXAMPLE_URL, /*baseUrl =*/null, | |
| 88 /*isNavigationToDifferentPage*/false, /*isFragmentNavigation*/fa lse); | |
| 89 assertEquals("onPageFinished should be called only for main frame fragme nt navigations.", | |
| 90 callCount, mContentsClient.getOnPageFinishedHelper().getCallCoun t()); | |
| 91 } | |
| 92 | |
| 93 @SmallTest | |
| 94 @UiThreadTest | |
| 95 @Feature({"AndroidWebView"}) | |
| 96 public void testOnReceivedError() { | |
| 97 int callCount = mContentsClient.getOnReceivedErrorHelper().getCallCount( ); | |
| 98 mWebContentsObserver.didFailLoad(/*isProvisionaLoad=*/false, /*isMainFra me=*/false, | |
| 99 NetError.ERR_TIMED_OUT, ERROR_DESCRIPTION, EXAMPLE_URL); | |
| 100 assertEquals("onReceivedError should only be called for the main frame", callCount, | |
| 101 mContentsClient.getOnReceivedErrorHelper().getCallCount()); | |
| 102 | |
| 103 callCount = mContentsClient.getOnReceivedErrorHelper().getCallCount(); | |
| 104 mWebContentsObserver.didFailLoad(/*isProvisionaLoad=*/false, /*isMainFra me=*/true, | |
| 105 NetError.ERR_TIMED_OUT, ERROR_DESCRIPTION, EXAMPLE_URL); | |
| 106 assertEquals("onReceivedError should be called for the main frame", call Count + 1, | |
| 107 mContentsClient.getOnReceivedErrorHelper().getCallCount()); | |
| 108 | |
| 109 callCount = mContentsClient.getOnReceivedErrorHelper().getCallCount(); | |
| 110 mWebContentsObserver.didFailLoad(/*isProvisionaLoad=*/false, /*isMainFra me=*/true, | |
| 111 NetError.ERR_ABORTED, ERROR_DESCRIPTION, EXAMPLE_URL); | |
| 112 assertEquals("onReceivedError should not be called for aborted navigatio ns", callCount, | |
| 113 mContentsClient.getOnReceivedErrorHelper().getCallCount()); | |
| 114 } | |
| 115 | |
| 116 @SmallTest | |
| 117 @UiThreadTest | |
| 118 @Feature({"AndroidWebView"}) | |
| 119 public void testDidNavigateMainFrame() { | |
| 120 int callCount = mContentsClient.getDoUpdateVisitedHistoryHelper().getCal lCount(); | |
| 121 mWebContentsObserver.didNavigateAnyFrame(/*url=*/null, /*baseUrl=*/null, | |
| 122 /*isReload=*/false); | |
| 123 assertEquals("doUpdateVisitedHistory should only be called for any url." , callCount + 1, | |
| 124 mContentsClient.getDoUpdateVisitedHistoryHelper().getCallCount() ); | |
|
boliu
2014/08/07 16:01:29
check isReload matches
mkosiba (inactive)
2014/08/08 10:58:44
Done.
| |
| 125 | |
| 126 callCount = mContentsClient.getDoUpdateVisitedHistoryHelper().getCallCou nt(); | |
| 127 mWebContentsObserver.didNavigateAnyFrame(/*url=*/EXAMPLE_URL, /*baseUrl= */null, | |
| 128 /*isReload=*/false); | |
| 129 assertEquals("doUpdateVisitedHistory should only be called for any url." , callCount + 1, | |
| 130 mContentsClient.getDoUpdateVisitedHistoryHelper().getCallCount() ); | |
| 131 | |
| 132 callCount = mContentsClient.getDoUpdateVisitedHistoryHelper().getCallCou nt(); | |
| 133 mWebContentsObserver.didNavigateAnyFrame(/*url=*/EXAMPLE_URL, /*baseUrl= */null, | |
| 134 /*isReload=*/true); | |
| 135 assertEquals("doUpdateVisitedHistory should be called for reloads.", cal lCount + 1, | |
| 136 mContentsClient.getDoUpdateVisitedHistoryHelper().getCallCount() ); | |
| 137 } | |
| 138 } | |
| OLD | NEW |