Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: libadblockplus-android-tests/src/org/adblockplus/libadblockplus/tests/NotificationTest.java

Issue 29678581: Issue 6000 - Rename "libadblockplus-android" (Closed)
Patch Set: addressed comments Created Jan. 29, 2018, 11:04 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 package org.adblockplus.libadblockplus.tests;
19
20 import org.adblockplus.libadblockplus.LazyWebRequest;
21 import org.adblockplus.libadblockplus.Notification;
22 import org.adblockplus.libadblockplus.ShowNotificationCallback;
23 import org.adblockplus.libadblockplus.WebRequest;
24
25 import org.junit.Test;
26
27 public class NotificationTest extends BaseFilterEngineTest
28 {
29 @Override
30 protected WebRequest createWebRequest()
31 {
32 return new LazyWebRequest();
33 }
34
35 protected void addNotification(String notification)
36 {
37 platform.getJsEngine().evaluate(
38 "(function()\n" +
39 "{\n" +
40 "require('notification').Notification.addNotification(" + notification + " );\n" +
41 "})();");
42 }
43
44 private class LocalShowNotificationCallback extends ShowNotificationCallback
45 {
46 private Notification retValue;
47
48 public Notification getRetValue()
49 {
50 return retValue;
51 }
52
53 @Override
54 public void showNotificationCallback(Notification notification)
55 {
56 retValue = notification;
57 }
58 }
59
60 protected Notification peekNotification(String url) throws InterruptedExceptio n
61 {
62 LocalShowNotificationCallback callback = new LocalShowNotificationCallback() ;
63 filterEngine.setShowNotificationCallback(callback);
64 filterEngine.showNextNotification(url);
65 filterEngine.removeShowNotificationCallback();
66 return callback.getRetValue();
67 }
68
69 @Test
70 public void testNoNotifications() throws InterruptedException
71 {
72 assertNull(peekNotification(""));
73 }
74
75 @Test
76 public void testAddNotification() throws InterruptedException
77 {
78 addNotification(
79 "{\n" +
80 " type: 'critical',\n" +
81 " title: 'testTitle',\n" +
82 " message: 'testMessage',\n" +
83 "}");
84 Notification notification = peekNotification("");
85 assertNotNull(notification);
86 assertEquals(Notification.Type.CRITICAL, notification.getType());
87 assertEquals("testTitle", notification.getTitle());
88 assertEquals("testMessage", notification.getMessageString());
89 }
90
91 @Test
92 public void testFilterByUrl() throws InterruptedException
93 {
94 addNotification("{ id:'no-filter', type:'critical' }");
95 addNotification("{ id:'www.com', type:'information', urlFilters:['||www.com$ document'] }");
96 addNotification("{ id:'www.de', type:'question', urlFilters:['||www.de$docum ent'] }");
97
98 Notification notification = peekNotification("");
99 assertNotNull(notification);
100 assertEquals(Notification.Type.CRITICAL, notification.getType());
101
102 notification = peekNotification("http://www.de");
103 assertNotNull(notification);
104 assertEquals(Notification.Type.QUESTION, notification.getType());
105
106 notification = peekNotification("http://www.com");
107 assertNotNull(notification);
108 assertEquals(Notification.Type.INFORMATION, notification.getType());
109 }
110
111 @Test
112 public void testMarkAsShown() throws InterruptedException
113 {
114 addNotification("{ id: 'id', type: 'information' }");
115 assertNotNull(peekNotification(""));
116
117 Notification notification = peekNotification("");
118 assertNotNull(notification);
119
120 Thread.sleep(1000);
121 notification.markAsShown();
122
123 assertNull(peekNotification(""));
124 }
125 }
OLDNEW

Powered by Google App Engine
This is Rietveld