Commit 6b2be2c1 authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Avoid having to mock LibraryLoader in Native Java Unittests

This change makes it so we don't have to mock the LibraryLoader in all
Native Java Unittests that use GURL (which talks to the LibraryLoader
to see if the libraries have been loaded).

Bug: 783819
Change-Id: I56c60a0043c9547a98674fdb74096517bca8f355
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2025974
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736534}
parent d54bb28e
...@@ -793,6 +793,16 @@ public class LibraryLoader { ...@@ -793,6 +793,16 @@ public class LibraryLoader {
ContextCompat.getCodeCacheDir(ContextUtils.getApplicationContext()), LIBRARY_DIR); ContextCompat.getCodeCacheDir(ContextUtils.getApplicationContext()), LIBRARY_DIR);
} }
/**
* This sets the LibraryLoader internal state to its fully initialized state and should *only*
* be used by clients like NativeTests which manually load their native libraries without using
* the LibraryLoader.
*/
public void setLibrariesLoadedForNativeTests() {
mLoadState = LoadState.LOADED;
mInitialized = true;
}
@NativeMethods @NativeMethods
interface Natives { interface Natives {
// Only methods needed before or during normal JNI registration are during System.OnLoad. // Only methods needed before or during normal JNI registration are during System.OnLoad.
......
...@@ -50,5 +50,6 @@ public class NativeUnitTest extends NativeTest { ...@@ -50,5 +50,6 @@ public class NativeUnitTest extends NativeTest {
System.loadLibrary(library); System.loadLibrary(library);
Log.i(TAG, "loaded: %s", library); Log.i(TAG, "loaded: %s", library);
} }
LibraryLoader.getInstance().setLibrariesLoadedForNativeTests();
} }
} }
...@@ -20,10 +20,6 @@ class GURLAndroidTest : public ::testing::Test { ...@@ -20,10 +20,6 @@ class GURLAndroidTest : public ::testing::Test {
GURLAndroidTest() GURLAndroidTest()
: j_test_(Java_GURLJavaTest_Constructor(AttachCurrentThread())) {} : j_test_(Java_GURLJavaTest_Constructor(AttachCurrentThread())) {}
void SetUp() override {
Java_GURLJavaTest_setUp(AttachCurrentThread(), j_test_);
}
const base::android::ScopedJavaGlobalRef<jobject>& j_test() { const base::android::ScopedJavaGlobalRef<jobject>& j_test() {
return j_test_; return j_test_;
} }
......
...@@ -5,12 +5,9 @@ ...@@ -5,12 +5,9 @@
package org.chromium.url; package org.chromium.url;
import org.junit.Assert; import org.junit.Assert;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.CalledByNativeJavaTest; import org.chromium.base.annotations.CalledByNativeJavaTest;
import org.chromium.base.library_loader.LibraryLoader;
import java.net.URISyntaxException; import java.net.URISyntaxException;
...@@ -20,18 +17,9 @@ import java.net.URISyntaxException; ...@@ -20,18 +17,9 @@ import java.net.URISyntaxException;
* correctly. * correctly.
*/ */
public class GURLJavaTest { public class GURLJavaTest {
@Mock
private LibraryLoader mLibraryLoader;
@CalledByNative @CalledByNative
private GURLJavaTest() {} private GURLJavaTest() {}
@CalledByNative
public void setUp() {
MockitoAnnotations.initMocks(this);
LibraryLoader.setLibraryLoaderForTesting(mLibraryLoader);
}
@CalledByNative @CalledByNative
public GURL createGURL(String uri) { public GURL createGURL(String uri) {
return new GURL(uri); return new GURL(uri);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment