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

Side by Side Diff: test/Notification.cpp

Issue 29539858: Issue 5506 - Make the notification test work. (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Address review comments. Created Sept. 12, 2017, 12:53 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/BaseJsTest.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include <iostream>
19 #include <AdblockPlus/DefaultLogSystem.h>
sergei 2017/09/12 13:34:09 These headers are still not required.
hub 2017/09/12 15:51:10 Done.
18 #include "BaseJsTest.h" 20 #include "BaseJsTest.h"
19 21
20 using namespace AdblockPlus; 22 using namespace AdblockPlus;
21 23
22 namespace 24 namespace
23 { 25 {
24 class NotificationTest : public BaseJsTest 26 class NotificationTest : public BaseJsTest
25 { 27 {
26 protected: 28 protected:
27 void SetUp() 29 void SetUp()
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 return; 75 return;
74 } 76 }
75 ServerResponse serverResponse; 77 ServerResponse serverResponse;
76 serverResponse.status = IWebRequest::NS_OK; 78 serverResponse.status = IWebRequest::NS_OK;
77 serverResponse.responseStatus = 200; 79 serverResponse.responseStatus = 200;
78 serverResponse.responseText = responseText; 80 serverResponse.responseText = responseText;
79 getCallback(serverResponse); 81 getCallback(serverResponse);
80 } 82 }
81 }; 83 };
82 84
83
84 // To run this test one needs to set INITIAL_DELAY to about 2000 msec 85 // To run this test one needs to set INITIAL_DELAY to about 2000 msec
85 // in notification.js. 86 // in notification.js.
86 class NotificationMockWebRequestTest : public BaseJsTest 87 class NotificationMockWebRequestTest : public BaseJsTest
87 { 88 {
88 protected: 89 protected:
89 bool isNotificationCallbackCalled; 90 AdblockPlus::Sync sync;
90 void SetUp() 91 void SetUp()
91 { 92 {
92 isNotificationCallbackCalled = false;
93 const char* responseJsonText = "{" 93 const char* responseJsonText = "{"
94 "\"notifications\": [{" 94 "\"notifications\": [{"
95 "\"id\": \"some id\"," 95 "\"id\": \"some id\","
96 "\"type\": \"information\"," 96 "\"type\": \"information\","
97 "\"message\": {" 97 "\"message\": {"
98 "\"en-US\": \"message\"" 98 "\"en-US\": \"message\""
99 "}," 99 "},"
100 "\"title\": \"Title\"" 100 "\"title\": \"Title\""
101 "}]" 101 "}]"
102 "}"; 102 "}";
103 103
104 ThrowingPlatformCreationParameters platformParams; 104 LazyFileSystem* fileSystem;
105 platformParams.fileSystem.reset(new LazyFileSystem()); 105 AdblockPlus::Platform::CreationParameters platformParams;
106 platformParams.logSystem.reset(new ThrowingLogSystem());
sergei 2017/09/12 13:34:09 These two lines can be replaced by original `Throw
hub 2017/09/12 15:51:10 Done.
107 platformParams.timer.reset(new ManualTimer());
108 platformParams.fileSystem.reset(fileSystem = new LazyFileSystem());
106 platformParams.webRequest.reset(new MockWebRequest(responseJsonText)); 109 platformParams.webRequest.reset(new MockWebRequest(responseJsonText));
107 platform.reset(new Platform(std::move(platformParams))); 110 platform.reset(new Platform(std::move(platformParams)));
108 111
112 CreateFilterEngine(*fileSystem, *platform);
109 auto& filterEngine = platform->GetFilterEngine(); 113 auto& filterEngine = platform->GetFilterEngine();
110 filterEngine.SetShowNotificationCallback( 114 filterEngine.SetShowNotificationCallback(
111 [this](Notification&& notification) { 115 [this](Notification&& notification) {
112 isNotificationCallbackCalled = true; 116 sync.Set();
113 EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notificatio n.GetType()); 117 EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notificatio n.GetType());
114 EXPECT_EQ("Title", notification.GetTexts().title); 118 EXPECT_EQ("Title", notification.GetTexts().title);
115 EXPECT_EQ("message", notification.GetTexts().message); 119 EXPECT_EQ("message", notification.GetTexts().message);
116 notification.MarkAsShown(); 120 notification.MarkAsShown();
117 }); 121 });
118 } 122 }
119 }; 123 };
120 } 124 }
121 125
122 TEST_F(NotificationTest, NoNotifications) 126 TEST_F(NotificationTest, NoNotifications)
123 { 127 {
124 EXPECT_FALSE(PeekNotification()); 128 EXPECT_FALSE(PeekNotification());
125 } 129 }
126 130
127 TEST_F(NotificationMockWebRequestTest, DISABLED_SingleNotification) 131 TEST_F(NotificationMockWebRequestTest, SingleNotification)
128 { 132 {
129 AdblockPlus::Sleep(5000/*msec*/); // it's a hack 133 auto& filterEngine = platform->GetFilterEngine();
130 EXPECT_TRUE(isNotificationCallbackCalled); 134 static_cast<ManualTimer&>(platform->GetTimer()).runPending();
135 filterEngine.ShowNextNotification();
136 EXPECT_TRUE(sync.WaitFor(std::chrono::seconds(4)));
131 } 137 }
132 138
133 TEST_F(NotificationTest, AddNotification) 139 TEST_F(NotificationTest, AddNotification)
134 { 140 {
135 AddNotification("{" 141 AddNotification("{"
136 "type: 'critical'," 142 "type: 'critical',"
137 "title: 'testTitle'," 143 "title: 'testTitle',"
138 "message: 'testMessage'," 144 "message: 'testMessage',"
139 "}"); 145 "}");
140 auto notification = PeekNotification(); 146 auto notification = PeekNotification();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 TEST_F(NotificationTest, Links) 194 TEST_F(NotificationTest, Links)
189 { 195 {
190 AddNotification("{ id: 'id', links: ['link1', 'link2'] }"); 196 AddNotification("{ id: 'id', links: ['link1', 'link2'] }");
191 auto notification = PeekNotification(); 197 auto notification = PeekNotification();
192 ASSERT_TRUE(notification); 198 ASSERT_TRUE(notification);
193 std::vector<std::string> notificationLinks = notification->GetLinks(); 199 std::vector<std::string> notificationLinks = notification->GetLinks();
194 ASSERT_EQ(2u, notificationLinks.size()); 200 ASSERT_EQ(2u, notificationLinks.size());
195 EXPECT_EQ("link1", notificationLinks[0]); 201 EXPECT_EQ("link1", notificationLinks[0]);
196 EXPECT_EQ("link2", notificationLinks[1]); 202 EXPECT_EQ("link2", notificationLinks[1]);
197 } 203 }
OLDNEW
« no previous file with comments | « test/BaseJsTest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld