blob: f457f6a550c15cb49e97af947f995fd0675d07e4 [file] [log] [blame]
Julia Reynoldsf7321592017-05-24 16:09:19 -04001/*
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 */
16
17package com.android.server.notification;
18
19import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
20
21import static junit.framework.Assert.assertEquals;
22
23import android.app.NotificationChannel;
24import android.os.Parcel;
25import android.support.test.runner.AndroidJUnit4;
26import android.test.suitebuilder.annotation.SmallTest;
27
Julia Reynolds0f170002017-07-10 10:51:01 -040028import com.android.internal.util.FastXmlSerializer;
29
Julia Reynoldsf7321592017-05-24 16:09:19 -040030import org.junit.Test;
31import org.junit.runner.RunWith;
Julia Reynolds0f170002017-07-10 10:51:01 -040032import org.xmlpull.v1.XmlSerializer;
33
34import java.io.BufferedOutputStream;
35import java.io.ByteArrayOutputStream;
Julia Reynoldsf7321592017-05-24 16:09:19 -040036
37@SmallTest
38@RunWith(AndroidJUnit4.class)
39public class NotificationChannelTest extends NotificationTestCase {
40
41 @Test
42 public void testWriteToParcel() {
43 NotificationChannel channel =
44 new NotificationChannel("1", "one", IMPORTANCE_DEFAULT);
45 Parcel parcel = Parcel.obtain();
46 channel.writeToParcel(parcel, 0);
47 parcel.setDataPosition(0);
48 NotificationChannel channel1 = NotificationChannel.CREATOR.createFromParcel(parcel);
49 assertEquals(channel, channel1);
50 }
51
52 @Test
53 public void testSystemBlockable() {
54 NotificationChannel channel = new NotificationChannel("a", "ab", IMPORTANCE_DEFAULT);
55 assertEquals(false, channel.isBlockableSystem());
56 channel.setBlockableSystem(true);
57 assertEquals(true, channel.isBlockableSystem());
58 }
Julia Reynolds0f170002017-07-10 10:51:01 -040059
60 @Test
61 public void testEmptyVibration_noException() throws Exception {
62 NotificationChannel channel = new NotificationChannel("a", "ab", IMPORTANCE_DEFAULT);
63 channel.setVibrationPattern(new long[0]);
64
65 XmlSerializer serializer = new FastXmlSerializer();
66 ByteArrayOutputStream baos = new ByteArrayOutputStream();
67 serializer.setOutput(new BufferedOutputStream(baos), "utf-8");
68 channel.writeXml(serializer);
69 }
Julia Reynoldsf7321592017-05-24 16:09:19 -040070}