Commit 91804957 authored by Patrick Noland's avatar Patrick Noland Committed by Commit Bot

[EoC] Guard against null readinessState when canonical url is resolved

Bug: 847119
Change-Id: I5d7210b131304bf09a431d26aaf64ceae0e10a23
Reviewed-on: https://chromium-review.googlesource.com/1077427Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Commit-Queue: Patrick Noland <pnoland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#563004}
parent 7698eb35
......@@ -299,19 +299,28 @@ class FetchHelper {
if (shouldFetchCanonicalUrl(tab)) {
mFetchRequestedForCurrentTab = true;
String url = tab.getUrl();
tab.getWebContents().getMainFrame().getCanonicalUrlForSharing(new Callback<String>() {
@Override
public void onResult(String result) {
if (tab != mCurrentTab) {
return;
}
// Reset mFetchRequestedForCurrentTab so that it remains false if
// maybeStartFetchWithCanonicalURLResolved doesn't end up requesting
// suggestions. If it does end up requesting suggestions,
// mFetchRequestedForCurrentTab will be set back to true in the same synchronous
// flow of execution, so there shouldn't be a race condition.
// mFetchRequestedForCurrentTab will be set back to true in the same
// synchronous flow of execution, so there shouldn't be a race condition.
mFetchRequestedForCurrentTab = false;
TabFetchReadinessState tabFetchReadinessState = getTabFetchReadinessState(tab);
tabFetchReadinessState.setCanonicalUrl(result);
maybeStartFetchWithCanonicalURLResolved(
tab, getUrlToFetchFor(tab.getUrl(), result));
if (tabFetchReadinessState != null && tabFetchReadinessState.isTrackingPage()
&& tabFetchReadinessState.isContextTheSame(url)) {
tabFetchReadinessState.setCanonicalUrl(result);
maybeStartFetchWithCanonicalURLResolved(
tab, getUrlToFetchFor(tab.getUrl(), result));
}
}
});
return;
......
......@@ -418,6 +418,32 @@ public final class FetchHelperTest {
verify(mDelegate, times(1)).requestSuggestions(DIFFERENT_URL);
}
@Test
public void canonicalUrl_readinessStateIsNull() {
doReturn(true).when(mTab).isLoading();
FetchHelper helper = createFetchHelper();
doReturn(mFrameHost).when(mWebContents).getMainFrame();
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
if (invocation.getArguments()[0] instanceof Callback) {
closeTab(mTab);
@SuppressWarnings("unchecked")
Callback<String> callback = (Callback<String>) invocation.getArguments()[0];
callback.onResult(DIFFERENT_URL);
}
return null;
}
})
.when(mFrameHost)
.getCanonicalUrlForSharing(any());
getTabObserver().onPageLoadFinished(mTab);
runUntilFetchPossible();
verify(mDelegate, times(0)).requestSuggestions(DIFFERENT_URL);
}
private void addTab(Tab tab) {
getTabModelObserver().didAddTab(tab, TabLaunchType.FROM_LINK);
}
......
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