Commit d1a3a027 authored by Filip Gorski's avatar Filip Gorski Committed by Commit Bot

[EoC] Fixing triggering on pages that don't reload

* Adding handling of the onUrlUpdated signal in cases where FetchHelper
  is considers the tab current, but the URL context changed.

Bug: 889518
Change-Id: Ibbf3e57e5861ac0d9fccce7abda946b4dbb6c48a
Reviewed-on: https://chromium-review.googlesource.com/1246592Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Filip Gorski <fgorski@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594530}
parent ffa01b02
......@@ -171,6 +171,18 @@ class FetchHelper {
getTabFetchReadinessState(tab).updateUrl(url);
}
@Override
public void onUrlUpdated(Tab tab) {
assert !tab.isIncognito();
// This address cases, where pages are implemented as a single page app and
// switching between articles updates URL, but does not cause a page reload.
if (tab == mCurrentTab
&& !getTabFetchReadinessState(tab).isContextTheSame(tab.getUrl())) {
clearState();
getTabFetchReadinessState(tab).updateUrl(tab.getUrl());
}
}
@Override
public void didFirstVisuallyNonEmptyPaint(Tab tab) {
setTimeBaselineAndMaybeFetch(tab);
......
......@@ -148,6 +148,27 @@ public final class FetchHelperTest {
verify(mDelegate, times(2)).clearState();
}
@Test
public void tabObserver_onUrlUpdated() {
FetchHelper helper = createFetchHelper();
doReturn(DIFFERENT_URL).when(mTab).getUrl();
getTabObserver().onUrlUpdated(mTab);
verify(mDelegate, times(1)).clearState();
// Normally we would change the suffix here, but ShadowUrlUtilities don't support that now.
doReturn(STARTING_URL).when(mTab).getUrl();
getTabObserver().onUrlUpdated(mTab);
verify(mDelegate, times(2)).clearState();
// Should be ignored, because URL is the same.
getTabObserver().onUrlUpdated(mTab);
verify(mDelegate, times(2)).clearState();
// Should be ignored, because tab is different.
doReturn(STARTING_URL).when(mTab2).getUrl();
getTabObserver().onUrlUpdated(mTab2);
verify(mDelegate, times(2)).clearState();
}
@Test
public void tabObserver_didFirstVisuallyNonEmptyPaint() {
delayFetchExecutionTest((tabObserver) -> tabObserver.didFirstVisuallyNonEmptyPaint(mTab));
......
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