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

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

Issue 2831383002: [Android O] Refactor channel definitions into new class (Closed)
Patch Set: 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.is; 8 import static org.hamcrest.Matchers.is;
9 import static org.junit.Assert.assertThat; 9 import static org.junit.Assert.assertThat;
10 10
(...skipping 10 matching lines...) Expand all
21 * Unit tests for ChannelsInitializer. 21 * Unit tests for ChannelsInitializer.
22 */ 22 */
23 @RunWith(BlockJUnit4ClassRunner.class) 23 @RunWith(BlockJUnit4ClassRunner.class)
24 public class ChannelsInitializerTest { 24 public class ChannelsInitializerTest {
25 private ChannelsInitializer mChannelsInitializer; 25 private ChannelsInitializer mChannelsInitializer;
26 private MockNotificationManagerProxy mMockNotificationManager; 26 private MockNotificationManagerProxy mMockNotificationManager;
27 27
28 @Before 28 @Before
29 public void setUp() throws Exception { 29 public void setUp() throws Exception {
30 mMockNotificationManager = new MockNotificationManagerProxy(); 30 mMockNotificationManager = new MockNotificationManagerProxy();
31 mChannelsInitializer = new ChannelsInitializer(mMockNotificationManager) ; 31 mChannelsInitializer =
32 new ChannelsInitializer(mMockNotificationManager, new ChannelDef initions());
32 } 33 }
33 34
34 @Test 35 @Test
35 public void testInitializeStartupChannels() throws Exception { 36 public void testInitializeStartupChannels() throws Exception {
36 mChannelsInitializer.initializeStartupChannels(); 37 mChannelsInitializer.initializeStartupChannels();
37 assertThat(mMockNotificationManager.getNotificationChannelIds(), 38 assertThat(mMockNotificationManager.getNotificationChannelIds(),
38 containsInAnyOrder(ChannelsInitializer.CHANNEL_ID_BROWSER, 39 containsInAnyOrder(ChannelDefinitions.CHANNEL_ID_BROWSER,
39 ChannelsInitializer.CHANNEL_ID_DOWNLOADS, 40 ChannelDefinitions.CHANNEL_ID_DOWNLOADS,
40 ChannelsInitializer.CHANNEL_ID_INCOGNITO, 41 ChannelDefinitions.CHANNEL_ID_INCOGNITO,
41 ChannelsInitializer.CHANNEL_ID_SITES, 42 ChannelDefinitions.CHANNEL_ID_SITES, ChannelDefinitions. CHANNEL_ID_MEDIA));
42 ChannelsInitializer.CHANNEL_ID_MEDIA));
43 } 43 }
44 44
45 @Test 45 @Test
46 public void testEnsureInitialized_browserChannel() throws Exception { 46 public void testEnsureInitialized_browserChannel() throws Exception {
47 mChannelsInitializer.ensureInitialized(ChannelsInitializer.CHANNEL_ID_BR OWSER); 47 mChannelsInitializer.ensureInitialized(ChannelDefinitions.CHANNEL_ID_BRO WSER);
48 48
49 assertThat(mMockNotificationManager.getChannels().size(), is(1)); 49 assertThat(mMockNotificationManager.getChannels().size(), is(1));
50 ChannelsInitializer.Channel channel = mMockNotificationManager.getChanne ls().get(0); 50 ChannelDefinitions.Channel channel = mMockNotificationManager.getChannel s().get(0);
51 assertThat(channel.mId, is(ChannelsInitializer.CHANNEL_ID_BROWSER)); 51 assertThat(channel.mId, is(ChannelDefinitions.CHANNEL_ID_BROWSER));
52 assertThat( 52 assertThat(
53 channel.mNameResId, is(org.chromium.chrome.R.string.notification _category_browser)); 53 channel.mNameResId, is(org.chromium.chrome.R.string.notification _category_browser));
54 assertThat(channel.mImportance, is(NotificationManager.IMPORTANCE_LOW)); 54 assertThat(channel.mImportance, is(NotificationManager.IMPORTANCE_LOW));
55 assertThat(channel.mGroupId, is(ChannelsInitializer.CHANNEL_GROUP_ID_GEN ERAL)); 55 assertThat(channel.mGroupId, is(ChannelDefinitions.CHANNEL_GROUP_ID_GENE RAL));
56 56
57 assertThat(mMockNotificationManager.getNotificationChannelGroups().size( ), is(1)); 57 assertThat(mMockNotificationManager.getNotificationChannelGroups().size( ), is(1));
58 ChannelsInitializer.ChannelGroup group = 58 ChannelDefinitions.ChannelGroup group =
59 mMockNotificationManager.getNotificationChannelGroups().get(0); 59 mMockNotificationManager.getNotificationChannelGroups().get(0);
60 assertThat(group.mId, is(ChannelsInitializer.CHANNEL_GROUP_ID_GENERAL)); 60 assertThat(group.mId, is(ChannelDefinitions.CHANNEL_GROUP_ID_GENERAL));
61 assertThat(group.mNameResId, 61 assertThat(group.mNameResId,
62 is(org.chromium.chrome.R.string.notification_category_group_gene ral)); 62 is(org.chromium.chrome.R.string.notification_category_group_gene ral));
63 } 63 }
64 64
65 @Test 65 @Test
66 public void testEnsureInitialized_downloadsChannel() throws Exception { 66 public void testEnsureInitialized_downloadsChannel() throws Exception {
67 mChannelsInitializer.ensureInitialized(ChannelsInitializer.CHANNEL_ID_DO WNLOADS); 67 mChannelsInitializer.ensureInitialized(ChannelDefinitions.CHANNEL_ID_DOW NLOADS);
68 68
69 assertThat(mMockNotificationManager.getChannels().size(), is(1)); 69 assertThat(mMockNotificationManager.getChannels().size(), is(1));
70 ChannelsInitializer.Channel channel = mMockNotificationManager.getChanne ls().get(0); 70 ChannelDefinitions.Channel channel = mMockNotificationManager.getChannel s().get(0);
71 assertThat(channel.mId, is(ChannelsInitializer.CHANNEL_ID_DOWNLOADS)); 71 assertThat(channel.mId, is(ChannelDefinitions.CHANNEL_ID_DOWNLOADS));
72 assertThat(channel.mNameResId, 72 assertThat(channel.mNameResId,
73 is(org.chromium.chrome.R.string.notification_category_downloads) ); 73 is(org.chromium.chrome.R.string.notification_category_downloads) );
74 assertThat(channel.mImportance, is(NotificationManager.IMPORTANCE_LOW)); 74 assertThat(channel.mImportance, is(NotificationManager.IMPORTANCE_LOW));
75 assertThat(channel.mGroupId, is(ChannelsInitializer.CHANNEL_GROUP_ID_GEN ERAL)); 75 assertThat(channel.mGroupId, is(ChannelDefinitions.CHANNEL_GROUP_ID_GENE RAL));
76 76
77 assertThat(mMockNotificationManager.getNotificationChannelGroups().size( ), is(1)); 77 assertThat(mMockNotificationManager.getNotificationChannelGroups().size( ), is(1));
78 ChannelsInitializer.ChannelGroup group = 78 ChannelDefinitions.ChannelGroup group =
79 mMockNotificationManager.getNotificationChannelGroups().get(0); 79 mMockNotificationManager.getNotificationChannelGroups().get(0);
80 assertThat(group.mId, is(ChannelsInitializer.CHANNEL_GROUP_ID_GENERAL)); 80 assertThat(group.mId, is(ChannelDefinitions.CHANNEL_GROUP_ID_GENERAL));
81 assertThat(group.mNameResId, 81 assertThat(group.mNameResId,
82 is(org.chromium.chrome.R.string.notification_category_group_gene ral)); 82 is(org.chromium.chrome.R.string.notification_category_group_gene ral));
83 } 83 }
84 84
85 @Test 85 @Test
86 public void testEnsureInitialized_incognitoChannel() throws Exception { 86 public void testEnsureInitialized_incognitoChannel() throws Exception {
87 mChannelsInitializer.ensureInitialized(ChannelsInitializer.CHANNEL_ID_IN COGNITO); 87 mChannelsInitializer.ensureInitialized(ChannelDefinitions.CHANNEL_ID_INC OGNITO);
88 88
89 assertThat(mMockNotificationManager.getChannels().size(), is(1)); 89 assertThat(mMockNotificationManager.getChannels().size(), is(1));
90 ChannelsInitializer.Channel channel = mMockNotificationManager.getChanne ls().get(0); 90 ChannelDefinitions.Channel channel = mMockNotificationManager.getChannel s().get(0);
91 assertThat(channel.mId, is(ChannelsInitializer.CHANNEL_ID_INCOGNITO)); 91 assertThat(channel.mId, is(ChannelDefinitions.CHANNEL_ID_INCOGNITO));
92 assertThat(channel.mNameResId, 92 assertThat(channel.mNameResId,
93 is(org.chromium.chrome.R.string.notification_category_incognito) ); 93 is(org.chromium.chrome.R.string.notification_category_incognito) );
94 assertThat(channel.mImportance, is(NotificationManager.IMPORTANCE_LOW)); 94 assertThat(channel.mImportance, is(NotificationManager.IMPORTANCE_LOW));
95 assertThat(channel.mGroupId, is(ChannelsInitializer.CHANNEL_GROUP_ID_GEN ERAL)); 95 assertThat(channel.mGroupId, is(ChannelDefinitions.CHANNEL_GROUP_ID_GENE RAL));
96 96
97 assertThat(mMockNotificationManager.getNotificationChannelGroups().size( ), is(1)); 97 assertThat(mMockNotificationManager.getNotificationChannelGroups().size( ), is(1));
98 ChannelsInitializer.ChannelGroup group = 98 ChannelDefinitions.ChannelGroup group =
99 mMockNotificationManager.getNotificationChannelGroups().get(0); 99 mMockNotificationManager.getNotificationChannelGroups().get(0);
100 assertThat(group.mId, is(ChannelsInitializer.CHANNEL_GROUP_ID_GENERAL)); 100 assertThat(group.mId, is(ChannelDefinitions.CHANNEL_GROUP_ID_GENERAL));
101 assertThat(group.mNameResId, 101 assertThat(group.mNameResId,
102 is(org.chromium.chrome.R.string.notification_category_group_gene ral)); 102 is(org.chromium.chrome.R.string.notification_category_group_gene ral));
103 } 103 }
104 104
105 @Test 105 @Test
106 public void testEnsureInitialized_mediaChannel() throws Exception { 106 public void testEnsureInitialized_mediaChannel() throws Exception {
107 mChannelsInitializer.ensureInitialized(ChannelsInitializer.CHANNEL_ID_ME DIA); 107 mChannelsInitializer.ensureInitialized(ChannelDefinitions.CHANNEL_ID_MED IA);
108 108
109 assertThat(mMockNotificationManager.getChannels().size(), is(1)); 109 assertThat(mMockNotificationManager.getChannels().size(), is(1));
110 ChannelsInitializer.Channel channel = mMockNotificationManager.getChanne ls().get(0); 110 ChannelDefinitions.Channel channel = mMockNotificationManager.getChannel s().get(0);
111 assertThat(channel.mId, is(ChannelsInitializer.CHANNEL_ID_MEDIA)); 111 assertThat(channel.mId, is(ChannelDefinitions.CHANNEL_ID_MEDIA));
112 assertThat( 112 assertThat(
113 channel.mNameResId, is(org.chromium.chrome.R.string.notification _category_media)); 113 channel.mNameResId, is(org.chromium.chrome.R.string.notification _category_media));
114 assertThat(channel.mImportance, is(NotificationManager.IMPORTANCE_LOW)); 114 assertThat(channel.mImportance, is(NotificationManager.IMPORTANCE_LOW));
115 assertThat(channel.mGroupId, is(ChannelsInitializer.CHANNEL_GROUP_ID_GEN ERAL)); 115 assertThat(channel.mGroupId, is(ChannelDefinitions.CHANNEL_GROUP_ID_GENE RAL));
116 116
117 assertThat(mMockNotificationManager.getNotificationChannelGroups().size( ), is(1)); 117 assertThat(mMockNotificationManager.getNotificationChannelGroups().size( ), is(1));
118 ChannelsInitializer.ChannelGroup group = 118 ChannelDefinitions.ChannelGroup group =
119 mMockNotificationManager.getNotificationChannelGroups().get(0); 119 mMockNotificationManager.getNotificationChannelGroups().get(0);
120 assertThat(group.mId, is(ChannelsInitializer.CHANNEL_GROUP_ID_GENERAL)); 120 assertThat(group.mId, is(ChannelDefinitions.CHANNEL_GROUP_ID_GENERAL));
121 assertThat(group.mNameResId, 121 assertThat(group.mNameResId,
122 is(org.chromium.chrome.R.string.notification_category_group_gene ral)); 122 is(org.chromium.chrome.R.string.notification_category_group_gene ral));
123 } 123 }
124 124
125 @Test 125 @Test
126 public void testEnsureInitialized_sitesChannel() throws Exception { 126 public void testEnsureInitialized_sitesChannel() throws Exception {
127 mChannelsInitializer.ensureInitialized(ChannelsInitializer.CHANNEL_ID_SI TES); 127 mChannelsInitializer.ensureInitialized(ChannelDefinitions.CHANNEL_ID_SIT ES);
128 128
129 assertThat(mMockNotificationManager.getChannels().size(), is(1)); 129 assertThat(mMockNotificationManager.getChannels().size(), is(1));
130 130
131 ChannelsInitializer.Channel channel = mMockNotificationManager.getChanne ls().get(0); 131 ChannelDefinitions.Channel channel = mMockNotificationManager.getChannel s().get(0);
132 assertThat(channel.mId, is(ChannelsInitializer.CHANNEL_ID_SITES)); 132 assertThat(channel.mId, is(ChannelDefinitions.CHANNEL_ID_SITES));
133 assertThat( 133 assertThat(
134 channel.mNameResId, is(org.chromium.chrome.R.string.notification _category_sites)); 134 channel.mNameResId, is(org.chromium.chrome.R.string.notification _category_sites));
135 assertThat(channel.mImportance, is(NotificationManager.IMPORTANCE_DEFAUL T)); 135 assertThat(channel.mImportance, is(NotificationManager.IMPORTANCE_DEFAUL T));
136 assertThat(channel.mGroupId, is(ChannelsInitializer.CHANNEL_GROUP_ID_GEN ERAL)); 136 assertThat(channel.mGroupId, is(ChannelDefinitions.CHANNEL_GROUP_ID_GENE RAL));
137 137
138 assertThat(mMockNotificationManager.getNotificationChannelGroups().size( ), is(1)); 138 assertThat(mMockNotificationManager.getNotificationChannelGroups().size( ), is(1));
139 ChannelsInitializer.ChannelGroup group = 139 ChannelDefinitions.ChannelGroup group =
140 mMockNotificationManager.getNotificationChannelGroups().get(0); 140 mMockNotificationManager.getNotificationChannelGroups().get(0);
141 assertThat(group.mId, is(ChannelsInitializer.CHANNEL_GROUP_ID_GENERAL)); 141 assertThat(group.mId, is(ChannelDefinitions.CHANNEL_GROUP_ID_GENERAL));
142 assertThat(group.mNameResId, 142 assertThat(group.mNameResId,
143 is(org.chromium.chrome.R.string.notification_category_group_gene ral)); 143 is(org.chromium.chrome.R.string.notification_category_group_gene ral));
144 } 144 }
145 145
146 @Test 146 @Test
147 public void testEnsureInitialized_multipleCalls() throws Exception { 147 public void testEnsureInitialized_multipleCalls() throws Exception {
148 mChannelsInitializer.ensureInitialized(ChannelsInitializer.CHANNEL_ID_SI TES); 148 mChannelsInitializer.ensureInitialized(ChannelDefinitions.CHANNEL_ID_SIT ES);
149 mChannelsInitializer.ensureInitialized(ChannelsInitializer.CHANNEL_ID_BR OWSER); 149 mChannelsInitializer.ensureInitialized(ChannelDefinitions.CHANNEL_ID_BRO WSER);
150 assertThat(mMockNotificationManager.getChannels().size(), is(2)); 150 assertThat(mMockNotificationManager.getChannels().size(), is(2));
151 } 151 }
152 } 152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698