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

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

Issue 2632043002: Create ContentShellActivityTestRule and BaseJUnitRunner (Closed)
Patch Set: Add TODO for launchContentShellWithUrlSync Created 3 years, 10 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.content.browser.test;
6
7 import android.support.test.InstrumentationRegistry;
8
9 import org.junit.Assert;
10 import org.junit.rules.TestRule;
11 import org.junit.runner.Description;
12 import org.junit.runners.model.Statement;
13
14 import org.chromium.base.PathUtils;
15 import org.chromium.base.ThreadUtils;
16 import org.chromium.base.library_loader.LibraryLoader;
17 import org.chromium.base.library_loader.LibraryProcessType;
18 import org.chromium.base.library_loader.ProcessInitException;
19 import org.chromium.content.browser.BrowserStartupController;
20 import org.chromium.content.browser.test.util.ApplicationUtils;
21
22 /**
23 * TestRule that adds support for loading and dealing with native libraries.
24 */
25 public class NativeLibraryTestRule implements TestRule {
26 private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "content";
27
28 /**
29 * Loads the native library on the activity UI thread (must not be called fr om the UI thread).
30 */
31 public void loadNativeLibraryNoBrowserProcess() {
32 handleNativeInitialization(false);
33 }
34
35 /**
36 * Loads the native library on the activity UI thread (must not be called fr om the UI thread).
37 * After loading the library, this will initialize the browser process.
38 */
39 public void loadNativeLibraryAndInitBrowserProcess() {
40 handleNativeInitialization(true);
41 }
42
43 private void handleNativeInitialization(final boolean initBrowserProcess) {
44 Assert.assertFalse(ThreadUtils.runningOnUiThread());
45
46 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
47
48 ApplicationUtils.waitForLibraryDependencies(InstrumentationRegistry.getI nstrumentation());
49
50 // LibraryLoader is not in general multithreaded; as other Instrumentati onTestCase code
51 // (specifically, ChromeBrowserProvider) uses it from the main thread we must do
52 // likewise.
53 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
54 @Override
55 public void run() {
56 nativeInitialization(initBrowserProcess);
57 }
58 });
59 }
60
61 private void nativeInitialization(boolean initBrowserProcess) {
62 if (initBrowserProcess) {
63 try {
64 BrowserStartupController.get(LibraryProcessType.PROCESS_BROWSER)
65 .startBrowserProcessesSync(false);
66 } catch (ProcessInitException e) {
67 throw new Error(e);
68 }
69 } else {
70 try {
71 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInit ialized();
72 } catch (ProcessInitException e) {
73 throw new Error(e);
74 }
75 }
76 }
77
78 @Override
79 public Statement apply(Statement base, Description description) {
80 return new Statement() {
81 @Override
82 public void evaluate() throws Throwable {
83 base.evaluate();
84 }
85 };
86 }
87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698