Chromium Code Reviews| Index: chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappNavigationTest.java |
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappNavigationTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappNavigationTest.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..66672d8be4cb64fc04e5d00dfc0e9d119d3260f2 |
| --- /dev/null |
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappNavigationTest.java |
| @@ -0,0 +1,134 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
|
dominickn
2017/05/01 00:41:41
Nit: new file, use 2017
piotrs
2017/05/01 02:55:07
Done.
|
| +// 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.app.Activity; |
| +import android.content.Intent; |
| +import android.graphics.Color; |
| +import android.support.test.filters.SmallTest; |
| + |
| +import org.chromium.base.ActivityState; |
| +import org.chromium.base.ApiCompatibilityUtils; |
| +import org.chromium.base.ApplicationStatus; |
| +import org.chromium.base.ApplicationStatus.ActivityStateListener; |
| +import org.chromium.base.ThreadUtils; |
| +import org.chromium.base.test.util.Feature; |
| +import org.chromium.chrome.R; |
| +import org.chromium.chrome.browser.ShortcutHelper; |
| +import org.chromium.chrome.browser.customtabs.CustomTabActivity; |
| +import org.chromium.content.browser.test.util.Criteria; |
| +import org.chromium.content.browser.test.util.CriteriaHelper; |
| +import org.chromium.content_public.browser.LoadUrlParams; |
| +import org.chromium.net.test.EmbeddedTestServer; |
| +import org.chromium.ui.base.PageTransition; |
| + |
| +/** |
| + * Tests web navigations originating from a WebappActivity. |
| + */ |
| +public class WebappNavigationTest extends WebappActivityTestBase implements ActivityStateListener { |
| + private static final String OFF_ORIGIN_URL = "https://www.google.com/"; |
| + private static final String WEB_APP_PATH = "/chrome/test/data/banners/manifest_test_page.html"; |
| + private static final String OTHER_PAGE_PATH = |
| + "/chrome/test/data/banners/manifest_no_service_worker.html"; |
| + |
| + private EmbeddedTestServer mTestServer; |
| + private Activity mMostRecentActivity; |
| + |
| + @Override |
| + protected void setUp() throws Exception { |
| + super.setUp(); |
| + mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext()); |
| + ApplicationStatus.registerStateListenerForAllActivities(this); |
| + } |
| + |
| + @Override |
| + protected void tearDown() throws Exception { |
| + ApplicationStatus.unregisterActivityStateListener(this); |
| + mTestServer.stopAndDestroyServer(); |
| + super.tearDown(); |
| + } |
| + |
| + @Override |
| + public void onActivityStateChange(Activity activity, int newState) { |
| + if (newState == ActivityState.RESUMED) { |
| + mMostRecentActivity = activity; |
| + } |
| + } |
| + |
| + @SmallTest |
| + @Feature({"Webapps"}) |
| + public void testOffOriginNavigationUsingLinkAndNoWebappThemeColor() throws Exception { |
| + runWebappActivityAndWaitForIdle(createIntent()); |
| + |
| + // Not using #loadUrl, as it expects the URL to load in the activity under test, |
| + // which is not happening here. |
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| + @Override |
| + public void run() { |
| + getActivity().getActivityTab().loadUrl( |
| + new LoadUrlParams(OFF_ORIGIN_URL, PageTransition.LINK)); |
| + } |
| + }); |
| + |
| + CustomTabActivity cta = assertCustomTabActivityLaunchedForOffOriginUrl(); |
|
dominickn
2017/05/01 00:41:41
Nit: the variable name here should probably be cus
piotrs
2017/05/01 02:55:07
Oh, you got me... changed, but now I have to add o
|
| + |
| + assertEquals("CCT Toolbar should use default primary color if theme color is not specified", |
| + ApiCompatibilityUtils.getColor(cta.getResources(), R.color.default_primary_color), |
| + cta.getToolbarManager().getPrimaryColor()); |
| + } |
| + |
| + @SmallTest |
| + @Feature({"Webapps"}) |
| + public void testOffOriginNavigationUsingJavaScriptAndWebappThemeColor() throws Exception { |
| + runWebappActivityAndWaitForIdle( |
| + createIntent().putExtra(ShortcutHelper.EXTRA_THEME_COLOR, (long) Color.CYAN)); |
| + |
| + runJavaScriptCodeInCurrentTab(String.format("window.top.location = '%s'", OFF_ORIGIN_URL)); |
| + |
| + CustomTabActivity cta = assertCustomTabActivityLaunchedForOffOriginUrl(); |
|
dominickn
2017/05/01 00:41:41
Nit: variable name
piotrs
2017/05/01 02:55:06
Done.
|
| + |
| + assertEquals("CCT Toolbar should use the theme color of a webapp", Color.CYAN, |
| + cta.getToolbarManager().getPrimaryColor()); |
| + } |
| + |
| + private CustomTabActivity assertCustomTabActivityLaunchedForOffOriginUrl() { |
| + CriteriaHelper.pollUiThread(new Criteria() { |
| + @Override |
| + public boolean isSatisfied() { |
| + return mMostRecentActivity instanceof CustomTabActivity; |
| + } |
| + }); |
| + |
| + CustomTabActivity customTab = (CustomTabActivity) mMostRecentActivity; |
| + |
| + waitUntilIdle(customTab); |
| + // Dropping the TLD as Google can redirect to a local site, so this could fail outside US. |
| + assertTrue(customTab.getActivityTab().getUrl().startsWith("https://www.google.")); |
| + |
| + return customTab; |
| + } |
| + |
| + @SmallTest |
| + @Feature({"Webapps"}) |
| + public void testInOriginNavigationStaysInWebapp() throws Exception { |
| + runWebappActivityAndWaitForIdle(createIntent()); |
| + |
| + String otherPageUrl = mTestServer.getURL(OTHER_PAGE_PATH); |
| + loadUrlInTab(otherPageUrl, PageTransition.LINK, getActivity().getActivityTab()); |
| + |
| + waitUntilIdle(); |
| + assertEquals(otherPageUrl, getActivity().getActivityTab().getUrl()); |
| + |
| + assertSame(getActivity(), mMostRecentActivity); |
| + } |
| + |
| + private void runWebappActivityAndWaitForIdle(Intent intent) throws Exception { |
| + startWebappActivity( |
| + intent.putExtra(ShortcutHelper.EXTRA_URL, mTestServer.getURL(WEB_APP_PATH))); |
| + |
| + waitUntilSplashscreenHides(); |
| + waitUntilIdle(); |
| + } |
| +} |