Left: | ||
Right: |
OLD | NEW |
---|---|
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> | |
18 #include "BaseJsTest.h" | 20 #include "BaseJsTest.h" |
21 #include "../src/DefaultTimer.h" | |
sergei
2017/09/12 09:22:48
It seems these headers are not required.
hub
2017/09/12 12:59:09
Done.
| |
19 | 22 |
20 using namespace AdblockPlus; | 23 using namespace AdblockPlus; |
21 | 24 |
22 namespace | 25 namespace |
23 { | 26 { |
24 class NotificationTest : public BaseJsTest | 27 class NotificationTest : public BaseJsTest |
25 { | 28 { |
26 protected: | 29 protected: |
27 void SetUp() | 30 void SetUp() |
28 { | 31 { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 return; | 76 return; |
74 } | 77 } |
75 ServerResponse serverResponse; | 78 ServerResponse serverResponse; |
76 serverResponse.status = IWebRequest::NS_OK; | 79 serverResponse.status = IWebRequest::NS_OK; |
77 serverResponse.responseStatus = 200; | 80 serverResponse.responseStatus = 200; |
78 serverResponse.responseText = responseText; | 81 serverResponse.responseText = responseText; |
79 getCallback(serverResponse); | 82 getCallback(serverResponse); |
80 } | 83 } |
81 }; | 84 }; |
82 | 85 |
83 | |
84 // To run this test one needs to set INITIAL_DELAY to about 2000 msec | 86 // To run this test one needs to set INITIAL_DELAY to about 2000 msec |
85 // in notification.js. | 87 // in notification.js. |
86 class NotificationMockWebRequestTest : public BaseJsTest | 88 class NotificationMockWebRequestTest : public BaseJsTest |
87 { | 89 { |
88 protected: | 90 protected: |
89 bool isNotificationCallbackCalled; | 91 AdblockPlus::Sync sync; |
sergei
2017/09/12 09:22:48
It seems sync is not needed.
hub
2017/09/12 12:59:09
yes it is. Line 112 and line 135
sergei
2017/09/12 13:34:09
There are no other threads, so sync is not needed,
hub
2017/09/12 15:51:10
Done.
| |
90 void SetUp() | 92 void SetUp() |
91 { | 93 { |
92 isNotificationCallbackCalled = false; | |
93 const char* responseJsonText = "{" | 94 const char* responseJsonText = "{" |
94 "\"notifications\": [{" | 95 "\"notifications\": [{" |
95 "\"id\": \"some id\"," | 96 "\"id\": \"some id\"," |
96 "\"type\": \"information\"," | 97 "\"type\": \"information\"," |
97 "\"message\": {" | 98 "\"message\": {" |
98 "\"en-US\": \"message\"" | 99 "\"en-US\": \"message\"" |
99 "}," | 100 "}," |
100 "\"title\": \"Title\"" | 101 "\"title\": \"Title\"" |
101 "}]" | 102 "}]" |
102 "}"; | 103 "}"; |
103 | 104 |
104 ThrowingPlatformCreationParameters platformParams; | 105 AdblockPlus::Platform::CreationParameters platformParams; |
106 platformParams.logSystem.reset(new AdblockPlus::DefaultLogSystem()); | |
sergei
2017/09/12 09:22:48
What about using of ThrowingLogSystem as earlier?
hub
2017/09/12 12:59:09
Done.
| |
107 platformParams.timer.reset(new ManualTimer()); | |
sergei
2017/09/12 09:22:48
I would recommend to use DelayedTimer and not crea
hub
2017/09/12 12:59:09
DelayedTimer doesn't do what I want. The idea of M
sergei
2017/09/12 13:34:09
I still think that DelayedTimer is better here bec
hub
2017/09/12 15:51:10
I see.
Done.
| |
105 platformParams.fileSystem.reset(new LazyFileSystem()); | 108 platformParams.fileSystem.reset(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 |
109 auto& filterEngine = platform->GetFilterEngine(); | 112 auto& filterEngine = platform->GetFilterEngine(); |
sergei
2017/09/12 09:22:48
I think here is a dead lock, it should be as above
hub
2017/09/12 12:59:08
Done.
| |
110 filterEngine.SetShowNotificationCallback( | 113 filterEngine.SetShowNotificationCallback( |
111 [this](Notification&& notification) { | 114 [this](Notification&& notification) { |
112 isNotificationCallbackCalled = true; | 115 sync.Set(); |
113 EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notificatio n.GetType()); | 116 EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notificatio n.GetType()); |
114 EXPECT_EQ("Title", notification.GetTexts().title); | 117 EXPECT_EQ("Title", notification.GetTexts().title); |
115 EXPECT_EQ("message", notification.GetTexts().message); | 118 EXPECT_EQ("message", notification.GetTexts().message); |
116 notification.MarkAsShown(); | 119 notification.MarkAsShown(); |
117 }); | 120 }); |
118 } | 121 } |
119 }; | 122 }; |
120 } | 123 } |
121 | 124 |
122 TEST_F(NotificationTest, NoNotifications) | 125 TEST_F(NotificationTest, NoNotifications) |
123 { | 126 { |
124 EXPECT_FALSE(PeekNotification()); | 127 EXPECT_FALSE(PeekNotification()); |
125 } | 128 } |
126 | 129 |
127 TEST_F(NotificationMockWebRequestTest, DISABLED_SingleNotification) | 130 TEST_F(NotificationMockWebRequestTest, SingleNotification) |
128 { | 131 { |
129 AdblockPlus::Sleep(5000/*msec*/); // it's a hack | 132 auto& filterEngine = platform->GetFilterEngine(); |
130 EXPECT_TRUE(isNotificationCallbackCalled); | 133 static_cast<ManualTimer&>(platform->GetTimer()).runOne(); |
sergei
2017/09/12 09:22:48
I still think that it would be more reliable to fi
hub
2017/09/12 12:59:08
I changed it to a runPending() which will run all
| |
134 filterEngine.ShowNextNotification(); | |
135 EXPECT_TRUE(sync.WaitFor(std::chrono::seconds(4))); | |
131 } | 136 } |
132 | 137 |
133 TEST_F(NotificationTest, AddNotification) | 138 TEST_F(NotificationTest, AddNotification) |
134 { | 139 { |
135 AddNotification("{" | 140 AddNotification("{" |
136 "type: 'critical'," | 141 "type: 'critical'," |
137 "title: 'testTitle'," | 142 "title: 'testTitle'," |
138 "message: 'testMessage'," | 143 "message: 'testMessage'," |
139 "}"); | 144 "}"); |
140 auto notification = PeekNotification(); | 145 auto notification = PeekNotification(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 TEST_F(NotificationTest, Links) | 193 TEST_F(NotificationTest, Links) |
189 { | 194 { |
190 AddNotification("{ id: 'id', links: ['link1', 'link2'] }"); | 195 AddNotification("{ id: 'id', links: ['link1', 'link2'] }"); |
191 auto notification = PeekNotification(); | 196 auto notification = PeekNotification(); |
192 ASSERT_TRUE(notification); | 197 ASSERT_TRUE(notification); |
193 std::vector<std::string> notificationLinks = notification->GetLinks(); | 198 std::vector<std::string> notificationLinks = notification->GetLinks(); |
194 ASSERT_EQ(2u, notificationLinks.size()); | 199 ASSERT_EQ(2u, notificationLinks.size()); |
195 EXPECT_EQ("link1", notificationLinks[0]); | 200 EXPECT_EQ("link1", notificationLinks[0]); |
196 EXPECT_EQ("link2", notificationLinks[1]); | 201 EXPECT_EQ("link2", notificationLinks[1]); |
197 } | 202 } |
OLD | NEW |