| Index: test/Notification.cpp |
| =================================================================== |
| --- a/test/Notification.cpp |
| +++ b/test/Notification.cpp |
| @@ -75,42 +75,45 @@ |
| ServerResponse serverResponse; |
| serverResponse.status = IWebRequest::NS_OK; |
| serverResponse.responseStatus = 200; |
| serverResponse.responseText = responseText; |
| getCallback(serverResponse); |
| } |
| }; |
| - |
| // To run this test one needs to set INITIAL_DELAY to about 2000 msec |
| // in notification.js. |
| class NotificationMockWebRequestTest : public BaseJsTest |
| { |
| protected: |
| bool isNotificationCallbackCalled; |
| + DelayedTimer::SharedTasks timerTasks; |
| void SetUp() |
| { |
| isNotificationCallbackCalled = false; |
| const char* responseJsonText = "{" |
| "\"notifications\": [{" |
| "\"id\": \"some id\"," |
| "\"type\": \"information\"," |
| "\"message\": {" |
| "\"en-US\": \"message\"" |
| "}," |
| "\"title\": \"Title\"" |
| "}]" |
| "}"; |
| + LazyFileSystem* fileSystem; |
| ThrowingPlatformCreationParameters platformParams; |
| - platformParams.fileSystem.reset(new LazyFileSystem()); |
| + platformParams.timer = DelayedTimer::New(timerTasks); |
| + platformParams.fileSystem.reset(fileSystem = new LazyFileSystem()); |
| platformParams.webRequest.reset(new MockWebRequest(responseJsonText)); |
| platform.reset(new Platform(std::move(platformParams))); |
| + CreateFilterEngine(*fileSystem, *platform); |
| auto& filterEngine = platform->GetFilterEngine(); |
| filterEngine.SetShowNotificationCallback( |
| [this](Notification&& notification) { |
| isNotificationCallbackCalled = true; |
| EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notification.GetType()); |
| EXPECT_EQ("Title", notification.GetTexts().title); |
| EXPECT_EQ("message", notification.GetTexts().message); |
| notification.MarkAsShown(); |
| @@ -119,19 +122,25 @@ |
| }; |
| } |
| TEST_F(NotificationTest, NoNotifications) |
| { |
| EXPECT_FALSE(PeekNotification()); |
| } |
| -TEST_F(NotificationMockWebRequestTest, DISABLED_SingleNotification) |
| +TEST_F(NotificationMockWebRequestTest, SingleNotification) |
| { |
| - AdblockPlus::Sleep(5000/*msec*/); // it's a hack |
| + auto& filterEngine = platform->GetFilterEngine(); |
| + auto ii = timerTasks->begin(); |
| + while(!isNotificationCallbackCalled && ii != timerTasks->end()) { |
| + ii->callback(); |
| + ii = timerTasks->erase(ii); |
| + filterEngine.ShowNextNotification(); |
| + } |
| EXPECT_TRUE(isNotificationCallbackCalled); |
| } |
| TEST_F(NotificationTest, AddNotification) |
| { |
| AddNotification("{" |
| "type: 'critical'," |
| "title: 'testTitle'," |