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

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

Issue 1432083004: [Android WebView] Fire onPageFinished from WebContentsObserver::didStopLoading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed AwWebContentsObserverTest#testOnPageFinished Created 5 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 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 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.suitebuilder.annotation.SmallTest; 7 import android.test.suitebuilder.annotation.SmallTest;
8 8
9 import org.chromium.android_webview.AwContentsStatics; 9 import org.chromium.android_webview.AwContentsStatics;
10 import org.chromium.android_webview.AwWebContentsObserver; 10 import org.chromium.android_webview.AwWebContentsObserver;
(...skipping 18 matching lines...) Expand all
29 super.setUp(); 29 super.setUp();
30 mContentsClient = new TestAwContentsClient(); 30 mContentsClient = new TestAwContentsClient();
31 mTestContainerView = createAwTestContainerViewOnMainSync(mContentsClient ); 31 mTestContainerView = createAwTestContainerViewOnMainSync(mContentsClient );
32 mUnreachableWebDataUrl = AwContentsStatics.getUnreachableWebDataUrl(); 32 mUnreachableWebDataUrl = AwContentsStatics.getUnreachableWebDataUrl();
33 // AwWebContentsObserver constructor must be run on the UI thread. 33 // AwWebContentsObserver constructor must be run on the UI thread.
34 getInstrumentation().runOnMainSync(new Runnable() { 34 getInstrumentation().runOnMainSync(new Runnable() {
35 @Override 35 @Override
36 public void run() { 36 public void run() {
37 mWebContentsObserver = new AwWebContentsObserver( 37 mWebContentsObserver = new AwWebContentsObserver(
38 mTestContainerView.getContentViewCore().getWebContents() , 38 mTestContainerView.getContentViewCore().getWebContents() ,
39 mTestContainerView.getAwContents(), mContentsClient); 39 null, mContentsClient);
gsennton 2015/11/13 02:35:39 I guess this is to avoid the whole loadDataWithBas
mnaganov (inactive) 2015/11/13 17:41:37 That's correct. Added a comment.
40 } 40 }
41 }); 41 });
42 } 42 }
43 43
44 @SmallTest 44 @SmallTest
45 @Feature({"AndroidWebView"}) 45 @Feature({"AndroidWebView"})
46 public void testOnPageFinished() throws Throwable { 46 public void testOnPageFinished() throws Throwable {
47 int frameId = 0; 47 int frameId = 0;
48 boolean mainFrame = true; 48 boolean mainFrame = true;
49 boolean subFrame = false; 49 boolean subFrame = false;
50 final TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHel per = 50 final TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHel per =
51 mContentsClient.getOnPageFinishedHelper(); 51 mContentsClient.getOnPageFinishedHelper();
52 52
53 int callCount = onPageFinishedHelper.getCallCount(); 53 int callCount = onPageFinishedHelper.getCallCount();
54 mWebContentsObserver.didFinishLoad(frameId, EXAMPLE_URL, mainFrame); 54 mWebContentsObserver.didFinishLoad(frameId, EXAMPLE_URL, mainFrame);
55 mWebContentsObserver.didStopLoading(EXAMPLE_URL);
55 onPageFinishedHelper.waitForCallback(callCount); 56 onPageFinishedHelper.waitForCallback(callCount);
56 assertEquals("onPageFinished should be called for main frame navigations .", callCount + 1, 57 assertEquals("onPageFinished should be called for main frame navigations .", callCount + 1,
57 onPageFinishedHelper.getCallCount()); 58 onPageFinishedHelper.getCallCount());
58 assertEquals("onPageFinished should be called for main frame navigations .", EXAMPLE_URL, 59 assertEquals("onPageFinished should be called for main frame navigations .", EXAMPLE_URL,
59 onPageFinishedHelper.getUrl()); 60 onPageFinishedHelper.getUrl());
60 61
61 // In order to check that callbacks are *not* firing, first we execute c ode 62 // In order to check that callbacks are *not* firing, first we execute c ode
62 // that shoudn't emit callbacks, then code that emits a callback, and ch eck that we 63 // that shoudn't emit callbacks, then code that emits a callback, and ch eck that we
63 // have got only one callback, and that its URL is from the last call. S ince 64 // have got only one callback, and that its URL is from the last call. S ince
64 // callbacks are serialized, that means we didn't have a callback for th e first call. 65 // callbacks are serialized, that means we didn't have a callback for th e first call.
65 callCount = onPageFinishedHelper.getCallCount(); 66 callCount = onPageFinishedHelper.getCallCount();
66 mWebContentsObserver.didFinishLoad(frameId, EXAMPLE_URL, subFrame); 67 mWebContentsObserver.didFinishLoad(frameId, EXAMPLE_URL, subFrame);
67 mWebContentsObserver.didFinishLoad(frameId, SYNC_URL, mainFrame); 68 mWebContentsObserver.didFinishLoad(frameId, SYNC_URL, mainFrame);
69 mWebContentsObserver.didStopLoading(SYNC_URL);
68 onPageFinishedHelper.waitForCallback(callCount); 70 onPageFinishedHelper.waitForCallback(callCount);
69 assertEquals("onPageFinished should only be called for the main frame.", callCount + 1, 71 assertEquals("onPageFinished should only be called for the main frame.", callCount + 1,
70 onPageFinishedHelper.getCallCount()); 72 onPageFinishedHelper.getCallCount());
71 assertEquals("onPageFinished should only be called for the main frame.", SYNC_URL, 73 assertEquals("onPageFinished should only be called for the main frame.", SYNC_URL,
72 onPageFinishedHelper.getUrl()); 74 onPageFinishedHelper.getUrl());
73 75
74 callCount = onPageFinishedHelper.getCallCount(); 76 callCount = onPageFinishedHelper.getCallCount();
75 mWebContentsObserver.didFinishLoad(frameId, mUnreachableWebDataUrl, main Frame); 77 mWebContentsObserver.didFinishLoad(frameId, mUnreachableWebDataUrl, main Frame);
76 mWebContentsObserver.didFinishLoad(frameId, SYNC_URL, mainFrame); 78 mWebContentsObserver.didFinishLoad(frameId, SYNC_URL, mainFrame);
79 mWebContentsObserver.didStopLoading(SYNC_URL);
77 onPageFinishedHelper.waitForCallback(callCount); 80 onPageFinishedHelper.waitForCallback(callCount);
78 assertEquals("onPageFinished should not be called for the error url.", c allCount + 1, 81 assertEquals("onPageFinished should not be called for the error url.", c allCount + 1,
79 onPageFinishedHelper.getCallCount()); 82 onPageFinishedHelper.getCallCount());
80 assertEquals("onPageFinished should not be called for the error url.", S YNC_URL, 83 assertEquals("onPageFinished should not be called for the error url.", S YNC_URL,
81 onPageFinishedHelper.getUrl()); 84 onPageFinishedHelper.getUrl());
82 85
83 String baseUrl = null; 86 String baseUrl = null;
84 boolean navigationToDifferentPage = true; 87 boolean navigationToDifferentPage = true;
85 boolean fragmentNavigation = true; 88 boolean fragmentNavigation = true;
86 int httpStatusCode = 200; 89 int httpStatusCode = 200;
87 callCount = onPageFinishedHelper.getCallCount(); 90 callCount = onPageFinishedHelper.getCallCount();
88 mWebContentsObserver.didNavigateMainFrame(EXAMPLE_URL, baseUrl, 91 mWebContentsObserver.didNavigateMainFrame(EXAMPLE_URL, baseUrl,
89 !navigationToDifferentPage, fragmentNavigation, httpStatusCode); 92 !navigationToDifferentPage, fragmentNavigation, httpStatusCode);
93 mWebContentsObserver.didStopLoading(EXAMPLE_URL);
90 onPageFinishedHelper.waitForCallback(callCount); 94 onPageFinishedHelper.waitForCallback(callCount);
91 assertEquals("onPageFinished should be called for main frame fragment na vigations.", 95 assertEquals("onPageFinished should be called for main frame fragment na vigations.",
92 callCount + 1, onPageFinishedHelper.getCallCount()); 96 callCount + 1, onPageFinishedHelper.getCallCount());
93 assertEquals("onPageFinished should be called for main frame fragment na vigations.", 97 assertEquals("onPageFinished should be called for main frame fragment na vigations.",
94 EXAMPLE_URL, onPageFinishedHelper.getUrl()); 98 EXAMPLE_URL, onPageFinishedHelper.getUrl());
95 99
96 callCount = onPageFinishedHelper.getCallCount(); 100 callCount = onPageFinishedHelper.getCallCount();
97 mWebContentsObserver.didNavigateMainFrame(EXAMPLE_URL, baseUrl, 101 mWebContentsObserver.didNavigateMainFrame(EXAMPLE_URL, baseUrl,
98 !navigationToDifferentPage, !fragmentNavigation, httpStatusCode) ; 102 !navigationToDifferentPage, !fragmentNavigation, httpStatusCode) ;
99 mWebContentsObserver.didFinishLoad(frameId, SYNC_URL, mainFrame); 103 mWebContentsObserver.didFinishLoad(frameId, SYNC_URL, mainFrame);
104 mWebContentsObserver.didStopLoading(SYNC_URL);
100 onPageFinishedHelper.waitForCallback(callCount); 105 onPageFinishedHelper.waitForCallback(callCount);
101 onPageFinishedHelper.waitForCallback(callCount); 106 onPageFinishedHelper.waitForCallback(callCount);
102 assertEquals("onPageFinished should be called only for main frame fragme nt navigations.", 107 assertEquals("onPageFinished should be called only for main frame fragme nt navigations.",
103 callCount + 1, onPageFinishedHelper.getCallCount()); 108 callCount + 1, onPageFinishedHelper.getCallCount());
104 assertEquals("onPageFinished should be called only for main frame fragme nt navigations.", 109 assertEquals("onPageFinished should be called only for main frame fragme nt navigations.",
105 SYNC_URL, onPageFinishedHelper.getUrl()); 110 SYNC_URL, onPageFinishedHelper.getUrl());
106 } 111 }
107 112
108 @SmallTest 113 @SmallTest
109 @Feature({"AndroidWebView"}) 114 @Feature({"AndroidWebView"})
(...skipping 25 matching lines...) Expand all
135 callCount = doUpdateVisitedHistoryHelper.getCallCount(); 140 callCount = doUpdateVisitedHistoryHelper.getCallCount();
136 mWebContentsObserver.didNavigateAnyFrame(EXAMPLE_URL, baseUrl, reload); 141 mWebContentsObserver.didNavigateAnyFrame(EXAMPLE_URL, baseUrl, reload);
137 doUpdateVisitedHistoryHelper.waitForCallback(callCount); 142 doUpdateVisitedHistoryHelper.waitForCallback(callCount);
138 assertEquals("doUpdateVisitedHistory should be called for reloads.", cal lCount + 1, 143 assertEquals("doUpdateVisitedHistory should be called for reloads.", cal lCount + 1,
139 doUpdateVisitedHistoryHelper.getCallCount()); 144 doUpdateVisitedHistoryHelper.getCallCount());
140 assertEquals("doUpdateVisitedHistory should be called for reloads.", EXA MPLE_URL, 145 assertEquals("doUpdateVisitedHistory should be called for reloads.", EXA MPLE_URL,
141 doUpdateVisitedHistoryHelper.getUrl()); 146 doUpdateVisitedHistoryHelper.getUrl());
142 assertEquals(reload, doUpdateVisitedHistoryHelper.getIsReload()); 147 assertEquals(reload, doUpdateVisitedHistoryHelper.getIsReload());
143 } 148 }
144 } 149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698