| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.precache; | 5 package org.chromium.chrome.browser.precache; |
| 6 | 6 |
| 7 import android.support.test.InstrumentationRegistry; |
| 7 import android.support.test.filters.SmallTest; | 8 import android.support.test.filters.SmallTest; |
| 8 | 9 |
| 10 import org.junit.After; |
| 9 import org.junit.Assert; | 11 import org.junit.Assert; |
| 12 import org.junit.Before; |
| 10 import org.junit.Rule; | 13 import org.junit.Rule; |
| 11 import org.junit.Test; | 14 import org.junit.Test; |
| 12 import org.junit.runner.RunWith; | 15 import org.junit.runner.RunWith; |
| 13 | 16 |
| 14 import org.chromium.base.ContextUtils; | 17 import org.chromium.base.ContextUtils; |
| 15 import org.chromium.base.library_loader.LibraryLoader; | 18 import org.chromium.base.library_loader.LibraryLoader; |
| 16 import org.chromium.base.test.BaseJUnit4ClassRunner; | 19 import org.chromium.base.test.BaseJUnit4ClassRunner; |
| 17 import org.chromium.base.test.util.Feature; | 20 import org.chromium.base.test.util.Feature; |
| 18 import org.chromium.base.test.util.MetricsUtils.HistogramDelta; | 21 import org.chromium.base.test.util.MetricsUtils.HistogramDelta; |
| 19 import org.chromium.base.test.util.RetryOnFailure; | 22 import org.chromium.base.test.util.RetryOnFailure; |
| 23 import org.chromium.chrome.test.util.browser.signin.SigninTestUtil; |
| 20 import org.chromium.content.browser.test.NativeLibraryTestRule; | 24 import org.chromium.content.browser.test.NativeLibraryTestRule; |
| 21 | 25 |
| 22 import java.util.ArrayList; | 26 import java.util.ArrayList; |
| 23 import java.util.Arrays; | 27 import java.util.Arrays; |
| 24 import java.util.List; | 28 import java.util.List; |
| 25 | 29 |
| 26 /** | 30 /** |
| 27 * Tests of {@link PrecacheUMA}. | 31 * Tests of {@link PrecacheUMA}. |
| 28 */ | 32 */ |
| 29 @RunWith(BaseJUnit4ClassRunner.class) | 33 @RunWith(BaseJUnit4ClassRunner.class) |
| 30 public class PrecacheUMATest { | 34 public class PrecacheUMATest { |
| 31 @Rule | 35 @Rule |
| 32 public NativeLibraryTestRule mActivityTestRule = new NativeLibraryTestRule()
; | 36 public NativeLibraryTestRule mActivityTestRule = new NativeLibraryTestRule()
; |
| 33 | 37 |
| 38 @Before |
| 39 public void setUp() { |
| 40 // TODO (thildebr): This is just copied from the ChromeBrowserTestRule b
ecause we need to |
| 41 // be selective of when we load the native library, so we can't just use
the rule. |
| 42 SigninTestUtil.setUpAuthForTest(InstrumentationRegistry.getInstrumentati
on()); |
| 43 } |
| 44 |
| 45 @After |
| 46 public void tearDown() { |
| 47 // TODO (thildebr): Also copied from ChromeBrowserTestRule until there's
a better way. |
| 48 SigninTestUtil.resetSigninState(); |
| 49 SigninTestUtil.tearDownAuthForTest(); |
| 50 } |
| 51 |
| 34 @Test | 52 @Test |
| 35 @SmallTest | 53 @SmallTest |
| 36 @Feature({"Precache"}) | 54 @Feature({"Precache"}) |
| 37 public void testUMAEventBitPositionAndMask() { | 55 public void testUMAEventBitPositionAndMask() { |
| 38 // Test the bitmask and bit position of all UMA Events. | 56 // Test the bitmask and bit position of all UMA Events. |
| 39 for (int event = PrecacheUMA.Event.EVENT_START; event < PrecacheUMA.Even
t.EVENT_END; | 57 for (int event = PrecacheUMA.Event.EVENT_START; event < PrecacheUMA.Even
t.EVENT_END; |
| 40 ++event) { | 58 ++event) { |
| 41 long bitmask = PrecacheUMA.Event.getBitMask(event); | 59 long bitmask = PrecacheUMA.Event.getBitMask(event); |
| 42 Assert.assertTrue(bitmask > 0); | 60 Assert.assertTrue(bitmask > 0); |
| 43 Assert.assertEquals(bitmask, 1L << PrecacheUMA.Event.getBitPosition(
event)); | 61 Assert.assertEquals(bitmask, 1L << PrecacheUMA.Event.getBitPosition(
event)); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 if (events.contains(event)) { | 162 if (events.contains(event)) { |
| 145 Assert.assertEquals( | 163 Assert.assertEquals( |
| 146 1, histograms[PrecacheUMA.Event.getBitPosition(event)].g
etDelta()); | 164 1, histograms[PrecacheUMA.Event.getBitPosition(event)].g
etDelta()); |
| 147 } else { | 165 } else { |
| 148 Assert.assertEquals( | 166 Assert.assertEquals( |
| 149 0, histograms[PrecacheUMA.Event.getBitPosition(event)].g
etDelta()); | 167 0, histograms[PrecacheUMA.Event.getBitPosition(event)].g
etDelta()); |
| 150 } | 168 } |
| 151 } | 169 } |
| 152 } | 170 } |
| 153 } | 171 } |
| OLD | NEW |