| 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 "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 |
|
sergei
2017/08/23 18:00:12
Could you please also remove this define and move
hub
2017/08/23 19:21:56
Done.
| |
| 25 | 25 |
| 26 namespace | 26 namespace |
| 27 { | 27 { |
| 28 class NotificationTest : public BaseJsTest | 28 class NotificationTest : public BaseJsTest |
| 29 { | 29 { |
| 30 protected: | 30 protected: |
| 31 void SetUp() | 31 void SetUp() |
| 32 { | 32 { |
| 33 LazyFileSystem* fileSystem; | 33 LazyFileSystem* fileSystem; |
| 34 ThrowingPlatformCreationParameters platformParams; | 34 ThrowingPlatformCreationParameters platformParams; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 return; | 77 return; |
| 78 } | 78 } |
| 79 ServerResponse serverResponse; | 79 ServerResponse serverResponse; |
| 80 serverResponse.status = IWebRequest::NS_OK; | 80 serverResponse.status = IWebRequest::NS_OK; |
| 81 serverResponse.responseStatus = 200; | 81 serverResponse.responseStatus = 200; |
| 82 serverResponse.responseText = responseText; | 82 serverResponse.responseText = responseText; |
| 83 getCallback(serverResponse); | 83 getCallback(serverResponse); |
| 84 } | 84 } |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 #ifdef NotificationMockWebRequestTest_ENABLED | |
| 88 class NotificationMockWebRequestTest : public BaseJsTest | 87 class NotificationMockWebRequestTest : public BaseJsTest |
| 89 { | 88 { |
| 90 protected: | 89 protected: |
| 91 bool isNotificationCallbackCalled; | 90 bool isNotificationCallbackCalled; |
| 92 void SetUp() | 91 void SetUp() |
| 93 { | 92 { |
| 94 BaseJsTest::SetUp(); | 93 BaseJsTest::SetUp(); |
|
sergei
2017/08/23 18:00:12
Since platform is created below could you please r
hub
2017/08/23 19:21:56
Done.
| |
| 95 isNotificationCallbackCalled = false; | 94 isNotificationCallbackCalled = false; |
| 96 jsEngine->SetFileSystem( | |
| 97 std::shared_ptr<LazyFileSystem>(new LazyFileSystem())); | |
| 98 const char* responseJsonText = "{" | 95 const char* responseJsonText = "{" |
| 99 "\"notifications\": [{" | 96 "\"notifications\": [{" |
| 100 "\"id\": \"some id\"," | 97 "\"id\": \"some id\"," |
| 101 "\"type\": \"information\"," | 98 "\"type\": \"information\"," |
| 102 "\"message\": {" | 99 "\"message\": {" |
| 103 "\"en-US\": \"message\"" | 100 "\"en-US\": \"message\"" |
| 104 "}," | 101 "}," |
| 105 "\"title\": \"Title\"" | 102 "\"title\": \"Title\"" |
| 106 "}]" | 103 "}]" |
| 107 "}"; | 104 "}"; |
| 108 jsEngine->SetWebRequest(std::shared_ptr<MockWebRequest>( | 105 |
| 109 new MockWebRequest(responseJsonText))); | 106 ThrowingPlatformCreationParameters platformParams; |
| 110 jsEngine->SetLogSystem(LogSystemPtr(new DefaultLogSystem())); | 107 platformParams.fileSystem.reset(new LazyFileSystem()); |
| 111 filterEngine = FilterEngine::Create(jsEngine); | 108 platformParams.webRequest.reset(new MockWebRequest(responseJsonText)); |
| 112 filterEngine->SetShowNotificationCallback( | 109 platform.reset(new Platform(std::move(platformParams))); |
| 110 | |
| 111 auto& filterEngine = platform->GetFilterEngine(); | |
| 112 filterEngine.SetShowNotificationCallback( | |
| 113 [this](Notification&& notification) { | 113 [this](Notification&& notification) { |
| 114 isNotificationCallbackCalled = true; | 114 isNotificationCallbackCalled = true; |
| 115 EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notificatio n.GetType()); | 115 EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notificatio n.GetType()); |
| 116 EXPECT_EQ("Title", notification.GetTexts().title); | 116 EXPECT_EQ("Title", notification.GetTexts().title); |
| 117 EXPECT_EQ("message", notification.GetTexts().message); | 117 EXPECT_EQ("message", notification.GetTexts().message); |
| 118 notification.MarkAsShown(); | 118 notification.MarkAsShown(); |
| 119 }); | 119 }); |
| 120 } | 120 } |
| 121 }; | 121 }; |
| 122 #endif | |
| 123 } | 122 } |
| 124 | 123 |
| 125 TEST_F(NotificationTest, NoNotifications) | 124 TEST_F(NotificationTest, NoNotifications) |
| 126 { | 125 { |
| 127 EXPECT_FALSE(PeekNotification()); | 126 EXPECT_FALSE(PeekNotification()); |
| 128 } | 127 } |
| 129 | 128 |
| 130 #ifdef NotificationMockWebRequestTest_ENABLED | 129 TEST_F(NotificationMockWebRequestTest, DISABLED_SingleNotification) |
| 131 TEST_F(NotificationMockWebRequestTest, SingleNotification) | |
| 132 { | 130 { |
| 133 AdblockPlus::Sleep(5000/*msec*/); // it's a hack | 131 AdblockPlus::Sleep(5000/*msec*/); // it's a hack |
| 134 EXPECT_TRUE(isNotificationCallbackCalled); | 132 EXPECT_TRUE(isNotificationCallbackCalled); |
| 135 } | 133 } |
| 136 #endif | |
| 137 | 134 |
| 138 TEST_F(NotificationTest, AddNotification) | 135 TEST_F(NotificationTest, AddNotification) |
| 139 { | 136 { |
| 140 AddNotification("{" | 137 AddNotification("{" |
| 141 "type: 'critical'," | 138 "type: 'critical'," |
| 142 "title: 'testTitle'," | 139 "title: 'testTitle'," |
| 143 "message: 'testMessage'," | 140 "message: 'testMessage'," |
| 144 "}"); | 141 "}"); |
| 145 auto notification = PeekNotification(); | 142 auto notification = PeekNotification(); |
| 146 ASSERT_TRUE(notification); | 143 ASSERT_TRUE(notification); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 TEST_F(NotificationTest, Links) | 190 TEST_F(NotificationTest, Links) |
| 194 { | 191 { |
| 195 AddNotification("{ id: 'id', links: ['link1', 'link2'] }"); | 192 AddNotification("{ id: 'id', links: ['link1', 'link2'] }"); |
| 196 auto notification = PeekNotification(); | 193 auto notification = PeekNotification(); |
| 197 ASSERT_TRUE(notification); | 194 ASSERT_TRUE(notification); |
| 198 std::vector<std::string> notificationLinks = notification->GetLinks(); | 195 std::vector<std::string> notificationLinks = notification->GetLinks(); |
| 199 ASSERT_EQ(2u, notificationLinks.size()); | 196 ASSERT_EQ(2u, notificationLinks.size()); |
| 200 EXPECT_EQ("link1", notificationLinks[0]); | 197 EXPECT_EQ("link1", notificationLinks[0]); |
| 201 EXPECT_EQ("link2", notificationLinks[1]); | 198 EXPECT_EQ("link2", notificationLinks[1]); |
| 202 } | 199 } |
| OLD | NEW |