OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.webapps; | 5 package org.chromium.chrome.browser.webapps; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.content.SharedPreferences; | 10 import android.content.SharedPreferences; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 * FLAG_ACTIVITY_NEW_DOCUMENT mechanism. Moreover, we don't have access to the
task list pre-L so | 49 * FLAG_ACTIVITY_NEW_DOCUMENT mechanism. Moreover, we don't have access to the
task list pre-L so |
50 * we have to assume that any non-running WebappActivities are not listed in And
roid's Overview. | 50 * we have to assume that any non-running WebappActivities are not listed in And
roid's Overview. |
51 */ | 51 */ |
52 public class WebappModeTest extends MultiActivityTestBase { | 52 public class WebappModeTest extends MultiActivityTestBase { |
53 private static final String WEBAPP_1_ID = "webapp_id_1"; | 53 private static final String WEBAPP_1_ID = "webapp_id_1"; |
54 private static final String WEBAPP_1_URL = UrlUtils.encodeHtmlDataUri( | 54 private static final String WEBAPP_1_URL = UrlUtils.encodeHtmlDataUri( |
55 "<html><head><title>Web app #1</title><meta name='viewport' " | 55 "<html><head><title>Web app #1</title><meta name='viewport' " |
56 + "content='width=device-width initial-scale=0.5, maximum-scale=0.5'
></head>" | 56 + "content='width=device-width initial-scale=0.5, maximum-scale=0.5'
></head>" |
57 + "<body bgcolor='#011684'>Webapp 1</body></html>"); | 57 + "<body bgcolor='#011684'>Webapp 1</body></html>"); |
58 private static final String WEBAPP_1_TITLE = "Web app #1"; | 58 private static final String WEBAPP_1_TITLE = "Web app #1"; |
59 private static final String WEBAPP_1_ORIGIN = "https://www.google.com"; | |
60 | 59 |
61 private static final String WEBAPP_2_ID = "webapp_id_2"; | 60 private static final String WEBAPP_2_ID = "webapp_id_2"; |
62 private static final String WEBAPP_2_URL = | 61 private static final String WEBAPP_2_URL = |
63 UrlUtils.encodeHtmlDataUri("<html><body bgcolor='#840116'>Webapp 2</
body></html>"); | 62 UrlUtils.encodeHtmlDataUri("<html><body bgcolor='#840116'>Webapp 2</
body></html>"); |
64 private static final String WEBAPP_2_TITLE = "Web app #2"; | 63 private static final String WEBAPP_2_TITLE = "Web app #2"; |
65 private static final String WEBAPP_2_ORIGIN = "http://google.com"; | |
66 | 64 |
67 private static final String WEBAPP_ICON = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABC
AIAAACQd1PeAAAACXB" | 65 private static final String WEBAPP_ICON = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABC
AIAAACQd1PeAAAACXB" |
68 + "IWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wQIFB4cxOfiSQAAABl0RVh0Q29tbWVu
dABDcmVhdGVkIHdpdG" | 66 + "IWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wQIFB4cxOfiSQAAABl0RVh0Q29tbWVu
dABDcmVhdGVkIHdpdG" |
69 + "ggR0lNUFeBDhcAAAAMSURBVAjXY2AUawEAALcAnI/TkI8AAAAASUVORK5CYII="; | 67 + "ggR0lNUFeBDhcAAAAMSURBVAjXY2AUawEAALcAnI/TkI8AAAAASUVORK5CYII="; |
70 | 68 |
71 private void fireWebappIntent(String id, String url, String title, String ic
on, | 69 private Intent createIntent(String id, String url, String title, String icon
, boolean addMac) { |
72 boolean addMac) throws Exception { | |
73 Intent intent = new Intent(); | 70 Intent intent = new Intent(); |
74 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 71 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
75 intent.setPackage(getInstrumentation().getTargetContext().getPackageName
()); | 72 intent.setPackage(getInstrumentation().getTargetContext().getPackageName
()); |
76 intent.setAction(WebappLauncherActivity.ACTION_START_WEBAPP); | 73 intent.setAction(WebappLauncherActivity.ACTION_START_WEBAPP); |
77 if (addMac) { | 74 if (addMac) { |
78 // Needed for security reasons. If the MAC is excluded, the URL of
the webapp is opened | 75 // Needed for security reasons. If the MAC is excluded, the URL of
the webapp is opened |
79 // in a browser window, instead. | 76 // in a browser window, instead. |
80 String mac = ShortcutHelper.getEncodedMac(getInstrumentation().getTa
rgetContext(), url); | 77 String mac = ShortcutHelper.getEncodedMac(getInstrumentation().getTa
rgetContext(), url); |
81 intent.putExtra(ShortcutHelper.EXTRA_MAC, mac); | 78 intent.putExtra(ShortcutHelper.EXTRA_MAC, mac); |
82 } | 79 } |
83 | 80 |
84 WebappInfo webappInfo = WebappInfo.create(id, url, icon, title, null, | 81 WebappInfo webappInfo = WebappInfo.create(id, url, icon, title, null, |
85 ScreenOrientationValues.PORTRAIT, ShortcutSource.UNKNOWN, | 82 ScreenOrientationValues.PORTRAIT, ShortcutSource.UNKNOWN, |
86 ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, | 83 ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, |
87 ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, false); | 84 ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING, false); |
88 webappInfo.setWebappIntentExtras(intent); | 85 webappInfo.setWebappIntentExtras(intent); |
89 | 86 |
| 87 return intent; |
| 88 } |
| 89 |
| 90 private void fireWebappIntent(String id, String url, String title, String ic
on, |
| 91 boolean addMac) throws Exception { |
| 92 Intent intent = createIntent(id, url, title, icon, addMac); |
| 93 |
90 getInstrumentation().getTargetContext().startActivity(intent); | 94 getInstrumentation().getTargetContext().startActivity(intent); |
91 getInstrumentation().waitForIdleSync(); | 95 getInstrumentation().waitForIdleSync(); |
92 ApplicationTestUtils.waitUntilChromeInForeground(); | 96 ApplicationTestUtils.waitUntilChromeInForeground(); |
93 } | 97 } |
94 | 98 |
95 @Override | 99 @Override |
96 public void setUp() throws Exception { | 100 public void setUp() throws Exception { |
97 super.setUp(); | 101 super.setUp(); |
98 | 102 |
99 // Register the webapps so when the data storage is opened, the test doe
sn't crash. There is | 103 // Register the webapps so when the data storage is opened, the test doe
sn't crash. There is |
100 // no race condition with the retrival as AsyncTasks are run sequentiall
y on the background | 104 // no race condition with the retrieval as AsyncTasks are run sequential
ly on the background |
101 // thread. | 105 // thread. |
102 WebappRegistry.registerWebapp(getInstrumentation().getTargetContext(), W
EBAPP_1_ID, | 106 WebappRegistry.registerWebapp(getInstrumentation().getTargetContext(), W
EBAPP_1_ID, |
103 WEBAPP_1_ORIGIN); | 107 new WebappRegistry.FetchWebappDataStorageCallback() { |
| 108 @Override |
| 109 public void onWebappDataStorageRetrieved(WebappDataStorage s
torage) { |
| 110 storage.updateFromShortcutIntent(createIntent( |
| 111 WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAP
P_ICON, true)); |
| 112 } |
| 113 } |
| 114 ); |
104 WebappRegistry.registerWebapp(getInstrumentation().getTargetContext(), W
EBAPP_2_ID, | 115 WebappRegistry.registerWebapp(getInstrumentation().getTargetContext(), W
EBAPP_2_ID, |
105 WEBAPP_2_ORIGIN); | 116 new WebappRegistry.FetchWebappDataStorageCallback() { |
| 117 @Override |
| 118 public void onWebappDataStorageRetrieved(WebappDataStorage s
torage) { |
| 119 storage.updateFromShortcutIntent(createIntent( |
| 120 WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAP
P_ICON, true)); |
| 121 } |
| 122 } |
| 123 ); |
106 } | 124 } |
107 | 125 |
108 /** | 126 /** |
109 * Tests that WebappActivities are started properly. | 127 * Tests that WebappActivities are started properly. |
110 */ | 128 */ |
111 @MediumTest | 129 @MediumTest |
112 public void testWebappLaunches() throws Exception { | 130 public void testWebappLaunches() throws Exception { |
113 final WebappActivity firstActivity = | 131 final WebappActivity firstActivity = |
114 startWebappActivity(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, W
EBAPP_ICON); | 132 startWebappActivity(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, W
EBAPP_ICON); |
115 final int firstTabId = firstActivity.getActivityTab().getId(); | 133 final int firstTabId = firstActivity.getActivityTab().getId(); |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 | 373 |
356 WebappActivity webappActivity = (WebappActivity) lastActivity; | 374 WebappActivity webappActivity = (WebappActivity) lastActivity; |
357 if (webappActivity.getActivityTab() == null) return false; | 375 if (webappActivity.getActivityTab() == null) return false; |
358 | 376 |
359 View rootView = webappActivity.findViewById(android.R.id.content); | 377 View rootView = webappActivity.findViewById(android.R.id.content); |
360 if (!rootView.hasWindowFocus()) return false; | 378 if (!rootView.hasWindowFocus()) return false; |
361 | 379 |
362 return true; | 380 return true; |
363 } | 381 } |
364 } | 382 } |
OLD | NEW |