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.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
8 import android.content.Intent; | |
9 import android.graphics.Color; | 8 import android.graphics.Color; |
10 import android.os.Build; | 9 import android.os.Build; |
11 import android.support.test.filters.SmallTest; | 10 import android.support.test.filters.SmallTest; |
12 | 11 |
| 12 import org.junit.Assert; |
| 13 import org.junit.Before; |
| 14 import org.junit.Rule; |
| 15 import org.junit.Test; |
| 16 import org.junit.runner.RunWith; |
| 17 |
13 import org.chromium.base.ThreadUtils; | 18 import org.chromium.base.ThreadUtils; |
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; |
| 23 import org.chromium.chrome.browser.ChromeSwitches; |
17 import org.chromium.chrome.browser.ShortcutHelper; | 24 import org.chromium.chrome.browser.ShortcutHelper; |
18 import org.chromium.chrome.browser.metrics.WebappUma; | 25 import org.chromium.chrome.browser.metrics.WebappUma; |
19 import org.chromium.chrome.browser.tab.TabTestUtils; | 26 import org.chromium.chrome.browser.tab.TabTestUtils; |
20 import org.chromium.chrome.browser.util.ColorUtils; | 27 import org.chromium.chrome.browser.util.ColorUtils; |
| 28 import org.chromium.chrome.test.ChromeActivityTestRule; |
| 29 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
21 import org.chromium.content.browser.test.util.Criteria; | 30 import org.chromium.content.browser.test.util.Criteria; |
22 import org.chromium.content.browser.test.util.CriteriaHelper; | 31 import org.chromium.content.browser.test.util.CriteriaHelper; |
23 | 32 |
24 import java.util.concurrent.Callable; | 33 import java.util.concurrent.Callable; |
25 | 34 |
26 /** | 35 /** |
27 * Tests for splash screens with EXTRA_THEME_COLOR specified in the Intent. | 36 * Tests for splash screens with EXTRA_THEME_COLOR specified in the Intent. |
28 */ | 37 */ |
29 public class WebappSplashScreenThemeColorTest extends WebappActivityTestBase { | 38 @RunWith(ChromeJUnit4ClassRunner.class) |
30 @Override | 39 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, |
31 protected void setUp() throws Exception { | 40 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) |
32 super.setUp(); | 41 public class WebappSplashScreenThemeColorTest { |
33 startWebappActivity(); | 42 @Rule |
| 43 public final WebappActivityTestRule mActivityTestRule = new WebappActivityTe
stRule(); |
| 44 |
| 45 @Before |
| 46 public void setUp() throws Exception { |
| 47 mActivityTestRule.startWebappActivity( |
| 48 mActivityTestRule.createIntent() |
| 49 .putExtra(ShortcutHelper.EXTRA_URL, "http://localhost") |
| 50 // This is setting Color.Magenta with 50% opacity. |
| 51 .putExtra(ShortcutHelper.EXTRA_THEME_COLOR, 0x80FF00FFL)
); |
34 } | 52 } |
35 | 53 |
36 @Override | 54 @Test |
37 protected Intent createIntent() { | |
38 Intent intent = super.createIntent(); | |
39 intent.putExtra(ShortcutHelper.EXTRA_URL, "http://localhost"); | |
40 // This is setting Color.Magenta with 50% opacity. | |
41 intent.putExtra(ShortcutHelper.EXTRA_THEME_COLOR, 0x80FF00FFL); | |
42 return intent; | |
43 } | |
44 | |
45 @SmallTest | 55 @SmallTest |
46 @Feature({"Webapps"}) | 56 @Feature({"Webapps"}) |
47 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 57 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
48 public void testThemeColorWhenSpecified() { | 58 public void testThemeColorWhenSpecified() { |
49 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return; | 59 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return; |
50 | 60 |
51 assertEquals(ColorUtils.getDarkenedColorForStatusBar(Color.MAGENTA), | 61 Assert.assertEquals(ColorUtils.getDarkenedColorForStatusBar(Color.MAGENT
A), |
52 getActivity().getWindow().getStatusBarColor()); | 62 mActivityTestRule.getActivity().getWindow().getStatusBarColor())
; |
53 } | 63 } |
54 | 64 |
| 65 @Test |
55 @SmallTest | 66 @SmallTest |
56 @Feature({"Webapps"}) | 67 @Feature({"Webapps"}) |
57 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 68 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
58 @RetryOnFailure | 69 @RetryOnFailure |
59 public void testThemeColorNotUsedIfPagesHasOne() { | 70 public void testThemeColorNotUsedIfPagesHasOne() { |
60 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return; | 71 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return; |
61 | 72 |
62 ThreadUtils.runOnUiThread(new Runnable() { | 73 ThreadUtils.runOnUiThread(new Runnable() { |
63 @Override | 74 @Override |
64 public void run() { | 75 public void run() { |
65 TabTestUtils.simulateChangeThemeColor(getActivity().getActivityT
ab(), Color.GREEN); | 76 TabTestUtils.simulateChangeThemeColor( |
| 77 mActivityTestRule.getActivity().getActivityTab(), Color.
GREEN); |
66 } | 78 } |
67 }); | 79 }); |
68 | 80 |
69 // Waits for theme-color to change so the test doesn't rely on system ti
ming. | 81 // Waits for theme-color to change so the test doesn't rely on system ti
ming. |
70 CriteriaHelper.pollInstrumentationThread(Criteria.equals( | 82 CriteriaHelper.pollInstrumentationThread(Criteria.equals( |
71 ColorUtils.getDarkenedColorForStatusBar(Color.GREEN), new Callab
le<Integer>() { | 83 ColorUtils.getDarkenedColorForStatusBar(Color.GREEN), new Callab
le<Integer>() { |
72 @Override | 84 @Override |
73 public Integer call() { | 85 public Integer call() { |
74 return getActivity().getWindow().getStatusBarColor(); | 86 return mActivityTestRule.getActivity().getWindow().getSt
atusBarColor(); |
75 } | 87 } |
76 })); | 88 })); |
77 } | 89 } |
78 | 90 |
| 91 @Test |
79 @SmallTest | 92 @SmallTest |
80 @Feature({"Webapps"}) | 93 @Feature({"Webapps"}) |
81 public void testUmaThemeColorCustom() { | 94 public void testUmaThemeColorCustom() { |
82 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 95 Assert.assertEquals(1, |
83 WebappUma.HISTOGRAM_SPLASHSCREEN_THEMECOLOR, | 96 RecordHistogram.getHistogramValueCountForTesting( |
84 WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM)); | 97 WebappUma.HISTOGRAM_SPLASHSCREEN_THEMECOLOR, |
| 98 WebappUma.SPLASHSCREEN_COLOR_STATUS_CUSTOM)); |
85 } | 99 } |
86 } | 100 } |
OLD | NEW |