Chromium Code Reviews| 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.precache; | 5 package org.chromium.chrome.browser.precache; |
| 6 | 6 |
| 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E ND_DEVICE; | 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E ND_DEVICE; |
| 8 | 8 |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.support.test.InstrumentationRegistry; | 10 import android.support.test.InstrumentationRegistry; |
| 11 import android.support.test.filters.SmallTest; | 11 import android.support.test.filters.SmallTest; |
| 12 | 12 |
| 13 import com.google.android.gms.gcm.Task; | 13 import com.google.android.gms.gcm.Task; |
| 14 | 14 |
| 15 import org.junit.After; | 15 import org.junit.After; |
| 16 import org.junit.Assert; | 16 import org.junit.Assert; |
| 17 import org.junit.Before; | 17 import org.junit.Before; |
| 18 import org.junit.Rule; | 18 import org.junit.Rule; |
| 19 import org.junit.Test; | 19 import org.junit.Test; |
| 20 import org.junit.runner.RunWith; | 20 import org.junit.runner.RunWith; |
| 21 | 21 |
| 22 import org.chromium.base.ContextUtils; | 22 import org.chromium.base.ContextUtils; |
| 23 import org.chromium.base.ThreadUtils; | 23 import org.chromium.base.ThreadUtils; |
| 24 import org.chromium.base.test.BaseJUnit4ClassRunner; | 24 import org.chromium.base.test.BaseJUnit4ClassRunner; |
| 25 import org.chromium.base.test.util.Feature; | 25 import org.chromium.base.test.util.Feature; |
| 26 import org.chromium.base.test.util.Restriction; | 26 import org.chromium.base.test.util.Restriction; |
| 27 import org.chromium.chrome.browser.preferences.privacy.PrivacyPreferencesManager ; | 27 import org.chromium.chrome.browser.preferences.privacy.PrivacyPreferencesManager ; |
| 28 import org.chromium.chrome.browser.sync.ProfileSyncService; | 28 import org.chromium.chrome.browser.sync.ProfileSyncService; |
| 29 import org.chromium.content.browser.test.NativeLibraryTestRule; | 29 import org.chromium.chrome.browser.test.ChromeBrowserTestRule; |
| 30 | 30 |
| 31 import java.util.EnumSet; | 31 import java.util.EnumSet; |
| 32 import java.util.concurrent.Callable; | 32 import java.util.concurrent.Callable; |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * Unit tests for {@link PrecacheLauncher}. | 35 * Unit tests for {@link PrecacheLauncher}. |
| 36 * | 36 * |
| 37 * setUp/tearDown code was inspired by org.chromium.chrome.browser.sync.ui.Passp hraseActivityTest. | 37 * setUp/tearDown code was inspired by org.chromium.chrome.browser.sync.ui.Passp hraseActivityTest. |
| 38 */ | 38 */ |
| 39 @RunWith(BaseJUnit4ClassRunner.class) | 39 @RunWith(BaseJUnit4ClassRunner.class) |
| 40 public class PrecacheLauncherTest { | 40 public class PrecacheLauncherTest { |
| 41 @Rule | 41 @Rule |
| 42 public NativeLibraryTestRule mActivityTestRule = new NativeLibraryTestRule() ; | 42 public final ChromeBrowserTestRule mBrowserTestRule = new ChromeBrowserTestR ule(); |
| 43 | 43 |
| 44 private StubProfileSyncService mSync; | 44 private StubProfileSyncService mSync; |
| 45 private PrecacheLauncherUnderTest mLauncher; | 45 private PrecacheLauncherUnderTest mLauncher; |
| 46 private MockPrecacheTaskScheduler mPrecacheTaskScheduler; | 46 private MockPrecacheTaskScheduler mPrecacheTaskScheduler; |
| 47 | 47 |
| 48 private class PrecacheLauncherUnderTest extends PrecacheLauncher { | 48 private class PrecacheLauncherUnderTest extends PrecacheLauncher { |
| 49 private boolean mShouldRun = false; | 49 private boolean mShouldRun = false; |
| 50 | 50 |
| 51 @Override | 51 @Override |
| 52 protected void onPrecacheCompleted(boolean tryAgainSoon) {} | 52 protected void onPrecacheCompleted(boolean tryAgainSoon) {} |
| 53 | 53 |
| 54 @Override | 54 @Override |
| 55 boolean nativeShouldRun() { | 55 boolean nativeShouldRun() { |
| 56 return mShouldRun; | 56 return mShouldRun; |
| 57 } | 57 } |
| 58 | 58 |
| 59 /** | 59 /**R |
|
Ted C
2017/06/29 20:20:55
STUVWXYandZ!
troyhildebrandt
2017/06/29 20:43:48
Congratulations on finding the easter egg...? Done
| |
| 60 * Modify the return value of nativeShouldRun. This will notify sync sta te subscribers, as | 60 * Modify the return value of nativeShouldRun. This will notify sync sta te subscribers, as |
| 61 * if the user changed their sync preferences. | 61 * if the user changed their sync preferences. |
| 62 */ | 62 */ |
| 63 void setShouldRun(boolean shouldRun) { | 63 void setShouldRun(boolean shouldRun) { |
| 64 mShouldRun = shouldRun; | 64 mShouldRun = shouldRun; |
| 65 notifySyncChanged(); | 65 notifySyncChanged(); |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 private static class StubProfileSyncService extends ProfileSyncService { | 69 private static class StubProfileSyncService extends ProfileSyncService { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 mLauncher = new PrecacheLauncherUnderTest(); | 105 mLauncher = new PrecacheLauncherUnderTest(); |
| 106 | 106 |
| 107 mPrecacheTaskScheduler = new MockPrecacheTaskScheduler(); | 107 mPrecacheTaskScheduler = new MockPrecacheTaskScheduler(); |
| 108 PrecacheController.setTaskScheduler(mPrecacheTaskScheduler); | 108 PrecacheController.setTaskScheduler(mPrecacheTaskScheduler); |
| 109 | 109 |
| 110 // The target context persists throughout the entire test run, and so le aks state between | 110 // The target context persists throughout the entire test run, and so le aks state between |
| 111 // tests. We reset the is_precaching_enabled pref to false to make the t est run consistent, | 111 // tests. We reset the is_precaching_enabled pref to false to make the t est run consistent, |
| 112 // in case another test class has modified this pref. | 112 // in case another test class has modified this pref. |
| 113 PrecacheController.setIsPrecachingEnabled(getTargetContext(), false); | 113 PrecacheController.setIsPrecachingEnabled(getTargetContext(), false); |
| 114 | 114 |
| 115 // ProfileSyncService needs the browser process to be running. | |
| 116 mActivityTestRule.loadNativeLibraryAndInitBrowserProcess(); | |
| 117 | |
| 118 // ProfileSyncService must be initialized on the UI thread. Oddly, even though | 115 // ProfileSyncService must be initialized on the UI thread. Oddly, even though |
| 119 // ThreadUtils.runningOnUiThread() is true here, it's, no, not really, n o. | 116 // ThreadUtils.runningOnUiThread() is true here, it's, no, not really, n o. |
| 120 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 117 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 121 @Override | 118 @Override |
| 122 public void run() { | 119 public void run() { |
| 123 // The StubProfileSyncService stubs out isEngineInitialized so w e can change that | 120 // The StubProfileSyncService stubs out isEngineInitialized so w e can change that |
| 124 // on the fly. | 121 // on the fly. |
| 125 mSync = new StubProfileSyncService(); | 122 mSync = new StubProfileSyncService(); |
| 126 ProfileSyncService.overrideForTests(mSync); | 123 ProfileSyncService.overrideForTests(mSync); |
| 127 // This is currently the default, but let's verify that, lest it ever change and we | 124 // This is currently the default, but let's verify that, lest it ever change and we |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 /** Notify listeners that sync preferences have changed. This is run by setS houldRun. */ | 268 /** Notify listeners that sync preferences have changed. This is run by setS houldRun. */ |
| 272 private void notifySyncChanged() { | 269 private void notifySyncChanged() { |
| 273 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 270 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 274 @Override | 271 @Override |
| 275 public void run() { | 272 public void run() { |
| 276 mSync.syncStateChanged(); | 273 mSync.syncStateChanged(); |
| 277 } | 274 } |
| 278 }); | 275 }); |
| 279 } | 276 } |
| 280 } | 277 } |
| OLD | NEW |