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: addressed review comment Created Aug. 23, 2017, 7: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 | « 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.
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 83
84 // To run this test one needs to set INITIAL_DELAY to about 2000 msec
85 // in notification.js.
88 class NotificationMockWebRequestTest : public BaseJsTest 86 class NotificationMockWebRequestTest : public BaseJsTest
89 { 87 {
90 protected: 88 protected:
91 bool isNotificationCallbackCalled; 89 bool isNotificationCallbackCalled;
92 void SetUp() 90 void SetUp()
93 { 91 {
94 BaseJsTest::SetUp();
95 isNotificationCallbackCalled = false; 92 isNotificationCallbackCalled = false;
96 jsEngine->SetFileSystem(
97 std::shared_ptr<LazyFileSystem>(new LazyFileSystem()));
98 const char* responseJsonText = "{" 93 const char* responseJsonText = "{"
99 "\"notifications\": [{" 94 "\"notifications\": [{"
100 "\"id\": \"some id\"," 95 "\"id\": \"some id\","
101 "\"type\": \"information\"," 96 "\"type\": \"information\","
102 "\"message\": {" 97 "\"message\": {"
103 "\"en-US\": \"message\"" 98 "\"en-US\": \"message\""
104 "}," 99 "},"
105 "\"title\": \"Title\"" 100 "\"title\": \"Title\""
106 "}]" 101 "}]"
107 "}"; 102 "}";
108 jsEngine->SetWebRequest(std::shared_ptr<MockWebRequest>( 103
109 new MockWebRequest(responseJsonText))); 104 ThrowingPlatformCreationParameters platformParams;
110 jsEngine->SetLogSystem(LogSystemPtr(new DefaultLogSystem())); 105 platformParams.fileSystem.reset(new LazyFileSystem());
111 filterEngine = FilterEngine::Create(jsEngine); 106 platformParams.webRequest.reset(new MockWebRequest(responseJsonText));
112 filterEngine->SetShowNotificationCallback( 107 platform.reset(new Platform(std::move(platformParams)));
108
109 auto& filterEngine = platform->GetFilterEngine();
110 filterEngine.SetShowNotificationCallback(
113 [this](Notification&& notification) { 111 [this](Notification&& notification) {
114 isNotificationCallbackCalled = true; 112 isNotificationCallbackCalled = true;
115 EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notificatio n.GetType()); 113 EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notificatio n.GetType());
116 EXPECT_EQ("Title", notification.GetTexts().title); 114 EXPECT_EQ("Title", notification.GetTexts().title);
117 EXPECT_EQ("message", notification.GetTexts().message); 115 EXPECT_EQ("message", notification.GetTexts().message);
118 notification.MarkAsShown(); 116 notification.MarkAsShown();
119 }); 117 });
120 } 118 }
121 }; 119 };
122 #endif
123 } 120 }
124 121
125 TEST_F(NotificationTest, NoNotifications) 122 TEST_F(NotificationTest, NoNotifications)
126 { 123 {
127 EXPECT_FALSE(PeekNotification()); 124 EXPECT_FALSE(PeekNotification());
128 } 125 }
129 126
130 #ifdef NotificationMockWebRequestTest_ENABLED 127 TEST_F(NotificationMockWebRequestTest, DISABLED_SingleNotification)
131 TEST_F(NotificationMockWebRequestTest, SingleNotification)
132 { 128 {
133 AdblockPlus::Sleep(5000/*msec*/); // it's a hack 129 AdblockPlus::Sleep(5000/*msec*/); // it's a hack
134 EXPECT_TRUE(isNotificationCallbackCalled); 130 EXPECT_TRUE(isNotificationCallbackCalled);
135 } 131 }
136 #endif
137 132
138 TEST_F(NotificationTest, AddNotification) 133 TEST_F(NotificationTest, AddNotification)
139 { 134 {
140 AddNotification("{" 135 AddNotification("{"
141 "type: 'critical'," 136 "type: 'critical',"
142 "title: 'testTitle'," 137 "title: 'testTitle',"
143 "message: 'testMessage'," 138 "message: 'testMessage',"
144 "}"); 139 "}");
145 auto notification = PeekNotification(); 140 auto notification = PeekNotification();
146 ASSERT_TRUE(notification); 141 ASSERT_TRUE(notification);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 TEST_F(NotificationTest, Links) 188 TEST_F(NotificationTest, Links)
194 { 189 {
195 AddNotification("{ id: 'id', links: ['link1', 'link2'] }"); 190 AddNotification("{ id: 'id', links: ['link1', 'link2'] }");
196 auto notification = PeekNotification(); 191 auto notification = PeekNotification();
197 ASSERT_TRUE(notification); 192 ASSERT_TRUE(notification);
198 std::vector<std::string> notificationLinks = notification->GetLinks(); 193 std::vector<std::string> notificationLinks = notification->GetLinks();
199 ASSERT_EQ(2u, notificationLinks.size()); 194 ASSERT_EQ(2u, notificationLinks.size());
200 EXPECT_EQ("link1", notificationLinks[0]); 195 EXPECT_EQ("link1", notificationLinks[0]);
201 EXPECT_EQ("link2", notificationLinks[1]); 196 EXPECT_EQ("link2", notificationLinks[1]);
202 } 197 }
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