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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 | 22 // This define enables NotificationMockWebRequestTest but to run it |
23 // one need to set INITIAL_DELAY to about 2000 msec in notification.js. | 23 // one need to set INITIAL_DELAY to about 2000 msec in notification.js. |
24 //#define NotificationMockWebRequestTest_ENABLED | 24 //#define NotificationMockWebRequestTest_ENABLED |
25 | 25 |
26 namespace | 26 namespace |
27 { | 27 { |
28 typedef std::shared_ptr<FilterEngine> FilterEnginePtr; | 28 typedef std::shared_ptr<FilterEngine> FilterEnginePtr; |
29 | 29 |
30 class NotificationTest : public ::testing::Test | 30 class NotificationTest : public BaseJsTest |
31 { | 31 { |
32 protected: | 32 protected: |
33 std::unique_ptr<Platform> platform; | |
34 FilterEnginePtr filterEngine; | 33 FilterEnginePtr filterEngine; |
35 void SetUp() | 34 void SetUp() |
36 { | 35 { |
37 LazyFileSystem* fileSystem; | 36 LazyFileSystem* fileSystem; |
38 ThrowingPlatformCreationParameters platformParams; | 37 ThrowingPlatformCreationParameters platformParams; |
39 platformParams.timer.reset(new NoopTimer()); | 38 platformParams.timer.reset(new NoopTimer()); |
40 platformParams.fileSystem.reset(fileSystem = new LazyFileSystem()); | 39 platformParams.fileSystem.reset(fileSystem = new LazyFileSystem()); |
41 platformParams.webRequest.reset(new NoopWebRequest()); | 40 platformParams.webRequest.reset(new NoopWebRequest()); |
42 platform.reset(new Platform(std::move(platformParams))); | 41 platform.reset(new Platform(std::move(platformParams))); |
43 filterEngine = CreateFilterEngine(*fileSystem, *platform); | 42 filterEngine = CreateFilterEngine(*fileSystem, *platform); |
44 } | 43 } |
45 | 44 |
46 void AddNotification(const std::string& notification) | 45 void AddNotification(const std::string& notification) |
47 { | 46 { |
48 filterEngine->GetJsEngine()->Evaluate("(function()" | 47 GetJsEngine().Evaluate("(function()" |
49 "{" | 48 "{" |
50 "require('notification').Notification.addNotification(" + notification +
");" | 49 "require('notification').Notification.addNotification(" + notification +
");" |
51 "})();"); | 50 "})();"); |
52 } | 51 } |
53 | 52 |
54 std::unique_ptr<Notification> PeekNotification(const std::string& url = std:
:string()) | 53 std::unique_ptr<Notification> PeekNotification(const std::string& url = std:
:string()) |
55 { | 54 { |
56 std::unique_ptr<Notification> retValue; | 55 std::unique_ptr<Notification> retValue; |
57 filterEngine->SetShowNotificationCallback( | 56 filterEngine->SetShowNotificationCallback( |
58 [&retValue](Notification&& notification) { | 57 [&retValue](Notification&& notification) { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 TEST_F(NotificationTest, Links) | 196 TEST_F(NotificationTest, Links) |
198 { | 197 { |
199 AddNotification("{ id: 'id', links: ['link1', 'link2'] }"); | 198 AddNotification("{ id: 'id', links: ['link1', 'link2'] }"); |
200 auto notification = PeekNotification(); | 199 auto notification = PeekNotification(); |
201 ASSERT_TRUE(notification); | 200 ASSERT_TRUE(notification); |
202 std::vector<std::string> notificationLinks = notification->GetLinks(); | 201 std::vector<std::string> notificationLinks = notification->GetLinks(); |
203 ASSERT_EQ(2u, notificationLinks.size()); | 202 ASSERT_EQ(2u, notificationLinks.size()); |
204 EXPECT_EQ("link1", notificationLinks[0]); | 203 EXPECT_EQ("link1", notificationLinks[0]); |
205 EXPECT_EQ("link2", notificationLinks[1]); | 204 EXPECT_EQ("link2", notificationLinks[1]); |
206 } | 205 } |
OLD | NEW |