Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: content/public/test/android/javatests/src/org/chromium/content/browser/test/NativeLibraryTestRule.java

Issue 2778103002: Alternative: Convert Chrome NativeLibraryTestBase tests example (Closed)
Patch Set: change BUILD.gn Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/IntentHandlerTest.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.content.browser.test; 5 package org.chromium.content.browser.test;
6 6
7 import android.support.test.InstrumentationRegistry; 7 import android.support.test.InstrumentationRegistry;
8 8
9 import org.junit.Assert;
9 import org.junit.rules.TestRule; 10 import org.junit.rules.TestRule;
10 import org.junit.runner.Description; 11 import org.junit.runner.Description;
11 import org.junit.runners.model.Statement; 12 import org.junit.runners.model.Statement;
12 13
14 import org.chromium.base.test.SetUpTestRule;
15
13 /** 16 /**
14 * TestRule that adds support for loading and dealing with native libraries. 17 * TestRule that adds support for loading and dealing with native libraries.
15 * 18 *
16 * NativeLibraryTestRule does not interact with any Activity. 19 * NativeLibraryTestRule does not interact with any Activity.
17 */ 20 */
18 public class NativeLibraryTestRule implements TestRule { 21 public class NativeLibraryTestRule implements TestRule, SetUpTestRule<NativeLibr aryTestRule> {
19 private final NativeLibraryTestCommon mTestCommon = new NativeLibraryTestCom mon(); 22 private final NativeLibraryTestCommon mTestCommon = new NativeLibraryTestCom mon();
23 private NativeLibraryInitializationOption mInitOption;
24 private boolean mShouldSetUp = false;
25
26 public enum NativeLibraryInitializationOption { INIT_BROWSER_PROCESS, NO_BRO WSER_PROCESS }
20 27
21 /** 28 /**
22 * Loads the native library on the activity UI thread (must not be called fr om the UI thread). 29 * Loads the native library on the activity UI thread (must not be called fr om the UI thread).
23 */ 30 */
24 public void loadNativeLibraryNoBrowserProcess() { 31 public void loadNativeLibraryNoBrowserProcess() {
25 mTestCommon.handleNativeInitialization(false, InstrumentationRegistry.ge tInstrumentation()); 32 mTestCommon.handleNativeInitialization(false, InstrumentationRegistry.ge tInstrumentation());
26 } 33 }
27 34
28 /** 35 /**
29 * Loads the native library on the activity UI thread (must not be called fr om the UI thread). 36 * Loads the native library on the activity UI thread (must not be called fr om the UI thread).
30 * After loading the library, this will initialize the browser process. 37 * After loading the library, this will initialize the browser process.
31 */ 38 */
32 public void loadNativeLibraryAndInitBrowserProcess() { 39 public void loadNativeLibraryAndInitBrowserProcess() {
33 mTestCommon.handleNativeInitialization(true, InstrumentationRegistry.get Instrumentation()); 40 mTestCommon.handleNativeInitialization(true, InstrumentationRegistry.get Instrumentation());
34 } 41 }
35 42
43 public NativeLibraryTestRule setInitOption(NativeLibraryInitializationOption option) {
44 mInitOption = option;
45 return this;
46 }
47
48 @Override
49 public NativeLibraryTestRule shouldSetUp(boolean runSetUp) {
50 mShouldSetUp = runSetUp;
51 return this;
52 }
53
36 @Override 54 @Override
37 public Statement apply(Statement base, Description description) { 55 public Statement apply(Statement base, Description description) {
38 return base; 56 return new SetUpStatement(base, this, mShouldSetUp);
57 }
58
59 @Override
60 public void setUp() {
61 Assert.assertNotNull("Initialization option not set, please call "
62 + "NativeLibraryTestRule#setInitOption to set up",
63 mInitOption);
64 if (mInitOption.equals(NativeLibraryInitializationOption.INIT_BROWSER_PR OCESS)) {
65 loadNativeLibraryAndInitBrowserProcess();
66 } else if (mInitOption.equals(NativeLibraryInitializationOption.NO_BROWS ER_PROCESS)) {
67 loadNativeLibraryNoBrowserProcess();
68 } else {
69 throw new AssertionError("Initialization option not recognized");
70 }
39 } 71 }
40 } 72 }
OLDNEW
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/IntentHandlerTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698