blob: 20d7a2af15407d5ba5550cafd26d974a2b87378e [file] [log] [blame]
Julia Reynolds7bcb57b2018-01-22 10:37:58 -05001/**
2 * Copyright (c) 2017, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Julia Reynolds503ed942017-10-04 16:04:56 -040016package com.android.server.notification;
17
18import static android.service.notification.NotificationStats.DISMISSAL_PEEK;
Julia Reynoldsfd4099d2018-08-21 11:06:06 -040019import static android.service.notification.NotificationStats.DISMISS_SENTIMENT_NEGATIVE;
Julia Reynolds503ed942017-10-04 16:04:56 -040020
21import static junit.framework.Assert.assertEquals;
22import static junit.framework.Assert.assertFalse;
23import static junit.framework.Assert.assertTrue;
24
25import android.os.Parcel;
26import android.service.notification.NotificationStats;
Julia Reynolds503ed942017-10-04 16:04:56 -040027import android.test.suitebuilder.annotation.SmallTest;
28
Brett Chabot84151d92019-02-27 15:37:59 -080029import androidx.test.runner.AndroidJUnit4;
30
Jason Monk74f5e362017-12-06 08:56:33 -050031import com.android.server.UiServiceTestCase;
32
Julia Reynolds503ed942017-10-04 16:04:56 -040033import org.junit.Test;
34import org.junit.runner.RunWith;
35
36@SmallTest
37@RunWith(AndroidJUnit4.class)
Jason Monk74f5e362017-12-06 08:56:33 -050038public class NotificationStatsTest extends UiServiceTestCase {
Julia Reynolds503ed942017-10-04 16:04:56 -040039
40 @Test
41 public void testConstructor() {
42 NotificationStats stats = new NotificationStats();
43
44 assertFalse(stats.hasSeen());
45 assertFalse(stats.hasDirectReplied());
46 assertFalse(stats.hasExpanded());
47 assertFalse(stats.hasInteracted());
48 assertFalse(stats.hasViewedSettings());
49 assertFalse(stats.hasSnoozed());
50 assertEquals(NotificationStats.DISMISSAL_NOT_DISMISSED, stats.getDismissalSurface());
Julia Reynoldsfd4099d2018-08-21 11:06:06 -040051 assertEquals(NotificationStats.DISMISS_SENTIMENT_UNKNOWN, stats.getDismissalSentiment());
Julia Reynolds503ed942017-10-04 16:04:56 -040052 }
53
54 @Test
55 public void testSeen() {
56 NotificationStats stats = new NotificationStats();
57 stats.setSeen();
58 assertTrue(stats.hasSeen());
59 assertFalse(stats.hasInteracted());
60 }
61
62 @Test
63 public void testDirectReplied() {
64 NotificationStats stats = new NotificationStats();
65 stats.setDirectReplied();
66 assertTrue(stats.hasDirectReplied());
67 assertTrue(stats.hasInteracted());
68 }
69
70 @Test
71 public void testExpanded() {
72 NotificationStats stats = new NotificationStats();
73 stats.setExpanded();
74 assertTrue(stats.hasExpanded());
75 assertTrue(stats.hasInteracted());
76 }
77
78 @Test
79 public void testSnoozed() {
80 NotificationStats stats = new NotificationStats();
81 stats.setSnoozed();
82 assertTrue(stats.hasSnoozed());
83 assertTrue(stats.hasInteracted());
84 }
85
86 @Test
87 public void testViewedSettings() {
88 NotificationStats stats = new NotificationStats();
89 stats.setViewedSettings();
90 assertTrue(stats.hasViewedSettings());
91 assertTrue(stats.hasInteracted());
92 }
93
94 @Test
95 public void testDismissalSurface() {
96 NotificationStats stats = new NotificationStats();
97 stats.setDismissalSurface(DISMISSAL_PEEK);
98 assertEquals(DISMISSAL_PEEK, stats.getDismissalSurface());
99 assertFalse(stats.hasInteracted());
100 }
101
102 @Test
Julia Reynoldsfd4099d2018-08-21 11:06:06 -0400103 public void testDismissalSentiment() {
104 NotificationStats stats = new NotificationStats();
105 stats.setDismissalSentiment(DISMISS_SENTIMENT_NEGATIVE);
106 assertEquals(DISMISS_SENTIMENT_NEGATIVE, stats.getDismissalSentiment());
107 assertFalse(stats.hasInteracted());
108 }
109
110 @Test
Julia Reynolds503ed942017-10-04 16:04:56 -0400111 public void testWriteToParcel() {
112 NotificationStats stats = new NotificationStats();
113 stats.setViewedSettings();
114 stats.setDismissalSurface(NotificationStats.DISMISSAL_AOD);
Julia Reynoldsfd4099d2018-08-21 11:06:06 -0400115 stats.setDismissalSentiment(NotificationStats.DISMISS_SENTIMENT_POSITIVE);
Julia Reynolds503ed942017-10-04 16:04:56 -0400116 Parcel parcel = Parcel.obtain();
117 stats.writeToParcel(parcel, 0);
118 parcel.setDataPosition(0);
119 NotificationStats stats1 = NotificationStats.CREATOR.createFromParcel(parcel);
120 assertEquals(stats, stats1);
121 }
122}