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