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

[Chromeshine] Don't emit a start event for suspended domains

This fixes a bug where we only suppressed start events for *newly*
suspended domains. This works most of the time, but not always, e.g.
when switching back to the tab after checking the dashboard in DWB.

Bug: 1144245
Change-Id: Ifc5d0a9345eb5ad462cff7775bd1fc2a7b63fe41
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2510733Reviewed-by: default avatarNatalie Chouinard <chouinard@chromium.org>
Commit-Queue: Patrick Noland <pnoland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822794}
parent 982ff9b3
...@@ -148,14 +148,14 @@ public class PageViewObserver { ...@@ -148,14 +148,14 @@ public class PageViewObserver {
boolean isSameDomain = newFqdn.equals(mLastFqdn); boolean isSameDomain = newFqdn.equals(mLastFqdn);
boolean isValidProtocol = URLUtil.isHttpUrl(newUrl) || URLUtil.isHttpsUrl(newUrl); boolean isValidProtocol = URLUtil.isHttpUrl(newUrl) || URLUtil.isHttpsUrl(newUrl);
boolean didSuspend = boolean isSuspended = mSuspensionTracker.isWebsiteSuspended(newFqdn);
checkSuspendedTabState(mSuspensionTracker.isWebsiteSuspended(newFqdn), newFqdn); boolean didSuspend = checkSuspendedTabState(isSuspended, newFqdn);
if (mLastFqdn != null && (didSuspend || !isSameDomain)) { if (mLastFqdn != null && (didSuspend || !isSameDomain)) {
reportStop(); reportStop();
} }
if (isValidProtocol && !didSuspend && !isSameDomain) { if (isValidProtocol && !isSuspended && !isSameDomain) {
mLastFqdn = newFqdn; mLastFqdn = newFqdn;
mEventTracker.addWebsiteEvent(new WebsiteEvent( mEventTracker.addWebsiteEvent(new WebsiteEvent(
System.currentTimeMillis(), mLastFqdn, WebsiteEvent.EventType.START)); System.currentTimeMillis(), mLastFqdn, WebsiteEvent.EventType.START));
......
...@@ -11,6 +11,7 @@ import static org.mockito.ArgumentMatchers.argThat; ...@@ -11,6 +11,7 @@ import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset; import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
...@@ -218,6 +219,22 @@ public final class PageViewObserverTest { ...@@ -218,6 +219,22 @@ public final class PageViewObserverTest {
verify(mEventTracker, times(0)).addWebsiteEvent(argThat(isStartEvent(DIFFERENT_FQDN))); verify(mEventTracker, times(0)).addWebsiteEvent(argThat(isStartEvent(DIFFERENT_FQDN)));
} }
@Test
public void switchToSuspendedTab_startNotReported() {
PageViewObserver observer = createPageViewObserver();
updateUrl(mTab, STARTING_URL);
doReturn(STARTING_URL).when(mTab).getUrlString();
doReturn(true).when(mSuspensionTracker).isWebsiteSuspended(STARTING_FQDN);
observer.notifySiteSuspensionChanged(STARTING_FQDN, true);
assertTrue(SuspendedTab.from(mTab).isShowing());
reset(mEventTracker);
onHidden(mTab, TabHidingType.ACTIVITY_HIDDEN);
onShown(mTab, TabSelectionType.FROM_USER);
verify(mEventTracker, never()).addWebsiteEvent(argThat(isStartEvent(STARTING_FQDN)));
}
@Test @Test
public void tabHidden_stopReported() { public void tabHidden_stopReported() {
PageViewObserver observer = createPageViewObserver(); PageViewObserver observer = createPageViewObserver();
......
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