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

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

Issue 2351113005: [Reland] Refactor WebappRegistry into a singleton instance. (Closed)
Patch Set: Checkstyle import order has changed overnight argh Created 4 years, 2 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; 9 import android.content.Intent;
10 import android.graphics.Bitmap; 10 import android.graphics.Bitmap;
(...skipping 10 matching lines...) Expand all
21 import org.chromium.base.ApiCompatibilityUtils; 21 import org.chromium.base.ApiCompatibilityUtils;
22 import org.chromium.base.ThreadUtils; 22 import org.chromium.base.ThreadUtils;
23 import org.chromium.base.metrics.RecordHistogram; 23 import org.chromium.base.metrics.RecordHistogram;
24 import org.chromium.base.test.util.Feature; 24 import org.chromium.base.test.util.Feature;
25 import org.chromium.base.test.util.RetryOnFailure; 25 import org.chromium.base.test.util.RetryOnFailure;
26 import org.chromium.chrome.R; 26 import org.chromium.chrome.R;
27 import org.chromium.chrome.browser.ShortcutHelper; 27 import org.chromium.chrome.browser.ShortcutHelper;
28 import org.chromium.chrome.browser.metrics.WebappUma; 28 import org.chromium.chrome.browser.metrics.WebappUma;
29 import org.chromium.chrome.browser.tab.Tab; 29 import org.chromium.chrome.browser.tab.Tab;
30 import org.chromium.chrome.browser.tab.TabTestUtils; 30 import org.chromium.chrome.browser.tab.TabTestUtils;
31 import org.chromium.content.browser.test.util.Criteria;
32 import org.chromium.content.browser.test.util.CriteriaHelper;
31 33
32 /** 34 /**
33 * Tests for splash screens. 35 * Tests for splash screens.
34 */ 36 */
35 public class WebappSplashScreenTest extends WebappActivityTestBase { 37 public class WebappSplashScreenTest extends WebappActivityTestBase {
38
39 private boolean mCallbackCalled;
40
41 private class CallbackCriteria extends Criteria {
42 public CallbackCriteria() {
43 mCallbackCalled = false;
44 }
45
46 @Override
47 public boolean isSatisfied() {
48 if (mCallbackCalled) {
49 mCallbackCalled = false;
50 return true;
51 }
52 return false;
53 }
54 }
55
36 private int getHistogramTotalCountFor(String histogram, int buckets) { 56 private int getHistogramTotalCountFor(String histogram, int buckets) {
37 int count = 0; 57 int count = 0;
38 58
39 for (int i = 0; i < buckets; ++i) { 59 for (int i = 0; i < buckets; ++i) {
40 count += RecordHistogram.getHistogramValueCountForTesting(histogram, i); 60 count += RecordHistogram.getHistogramValueCountForTesting(histogram, i);
41 } 61 }
42 62
43 return count; 63 return count;
44 } 64 }
45 65
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 248 }
229 249
230 @SmallTest 250 @SmallTest
231 @Feature({"Webapps"}) 251 @Feature({"Webapps"})
232 @RetryOnFailure 252 @RetryOnFailure
233 public void testRegularSplashScreenAppears() throws Exception { 253 public void testRegularSplashScreenAppears() throws Exception {
234 // Register a properly-sized icon for the splash screen. 254 // Register a properly-sized icon for the splash screen.
235 Context context = getInstrumentation().getTargetContext(); 255 Context context = getInstrumentation().getTargetContext();
236 int thresholdSize = context.getResources().getDimensionPixelSize( 256 int thresholdSize = context.getResources().getDimensionPixelSize(
237 R.dimen.webapp_splash_image_size_threshold); 257 R.dimen.webapp_splash_image_size_threshold);
238 int bitmapSize = thresholdSize + 1; 258 int size = thresholdSize + 1;
239 Bitmap splashBitmap = Bitmap.createBitmap(bitmapSize, bitmapSize, Bitmap .Config.ARGB_8888); 259 final Bitmap splashBitmap = Bitmap.createBitmap(size, size, Bitmap.Confi g.ARGB_8888);
240 WebappDataStorage.open(WEBAPP_ID).updateSplashScreenImage(splashBitmap); 260
261 WebappRegistry.getInstance().register(
262 WEBAPP_ID, new WebappRegistry.FetchWebappDataStorageCallback() {
263 @Override
264 public void onWebappDataStorageRetrieved(WebappDataStorage s torage) {
265 mCallbackCalled = true;
266 storage.updateSplashScreenImage(splashBitmap);
267 }
268 });
269 CriteriaHelper.pollUiThread(new CallbackCriteria());
241 270
242 startWebappActivity(createIntent()); 271 startWebappActivity(createIntent());
243 ViewGroup splashScreen = waitUntilSplashScreenAppears(); 272 ViewGroup splashScreen = waitUntilSplashScreenAppears();
244 assertTrue(getActivity().isSplashScreenVisibleForTests()); 273 assertTrue(getActivity().isSplashScreenVisibleForTests());
245 274
246 ImageView splashImage = 275 ImageView splashImage =
247 (ImageView) splashScreen.findViewById(R.id.webapp_splash_screen_ icon); 276 (ImageView) splashScreen.findViewById(R.id.webapp_splash_screen_ icon);
248 assertEquals(bitmapSize, splashImage.getMeasuredWidth()); 277 assertEquals(size, splashImage.getMeasuredWidth());
249 assertEquals(bitmapSize, splashImage.getMeasuredHeight()); 278 assertEquals(size, splashImage.getMeasuredHeight());
250 279
251 TextView splashText = (TextView) splashScreen.findViewById(R.id.webapp_s plash_screen_name); 280 TextView splashText = (TextView) splashScreen.findViewById(R.id.webapp_s plash_screen_name);
252 int[] rules = ((RelativeLayout.LayoutParams) splashText.getLayoutParams( )).getRules(); 281 int[] rules = ((RelativeLayout.LayoutParams) splashText.getLayoutParams( )).getRules();
253 assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.ALIGN_PARENT_BOTT OM]); 282 assertEquals(RelativeLayout.TRUE, rules[RelativeLayout.ALIGN_PARENT_BOTT OM]);
254 assertEquals(0, rules[RelativeLayout.BELOW]); 283 assertEquals(0, rules[RelativeLayout.BELOW]);
255 } 284 }
256 285
257 @SmallTest 286 @SmallTest
258 @Feature({"Webapps"}) 287 @Feature({"Webapps"})
259 @RetryOnFailure 288 @RetryOnFailure
260 public void testSmallSplashScreenAppears() throws Exception { 289 public void testSmallSplashScreenAppears() throws Exception {
261 // Register a smaller icon for the splash screen. 290 // Register a smaller icon for the splash screen.
262 Context context = getInstrumentation().getTargetContext(); 291 Context context = getInstrumentation().getTargetContext();
263 int thresholdSize = context.getResources().getDimensionPixelSize( 292 int thresholdSize = context.getResources().getDimensionPixelSize(
264 R.dimen.webapp_splash_image_size_threshold); 293 R.dimen.webapp_splash_image_size_threshold);
265 int bitmapSize = context.getResources().getDimensionPixelSize( 294 int size = context.getResources().getDimensionPixelSize(
266 R.dimen.webapp_splash_image_size_minimum); 295 R.dimen.webapp_splash_image_size_minimum);
267 Bitmap splashBitmap = Bitmap.createBitmap(bitmapSize, bitmapSize, Bitmap .Config.ARGB_8888); 296 final Bitmap splashBitmap = Bitmap.createBitmap(size, size, Bitmap.Confi g.ARGB_8888);
268 WebappDataStorage.open(WEBAPP_ID).updateSplashScreenImage(splashBitmap); 297
298 WebappRegistry.getInstance().register(
299 WEBAPP_ID, new WebappRegistry.FetchWebappDataStorageCallback() {
300 @Override
301 public void onWebappDataStorageRetrieved(WebappDataStorage s torage) {
302 mCallbackCalled = true;
303 storage.updateSplashScreenImage(splashBitmap);
304 }
305 });
306 CriteriaHelper.pollUiThread(new CallbackCriteria());
269 307
270 startWebappActivity(createIntent()); 308 startWebappActivity(createIntent());
271 ViewGroup splashScreen = waitUntilSplashScreenAppears(); 309 ViewGroup splashScreen = waitUntilSplashScreenAppears();
272 assertTrue(getActivity().isSplashScreenVisibleForTests()); 310 assertTrue(getActivity().isSplashScreenVisibleForTests());
273 311
274 // The icon is centered within a fixed-size area on the splash screen. 312 // The icon is centered within a fixed-size area on the splash screen.
275 ImageView splashImage = 313 ImageView splashImage =
276 (ImageView) splashScreen.findViewById(R.id.webapp_splash_screen_ icon); 314 (ImageView) splashScreen.findViewById(R.id.webapp_splash_screen_ icon);
277 assertEquals(thresholdSize, splashImage.getMeasuredWidth()); 315 assertEquals(thresholdSize, splashImage.getMeasuredWidth());
278 assertEquals(thresholdSize, splashImage.getMeasuredHeight()); 316 assertEquals(thresholdSize, splashImage.getMeasuredHeight());
279 317
280 // The web app name is anchored to the icon. 318 // The web app name is anchored to the icon.
281 TextView splashText = (TextView) splashScreen.findViewById(R.id.webapp_s plash_screen_name); 319 TextView splashText = (TextView) splashScreen.findViewById(R.id.webapp_s plash_screen_name);
282 int[] rules = ((RelativeLayout.LayoutParams) splashText.getLayoutParams( )).getRules(); 320 int[] rules = ((RelativeLayout.LayoutParams) splashText.getLayoutParams( )).getRules();
283 assertEquals(0, rules[RelativeLayout.ALIGN_PARENT_BOTTOM]); 321 assertEquals(0, rules[RelativeLayout.ALIGN_PARENT_BOTTOM]);
284 assertEquals(R.id.webapp_splash_screen_icon, rules[RelativeLayout.BELOW] ); 322 assertEquals(R.id.webapp_splash_screen_icon, rules[RelativeLayout.BELOW] );
285 } 323 }
286 324
287 @SmallTest 325 @SmallTest
288 @Feature({"Webapps"}) 326 @Feature({"Webapps"})
289 public void testSplashScreenWithoutImageAppears() throws Exception { 327 public void testSplashScreenWithoutImageAppears() throws Exception {
290 // Register an image that's too small for the splash screen. 328 // Register an image that's too small for the splash screen.
291 Context context = getInstrumentation().getTargetContext(); 329 Context context = getInstrumentation().getTargetContext();
292 int bitmapSize = context.getResources().getDimensionPixelSize( 330 int size = context.getResources().getDimensionPixelSize(
293 R.dimen.webapp_splash_image_size_minimum) - 1; 331 R.dimen.webapp_splash_image_size_minimum) - 1;
294 Bitmap splashBitmap = Bitmap.createBitmap(bitmapSize, bitmapSize, Bitmap .Config.ARGB_8888); 332 final Bitmap splashBitmap = Bitmap.createBitmap(size, size, Bitmap.Confi g.ARGB_8888);
295 WebappDataStorage.open(WEBAPP_ID).updateSplashScreenImage(splashBitmap); 333
334 WebappRegistry.getInstance().register(
335 WEBAPP_ID, new WebappRegistry.FetchWebappDataStorageCallback() {
336 @Override
337 public void onWebappDataStorageRetrieved(WebappDataStorage s torage) {
338 mCallbackCalled = true;
339 storage.updateSplashScreenImage(splashBitmap);
340 }
341 });
342 CriteriaHelper.pollUiThread(new CallbackCriteria());
296 343
297 Intent intent = createIntent(); 344 Intent intent = createIntent();
298 intent.putExtra(ShortcutHelper.EXTRA_IS_ICON_GENERATED, true); 345 intent.putExtra(ShortcutHelper.EXTRA_IS_ICON_GENERATED, true);
299 startWebappActivity(intent); 346 startWebappActivity(intent);
300 ViewGroup splashScreen = waitUntilSplashScreenAppears(); 347 ViewGroup splashScreen = waitUntilSplashScreenAppears();
301 assertTrue(getActivity().isSplashScreenVisibleForTests()); 348 assertTrue(getActivity().isSplashScreenVisibleForTests());
302 349
303 // There's no icon displayed. 350 // There's no icon displayed.
304 ImageView splashImage = 351 ImageView splashImage =
305 (ImageView) splashScreen.findViewById(R.id.webapp_splash_screen_ icon); 352 (ImageView) splashScreen.findViewById(R.id.webapp_splash_screen_ icon);
(...skipping 29 matching lines...) Expand all
335 382
336 // The web app name is anchored to the top of the spacer. 383 // The web app name is anchored to the top of the spacer.
337 TextView splashText = (TextView) splashScreen.findViewById(R.id.webapp_s plash_screen_name); 384 TextView splashText = (TextView) splashScreen.findViewById(R.id.webapp_s plash_screen_name);
338 int[] rules = ((RelativeLayout.LayoutParams) splashText.getLayoutParams( )).getRules(); 385 int[] rules = ((RelativeLayout.LayoutParams) splashText.getLayoutParams( )).getRules();
339 assertEquals(0, rules[RelativeLayout.ALIGN_PARENT_BOTTOM]); 386 assertEquals(0, rules[RelativeLayout.ALIGN_PARENT_BOTTOM]);
340 assertEquals(0, rules[RelativeLayout.BELOW]); 387 assertEquals(0, rules[RelativeLayout.BELOW]);
341 assertEquals(0, rules[RelativeLayout.CENTER_IN_PARENT]); 388 assertEquals(0, rules[RelativeLayout.CENTER_IN_PARENT]);
342 assertEquals(R.id.webapp_splash_space, rules[RelativeLayout.ABOVE]); 389 assertEquals(R.id.webapp_splash_space, rules[RelativeLayout.ABOVE]);
343 } 390 }
344 } 391 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698