| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.test; | 5 package org.chromium.chrome.browser.test; |
| 6 | 6 |
| 7 import android.app.Instrumentation; | 7 import android.app.Instrumentation; |
| 8 import android.support.test.InstrumentationRegistry; | 8 import android.support.test.InstrumentationRegistry; |
| 9 | 9 |
| 10 import org.junit.runner.Description; | 10 import org.junit.runner.Description; |
| 11 import org.junit.runners.model.Statement; | 11 import org.junit.runners.model.Statement; |
| 12 | 12 |
| 13 import org.chromium.chrome.test.util.browser.signin.SigninTestUtil; | 13 import org.chromium.chrome.test.util.browser.signin.SigninTestUtil; |
| 14 import org.chromium.content.browser.test.NativeLibraryTestRule; | 14 import org.chromium.content.browser.test.NativeLibraryTestRule; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * JUnit test rule that takes care of important initialization for Chrome-specif
ic tests, such as | 17 * JUnit test rule that takes care of important initialization for Chrome-specif
ic tests, such as |
| 18 * initializing the AccountManagerHelper. | 18 * initializing the AccountManagerHelper. |
| 19 */ | 19 */ |
| 20 public class ChromeBrowserTestRule extends NativeLibraryTestRule { | 20 public class ChromeBrowserTestRule extends NativeLibraryTestRule { |
| 21 private final boolean mInitBrowserProcess; | 21 private final boolean mInitBrowserProcess; |
| 22 | 22 |
| 23 public ChromeBrowserTestRule(boolean initBrowserProcess) { | 23 public ChromeBrowserTestRule(boolean initBrowserProcess) { |
| 24 mInitBrowserProcess = initBrowserProcess; | 24 mInitBrowserProcess = initBrowserProcess; |
| 25 } | 25 } |
| 26 | 26 |
| 27 void initialize(final boolean initBrowserProcess, Instrumentation instrument
ation) { | 27 void initialize(final boolean initBrowserProcess, Instrumentation instrument
ation) { |
| 28 SigninTestUtil.setUpAuthForTest(instrumentation); | 28 SigninTestUtil.setUpAuthForTest(); |
| 29 if (initBrowserProcess) { | 29 if (initBrowserProcess) { |
| 30 loadNativeLibraryAndInitBrowserProcess(); | 30 loadNativeLibraryAndInitBrowserProcess(); |
| 31 } else { | 31 } else { |
| 32 loadNativeLibraryNoBrowserProcess(); | 32 loadNativeLibraryNoBrowserProcess(); |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 | 35 |
| 36 @Override | 36 @Override |
| 37 public Statement apply(final Statement base, Description description) { | 37 public Statement apply(final Statement base, Description description) { |
| 38 return new Statement() { | 38 return new Statement() { |
| 39 @Override | 39 @Override |
| 40 public void evaluate() throws Throwable { | 40 public void evaluate() throws Throwable { |
| 41 /** | 41 /** |
| 42 * Loads the native library on the activity UI thread (must not
be called from the | 42 * Loads the native library on the activity UI thread (must not
be called from the |
| 43 * UI thread). After loading the library, this will initialize
the browser process | 43 * UI thread). After loading the library, this will initialize
the browser process |
| 44 * if necessary. | 44 * if necessary. |
| 45 */ | 45 */ |
| 46 initialize(mInitBrowserProcess, InstrumentationRegistry.getInstr
umentation()); | 46 initialize(mInitBrowserProcess, InstrumentationRegistry.getInstr
umentation()); |
| 47 try { | 47 try { |
| 48 base.evaluate(); | 48 base.evaluate(); |
| 49 } finally { | 49 } finally { |
| 50 tearDown(); | 50 tearDown(); |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 }; | 53 }; |
| 54 } | 54 } |
| 55 | 55 |
| 56 public void tearDown() { | 56 public void tearDown() { |
| 57 SigninTestUtil.resetSigninState(); | 57 SigninTestUtil.resetSigninState(); |
| 58 SigninTestUtil.tearDownAuthForTest(); | |
| 59 } | 58 } |
| 60 } | 59 } |
| OLD | NEW |