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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 * FLAG_ACTIVITY_NEW_DOCUMENT mechanism. Moreover, we don't have access to the
task list pre-L so | 44 * FLAG_ACTIVITY_NEW_DOCUMENT mechanism. Moreover, we don't have access to the
task list pre-L so |
45 * we have to assume that any non-running WebappActivities are not listed in And
roid's Overview. | 45 * we have to assume that any non-running WebappActivities are not listed in And
roid's Overview. |
46 */ | 46 */ |
47 public class WebappModeTest extends MultiActivityTestBase { | 47 public class WebappModeTest extends MultiActivityTestBase { |
48 private static final String WEBAPP_1_ID = "webapp_id_1"; | 48 private static final String WEBAPP_1_ID = "webapp_id_1"; |
49 private static final String WEBAPP_1_URL = UrlUtils.encodeHtmlDataUri( | 49 private static final String WEBAPP_1_URL = UrlUtils.encodeHtmlDataUri( |
50 "<html><head><title>Web app #1</title><meta name='viewport' " | 50 "<html><head><title>Web app #1</title><meta name='viewport' " |
51 + "content='width=device-width initial-scale=0.5, maximum-scale=0.5'
></head>" | 51 + "content='width=device-width initial-scale=0.5, maximum-scale=0.5'
></head>" |
52 + "<body bgcolor='#011684'>Webapp 1</body></html>"); | 52 + "<body bgcolor='#011684'>Webapp 1</body></html>"); |
53 private static final String WEBAPP_1_TITLE = "Web app #1"; | 53 private static final String WEBAPP_1_TITLE = "Web app #1"; |
| 54 private static final String WEBAPP_1_ORIGIN = "https://www.google.com"; |
54 | 55 |
55 private static final String WEBAPP_2_ID = "webapp_id_2"; | 56 private static final String WEBAPP_2_ID = "webapp_id_2"; |
56 private static final String WEBAPP_2_URL = | 57 private static final String WEBAPP_2_URL = |
57 UrlUtils.encodeHtmlDataUri("<html><body bgcolor='#840116'>Webapp 2</
body></html>"); | 58 UrlUtils.encodeHtmlDataUri("<html><body bgcolor='#840116'>Webapp 2</
body></html>"); |
58 private static final String WEBAPP_2_TITLE = "Web app #2"; | 59 private static final String WEBAPP_2_TITLE = "Web app #2"; |
| 60 private static final String WEBAPP_2_ORIGIN = "http://google.com"; |
59 | 61 |
60 private static final String WEBAPP_ICON = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABC
AIAAACQd1PeAAAACXB" | 62 private static final String WEBAPP_ICON = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABC
AIAAACQd1PeAAAACXB" |
61 + "IWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wQIFB4cxOfiSQAAABl0RVh0Q29tbWVu
dABDcmVhdGVkIHdpdG" | 63 + "IWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wQIFB4cxOfiSQAAABl0RVh0Q29tbWVu
dABDcmVhdGVkIHdpdG" |
62 + "ggR0lNUFeBDhcAAAAMSURBVAjXY2AUawEAALcAnI/TkI8AAAAASUVORK5CYII="; | 64 + "ggR0lNUFeBDhcAAAAMSURBVAjXY2AUawEAALcAnI/TkI8AAAAASUVORK5CYII="; |
63 | 65 |
64 private void fireWebappIntent(String id, String url, String title, String ic
on, | 66 private void fireWebappIntent(String id, String url, String title, String ic
on, |
65 boolean addMac) throws Exception { | 67 boolean addMac) throws Exception { |
66 Intent intent = new Intent(); | 68 Intent intent = new Intent(); |
67 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 69 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
68 intent.setPackage(getInstrumentation().getTargetContext().getPackageName
()); | 70 intent.setPackage(getInstrumentation().getTargetContext().getPackageName
()); |
(...skipping 16 matching lines...) Expand all Loading... |
85 ApplicationTestUtils.waitUntilChromeInForeground(); | 87 ApplicationTestUtils.waitUntilChromeInForeground(); |
86 } | 88 } |
87 | 89 |
88 @Override | 90 @Override |
89 public void setUp() throws Exception { | 91 public void setUp() throws Exception { |
90 super.setUp(); | 92 super.setUp(); |
91 | 93 |
92 // Register the webapps so when the data storage is opened, the test doe
sn't crash. There is | 94 // Register the webapps so when the data storage is opened, the test doe
sn't crash. There is |
93 // no race condition with the retrival as AsyncTasks are run sequentiall
y on the background | 95 // no race condition with the retrival as AsyncTasks are run sequentiall
y on the background |
94 // thread. | 96 // thread. |
95 WebappRegistry.registerWebapp(getInstrumentation().getTargetContext(), W
EBAPP_1_ID); | 97 WebappRegistry.registerWebapp(getInstrumentation().getTargetContext(), W
EBAPP_1_ID, |
96 WebappRegistry.registerWebapp(getInstrumentation().getTargetContext(), W
EBAPP_2_ID); | 98 WEBAPP_1_ORIGIN); |
| 99 WebappRegistry.registerWebapp(getInstrumentation().getTargetContext(), W
EBAPP_2_ID, |
| 100 WEBAPP_2_ORIGIN); |
97 } | 101 } |
98 | 102 |
99 /** | 103 /** |
100 * Tests that WebappActivities are started properly. | 104 * Tests that WebappActivities are started properly. |
101 */ | 105 */ |
102 @MediumTest | 106 @MediumTest |
103 public void testWebappLaunches() throws Exception { | 107 public void testWebappLaunches() throws Exception { |
104 final WebappActivity firstActivity = | 108 final WebappActivity firstActivity = |
105 startWebappActivity(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, W
EBAPP_ICON); | 109 startWebappActivity(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, W
EBAPP_ICON); |
106 final int firstTabId = firstActivity.getActivityTab().getId(); | 110 final int firstTabId = firstActivity.getActivityTab().getId(); |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 332 |
329 WebappActivity webappActivity = (WebappActivity) lastActivity; | 333 WebappActivity webappActivity = (WebappActivity) lastActivity; |
330 if (webappActivity.getActivityTab() == null) return false; | 334 if (webappActivity.getActivityTab() == null) return false; |
331 | 335 |
332 View rootView = webappActivity.findViewById(android.R.id.content); | 336 View rootView = webappActivity.findViewById(android.R.id.content); |
333 if (!rootView.hasWindowFocus()) return false; | 337 if (!rootView.hasWindowFocus()) return false; |
334 | 338 |
335 return true; | 339 return true; |
336 } | 340 } |
337 } | 341 } |
OLD | NEW |