OLD | NEW |
---|---|
(Empty) | |
1 // 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.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.chrome.browser.webapps; | |
6 | |
7 import android.app.Activity; | |
8 import android.content.Intent; | |
9 import android.graphics.Color; | |
10 import android.support.test.filters.SmallTest; | |
11 | |
12 import org.chromium.base.ActivityState; | |
13 import org.chromium.base.ApiCompatibilityUtils; | |
14 import org.chromium.base.ApplicationStatus; | |
15 import org.chromium.base.ApplicationStatus.ActivityStateListener; | |
16 import org.chromium.base.ThreadUtils; | |
17 import org.chromium.base.test.util.Feature; | |
18 import org.chromium.chrome.R; | |
19 import org.chromium.chrome.browser.ShortcutHelper; | |
20 import org.chromium.chrome.browser.customtabs.CustomTabActivity; | |
21 import org.chromium.content.browser.test.util.Criteria; | |
22 import org.chromium.content.browser.test.util.CriteriaHelper; | |
23 import org.chromium.content_public.browser.LoadUrlParams; | |
24 import org.chromium.net.test.EmbeddedTestServer; | |
25 import org.chromium.ui.base.PageTransition; | |
26 | |
27 /** | |
28 * Tests web navigations originating from a WebappActivity. | |
29 */ | |
30 public class WebappNavigationTest extends WebappActivityTestBase implements Acti vityStateListener { | |
31 private static final String OFF_ORIGIN_URL = "https://www.google.com/"; | |
32 private static final String WEB_APP_PATH = "/chrome/test/data/banners/manife st_test_page.html"; | |
33 private static final String OTHER_PAGE_PATH = | |
34 "/chrome/test/data/banners/manifest_no_service_worker.html"; | |
35 | |
36 private EmbeddedTestServer mTestServer; | |
37 private Activity mMostRecentActivity; | |
38 | |
39 @Override | |
40 protected void setUp() throws Exception { | |
41 super.setUp(); | |
42 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation ().getContext()); | |
43 ApplicationStatus.registerStateListenerForAllActivities(this); | |
44 } | |
45 | |
46 @Override | |
47 protected void tearDown() throws Exception { | |
48 ApplicationStatus.unregisterActivityStateListener(this); | |
49 mTestServer.stopAndDestroyServer(); | |
50 super.tearDown(); | |
51 } | |
52 | |
53 @Override | |
54 public void onActivityStateChange(Activity activity, int newState) { | |
55 if (newState == ActivityState.RESUMED) { | |
56 mMostRecentActivity = activity; | |
57 } | |
58 } | |
59 | |
60 @SmallTest | |
61 @Feature({"Webapps"}) | |
62 public void testOffOriginNavigationUsingLinkAndNoWebappThemeColor() throws E xception { | |
63 runWebappActivityAndWaitForIdle(createIntent()); | |
64 | |
65 // Not using #loadUrl, as it expects the URL to load in the activity und er test, | |
66 // which is not happening here. | |
67 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
68 @Override | |
69 public void run() { | |
70 getActivity().getActivityTab().loadUrl( | |
71 new LoadUrlParams(OFF_ORIGIN_URL, PageTransition.LINK)); | |
72 } | |
73 }); | |
74 | |
75 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
| |
76 | |
77 assertEquals("CCT Toolbar should use default primary color if theme colo r is not specified", | |
78 ApiCompatibilityUtils.getColor(cta.getResources(), R.color.defau lt_primary_color), | |
79 cta.getToolbarManager().getPrimaryColor()); | |
80 } | |
81 | |
82 @SmallTest | |
83 @Feature({"Webapps"}) | |
84 public void testOffOriginNavigationUsingJavaScriptAndWebappThemeColor() thro ws Exception { | |
85 runWebappActivityAndWaitForIdle( | |
86 createIntent().putExtra(ShortcutHelper.EXTRA_THEME_COLOR, (long) Color.CYAN)); | |
87 | |
88 runJavaScriptCodeInCurrentTab(String.format("window.top.location = '%s'" , OFF_ORIGIN_URL)); | |
89 | |
90 CustomTabActivity cta = assertCustomTabActivityLaunchedForOffOriginUrl() ; | |
dominickn
2017/05/01 00:41:41
Nit: variable name
piotrs
2017/05/01 02:55:06
Done.
| |
91 | |
92 assertEquals("CCT Toolbar should use the theme color of a webapp", Color .CYAN, | |
93 cta.getToolbarManager().getPrimaryColor()); | |
94 } | |
95 | |
96 private CustomTabActivity assertCustomTabActivityLaunchedForOffOriginUrl() { | |
97 CriteriaHelper.pollUiThread(new Criteria() { | |
98 @Override | |
99 public boolean isSatisfied() { | |
100 return mMostRecentActivity instanceof CustomTabActivity; | |
101 } | |
102 }); | |
103 | |
104 CustomTabActivity customTab = (CustomTabActivity) mMostRecentActivity; | |
105 | |
106 waitUntilIdle(customTab); | |
107 // Dropping the TLD as Google can redirect to a local site, so this coul d fail outside US. | |
108 assertTrue(customTab.getActivityTab().getUrl().startsWith("https://www.g oogle.")); | |
109 | |
110 return customTab; | |
111 } | |
112 | |
113 @SmallTest | |
114 @Feature({"Webapps"}) | |
115 public void testInOriginNavigationStaysInWebapp() throws Exception { | |
116 runWebappActivityAndWaitForIdle(createIntent()); | |
117 | |
118 String otherPageUrl = mTestServer.getURL(OTHER_PAGE_PATH); | |
119 loadUrlInTab(otherPageUrl, PageTransition.LINK, getActivity().getActivit yTab()); | |
120 | |
121 waitUntilIdle(); | |
122 assertEquals(otherPageUrl, getActivity().getActivityTab().getUrl()); | |
123 | |
124 assertSame(getActivity(), mMostRecentActivity); | |
125 } | |
126 | |
127 private void runWebappActivityAndWaitForIdle(Intent intent) throws Exception { | |
128 startWebappActivity( | |
129 intent.putExtra(ShortcutHelper.EXTRA_URL, mTestServer.getURL(WEB _APP_PATH))); | |
130 | |
131 waitUntilSplashscreenHides(); | |
132 waitUntilIdle(); | |
133 } | |
134 } | |
OLD | NEW |