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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappSplashScreenTest.java

Issue 2863583002: Convert WebappActivityTestBase and direct children to JUnit4. (Closed)
Patch Set: Merge Created 3 years, 7 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 unified diff | Download patch
OLDNEW
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.annotation.TargetApi; 7 import android.annotation.TargetApi;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.Intent;
10 import android.graphics.Bitmap; 9 import android.graphics.Bitmap;
11 import android.graphics.Color; 10 import android.graphics.Color;
12 import android.graphics.drawable.ColorDrawable; 11 import android.graphics.drawable.ColorDrawable;
13 import android.os.Build; 12 import android.os.Build;
14 import android.support.test.filters.SmallTest; 13 import android.support.test.filters.SmallTest;
15 import android.view.View; 14 import android.view.View;
16 import android.view.ViewGroup; 15 import android.view.ViewGroup;
17 import android.widget.ImageView; 16 import android.widget.ImageView;
18 import android.widget.RelativeLayout; 17 import android.widget.RelativeLayout;
19 import android.widget.TextView; 18 import android.widget.TextView;
20 19
20 import org.junit.Assert;
21 import org.junit.Rule;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24
21 import org.chromium.base.ApiCompatibilityUtils; 25 import org.chromium.base.ApiCompatibilityUtils;
22 import org.chromium.base.ThreadUtils; 26 import org.chromium.base.ThreadUtils;
23 import org.chromium.base.metrics.RecordHistogram; 27 import org.chromium.base.metrics.RecordHistogram;
28 import org.chromium.base.test.util.CommandLineFlags;
24 import org.chromium.base.test.util.Feature; 29 import org.chromium.base.test.util.Feature;
25 import org.chromium.base.test.util.RetryOnFailure; 30 import org.chromium.base.test.util.RetryOnFailure;
26 import org.chromium.chrome.R; 31 import org.chromium.chrome.R;
32 import org.chromium.chrome.browser.ChromeSwitches;
27 import org.chromium.chrome.browser.ShortcutHelper; 33 import org.chromium.chrome.browser.ShortcutHelper;
28 import org.chromium.chrome.browser.metrics.WebappUma; 34 import org.chromium.chrome.browser.metrics.WebappUma;
29 import org.chromium.chrome.browser.tab.Tab; 35 import org.chromium.chrome.browser.tab.Tab;
30 import org.chromium.chrome.browser.tab.TabTestUtils; 36 import org.chromium.chrome.browser.tab.TabTestUtils;
37 import org.chromium.chrome.test.ChromeActivityTestRule;
38 import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
31 39
32 /** 40 /**
33 * Tests for splash screens. 41 * Tests for splash screens.
34 */ 42 */
35 public class WebappSplashScreenTest extends WebappActivityTestBase { 43 @RunWith(ChromeJUnit4ClassRunner.class)
44 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
45 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
46 public class WebappSplashScreenTest {
47 @Rule
48 public final WebappActivityTestRule mActivityTestRule = new WebappActivityTe stRule();
36 49
37 private int getHistogramTotalCountFor(String histogram, int buckets) { 50 private int getHistogramTotalCountFor(String histogram, int buckets) {
38 int count = 0; 51 int count = 0;
39 52
40 for (int i = 0; i < buckets; ++i) { 53 for (int i = 0; i < buckets; ++i) {
41 count += RecordHistogram.getHistogramValueCountForTesting(histogram, i); 54 count += RecordHistogram.getHistogramValueCountForTesting(histogram, i);
42 } 55 }
43 56
44 return count; 57 return count;
45 } 58 }
46 59
47 private boolean hasHistogramEntry(String histogram, int maxValue) { 60 private boolean hasHistogramEntry(String histogram, int maxValue) {
48 for (int i = 0; i < maxValue; ++i) { 61 for (int i = 0; i < maxValue; ++i) {
49 if (RecordHistogram.getHistogramValueCountForTesting(histogram, i) > 0) { 62 if (RecordHistogram.getHistogramValueCountForTesting(histogram, i) > 0) {
50 return true; 63 return true;
51 } 64 }
52 } 65 }
53 return false; 66 return false;
54 } 67 }
55 68
69 @Test
56 @SmallTest 70 @SmallTest
57 @Feature({"Webapps"}) 71 @Feature({"Webapps"})
58 @RetryOnFailure 72 @RetryOnFailure
59 public void testDefaultBackgroundColor() throws Exception { 73 public void testDefaultBackgroundColor() throws Exception {
60 startWebappActivity(); 74 mActivityTestRule.startWebappActivity();
61 ViewGroup splashScreen = waitUntilSplashScreenAppears(); 75 ViewGroup splashScreen = mActivityTestRule.waitUntilSplashScreenAppears( );
62 ColorDrawable background = (ColorDrawable) splashScreen.getBackground(); 76 ColorDrawable background = (ColorDrawable) splashScreen.getBackground();
63 77
64 assertEquals(ApiCompatibilityUtils.getColor(getActivity().getResources() , 78 Assert.assertEquals(
65 R.color.webapp_default_bg), 79 ApiCompatibilityUtils.getColor(
80 mActivityTestRule.getActivity().getResources(), R.color. webapp_default_bg),
66 background.getColor()); 81 background.getColor());
67 } 82 }
68 83
84 @Test
69 @SmallTest 85 @SmallTest
70 @Feature({"Webapps"}) 86 @Feature({"Webapps"})
71 @TargetApi(Build.VERSION_CODES.LOLLIPOP) 87 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
72 @RetryOnFailure 88 @RetryOnFailure
73 public void testThemeColorWhenNotSpecified() throws Exception { 89 public void testThemeColorWhenNotSpecified() throws Exception {
74 startWebappActivity(); 90 mActivityTestRule.startWebappActivity();
75 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return; 91 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return;
76 92
77 assertEquals(Color.BLACK, getActivity().getWindow().getStatusBarColor()) ; 93 Assert.assertEquals(
94 Color.BLACK, mActivityTestRule.getActivity().getWindow().getStat usBarColor());
78 } 95 }
79 96
97 @Test
80 @SmallTest 98 @SmallTest
81 @Feature({"Webapps"}) 99 @Feature({"Webapps"})
82 @RetryOnFailure 100 @RetryOnFailure
83 public void testHidesAfterFirstPaint() throws Exception { 101 public void testHidesAfterFirstPaint() throws Exception {
84 startWebappActivity(); 102 mActivityTestRule.startWebappActivity();
85 assertTrue(getActivity().isSplashScreenVisibleForTests()); 103 Assert.assertTrue(mActivityTestRule.getActivity().isSplashScreenVisibleF orTests());
86 104
87 ThreadUtils.runOnUiThread(new Runnable() { 105 ThreadUtils.runOnUiThread(new Runnable() {
88 @Override 106 @Override
89 public void run() { 107 public void run() {
90 TabTestUtils.simulateFirstVisuallyNonEmptyPaint(getActivity().ge tActivityTab()); 108 TabTestUtils.simulateFirstVisuallyNonEmptyPaint(
109 mActivityTestRule.getActivity().getActivityTab());
91 } 110 }
92 }); 111 });
93 112
94 waitUntilSplashscreenHides(); 113 mActivityTestRule.waitUntilSplashscreenHides();
95 } 114 }
96 115
116 @Test
97 @SmallTest 117 @SmallTest
98 @Feature({"Webapps"}) 118 @Feature({"Webapps"})
99 @RetryOnFailure 119 @RetryOnFailure
100 public void testHidesAfterCrash() throws Exception { 120 public void testHidesAfterCrash() throws Throwable {
101 startWebappActivity(); 121 mActivityTestRule.startWebappActivity();
102 assertTrue(getActivity().isSplashScreenVisibleForTests()); 122 Assert.assertTrue(mActivityTestRule.getActivity().isSplashScreenVisibleF orTests());
103 123
104 ThreadUtils.runOnUiThread(new Runnable() { 124 ThreadUtils.runOnUiThread(new Runnable() {
105 @Override 125 @Override
106 public void run() { 126 public void run() {
107 TabTestUtils.simulateCrash(getActivity().getActivityTab(), true) ; 127 TabTestUtils.simulateCrash(mActivityTestRule.getActivity().getAc tivityTab(), true);
108 } 128 }
109 }); 129 });
110 130
111 waitUntilSplashscreenHides(); 131 mActivityTestRule.waitUntilSplashscreenHides();
112 } 132 }
113 133
134 @Test
114 @SmallTest 135 @SmallTest
115 @Feature({"Webapps"}) 136 @Feature({"Webapps"})
116 @RetryOnFailure 137 @RetryOnFailure
117 public void testHidesAfterLoadCompletes() throws Exception { 138 public void testHidesAfterLoadCompletes() throws Exception {
118 startWebappActivity(); 139 mActivityTestRule.startWebappActivity();
119 assertTrue(getActivity().isSplashScreenVisibleForTests()); 140 Assert.assertTrue(mActivityTestRule.getActivity().isSplashScreenVisibleF orTests());
120 141
121 ThreadUtils.runOnUiThread(new Runnable() { 142 ThreadUtils.runOnUiThread(new Runnable() {
122 @Override 143 @Override
123 public void run() { 144 public void run() {
124 TabTestUtils.simulatePageLoadFinished(getActivity().getActivityT ab()); 145 TabTestUtils.simulatePageLoadFinished(
146 mActivityTestRule.getActivity().getActivityTab());
125 } 147 }
126 }); 148 });
127 149
128 waitUntilSplashscreenHides(); 150 mActivityTestRule.waitUntilSplashscreenHides();
129 } 151 }
130 152
153 @Test
131 @SmallTest 154 @SmallTest
132 @Feature({"Webapps"}) 155 @Feature({"Webapps"})
133 @RetryOnFailure 156 @RetryOnFailure
134 public void testHidesAfterLoadFails() throws Exception { 157 public void testHidesAfterLoadFails() throws Exception {
135 startWebappActivity(); 158 mActivityTestRule.startWebappActivity();
136 assertTrue(getActivity().isSplashScreenVisibleForTests()); 159 Assert.assertTrue(mActivityTestRule.getActivity().isSplashScreenVisibleF orTests());
137 160
138 ThreadUtils.runOnUiThread(new Runnable() { 161 ThreadUtils.runOnUiThread(new Runnable() {
139 @Override 162 @Override
140 public void run() { 163 public void run() {
141 TabTestUtils.simulatePageLoadFailed(getActivity().getActivityTab (), 0); 164 TabTestUtils.simulatePageLoadFailed(
165 mActivityTestRule.getActivity().getActivityTab(), 0);
142 } 166 }
143 }); 167 });
144 168
145 waitUntilSplashscreenHides(); 169 mActivityTestRule.waitUntilSplashscreenHides();
146 } 170 }
147 171
172 @Test
148 @SmallTest 173 @SmallTest
149 @Feature({"Webapps"}) 174 @Feature({"Webapps"})
150 @RetryOnFailure 175 @RetryOnFailure
151 public void testHidesAfterMultipleEvents() throws Exception { 176 public void testHidesAfterMultipleEvents() throws Exception {
152 startWebappActivity(); 177 mActivityTestRule.startWebappActivity();
153 assertTrue(getActivity().isSplashScreenVisibleForTests()); 178 Assert.assertTrue(mActivityTestRule.getActivity().isSplashScreenVisibleF orTests());
154 179
155 ThreadUtils.runOnUiThread(new Runnable() { 180 ThreadUtils.runOnUiThread(new Runnable() {
156 @Override 181 @Override
157 public void run() { 182 public void run() {
158 Tab tab = getActivity().getActivityTab(); 183 Tab tab = mActivityTestRule.getActivity().getActivityTab();
159 184
160 TabTestUtils.simulatePageLoadFinished(tab); 185 TabTestUtils.simulatePageLoadFinished(tab);
161 TabTestUtils.simulatePageLoadFailed(tab, 0); 186 TabTestUtils.simulatePageLoadFailed(tab, 0);
162 TabTestUtils.simulateFirstVisuallyNonEmptyPaint(tab); 187 TabTestUtils.simulateFirstVisuallyNonEmptyPaint(tab);
163 } 188 }
164 }); 189 });
165 190
166 waitUntilSplashscreenHides(); 191 mActivityTestRule.waitUntilSplashscreenHides();
167 } 192 }
168 193
194 @Test
169 @SmallTest 195 @SmallTest
170 @Feature({"Webapps"}) 196 @Feature({"Webapps"})
171 @RetryOnFailure 197 @RetryOnFailure
172 public void testUmaOnNativeLoad() throws Exception { 198 public void testUmaOnNativeLoad() throws Exception {
173 startWebappActivity(); 199 mActivityTestRule.startWebappActivity();
174 200
175 // Tests UMA values. 201 // Tests UMA values.
176 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( 202 Assert.assertEquals(1,
177 WebappUma.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR, 203 RecordHistogram.getHistogramValueCountForTesting(
178 WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT)); 204 WebappUma.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
179 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( 205 WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT));
180 WebappUma.HISTOGRAM_SPLASHSCREEN_THEMECOLOR, 206 Assert.assertEquals(1,
181 WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT)); 207 RecordHistogram.getHistogramValueCountForTesting(
182 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( 208 WebappUma.HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
183 WebappUma.HISTOGRAM_SPLASHSCREEN_ICON_TYPE, 209 WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT));
184 WebappUma.SPLASHSCREEN_ICON_TYPE_NONE)); 210 Assert.assertEquals(1,
211 RecordHistogram.getHistogramValueCountForTesting(
212 WebappUma.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
213 WebappUma.SPLASHSCREEN_ICON_TYPE_NONE));
185 214
186 // Tests UMA counts. 215 // Tests UMA counts.
187 assertEquals(1, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCRE EN_BACKGROUNDCOLOR, 216 Assert.assertEquals(1,
188 WebappUma.SPLASHSCREEN_COLOR_STATUS_MAX)); 217 getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCREEN_BACKG ROUNDCOLOR,
189 assertEquals(1, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCRE EN_THEMECOLOR, 218 WebappUma.SPLASHSCREEN_COLOR_STATUS_MAX));
190 WebappUma.SPLASHSCREEN_COLOR_STATUS_MAX)); 219 Assert.assertEquals(1,
191 assertEquals(1, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCRE EN_ICON_TYPE, 220 getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCREEN_THEME COLOR,
192 WebappUma.SPLASHSCREEN_ICON_TYPE_MAX)); 221 WebappUma.SPLASHSCREEN_COLOR_STATUS_MAX));
222 Assert.assertEquals(1,
223 getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCREEN_ICON_ TYPE,
224 WebappUma.SPLASHSCREEN_ICON_TYPE_MAX));
193 225
194 // Given that there is no icon, the ICON_SIZE UMA should not be recorded . 226 // Given that there is no icon, the ICON_SIZE UMA should not be recorded .
195 assertEquals(0, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCRE EN_ICON_SIZE, 50)); 227 Assert.assertEquals(
228 0, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCREEN_IC ON_SIZE, 50));
196 229
197 // DURATION and HIDES UMA should not have been recorded yet. 230 // DURATION and HIDES UMA should not have been recorded yet.
198 assertFalse(hasHistogramEntry(WebappUma.HISTOGRAM_SPLASHSCREEN_DURATION, 3000)); 231 Assert.assertFalse(hasHistogramEntry(WebappUma.HISTOGRAM_SPLASHSCREEN_DU RATION, 3000));
199 assertEquals(0, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCRE EN_HIDES, 232 Assert.assertEquals(0,
200 WebappUma.SPLASHSCREEN_HIDES_REASON_MAX)); 233 getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCREEN_HIDES ,
234 WebappUma.SPLASHSCREEN_HIDES_REASON_MAX));
201 } 235 }
202 236
237 @Test
203 @SmallTest 238 @SmallTest
204 @Feature({"Webapps"}) 239 @Feature({"Webapps"})
205 @RetryOnFailure 240 @RetryOnFailure
206 public void testUmaWhenSplashHides() throws Exception { 241 public void testUmaWhenSplashHides() throws Exception {
207 startWebappActivity(); 242 mActivityTestRule.startWebappActivity();
208 ThreadUtils.runOnUiThread(new Runnable() { 243 ThreadUtils.runOnUiThread(new Runnable() {
209 @Override 244 @Override
210 public void run() { 245 public void run() {
211 TabTestUtils.simulateFirstVisuallyNonEmptyPaint(getActivity().ge tActivityTab()); 246 TabTestUtils.simulateFirstVisuallyNonEmptyPaint(
247 mActivityTestRule.getActivity().getActivityTab());
212 } 248 }
213 }); 249 });
214 250
215 waitUntilSplashscreenHides(); 251 mActivityTestRule.waitUntilSplashscreenHides();
216 252
217 // DURATION and HIDES should now have a value. 253 // DURATION and HIDES should now have a value.
218 assertTrue(hasHistogramEntry(WebappUma.HISTOGRAM_SPLASHSCREEN_DURATION, 5000)); 254 Assert.assertTrue(hasHistogramEntry(WebappUma.HISTOGRAM_SPLASHSCREEN_DUR ATION, 5000));
219 assertEquals(1, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCRE EN_HIDES, 255 Assert.assertEquals(1,
220 WebappUma.SPLASHSCREEN_HIDES_REASON_MAX)); 256 getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCREEN_HIDES ,
257 WebappUma.SPLASHSCREEN_HIDES_REASON_MAX));
221 258
222 // The other UMA records should not have changed. 259 // The other UMA records should not have changed.
223 assertEquals(1, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCRE EN_BACKGROUNDCOLOR, 260 Assert.assertEquals(1,
224 WebappUma.SPLASHSCREEN_COLOR_STATUS_MAX)); 261 getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCREEN_BACKG ROUNDCOLOR,
225 assertEquals(1, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCRE EN_THEMECOLOR, 262 WebappUma.SPLASHSCREEN_COLOR_STATUS_MAX));
226 WebappUma.SPLASHSCREEN_COLOR_STATUS_MAX)); 263 Assert.assertEquals(1,
227 assertEquals(1, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCRE EN_ICON_TYPE, 264 getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCREEN_THEME COLOR,
228 WebappUma.SPLASHSCREEN_ICON_TYPE_MAX)); 265 WebappUma.SPLASHSCREEN_COLOR_STATUS_MAX));
229 assertEquals(0, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCRE EN_ICON_SIZE, 50)); 266 Assert.assertEquals(1,
267 getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCREEN_ICON_ TYPE,
268 WebappUma.SPLASHSCREEN_ICON_TYPE_MAX));
269 Assert.assertEquals(
270 0, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCREEN_IC ON_SIZE, 50));
230 } 271 }
231 272
273 @Test
232 @SmallTest 274 @SmallTest
233 @Feature({"Webapps"}) 275 @Feature({"Webapps"})
234 @RetryOnFailure 276 @RetryOnFailure
235 public void testRegularSplashScreenAppears() throws Exception { 277 public void testRegularSplashScreenAppears() throws Exception {
236 // Register a properly-sized icon for the splash screen. 278 // Register a properly-sized icon for the splash screen.
237 Context context = getInstrumentation().getTargetContext(); 279 Context context = mActivityTestRule.getInstrumentation().getTargetContex t();
238 int thresholdSize = context.getResources().getDimensionPixelSize( 280 int thresholdSize = context.getResources().getDimensionPixelSize(
239 R.dimen.webapp_splash_image_size_threshold); 281 R.dimen.webapp_splash_image_size_threshold);
240 int size = thresholdSize + 1; 282 int size = thresholdSize + 1;
241 Bitmap splashBitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB _8888); 283 Bitmap splashBitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB _8888);
242 String bitmapString = ShortcutHelper.encodeBitmapAsString(splashBitmap); 284 String bitmapString = ShortcutHelper.encodeBitmapAsString(splashBitmap);
243 285
244 TestFetchStorageCallback callback = new TestFetchStorageCallback(); 286 TestFetchStorageCallback callback = new TestFetchStorageCallback();
245 WebappRegistry.getInstance().register(WEBAPP_ID, callback); 287 WebappRegistry.getInstance().register(WebappActivityTestRule.WEBAPP_ID, callback);
246 callback.waitForCallback(0); 288 callback.waitForCallback(0);
247 callback.getStorage().updateSplashScreenImage(bitmapString); 289 callback.getStorage().updateSplashScreenImage(bitmapString);
248 290
249 startWebappActivity(createIntent()); 291 mActivityTestRule.startWebappActivity();
250 ViewGroup splashScreen = waitUntilSplashScreenAppears(); 292 ViewGroup splashScreen = mActivityTestRule.waitUntilSplashScreenAppears( );
251 assertTrue(getActivity().isSplashScreenVisibleForTests()); 293 Assert.assertTrue(mActivityTestRule.getActivity().isSplashScreenVisibleF orTests());
252 294
253 ImageView splashImage = 295 ImageView splashImage =
254 (ImageView) splashScreen.findViewById(R.id.webapp_splash_screen_ icon); 296 (ImageView) splashScreen.findViewById(R.id.webapp_splash_screen_ icon);
255 assertEquals(size, splashImage.getMeasuredWidth()); 297 Assert.assertEquals(size, splashImage.getMeasuredWidth());
256 assertEquals(size, splashImage.getMeasuredHeight()); 298 Assert.assertEquals(size, splashImage.getMeasuredHeight());
257 299
258 TextView splashText = (TextView) splashScreen.findViewById(R.id.webapp_s plash_screen_name); 300 TextView splashText = (TextView) splashScreen.findViewById(R.id.webapp_s plash_screen_name);
259 int[] rules = ((RelativeLayout.LayoutParams) splashText.getLayoutParams( )).getRules(); 301 int[] rules = ((RelativeLayout.LayoutParams) splashText.getLayoutParams( )).getRules();
260 assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.ALIGN_PARENT_BOTT OM]); 302 Assert.assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.ALIGN_PARE NT_BOTTOM]);
261 assertEquals(0, rules[RelativeLayout.BELOW]); 303 Assert.assertEquals(0, rules[RelativeLayout.BELOW]);
262 } 304 }
263 305
306 @Test
264 @SmallTest 307 @SmallTest
265 @Feature({"Webapps"}) 308 @Feature({"Webapps"})
266 @RetryOnFailure 309 @RetryOnFailure
267 public void testSmallSplashScreenAppears() throws Exception { 310 public void testSmallSplashScreenAppears() throws Exception {
268 // Register a smaller icon for the splash screen. 311 // Register a smaller icon for the splash screen.
269 Context context = getInstrumentation().getTargetContext(); 312 Context context = mActivityTestRule.getInstrumentation().getTargetContex t();
270 int thresholdSize = context.getResources().getDimensionPixelSize( 313 int thresholdSize = context.getResources().getDimensionPixelSize(
271 R.dimen.webapp_splash_image_size_threshold); 314 R.dimen.webapp_splash_image_size_threshold);
272 int size = context.getResources().getDimensionPixelSize( 315 int size = context.getResources().getDimensionPixelSize(
273 R.dimen.webapp_splash_image_size_minimum); 316 R.dimen.webapp_splash_image_size_minimum);
274 Bitmap splashBitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB _8888); 317 Bitmap splashBitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB _8888);
275 String bitmapString = ShortcutHelper.encodeBitmapAsString(splashBitmap); 318 String bitmapString = ShortcutHelper.encodeBitmapAsString(splashBitmap);
276 319
277 TestFetchStorageCallback callback = new TestFetchStorageCallback(); 320 TestFetchStorageCallback callback = new TestFetchStorageCallback();
278 WebappRegistry.getInstance().register(WEBAPP_ID, callback); 321 WebappRegistry.getInstance().register(WebappActivityTestRule.WEBAPP_ID, callback);
279 callback.waitForCallback(0); 322 callback.waitForCallback(0);
280 callback.getStorage().updateSplashScreenImage(bitmapString); 323 callback.getStorage().updateSplashScreenImage(bitmapString);
281 324
282 startWebappActivity(createIntent()); 325 mActivityTestRule.startWebappActivity();
283 ViewGroup splashScreen = waitUntilSplashScreenAppears(); 326 ViewGroup splashScreen = mActivityTestRule.waitUntilSplashScreenAppears( );
284 assertTrue(getActivity().isSplashScreenVisibleForTests()); 327 Assert.assertTrue(mActivityTestRule.getActivity().isSplashScreenVisibleF orTests());
285 328
286 // The icon is centered within a fixed-size area on the splash screen. 329 // The icon is centered within a fixed-size area on the splash screen.
287 ImageView splashImage = 330 ImageView splashImage =
288 (ImageView) splashScreen.findViewById(R.id.webapp_splash_screen_ icon); 331 (ImageView) splashScreen.findViewById(R.id.webapp_splash_screen_ icon);
289 assertEquals(thresholdSize, splashImage.getMeasuredWidth()); 332 Assert.assertEquals(thresholdSize, splashImage.getMeasuredWidth());
290 assertEquals(thresholdSize, splashImage.getMeasuredHeight()); 333 Assert.assertEquals(thresholdSize, splashImage.getMeasuredHeight());
291 334
292 // The web app name is anchored to the icon. 335 // The web app name is anchored to the icon.
293 TextView splashText = (TextView) splashScreen.findViewById(R.id.webapp_s plash_screen_name); 336 TextView splashText = (TextView) splashScreen.findViewById(R.id.webapp_s plash_screen_name);
294 int[] rules = ((RelativeLayout.LayoutParams) splashText.getLayoutParams( )).getRules(); 337 int[] rules = ((RelativeLayout.LayoutParams) splashText.getLayoutParams( )).getRules();
295 assertEquals(0, rules[RelativeLayout.ALIGN_PARENT_BOTTOM]); 338 Assert.assertEquals(0, rules[RelativeLayout.ALIGN_PARENT_BOTTOM]);
296 assertEquals(R.id.webapp_splash_screen_icon, rules[RelativeLayout.BELOW] ); 339 Assert.assertEquals(R.id.webapp_splash_screen_icon, rules[RelativeLayout .BELOW]);
297 } 340 }
298 341
342 @Test
299 @SmallTest 343 @SmallTest
300 @Feature({"Webapps"}) 344 @Feature({"Webapps"})
301 @RetryOnFailure 345 @RetryOnFailure
302 public void testSplashScreenWithoutImageAppears() throws Exception { 346 public void testSplashScreenWithoutImageAppears() throws Exception {
303 // Register an image that's too small for the splash screen. 347 // Register an image that's too small for the splash screen.
304 Context context = getInstrumentation().getTargetContext(); 348 Context context = mActivityTestRule.getInstrumentation().getTargetContex t();
305 int size = context.getResources().getDimensionPixelSize( 349 int size = context.getResources().getDimensionPixelSize(
306 R.dimen.webapp_splash_image_size_minimum) - 1; 350 R.dimen.webapp_splash_image_size_minimum) - 1;
307 Bitmap splashBitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB _8888); 351 Bitmap splashBitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB _8888);
308 String bitmapString = ShortcutHelper.encodeBitmapAsString(splashBitmap); 352 String bitmapString = ShortcutHelper.encodeBitmapAsString(splashBitmap);
309 353
310 TestFetchStorageCallback callback = new TestFetchStorageCallback(); 354 TestFetchStorageCallback callback = new TestFetchStorageCallback();
311 WebappRegistry.getInstance().register(WEBAPP_ID, callback); 355 WebappRegistry.getInstance().register(WebappActivityTestRule.WEBAPP_ID, callback);
312 callback.waitForCallback(0); 356 callback.waitForCallback(0);
313 callback.getStorage().updateSplashScreenImage(bitmapString); 357 callback.getStorage().updateSplashScreenImage(bitmapString);
314 358
315 Intent intent = createIntent(); 359 mActivityTestRule.startWebappActivity(mActivityTestRule.createIntent().p utExtra(
316 intent.putExtra(ShortcutHelper.EXTRA_IS_ICON_GENERATED, true); 360 ShortcutHelper.EXTRA_IS_ICON_GENERATED, true));
317 startWebappActivity(intent); 361 ViewGroup splashScreen = mActivityTestRule.waitUntilSplashScreenAppears( );
318 ViewGroup splashScreen = waitUntilSplashScreenAppears(); 362 Assert.assertTrue(mActivityTestRule.getActivity().isSplashScreenVisibleF orTests());
319 assertTrue(getActivity().isSplashScreenVisibleForTests());
320 363
321 // There's no icon displayed. 364 // There's no icon displayed.
322 ImageView splashImage = 365 ImageView splashImage =
323 (ImageView) splashScreen.findViewById(R.id.webapp_splash_screen_ icon); 366 (ImageView) splashScreen.findViewById(R.id.webapp_splash_screen_ icon);
324 assertNull(splashImage); 367 Assert.assertNull(splashImage);
325 368
326 View spacer = splashScreen.findViewById(R.id.webapp_splash_space); 369 View spacer = splashScreen.findViewById(R.id.webapp_splash_space);
327 assertNotNull(spacer); 370 Assert.assertNotNull(spacer);
328 371
329 // The web app name is anchored to the top of the spacer. 372 // The web app name is anchored to the top of the spacer.
330 TextView splashText = (TextView) splashScreen.findViewById(R.id.webapp_s plash_screen_name); 373 TextView splashText = (TextView) splashScreen.findViewById(R.id.webapp_s plash_screen_name);
331 int[] rules = ((RelativeLayout.LayoutParams) splashText.getLayoutParams( )).getRules(); 374 int[] rules = ((RelativeLayout.LayoutParams) splashText.getLayoutParams( )).getRules();
332 assertEquals(0, rules[RelativeLayout.ALIGN_PARENT_BOTTOM]); 375 Assert.assertEquals(0, rules[RelativeLayout.ALIGN_PARENT_BOTTOM]);
333 assertEquals(0, rules[RelativeLayout.BELOW]); 376 Assert.assertEquals(0, rules[RelativeLayout.BELOW]);
334 assertEquals(R.id.webapp_splash_space, rules[RelativeLayout.ABOVE]); 377 Assert.assertEquals(R.id.webapp_splash_space, rules[RelativeLayout.ABOVE ]);
335 } 378 }
336 379
380 @Test
337 @SmallTest 381 @SmallTest
338 @Feature({"Webapps"}) 382 @Feature({"Webapps"})
339 @RetryOnFailure 383 @RetryOnFailure
340 public void testSplashScreenAppearsWithoutRegisteredSplashImage() throws Exc eption { 384 public void testSplashScreenAppearsWithoutRegisteredSplashImage() throws Exc eption {
341 // Don't register anything for the web app, which represents apps that w ere added to the 385 // Don't register anything for the web app, which represents apps that w ere added to the
342 // home screen before splash screen images were downloaded. 386 // home screen before splash screen images were downloaded.
343 startWebappActivity(createIntent()); 387 mActivityTestRule.startWebappActivity();
344 ViewGroup splashScreen = waitUntilSplashScreenAppears(); 388 ViewGroup splashScreen = mActivityTestRule.waitUntilSplashScreenAppears( );
345 assertTrue(getActivity().isSplashScreenVisibleForTests()); 389 Assert.assertTrue(mActivityTestRule.getActivity().isSplashScreenVisibleF orTests());
346 390
347 // There's no icon displayed. 391 // There's no icon displayed.
348 ImageView splashImage = 392 ImageView splashImage =
349 (ImageView) splashScreen.findViewById(R.id.webapp_splash_screen_ icon); 393 (ImageView) splashScreen.findViewById(R.id.webapp_splash_screen_ icon);
350 assertNull(splashImage); 394 Assert.assertNull(splashImage);
351 395
352 View spacer = splashScreen.findViewById(R.id.webapp_splash_space); 396 View spacer = splashScreen.findViewById(R.id.webapp_splash_space);
353 assertNotNull(spacer); 397 Assert.assertNotNull(spacer);
354 398
355 // The web app name is anchored to the top of the spacer. 399 // The web app name is anchored to the top of the spacer.
356 TextView splashText = (TextView) splashScreen.findViewById(R.id.webapp_s plash_screen_name); 400 TextView splashText = (TextView) splashScreen.findViewById(R.id.webapp_s plash_screen_name);
357 int[] rules = ((RelativeLayout.LayoutParams) splashText.getLayoutParams( )).getRules(); 401 int[] rules = ((RelativeLayout.LayoutParams) splashText.getLayoutParams( )).getRules();
358 assertEquals(0, rules[RelativeLayout.ALIGN_PARENT_BOTTOM]); 402 Assert.assertEquals(0, rules[RelativeLayout.ALIGN_PARENT_BOTTOM]);
359 assertEquals(0, rules[RelativeLayout.BELOW]); 403 Assert.assertEquals(0, rules[RelativeLayout.BELOW]);
360 assertEquals(0, rules[RelativeLayout.CENTER_IN_PARENT]); 404 Assert.assertEquals(0, rules[RelativeLayout.CENTER_IN_PARENT]);
361 assertEquals(R.id.webapp_splash_space, rules[RelativeLayout.ABOVE]); 405 Assert.assertEquals(R.id.webapp_splash_space, rules[RelativeLayout.ABOVE ]);
362 } 406 }
363 } 407 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698