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