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 an icon registered in WebappRegistry. | 31 * Tests for splash screens with an icon registered in WebappRegistry. |
23 */ | 32 */ |
| 33 @RunWith(ChromeJUnit4ClassRunner.class) |
| 34 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, |
| 35 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) |
24 @RetryOnFailure | 36 @RetryOnFailure |
25 public class WebappSplashScreenIconTest extends WebappActivityTestBase { | 37 public class WebappSplashScreenIconTest { |
| 38 @Rule |
| 39 public final WebappActivityTestRule mActivityTestRule = new WebappActivityTe
stRule(); |
26 | 40 |
27 @Override | 41 @Before |
28 protected Intent createIntent() { | 42 public void setUp() throws Exception { |
29 Intent intent = super.createIntent(); | 43 WebappRegistry.getInstance() |
30 intent.putExtra(ShortcutHelper.EXTRA_ICON, TEST_ICON); | 44 .getWebappDataStorage(WebappActivityTestRule.WEBAPP_ID) |
31 return intent; | 45 .updateSplashScreenImage(WebappActivityTestRule.TEST_SPLASH_ICON
); |
| 46 mActivityTestRule.startWebappActivity(mActivityTestRule.createIntent().p
utExtra( |
| 47 ShortcutHelper.EXTRA_ICON, WebappActivityTestRule.TEST_ICON)); |
32 } | 48 } |
33 | 49 |
34 @Override | 50 @Test |
35 protected void setUp() throws Exception { | |
36 super.setUp(); | |
37 WebappRegistry.getInstance().getWebappDataStorage(WEBAPP_ID).updateSplas
hScreenImage( | |
38 TEST_SPLASH_ICON); | |
39 startWebappActivity(); | |
40 } | |
41 | |
42 @SmallTest | 51 @SmallTest |
43 @Feature({"Webapps"}) | 52 @Feature({"Webapps"}) |
44 public void testShowSplashIcon() { | 53 public void testShowSplashIcon() { |
45 ViewGroup splashScreen = waitUntilSplashScreenAppears(); | 54 ViewGroup splashScreen = mActivityTestRule.waitUntilSplashScreenAppears(
); |
46 ImageView splashImage = (ImageView) splashScreen.findViewById( | 55 ImageView splashImage = (ImageView) splashScreen.findViewById( |
47 R.id.webapp_splash_screen_icon); | 56 R.id.webapp_splash_screen_icon); |
48 BitmapDrawable drawable = (BitmapDrawable) splashImage.getDrawable(); | 57 BitmapDrawable drawable = (BitmapDrawable) splashImage.getDrawable(); |
49 | 58 |
50 assertEquals(512, drawable.getBitmap().getWidth()); | 59 Assert.assertEquals(512, drawable.getBitmap().getWidth()); |
51 assertEquals(512, drawable.getBitmap().getHeight()); | 60 Assert.assertEquals(512, drawable.getBitmap().getHeight()); |
52 } | 61 } |
53 | 62 |
| 63 @Test |
54 @SmallTest | 64 @SmallTest |
55 @Feature({"Webapps"}) | 65 @Feature({"Webapps"}) |
56 public void testUmaCustomIcon() { | 66 public void testUmaCustomIcon() { |
57 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 67 Assert.assertEquals(1, |
58 WebappUma.HISTOGRAM_SPLASHSCREEN_ICON_TYPE, | 68 RecordHistogram.getHistogramValueCountForTesting( |
59 WebappUma.SPLASHSCREEN_ICON_TYPE_CUSTOM)); | 69 WebappUma.HISTOGRAM_SPLASHSCREEN_ICON_TYPE, |
| 70 WebappUma.SPLASHSCREEN_ICON_TYPE_CUSTOM)); |
60 | 71 |
61 Bitmap icon = ShortcutHelper.decodeBitmapFromString(TEST_SPLASH_ICON); | 72 Bitmap icon = |
| 73 ShortcutHelper.decodeBitmapFromString(WebappActivityTestRule.TES
T_SPLASH_ICON); |
62 int sizeInDp = Math.round((float) icon.getWidth() | 74 int sizeInDp = Math.round((float) icon.getWidth() |
63 / getActivity().getResources().getDisplayMetrics().density); | 75 / mActivityTestRule.getActivity().getResources().getDisplayMetri
cs().density); |
64 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 76 Assert.assertEquals(1, |
65 WebappUma.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, sizeInDp)); | 77 RecordHistogram.getHistogramValueCountForTesting( |
| 78 WebappUma.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, sizeInDp)); |
66 } | 79 } |
67 } | 80 } |
OLD | NEW |