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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/webapps/ManifestUpgradeDetectorFetcherTest.java

Issue 2161163004: Split fetcher logic out of ManifestUpgradeDetector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'master' into webapk_updater_images0 Created 4 years, 4 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
Index: chrome/android/javatests/src/org/chromium/chrome/browser/webapps/ManifestUpgradeDetectorFetcherTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/ManifestUpgradeDetectorFetcherTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/ManifestUpgradeDetectorFetcherTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..8430403be6760ca5c995dc78945a4484e2473093
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/ManifestUpgradeDetectorFetcherTest.java
@@ -0,0 +1,133 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.webapps;
+
+import android.content.Context;
+import android.os.Environment;
+import android.test.suitebuilder.annotation.MediumTest;
+
+import org.chromium.base.ThreadUtils;
+import org.chromium.base.test.util.Feature;
+import org.chromium.chrome.browser.tab.Tab;
+import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
+import org.chromium.chrome.test.util.browser.TabLoadObserver;
+import org.chromium.content.browser.test.util.CallbackHelper;
+import org.chromium.net.test.EmbeddedTestServer;
+
+/**
+ * Tests the ManifestUpgradeDetectorFetcher.
+ */
+public class ManifestUpgradeDetectorFetcherTest extends ChromeTabbedActivityTestBase {
+
+ private static final String PAGE_URL1 = "/chrome/test/data/webapps/manifest_test_page.html";
+ private static final String PAGE_URL2 = "/chrome/test/data/webapps/manifest_test_page2.html";
+
+ // Data for {@link PAGE_URL1}'s Web Manifest.
+ private static final String WEB_MANIFEST_URL1 = "/chrome/test/data/webapps/manifest.json";
+ private static final String WEB_MANIFEST_NAME1 = "Manifest test app";
+
+ // Data for {@link PAGE_URL2}'s Web Manifest.
+ private static final String WEB_MANIFEST_URL2 = "/chrome/test/data/webapps/manifest2.json";
+ private static final String WEB_MANIFEST_NAME2 = "Manifest test app2";
+
+ // Scope for {@link PAGE_URL1} and {@link PAGE_URL2}.
+ private static final String WEB_MANIFEST_SCOPE = "/chrome/test/data";
+
+ private EmbeddedTestServer mTestServer;
+ private Tab mTab;
+
+ // CallbackHelper which blocks until the {@link ManifestUpgradeDetectorFetcher.Callback}
+ // callback is called.
+ private static class CallbackWaiter
+ extends CallbackHelper implements ManifestUpgradeDetectorFetcher.Callback {
+ private String mName;
+
+ @Override
+ public void onGotManifestData(String startUrl, String scopeUrl, String name,
+ String shortName, int displayMode, int orientation, long themeColor,
+ long backgroundColor) {
+ assertNull(mName);
+ mName = name;
+ notifyCalled();
+ }
+
+ public String name() {
+ return mName;
+ }
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ Context context = getInstrumentation().getTargetContext();
+ mTestServer = EmbeddedTestServer.createAndStartFileServer(
+ context, Environment.getExternalStorageDirectory());
+ mTab = getActivity().getActivityTab();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ mTestServer.stopAndDestroyServer();
+ super.tearDown();
+ }
+
+ @Override
+ public void startMainActivity() throws InterruptedException {
+ startMainActivityOnBlankPage();
+ }
+
+ /**
+ * Starts a ManifestUpgradeDetectorFetcher. Calls {@link callback} once the fetcher is done.
+ */
+ private void startManifestUpgradeDetectorFetcher(String scopeUrl, String manifestUrl,
+ final ManifestUpgradeDetectorFetcher.Callback callback) {
+ final ManifestUpgradeDetectorFetcher fetcher =
+ new ManifestUpgradeDetectorFetcher(mTab, scopeUrl, manifestUrl);
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ fetcher.start(callback);
+ }
+ });
+ }
+
+ /**
+ * Test starting ManifestUpgradeDetectorFetcher while a page with the desired manifest URL is
+ * loading.
+ */
+ @MediumTest
+ @Feature({"WebApk"})
+ public void testLaunchWithDesiredManifestUrl() throws Exception {
+ CallbackWaiter waiter = new CallbackWaiter();
+ startManifestUpgradeDetectorFetcher(mTestServer.getURL(WEB_MANIFEST_SCOPE),
+ mTestServer.getURL(WEB_MANIFEST_URL1), waiter);
+
+ TabLoadObserver tabLoadObserver = new TabLoadObserver(mTab);
+ tabLoadObserver.fullyLoadUrl(mTestServer.getURL(PAGE_URL1));
+ waiter.waitForCallback(0);
+
+ assertEquals(WEB_MANIFEST_NAME1, waiter.name());
+ }
+
+ /**
+ * Test starting ManifestUpgradeDetectorFetcher on page which uses a different manifest URL than
+ * the ManifestUpgradeDetectorFetcher is looking for. Check that the callback is only called
+ * once the user navigates to a page which uses the desired manifest URL.
+ */
+ @MediumTest
+ @Feature({"Webapps"})
+ public void testLaunchWithDifferentManifestUrl() throws Exception {
+ CallbackWaiter waiter = new CallbackWaiter();
+ startManifestUpgradeDetectorFetcher(mTestServer.getURL(WEB_MANIFEST_SCOPE),
+ mTestServer.getURL(WEB_MANIFEST_URL2), waiter);
+
+ TabLoadObserver tabLoadObserver = new TabLoadObserver(mTab);
+ tabLoadObserver.fullyLoadUrl(mTestServer.getURL(PAGE_URL1));
+ tabLoadObserver.fullyLoadUrl(mTestServer.getURL(PAGE_URL2));
+ waiter.waitForCallback(0);
+
+ assertEquals(WEB_MANIFEST_NAME2, waiter.name());
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698