1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 package org.mozilla.fenix.ui
7 import android.content.Context
8 import android.os.Build
9 import androidx.test.rule.GrantPermissionRule
10 import androidx.test.rule.GrantPermissionRule.grant
11 import mozilla.components.service.nimbus.messaging.FxNimbusMessaging
12 import org.json.JSONObject
13 import org.junit.Before
16 import org.mozilla.experiments.nimbus.HardcodedNimbusFeatures
17 import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
18 import org.mozilla.fenix.helpers.TestHelper
19 import org.mozilla.fenix.helpers.TestHelper.mDevice
20 import org.mozilla.fenix.helpers.TestSetup
21 import org.mozilla.fenix.nimbus.FxNimbus
22 import org.mozilla.fenix.ui.robots.notificationShade
25 * A UI test for testing the notification surface for Nimbus Messaging.
27 class NimbusMessagingNotificationTest : TestSetup() {
28 private lateinit var context: Context
29 private lateinit var hardcodedNimbus: HardcodedNimbusFeatures
32 val activityTestRule =
33 HomeActivityIntentTestRule.withDefaultSettingsOverrides(skipOnboarding = true)
36 val grantPermissionRule: GrantPermissionRule =
37 if (Build.VERSION.SDK_INT >= 33) {
38 grant("android.permission.POST_NOTIFICATIONS")
44 override fun setUp() {
46 context = TestHelper.appContext
50 fun testShowingNotificationMessage() {
51 hardcodedNimbus = HardcodedNimbusFeatures(
53 "messaging" to JSONObject(
56 "message-under-experiment": "test-default-browser-notification",
58 "test-default-browser-notification": {
59 "title": "preferences_set_as_default_browser",
60 "text": "default_browser_experiment_card_text",
61 "surface": "notification",
62 "style": "NOTIFICATION",
63 "action": "MAKE_DEFAULT_BROWSER",
73 // The scheduling of the Messaging Notification Worker happens in the HomeActivity
75 // We need to have connected FxNimbus to hardcodedNimbus by the time it is scheduled, so
76 // we finishActivity, connect, _then_ re-launch the activity so that the worker has
77 // hardcodedNimbus by the time its re-scheduled.
78 // Because the scheduling happens for a second time, the work request needs to replace the
80 activityTestRule.finishActivity()
81 hardcodedNimbus.connectWith(FxNimbus)
82 activityTestRule.launchActivity(null)
84 mDevice.openNotification()
87 FxNimbusMessaging.features.messaging.value().messages["test-default-browser-notification"]
88 verifySystemNotificationExists(data!!.title!!)
89 verifySystemNotificationExists(data.text)