Commit 1dc48032 authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Migrate UrlFormatterUnitTest to Instrumentation tests

Native Java Unittests are going away, these tests need to be migrated
to an Instrumentation Test apk.

Bug: 1103344
Change-Id: Idf14f10e535cc8a7f37271892fb823c4aad7a17e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2377549Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801890}
parent fa7848a7
......@@ -1103,6 +1103,7 @@ android_library("chrome_test_java") {
"//components/sync/protocol:protocol_java",
"//components/translate/content/android:javatests",
"//components/url_formatter/android:url_formatter_java",
"//components/url_formatter/android:url_formatter_javatests",
"//components/user_prefs/android:java",
"//components/webapk/android/libs/client:java",
"//content/public/android:content_java",
......
......@@ -352,7 +352,6 @@ test("components_unittests") {
"//components/signin/core/browser/android:java",
"//components/signin/public/android:java",
"//components/spellcheck/browser/android:java",
"//components/url_formatter/android:native_java_unittests_java",
"//components/variations/android:variations_java",
"//content/public/android:content_java",
"//content/public/browser",
......
......@@ -87,12 +87,4 @@ source_set("unit_tests") {
"//ui/gfx",
"//url",
]
if (is_android) {
sources += [ "url_formatter_android_unittest.cc" ]
deps += [
"android:native_j_unittests_jni_headers",
"android:native_java_unittests_java",
]
}
}
......@@ -4,6 +4,7 @@ include_rules = [
"-content",
"-ios",
"+content/public/test/android",
"+net",
"+ui/gfx",
]
......@@ -24,22 +24,19 @@ generate_jni("jni_headers") {
[ "java/src/org/chromium/components/url_formatter/UrlFormatter.java" ]
}
android_library("native_java_unittests_java") {
android_library("url_formatter_javatests") {
testonly = true
sources = [ "javatests/src/org/chromium/components/url_formatter/UrlFormatterUnitTest.java" ]
deps = [
":url_formatter_java",
"//base:base_java",
"//base:base_java_test_support",
"//content/public/test/android:content_java_test_support",
"//third_party/android_deps:androidx_core_core_java",
"//third_party/android_deps:androidx_test_runner_java",
"//third_party/android_support_test_runner:runner_java",
"//third_party/junit",
"//url:gurl_java",
]
sources = [ "native_java_unittests/src/org/chromium/components/url_formatter/UrlFormatterUnitTest.java" ]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
}
# See https://bugs.chromium.org/p/chromium/issues/detail?id=908819 for why we
# can't put 'java' in the name here.
generate_jni("native_j_unittests_jni_headers") {
testonly = true
sources = [ "native_java_unittests/src/org/chromium/components/url_formatter/UrlFormatterUnitTest.java" ]
}
......@@ -4,10 +4,16 @@
package org.chromium.components.url_formatter;
import androidx.test.filters.SmallTest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.CalledByNativeJavaTest;
import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.Batch;
import org.chromium.content_public.browser.test.NativeLibraryTestUtils;
/**
* Unit tests for {@link UrlFormatter}.
......@@ -15,11 +21,16 @@ import org.chromium.base.annotations.CalledByNativeJavaTest;
* These tests are basic sanity checks to ensure the plumbing is working correctly. The wrapped
* functions are tested much more thoroughly elsewhere.
*/
@RunWith(BaseJUnit4ClassRunner.class)
@Batch(Batch.UNIT_TESTS)
public class UrlFormatterUnitTest {
@CalledByNative
private UrlFormatterUnitTest() {}
@Before
public void setUp() {
NativeLibraryTestUtils.loadNativeLibraryNoBrowserProcess();
}
@CalledByNativeJavaTest
@Test
@SmallTest
public void testFixupUrl() {
Assert.assertEquals("http://google.com/", UrlFormatter.fixupUrl("google.com").getSpec());
Assert.assertEquals("chrome://version/", UrlFormatter.fixupUrl("about:").getSpec());
......@@ -28,7 +39,8 @@ public class UrlFormatterUnitTest {
Assert.assertFalse(UrlFormatter.fixupUrl("0x100.0").isValid());
}
@CalledByNativeJavaTest
@Test
@SmallTest
public void testFormatUrlForDisplayOmitUsernamePassword() {
Assert.assertEquals("http://google.com/path",
UrlFormatter.formatUrlForDisplayOmitUsernamePassword("http://google.com/path"));
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/android/jni_android.h"
#include "components/url_formatter/android/native_j_unittests_jni_headers/UrlFormatterUnitTest_jni.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::android::AttachCurrentThread;
class UrlFormatterUnitTest : public ::testing::Test {
public:
UrlFormatterUnitTest()
: j_test_(Java_UrlFormatterUnitTest_Constructor(AttachCurrentThread())) {}
const base::android::ScopedJavaGlobalRef<jobject>& j_test() {
return j_test_;
}
private:
base::android::ScopedJavaGlobalRef<jobject> j_test_;
};
JAVA_TESTS(UrlFormatterUnitTest, j_test())
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