Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: chrome/android/junit/src/org/chromium/chrome/browser/notifications/ChannelsInitializerTest.java

Issue 2832493002: [Android O] Only delete legacy notification channels on upgrade (Closed)
Patch Set: rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.notifications; 5 package org.chromium.chrome.browser.notifications;
6 6
7 import static org.hamcrest.Matchers.containsInAnyOrder; 7 import static org.hamcrest.Matchers.containsInAnyOrder;
8 import static org.hamcrest.Matchers.empty;
9 import static org.hamcrest.Matchers.hasSize;
8 import static org.hamcrest.Matchers.is; 10 import static org.hamcrest.Matchers.is;
11 import static org.hamcrest.Matchers.not;
9 import static org.junit.Assert.assertThat; 12 import static org.junit.Assert.assertThat;
10 13
11 import android.app.NotificationManager; 14 import android.app.NotificationManager;
12 15
13 import org.junit.Before; 16 import org.junit.Before;
14 import org.junit.Test; 17 import org.junit.Test;
15 import org.junit.runner.RunWith; 18 import org.junit.runner.RunWith;
16 import org.junit.runners.BlockJUnit4ClassRunner; 19 import org.junit.runners.BlockJUnit4ClassRunner;
17 20
18 import org.chromium.chrome.test.util.browser.notifications.MockNotificationManag erProxy; 21 import org.chromium.chrome.test.util.browser.notifications.MockNotificationManag erProxy;
19 22
20 /** 23 /**
21 * Unit tests for ChannelsInitializer. 24 * Unit tests for ChannelsInitializer.
22 */ 25 */
23 @RunWith(BlockJUnit4ClassRunner.class) 26 @RunWith(BlockJUnit4ClassRunner.class)
24 public class ChannelsInitializerTest { 27 public class ChannelsInitializerTest {
25 private ChannelsInitializer mChannelsInitializer; 28 private ChannelsInitializer mChannelsInitializer;
26 private MockNotificationManagerProxy mMockNotificationManager; 29 private MockNotificationManagerProxy mMockNotificationManager;
27 30
28 @Before 31 @Before
29 public void setUp() throws Exception { 32 public void setUp() throws Exception {
30 mMockNotificationManager = new MockNotificationManagerProxy(); 33 mMockNotificationManager = new MockNotificationManagerProxy();
31 mChannelsInitializer = 34 mChannelsInitializer =
32 new ChannelsInitializer(mMockNotificationManager, new ChannelDef initions()); 35 new ChannelsInitializer(mMockNotificationManager, new ChannelDef initions());
33 } 36 }
34 37
35 @Test 38 @Test
39 public void testDeleteLegacyChannels_noopOnCurrentDefinitions() throws Excep tion {
40 assertThat(mMockNotificationManager.getNotificationChannelIds(), is(empt y()));
41
42 mChannelsInitializer.deleteLegacyChannels();
43 assertThat(mMockNotificationManager.getNotificationChannelIds(), is(empt y()));
44
45 mChannelsInitializer.initializeStartupChannels();
46 assertThat(mMockNotificationManager.getNotificationChannelIds(), is(not( empty())));
47
48 int nChannels = mMockNotificationManager.getNotificationChannelIds().siz e();
49 mChannelsInitializer.deleteLegacyChannels();
50 assertThat(mMockNotificationManager.getNotificationChannelIds(), hasSize (nChannels));
51 }
52
53 @Test
36 public void testInitializeStartupChannels() throws Exception { 54 public void testInitializeStartupChannels() throws Exception {
37 mChannelsInitializer.initializeStartupChannels(); 55 mChannelsInitializer.initializeStartupChannels();
38 assertThat(mMockNotificationManager.getNotificationChannelIds(), 56 assertThat(mMockNotificationManager.getNotificationChannelIds(),
39 containsInAnyOrder(ChannelDefinitions.CHANNEL_ID_BROWSER, 57 containsInAnyOrder(ChannelDefinitions.CHANNEL_ID_BROWSER,
40 ChannelDefinitions.CHANNEL_ID_DOWNLOADS, 58 ChannelDefinitions.CHANNEL_ID_DOWNLOADS,
41 ChannelDefinitions.CHANNEL_ID_INCOGNITO, 59 ChannelDefinitions.CHANNEL_ID_INCOGNITO,
42 ChannelDefinitions.CHANNEL_ID_SITES, ChannelDefinitions. CHANNEL_ID_MEDIA)); 60 ChannelDefinitions.CHANNEL_ID_SITES, ChannelDefinitions. CHANNEL_ID_MEDIA));
43 } 61 }
44 62
45 @Test 63 @Test
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 is(org.chromium.chrome.R.string.notification_category_group_gene ral)); 161 is(org.chromium.chrome.R.string.notification_category_group_gene ral));
144 } 162 }
145 163
146 @Test 164 @Test
147 public void testEnsureInitialized_multipleCalls() throws Exception { 165 public void testEnsureInitialized_multipleCalls() throws Exception {
148 mChannelsInitializer.ensureInitialized(ChannelDefinitions.CHANNEL_ID_SIT ES); 166 mChannelsInitializer.ensureInitialized(ChannelDefinitions.CHANNEL_ID_SIT ES);
149 mChannelsInitializer.ensureInitialized(ChannelDefinitions.CHANNEL_ID_BRO WSER); 167 mChannelsInitializer.ensureInitialized(ChannelDefinitions.CHANNEL_ID_BRO WSER);
150 assertThat(mMockNotificationManager.getChannels().size(), is(2)); 168 assertThat(mMockNotificationManager.getChannels().size(), is(2));
151 } 169 }
152 } 170 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698