Commit ed647730 authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Move NotificationPlatformBridgeUnitTest to unit_tests

In order to migrate java.net.URI to GURL the junit tests that rely on
java.net.URI need to be moved to a test apk that supports the native
library.

This change moves the NotificationPlatformBridgeUnitTest unittests from
junit to unit_tests (Android only). These tests should be just as fast
as they were as junit tests (and much faster than chrome_test_apk unit
tests).

Bug: 783819
Change-Id: Ia64a3bbd630bb4861c9a405d28582bd97f5ad167
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1991725Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#730204}
parent 39a4b5ab
...@@ -2965,6 +2965,7 @@ android_library("native_java_unittests_java") { ...@@ -2965,6 +2965,7 @@ android_library("native_java_unittests_java") {
sources = [ sources = [
"native_java_unittests/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulatorTest.java", "native_java_unittests/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulatorTest.java",
"native_java_unittests/src/org/chromium/chrome/browser/installedapp/InstalledAppProviderTest.java", "native_java_unittests/src/org/chromium/chrome/browser/installedapp/InstalledAppProviderTest.java",
"native_java_unittests/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridgeUnitTest.java",
] ]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ] annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
...@@ -2977,5 +2978,6 @@ generate_jni("native_j_unittests_jni_headers") { ...@@ -2977,5 +2978,6 @@ generate_jni("native_j_unittests_jni_headers") {
sources = [ sources = [
"native_java_unittests/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulatorTest.java", "native_java_unittests/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulatorTest.java",
"native_java_unittests/src/org/chromium/chrome/browser/installedapp/InstalledAppProviderTest.java", "native_java_unittests/src/org/chromium/chrome/browser/installedapp/InstalledAppProviderTest.java",
"native_java_unittests/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridgeUnitTest.java",
] ]
} }
...@@ -114,7 +114,6 @@ chrome_junit_test_java_sources = [ ...@@ -114,7 +114,6 @@ chrome_junit_test_java_sources = [
"junit/src/org/chromium/chrome/browser/nfc/NfcSystemLevelPromptTest.java", "junit/src/org/chromium/chrome/browser/nfc/NfcSystemLevelPromptTest.java",
"junit/src/org/chromium/chrome/browser/night_mode/GlobalNightModeStateControllerTest.java", "junit/src/org/chromium/chrome/browser/night_mode/GlobalNightModeStateControllerTest.java",
"junit/src/org/chromium/chrome/browser/night_mode/GlobalNightModeStateProviderHolderTest.java", "junit/src/org/chromium/chrome/browser/night_mode/GlobalNightModeStateProviderHolderTest.java",
"junit/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridgeUnitTest.java",
"junit/src/org/chromium/chrome/browser/notifications/NotificationSystemStatusUtilUnitTest.java", "junit/src/org/chromium/chrome/browser/notifications/NotificationSystemStatusUtilUnitTest.java",
"junit/src/org/chromium/chrome/browser/notifications/NotificationTriggerBackgroundTaskTest.java", "junit/src/org/chromium/chrome/browser/notifications/NotificationTriggerBackgroundTaskTest.java",
"junit/src/org/chromium/chrome/browser/notifications/NotificationTriggerSchedulerTest.java", "junit/src/org/chromium/chrome/browser/notifications/NotificationTriggerSchedulerTest.java",
......
...@@ -10,11 +10,8 @@ import static org.junit.Assert.assertTrue; ...@@ -10,11 +10,8 @@ import static org.junit.Assert.assertTrue;
import android.app.Notification; import android.app.Notification;
import org.junit.Test; import org.chromium.base.annotations.CalledByNative;
import org.junit.runner.RunWith; import org.chromium.base.annotations.CalledByNativeJavaTest;
import org.robolectric.annotation.Config;
import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.notifications.channels.ChannelDefinitions; import org.chromium.chrome.browser.notifications.channels.ChannelDefinitions;
import org.chromium.chrome.browser.notifications.channels.SiteChannelsManager; import org.chromium.chrome.browser.notifications.channels.SiteChannelsManager;
...@@ -24,17 +21,18 @@ import java.util.Arrays; ...@@ -24,17 +21,18 @@ import java.util.Arrays;
/** /**
* Unit tests for NotificationPlatformBridge. * Unit tests for NotificationPlatformBridge.
*/ */
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class NotificationPlatformBridgeUnitTest { public class NotificationPlatformBridgeUnitTest {
@CalledByNative
private NotificationPlatformBridgeUnitTest() {}
/** /**
* Verifies that the getOriginFromTag method returns the origin for valid input, and null for * Verifies that the getOriginFromTag method returns the origin for valid input, and null for
* invalid input. * invalid input.
* *
* This is defined in functions in notification_id_generator.cc. * This is defined in functions in notification_id_generator.cc.
*/ */
@Test
@Feature({"Browser", "Notifications"}) @Feature({"Browser", "Notifications"})
@CalledByNativeJavaTest
public void testGetOriginFromNotificationTag() { public void testGetOriginFromNotificationTag() {
// The common case. // The common case.
assertEquals("https://example.com", assertEquals("https://example.com",
...@@ -62,8 +60,8 @@ public class NotificationPlatformBridgeUnitTest { ...@@ -62,8 +60,8 @@ public class NotificationPlatformBridgeUnitTest {
* Verifies that the getOriginFromChannelId method returns the origin for a site channel, * Verifies that the getOriginFromChannelId method returns the origin for a site channel,
* and null for any other channel or a null channel id. * and null for any other channel or a null channel id.
*/ */
@Test
@Feature({"Browser", "Notifications"}) @Feature({"Browser", "Notifications"})
@CalledByNativeJavaTest
public void testGetOriginFromChannelId() { public void testGetOriginFromChannelId() {
// Returns the expected origin for a channel id associated with a particular origin. // Returns the expected origin for a channel id associated with a particular origin.
assertEquals("https://example.com", assertEquals("https://example.com",
...@@ -83,8 +81,8 @@ public class NotificationPlatformBridgeUnitTest { ...@@ -83,8 +81,8 @@ public class NotificationPlatformBridgeUnitTest {
/** /**
* Verifies that the makeDefaults method returns the generated notification defaults. * Verifies that the makeDefaults method returns the generated notification defaults.
*/ */
@Test
@Feature({"Browser", "Notifications"}) @Feature({"Browser", "Notifications"})
@CalledByNativeJavaTest
public void testMakeDefaults() { public void testMakeDefaults() {
// 0 should be returned if pattern length is 0, silent is true, and vibration is enabled. // 0 should be returned if pattern length is 0, silent is true, and vibration is enabled.
assertEquals(0, NotificationPlatformBridge.makeDefaults(0, true, true)); assertEquals(0, NotificationPlatformBridge.makeDefaults(0, true, true));
...@@ -109,8 +107,8 @@ public class NotificationPlatformBridgeUnitTest { ...@@ -109,8 +107,8 @@ public class NotificationPlatformBridgeUnitTest {
* Verifies that the makeVibrationPattern method returns vibration pattern used * Verifies that the makeVibrationPattern method returns vibration pattern used
* in Android notification. * in Android notification.
*/ */
@Test
@Feature({"Browser", "Notifications"}) @Feature({"Browser", "Notifications"})
@CalledByNativeJavaTest
public void testMakeVibrationPattern() { public void testMakeVibrationPattern() {
assertTrue(Arrays.equals(new long[] {0, 100, 200, 300}, assertTrue(Arrays.equals(new long[] {0, 100, 200, 300},
NotificationPlatformBridge.makeVibrationPattern(new int[] {100, 200, 300}))); NotificationPlatformBridge.makeVibrationPattern(new int[] {100, 200, 300})));
......
// 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 "chrome/android/native_j_unittests_jni_headers/NotificationPlatformBridgeUnitTest_jni.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::android::AttachCurrentThread;
class NotificationPlatformBridgeUnitTest : public ::testing::Test {
public:
NotificationPlatformBridgeUnitTest()
: j_test_(Java_NotificationPlatformBridgeUnitTest_Constructor(
AttachCurrentThread())) {}
const base::android::ScopedJavaGlobalRef<jobject>& j_test() {
return j_test_;
}
private:
base::android::ScopedJavaGlobalRef<jobject> j_test_;
};
JAVA_TESTS(NotificationPlatformBridgeUnitTest, j_test())
...@@ -3779,6 +3779,7 @@ test("unit_tests") { ...@@ -3779,6 +3779,7 @@ test("unit_tests") {
"../browser/installedapp/installed_app_provider_unittest.cc", "../browser/installedapp/installed_app_provider_unittest.cc",
"../browser/media/android/cdm/media_drm_origin_id_manager_unittest.cc", "../browser/media/android/cdm/media_drm_origin_id_manager_unittest.cc",
"../browser/metrics/chrome_android_metrics_provider_unittest.cc", "../browser/metrics/chrome_android_metrics_provider_unittest.cc",
"../browser/notifications/notification_platform_bridge_android_unittest.cc",
"../browser/page_load_metrics/observers/android_page_load_metrics_observer_unittest.cc", "../browser/page_load_metrics/observers/android_page_load_metrics_observer_unittest.cc",
"../browser/password_manager/account_chooser_dialog_android_unittest.cc", "../browser/password_manager/account_chooser_dialog_android_unittest.cc",
"../browser/password_manager/auto_signin_first_run_dialog_android_unittest.cc", "../browser/password_manager/auto_signin_first_run_dialog_android_unittest.cc",
......
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