| 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.content.Intent; | |
| 8 import android.graphics.Bitmap; | 7 import android.graphics.Bitmap; |
| 9 import android.graphics.drawable.BitmapDrawable; | 8 import android.graphics.drawable.BitmapDrawable; |
| 10 import android.support.test.filters.SmallTest; | 9 import android.support.test.filters.SmallTest; |
| 11 import android.view.ViewGroup; | 10 import android.view.ViewGroup; |
| 12 import android.widget.ImageView; | 11 import android.widget.ImageView; |
| 13 | 12 |
| 13 import org.junit.Assert; |
| 14 import org.junit.Before; |
| 15 import org.junit.Rule; |
| 16 import org.junit.Test; |
| 17 import org.junit.runner.RunWith; |
| 18 |
| 14 import org.chromium.base.metrics.RecordHistogram; | 19 import org.chromium.base.metrics.RecordHistogram; |
| 20 import org.chromium.base.test.util.CommandLineFlags; |
| 15 import org.chromium.base.test.util.Feature; | 21 import org.chromium.base.test.util.Feature; |
| 16 import org.chromium.base.test.util.RetryOnFailure; | 22 import org.chromium.base.test.util.RetryOnFailure; |
| 17 import org.chromium.chrome.R; | 23 import org.chromium.chrome.R; |
| 24 import org.chromium.chrome.browser.ChromeSwitches; |
| 18 import org.chromium.chrome.browser.ShortcutHelper; | 25 import org.chromium.chrome.browser.ShortcutHelper; |
| 19 import org.chromium.chrome.browser.metrics.WebappUma; | 26 import org.chromium.chrome.browser.metrics.WebappUma; |
| 27 import org.chromium.chrome.test.ChromeActivityTestRule; |
| 28 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
| 20 | 29 |
| 21 /** | 30 /** |
| 22 * Tests for splash screens with EXTRA_ICON specified in the Intent. | 31 * Tests for splash screens with EXTRA_ICON specified in the Intent. |
| 23 */ | 32 */ |
| 24 public class WebappSplashScreenHomescreenIconTest extends WebappActivityTestBase
{ | 33 @RunWith(ChromeJUnit4ClassRunner.class) |
| 25 @Override | 34 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, |
| 26 protected void setUp() throws Exception { | 35 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) |
| 27 super.setUp(); | 36 public class WebappSplashScreenHomescreenIconTest { |
| 28 startWebappActivity(); | 37 @Rule |
| 38 public final WebappActivityTestRule mActivityTestRule = new WebappActivityTe
stRule(); |
| 39 |
| 40 @Before |
| 41 public void setUp() throws Exception { |
| 42 mActivityTestRule.startWebappActivity(mActivityTestRule.createIntent().p
utExtra( |
| 43 ShortcutHelper.EXTRA_ICON, WebappActivityTestRule.TEST_ICON)); |
| 29 } | 44 } |
| 30 | 45 |
| 31 @Override | 46 @Test |
| 32 protected Intent createIntent() { | |
| 33 Intent intent = super.createIntent(); | |
| 34 intent.putExtra(ShortcutHelper.EXTRA_ICON, TEST_ICON); | |
| 35 return intent; | |
| 36 } | |
| 37 | |
| 38 @SmallTest | 47 @SmallTest |
| 39 @Feature({"Webapps"}) | 48 @Feature({"Webapps"}) |
| 40 public void testShowFallbackIcon() { | 49 public void testShowFallbackIcon() { |
| 41 ViewGroup splashScreen = waitUntilSplashScreenAppears(); | 50 ViewGroup splashScreen = mActivityTestRule.waitUntilSplashScreenAppears(
); |
| 42 ImageView splashImage = (ImageView) splashScreen.findViewById( | 51 ImageView splashImage = (ImageView) splashScreen.findViewById( |
| 43 R.id.webapp_splash_screen_icon); | 52 R.id.webapp_splash_screen_icon); |
| 44 BitmapDrawable drawable = (BitmapDrawable) splashImage.getDrawable(); | 53 BitmapDrawable drawable = (BitmapDrawable) splashImage.getDrawable(); |
| 45 | 54 |
| 46 assertEquals(192, drawable.getBitmap().getWidth()); | 55 Assert.assertEquals(192, drawable.getBitmap().getWidth()); |
| 47 assertEquals(192, drawable.getBitmap().getHeight()); | 56 Assert.assertEquals(192, drawable.getBitmap().getHeight()); |
| 48 } | 57 } |
| 49 | 58 |
| 59 @Test |
| 50 @SmallTest | 60 @SmallTest |
| 51 @Feature({"Webapps"}) | 61 @Feature({"Webapps"}) |
| 52 @RetryOnFailure | 62 @RetryOnFailure |
| 53 public void testUmaFallbackIcon() { | 63 public void testUmaFallbackIcon() { |
| 54 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 64 Assert.assertEquals(1, |
| 55 WebappUma.HISTOGRAM_SPLASHSCREEN_ICON_TYPE, | 65 RecordHistogram.getHistogramValueCountForTesting( |
| 56 WebappUma.SPLASHSCREEN_ICON_TYPE_FALLBACK)); | 66 WebappUma.HISTOGRAM_SPLASHSCREEN_ICON_TYPE, |
| 67 WebappUma.SPLASHSCREEN_ICON_TYPE_FALLBACK)); |
| 57 | 68 |
| 58 Bitmap icon = ShortcutHelper.decodeBitmapFromString(TEST_ICON); | 69 Bitmap icon = ShortcutHelper.decodeBitmapFromString(WebappActivityTestRu
le.TEST_ICON); |
| 59 int sizeInDp = Math.round((float) icon.getWidth() | 70 int sizeInDp = Math.round((float) icon.getWidth() |
| 60 / getActivity().getResources().getDisplayMetrics().density); | 71 / mActivityTestRule.getActivity().getResources().getDisplayMetri
cs().density); |
| 61 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 72 Assert.assertEquals(1, |
| 62 WebappUma.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, sizeInDp)); | 73 RecordHistogram.getHistogramValueCountForTesting( |
| 74 WebappUma.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, sizeInDp)); |
| 63 } | 75 } |
| 64 } | 76 } |
| OLD | NEW |