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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/webapps/ManifestUpgradeDetectorTest.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/ManifestUpgradeDetectorTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/ManifestUpgradeDetectorTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/ManifestUpgradeDetectorTest.java
deleted file mode 100644
index 44e6b2786f4dad3bffd6401a674adbd7e56ac926..0000000000000000000000000000000000000000
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/ManifestUpgradeDetectorTest.java
+++ /dev/null
@@ -1,146 +0,0 @@
-// 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.blink_public.platform.WebDisplayMode;
-import org.chromium.chrome.browser.ShortcutHelper;
-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.content_public.common.ScreenOrientationValues;
-import org.chromium.net.test.EmbeddedTestServer;
-import org.chromium.webapk.lib.common.WebApkConstants;
-
-/**
- * Tests the ManifestUpgradeDetector.
- */
-public class ManifestUpgradeDetectorTest extends ChromeTabbedActivityTestBase {
- private static final String WEBAPK_ID = WebApkConstants.WEBAPK_ID_PREFIX + "webapp_id";
-
- /** The following field values are declared in {@link WEBAPK_WEB_MANIFEST_URL}. */
- private static final String WEBAPK_NAME = "Manifest test app";
- private static final String WEBAPK_SHORT_NAME = "App";
- private static final int WEBAPK_ORIENTATION = ScreenOrientationValues.LANDSCAPE;
- private static final String WEBAPK_START_URL_PATH =
- "/chrome/test/data/webapps/manifest_test_page.html";
- private static final String WEBAPK_SCOPE_PATH = "/chrome/test/data/webapps/";
- private static final String WEBAPK_WEB_MANIFEST_URL =
- "/chrome/test/data/webapps/manifest.json";
-
- private TestManifestUpgradeDetector mDetector;
- private EmbeddedTestServer mTestServer;
-
- /**
- * A ManifestUpgradeDetector that verifies the Web Manifest fetching pipeline and the
- * comparison are working correctly.
- */
- private static class TestManifestUpgradeDetector extends ManifestUpgradeDetector {
- public boolean mIsUpgraded;
- public String mStartUrl;
- public CallbackHelper mCallbackHelper;
-
- public TestManifestUpgradeDetector(Tab tab, WebappInfo info) {
- super(tab, info);
- mCallbackHelper = new CallbackHelper();
- }
-
- @Override
- protected boolean requireUpgrade(WebappInfo newInfo) {
- mIsUpgraded = super.requireUpgrade(newInfo);
- mStartUrl = newInfo.uri().toString();
- mCallbackHelper.notifyCalled();
- return mIsUpgraded;
- }
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- final Context context = getInstrumentation().getTargetContext();
- mTestServer = EmbeddedTestServer.createAndStartFileServer(
- context, Environment.getExternalStorageDirectory());
- }
-
- @Override
- protected void tearDown() throws Exception {
- mTestServer.stopAndDestroyServer();
- super.tearDown();
- }
-
- @Override
- public void startMainActivity() throws InterruptedException {
- startMainActivityOnBlankPage();
- }
-
- /**
- * Creates a WebappInfo with the properties in {@link WEBAPK_WEB_MANIFEST_URL}.
- */
- private WebappInfo createWebappInfo() {
- return WebappInfo.create(WEBAPK_ID,
- WEBAPK_START_URL_PATH,
- mTestServer.getURL(WEBAPK_SCOPE_PATH),
- null,
- WEBAPK_NAME,
- WEBAPK_SHORT_NAME,
- WebDisplayMode.Standalone,
- WEBAPK_ORIENTATION,
- 0,
- ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING,
- ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING,
- false,
- "",
- mTestServer.getURL(WEBAPK_WEB_MANIFEST_URL));
- }
-
- /**
- * Navigates to {@link startUrl} and waits till the ManifestUpgradeDetector gets the Web
- * Manifest data.
- * @param info: the old Webapp info passed in to initialize the detector.
- * @param startUrl: URL to navigate to and start URL of the old Webapp info.
- */
- private void waitUntilManifestDataAvailable(WebappInfo info, String startUrl) throws Exception {
- final Tab tab = getActivity().getActivityTab();
-
- mDetector = new TestManifestUpgradeDetector(tab, info);
- mDetector.setOverrideMetadataForTesting(true);
- mDetector.setStartUrlForTesting(startUrl);
-
- ThreadUtils.runOnUiThreadBlocking(new Runnable() {
- @Override
- public void run() {
- mDetector.start();
- }
- });
-
- CallbackHelper callbackHelper = mDetector.mCallbackHelper;
- int curCallCount = 0;
- new TabLoadObserver(tab).fullyLoadUrl(startUrl);
- callbackHelper.waitForCallback(curCallCount);
- }
-
- @MediumTest
- public void testManifestDoesNotUpgrade() throws Exception {
- waitUntilManifestDataAvailable(createWebappInfo(),
- mTestServer.getURL(WEBAPK_START_URL_PATH));
-
- assertFalse(mDetector.mIsUpgraded);
- }
-
- @MediumTest
- public void testStartUrlChangeShouldReturnUpgradeTrue() throws Exception {
- String currentStartUrl =
- "/chrome/test/data/webapps/manifest_test_page_test_start_url_change.html";
- waitUntilManifestDataAvailable(createWebappInfo(), mTestServer.getURL(currentStartUrl));
-
- assertTrue(mDetector.mIsUpgraded);
- assertEquals(mTestServer.getURL(WEBAPK_START_URL_PATH), mDetector.mStartUrl);
- }
-}

Powered by Google App Engine
This is Rietveld 408576698