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