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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/RecentTabsTest.java

Issue 2824623002: Last_n: Delete previously saved snapshot when navigating. (Closed)
Patch Set: Annotated method with @MainThread; comment updates Created 3 years, 8 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/android/BUILD.gn ('k') | chrome/browser/android/offline_pages/recent_tab_helper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/RecentTabsTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/RecentTabsTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/RecentTabsTest.java
index 4560a32e6fb2501af6a4df92f66329449d9bac62..5c55ae4320848c438ed2a7384ff14118ef182ea5 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/RecentTabsTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/RecentTabsTest.java
@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.offlinepages;
import android.content.Context;
+import android.support.annotation.MainThread;
import android.support.test.filters.MediumTest;
import org.chromium.base.Callback;
@@ -30,11 +31,13 @@ import java.util.concurrent.TimeUnit;
@CommandLineFlags.Add("enable-features=OfflineRecentPages")
public class RecentTabsTest extends ChromeTabbedActivityTestBase {
private static final String TEST_PAGE = "/chrome/test/data/android/about.html";
+ private static final String TEST_PAGE_2 = "/chrome/test/data/android/simple.html";
private static final int TIMEOUT_MS = 5000;
private OfflinePageBridge mOfflinePageBridge;
private EmbeddedTestServer mTestServer;
private String mTestPage;
+ private String mTestPage2;
private void initializeBridgeForProfile(final boolean incognitoProfile)
throws InterruptedException {
@@ -84,6 +87,7 @@ public class RecentTabsTest extends ChromeTabbedActivityTestBase {
mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
mTestPage = mTestServer.getURL(TEST_PAGE);
+ mTestPage2 = mTestServer.getURL(TEST_PAGE_2);
}
@Override
@@ -109,9 +113,9 @@ public class RecentTabsTest extends ChromeTabbedActivityTestBase {
// The tab should be foreground and so no snapshot should exist.
assertNull(getPageByClientId(firstTabClientId));
- // Note, that switching to a new tab must occur after the SnapshotController believes the
- // page quality is good enough. With the debug flag, the delay after DomContentLoaded is 0
- // so we can definitely snapshot after onload (which is what |loadUrlInNewTab| waits for).
+ // Note: switching to a new tab must occur after the SnapshotController believes the page
+ // quality is good enough. With the debug flag, the delay after DomContentLoaded is 0 so we
+ // can definitely snapshot after onload (which is what |loadUrlInNewTab| waits for).
// Switch to a new tab to cause the WebContents hidden event.
loadUrlInNewTab("about:blank");
@@ -120,10 +124,10 @@ public class RecentTabsTest extends ChromeTabbedActivityTestBase {
}
/**
- * Note: this test relies on a sleeping period because some of the taking actions are
- * complicated to track otherwise, so there is the possibility of flakiness. I chose 100ms from
- * local testing and I expect it to be "safe" but it flakiness is detected it might have to be
- * further increased.
+ * Note: this test relies on a sleeping period because some of the monitored actions are
+ * difficult to track deterministically. A sleep time of 100 ms was chosen based on local
+ * testing and is expected to be "safe". Nevertheless if flakiness is detected it might have to
+ * be further increased.
*/
@CommandLineFlags.Add("short-offline-page-snapshot-delay-for-test")
@MediumTest
@@ -178,6 +182,83 @@ public class RecentTabsTest extends ChromeTabbedActivityTestBase {
waitForPageWithClientId(firstTabClientId);
}
+ /**
+ * Verifies that a snapshot created by last_n is properly deleted when the tab is navigated to
+ * another page. The deletion of snapshots for pages that should not be available anymore is a
+ * privacy requirement for last_n.
+ */
+ @CommandLineFlags.Add("short-offline-page-snapshot-delay-for-test")
+ @MediumTest
+ public void testLastNPageIsDeletedUponNavigation() throws Exception {
+ // The tab of interest.
+ final Tab tab = loadUrlInNewTab(mTestPage);
+ final TabModelSelector tabModelSelector = tab.getTabModelSelector();
+
+ final ClientId firstTabClientId =
+ new ClientId(OfflinePageBridge.LAST_N_NAMESPACE, Integer.toString(tab.getId()));
+
+ // Switch to a new tab and wait for the snapshot to be created.
+ loadUrlInNewTab("about:blank");
+ waitForPageWithClientId(firstTabClientId);
+ OfflinePageItem offlinePage = getPageByClientId(firstTabClientId);
+ assertFalse(tab.equals(tabModelSelector.getCurrentTab()));
+
+ // Switch back to the initial tab and install the page deletion monitor for later usage.
+ final OfflinePageDeletionMonitor deletionMonitor =
+ new OfflinePageDeletionMonitor(offlinePage.getOfflineId());
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ TabModel tabModel = tabModelSelector.getModelForTabId(tab.getId());
+ int tabIndex = TabModelUtils.getTabIndexById(tabModel, tab.getId());
+ TabModelUtils.setIndex(tabModel, tabIndex);
+ deletionMonitor.installObserver();
+ }
+ });
+ assertEquals(tabModelSelector.getCurrentTab(), tab);
+
+ // Navigate to a new page and confirm the previously created snapshot has been deleted.
+ loadUrl(mTestPage2);
+ deletionMonitor.assertDeleted();
+ }
+
+ /**
+ * Verifies that a snapshot created by last_n is properly deleted when the tab is closed. The
+ * deletion of snapshots for pages that should not be available anymore is a privacy requirement
+ * for last_n.
+ */
+ @CommandLineFlags.Add("short-offline-page-snapshot-delay-for-test")
+ @MediumTest
+ public void testLastNPageIsDeletedUponClosure() throws Exception {
+ // The tab of interest.
+ final Tab tab = loadUrlInNewTab(mTestPage);
+ final TabModelSelector tabModelSelector = tab.getTabModelSelector();
+
+ final ClientId firstTabClientId =
+ new ClientId(OfflinePageBridge.LAST_N_NAMESPACE, Integer.toString(tab.getId()));
+
+ // Switch to a new tab and wait for the snapshot to be created.
+ loadUrlInNewTab("about:blank");
+ waitForPageWithClientId(firstTabClientId);
+ OfflinePageItem offlinePage = getPageByClientId(firstTabClientId);
+
+ // Requests closing of the tab allowing for closure undo and checks it's actually closing.
+ final int tabId = tab.getId();
+ final OfflinePageDeletionMonitor deletionMonitor =
+ new OfflinePageDeletionMonitor(offlinePage.getOfflineId());
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ deletionMonitor.installObserver();
+ TabModel tabModel = tabModelSelector.getModelForTabId(tabId);
+ tabModel.closeTab(tab, false, false, true);
+ tabModel.commitTabClosure(tabId);
+ }
+ });
+ assertNull(tabModelSelector.getTabById(tabId));
+ deletionMonitor.assertDeleted();
+ }
+
private void waitForPageWithClientId(final ClientId clientId) throws InterruptedException {
if (getPageByClientId(clientId) != null) return;
@@ -199,6 +280,32 @@ public class RecentTabsTest extends ChromeTabbedActivityTestBase {
assertTrue(semaphore.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS));
}
+ private class OfflinePageDeletionMonitor {
+ private final Semaphore mSemaphore = new Semaphore(0);
+ private final long mOfflineId;
+
+ public OfflinePageDeletionMonitor(long offlineId) {
+ mOfflineId = offlineId;
+ }
+
+ @MainThread
+ public void installObserver() {
+ mOfflinePageBridge.addObserver(new OfflinePageModelObserver() {
+ @Override
+ public void offlinePageDeleted(long offlineId, ClientId clientId) {
+ if (offlineId == mOfflineId) {
+ mOfflinePageBridge.removeObserver(this);
+ mSemaphore.release();
+ }
+ }
+ });
+ }
+
+ public void assertDeleted() throws InterruptedException {
+ assertTrue(mSemaphore.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS));
+ }
+ }
+
private OfflinePageItem getPageByClientId(ClientId clientId) throws InterruptedException {
final OfflinePageItem[] result = {null};
final Semaphore semaphore = new Semaphore(0);
@@ -223,4 +330,24 @@ public class RecentTabsTest extends ChromeTabbedActivityTestBase {
assertTrue(semaphore.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS));
return result[0];
}
+
+ private OfflinePageItem getPageByOfflineId(final long offlineId) throws InterruptedException {
+ final OfflinePageItem[] result = {null};
+ final Semaphore semaphore = new Semaphore(0);
+
+ ThreadUtils.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mOfflinePageBridge.getPageByOfflineId(offlineId, new Callback<OfflinePageItem>() {
+ @Override
+ public void onResult(OfflinePageItem item) {
+ result[0] = item;
+ semaphore.release();
+ }
+ });
+ }
+ });
+ assertTrue(semaphore.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS));
+ return result[0];
+ }
}
« no previous file with comments | « chrome/android/BUILD.gn ('k') | chrome/browser/android/offline_pages/recent_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698