blob: 2241047dec0ef88c2f34bc1e40e2a9972c7457da [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;
Jason Monk74f5e362017-12-06 08:56:33 -050029import com.android.server.UiServiceTestCase;
Julia Reynolds0f170002017-07-10 10:51:01 -040030
Julia Reynoldsf7321592017-05-24 16:09:19 -040031import org.junit.Test;
32import org.junit.runner.RunWith;
Julia Reynolds0f170002017-07-10 10:51:01 -040033import org.xmlpull.v1.XmlSerializer;
34
35import java.io.BufferedOutputStream;
36import java.io.ByteArrayOutputStream;
Julia Reynoldsf7321592017-05-24 16:09:19 -040037
38@SmallTest
39@RunWith(AndroidJUnit4.class)
Jason Monk74f5e362017-12-06 08:56:33 -050040public class NotificationChannelTest extends UiServiceTestCase {
Julia Reynoldsf7321592017-05-24 16:09:19 -040041
42 @Test
43 public void testWriteToParcel() {
44 NotificationChannel channel =
45 new NotificationChannel("1", "one", IMPORTANCE_DEFAULT);
46 Parcel parcel = Parcel.obtain();
47 channel.writeToParcel(parcel, 0);
48 parcel.setDataPosition(0);
49 NotificationChannel channel1 = NotificationChannel.CREATOR.createFromParcel(parcel);
50 assertEquals(channel, channel1);
51 }
52
53 @Test
54 public void testSystemBlockable() {
55 NotificationChannel channel = new NotificationChannel("a", "ab", IMPORTANCE_DEFAULT);
56 assertEquals(false, channel.isBlockableSystem());
57 channel.setBlockableSystem(true);
58 assertEquals(true, channel.isBlockableSystem());
59 }
Julia Reynolds0f170002017-07-10 10:51:01 -040060
61 @Test
62 public void testEmptyVibration_noException() throws Exception {
63 NotificationChannel channel = new NotificationChannel("a", "ab", IMPORTANCE_DEFAULT);
64 channel.setVibrationPattern(new long[0]);
65
66 XmlSerializer serializer = new FastXmlSerializer();
67 ByteArrayOutputStream baos = new ByteArrayOutputStream();
68 serializer.setOutput(new BufferedOutputStream(baos), "utf-8");
69 channel.writeXml(serializer);
70 }
Julia Reynoldsf7321592017-05-24 16:09:19 -040071}