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

Side by Side Diff: test/Notification.cpp

Issue 29525558: Issue 5506 - Fix notification test (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Review comments addressed. Created Aug. 23, 2017, 7:21 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 | « no previous file | 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 "BaseJsTest.h" 18 #include "BaseJsTest.h"
19 19
20 using namespace AdblockPlus; 20 using namespace AdblockPlus;
21 21
22 // This define enables NotificationMockWebRequestTest but to run it
23 // one need to set INITIAL_DELAY to about 2000 msec in notification.js.
sergei 2017/08/23 19:27:22 What about moving of the comment, it's essential t
hub 2017/08/23 19:54:05 Oops. Done.
24 //#define NotificationMockWebRequestTest_ENABLED
25
26 namespace 22 namespace
27 { 23 {
28 class NotificationTest : public BaseJsTest 24 class NotificationTest : public BaseJsTest
29 { 25 {
30 protected: 26 protected:
31 void SetUp() 27 void SetUp()
32 { 28 {
33 LazyFileSystem* fileSystem; 29 LazyFileSystem* fileSystem;
34 ThrowingPlatformCreationParameters platformParams; 30 ThrowingPlatformCreationParameters platformParams;
35 platformParams.timer.reset(new NoopTimer()); 31 platformParams.timer.reset(new NoopTimer());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 return; 73 return;
78 } 74 }
79 ServerResponse serverResponse; 75 ServerResponse serverResponse;
80 serverResponse.status = IWebRequest::NS_OK; 76 serverResponse.status = IWebRequest::NS_OK;
81 serverResponse.responseStatus = 200; 77 serverResponse.responseStatus = 200;
82 serverResponse.responseText = responseText; 78 serverResponse.responseText = responseText;
83 getCallback(serverResponse); 79 getCallback(serverResponse);
84 } 80 }
85 }; 81 };
86 82
87 #ifdef NotificationMockWebRequestTest_ENABLED
88 class NotificationMockWebRequestTest : public BaseJsTest 83 class NotificationMockWebRequestTest : public BaseJsTest
89 { 84 {
90 protected: 85 protected:
91 bool isNotificationCallbackCalled; 86 bool isNotificationCallbackCalled;
92 void SetUp() 87 void SetUp()
93 { 88 {
94 BaseJsTest::SetUp();
95 isNotificationCallbackCalled = false; 89 isNotificationCallbackCalled = false;
96 jsEngine->SetFileSystem(
97 std::shared_ptr<LazyFileSystem>(new LazyFileSystem()));
98 const char* responseJsonText = "{" 90 const char* responseJsonText = "{"
99 "\"notifications\": [{" 91 "\"notifications\": [{"
100 "\"id\": \"some id\"," 92 "\"id\": \"some id\","
101 "\"type\": \"information\"," 93 "\"type\": \"information\","
102 "\"message\": {" 94 "\"message\": {"
103 "\"en-US\": \"message\"" 95 "\"en-US\": \"message\""
104 "}," 96 "},"
105 "\"title\": \"Title\"" 97 "\"title\": \"Title\""
106 "}]" 98 "}]"
107 "}"; 99 "}";
108 jsEngine->SetWebRequest(std::shared_ptr<MockWebRequest>( 100
109 new MockWebRequest(responseJsonText))); 101 ThrowingPlatformCreationParameters platformParams;
110 jsEngine->SetLogSystem(LogSystemPtr(new DefaultLogSystem())); 102 platformParams.fileSystem.reset(new LazyFileSystem());
111 filterEngine = FilterEngine::Create(jsEngine); 103 platformParams.webRequest.reset(new MockWebRequest(responseJsonText));
112 filterEngine->SetShowNotificationCallback( 104 platform.reset(new Platform(std::move(platformParams)));
105
106 auto& filterEngine = platform->GetFilterEngine();
107 filterEngine.SetShowNotificationCallback(
113 [this](Notification&& notification) { 108 [this](Notification&& notification) {
114 isNotificationCallbackCalled = true; 109 isNotificationCallbackCalled = true;
115 EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notificatio n.GetType()); 110 EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notificatio n.GetType());
116 EXPECT_EQ("Title", notification.GetTexts().title); 111 EXPECT_EQ("Title", notification.GetTexts().title);
117 EXPECT_EQ("message", notification.GetTexts().message); 112 EXPECT_EQ("message", notification.GetTexts().message);
118 notification.MarkAsShown(); 113 notification.MarkAsShown();
119 }); 114 });
120 } 115 }
121 }; 116 };
122 #endif
123 } 117 }
124 118
125 TEST_F(NotificationTest, NoNotifications) 119 TEST_F(NotificationTest, NoNotifications)
126 { 120 {
127 EXPECT_FALSE(PeekNotification()); 121 EXPECT_FALSE(PeekNotification());
128 } 122 }
129 123
130 #ifdef NotificationMockWebRequestTest_ENABLED 124 TEST_F(NotificationMockWebRequestTest, DISABLED_SingleNotification)
131 TEST_F(NotificationMockWebRequestTest, SingleNotification)
132 { 125 {
133 AdblockPlus::Sleep(5000/*msec*/); // it's a hack 126 AdblockPlus::Sleep(5000/*msec*/); // it's a hack
134 EXPECT_TRUE(isNotificationCallbackCalled); 127 EXPECT_TRUE(isNotificationCallbackCalled);
135 } 128 }
136 #endif
137 129
138 TEST_F(NotificationTest, AddNotification) 130 TEST_F(NotificationTest, AddNotification)
139 { 131 {
140 AddNotification("{" 132 AddNotification("{"
141 "type: 'critical'," 133 "type: 'critical',"
142 "title: 'testTitle'," 134 "title: 'testTitle',"
143 "message: 'testMessage'," 135 "message: 'testMessage',"
144 "}"); 136 "}");
145 auto notification = PeekNotification(); 137 auto notification = PeekNotification();
146 ASSERT_TRUE(notification); 138 ASSERT_TRUE(notification);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 TEST_F(NotificationTest, Links) 185 TEST_F(NotificationTest, Links)
194 { 186 {
195 AddNotification("{ id: 'id', links: ['link1', 'link2'] }"); 187 AddNotification("{ id: 'id', links: ['link1', 'link2'] }");
196 auto notification = PeekNotification(); 188 auto notification = PeekNotification();
197 ASSERT_TRUE(notification); 189 ASSERT_TRUE(notification);
198 std::vector<std::string> notificationLinks = notification->GetLinks(); 190 std::vector<std::string> notificationLinks = notification->GetLinks();
199 ASSERT_EQ(2u, notificationLinks.size()); 191 ASSERT_EQ(2u, notificationLinks.size());
200 EXPECT_EQ("link1", notificationLinks[0]); 192 EXPECT_EQ("link1", notificationLinks[0]);
201 EXPECT_EQ("link2", notificationLinks[1]); 193 EXPECT_EQ("link2", notificationLinks[1]);
202 } 194 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld