| 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 5c55ae4320848c438ed2a7384ff14118ef182ea5..4560a32e6fb2501af6a4df92f66329449d9bac62 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,7 +5,6 @@
|
| 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;
|
| @@ -31,13 +30,11 @@
|
| @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 {
|
| @@ -87,7 +84,6 @@
|
|
|
| mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
|
| mTestPage = mTestServer.getURL(TEST_PAGE);
|
| - mTestPage2 = mTestServer.getURL(TEST_PAGE_2);
|
| }
|
|
|
| @Override
|
| @@ -113,9 +109,9 @@
|
| // The tab should be foreground and so no snapshot should exist.
|
| assertNull(getPageByClientId(firstTabClientId));
|
|
|
| - // 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).
|
| + // 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).
|
|
|
| // Switch to a new tab to cause the WebContents hidden event.
|
| loadUrlInNewTab("about:blank");
|
| @@ -124,10 +120,10 @@
|
| }
|
|
|
| /**
|
| - * 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.
|
| + * 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.
|
| */
|
| @CommandLineFlags.Add("short-offline-page-snapshot-delay-for-test")
|
| @MediumTest
|
| @@ -180,83 +176,6 @@
|
| assertEquals(tabModelSelector.getCurrentTab(), newTab);
|
| assertTrue(tab.isHidden());
|
| 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 {
|
| @@ -278,32 +197,6 @@
|
| }
|
| });
|
| 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 {
|
| @@ -330,24 +223,4 @@
|
| 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];
|
| - }
|
| }
|
|
|