Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/Notification.cpp

Issue 29419629: Issue 5164 - Remove NotificationPtr (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Created April 21, 2017, 2:08 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« include/AdblockPlus/Notification.h ('K') | « src/FilterEngine.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/Notification.cpp
===================================================================
--- a/test/Notification.cpp
+++ b/test/Notification.cpp
@@ -43,30 +43,30 @@
void AddNotification(const std::string& notification)
{
jsEngine->Evaluate("(function()"
"{"
"require('notification').Notification.addNotification(" + notification + ");"
"})();");
}
- NotificationPtr PeekNotification(const std::string& url = std::string())
+ Notification PeekNotification(const std::string& url = std::string())
sergei 2017/04/21 15:30:33 I think it would be better to use std::unique_ptr
hub 2017/04/21 16:29:31 and it would solve the other problem with the cons
{
- NotificationPtr retValue;
+ Notification retValue(filterEngine->GetJsEngine()->Evaluate("undefined"));
filterEngine->SetShowNotificationCallback(std::bind(
&NotificationTest::NotificationAvailableCallback,
std::placeholders::_1, std::ref(retValue)));
sergei 2017/04/21 15:30:33 JIC, now we may use lambda functions
hub 2017/04/21 16:29:31 ok will change that while I'm at it.
filterEngine->ShowNextNotification(url);
filterEngine->RemoveShowNotificationCallback();
return retValue;
}
- static void NotificationAvailableCallback(const NotificationPtr& src, NotificationPtr& dst)
+ static void NotificationAvailableCallback(const Notification& src, Notification& dst)
{
- EXPECT_TRUE(src);
+ EXPECT_FALSE(src.IsUndefined());
dst = src;
}
};
class MockWebRequest : public WebRequest
{
public:
std::string responseText;
@@ -115,32 +115,32 @@
new MockWebRequest(responseJsonText)));
jsEngine->SetLogSystem(LogSystemPtr(new DefaultLogSystem()));
filterEngine.reset(new FilterEngine(jsEngine));
filterEngine->SetShowNotificationCallback(
std::bind(&NotificationMockWebRequestTest::OnNotification,
this, std::placeholders::_1));
}
- void OnNotification(const NotificationPtr& notification)
+ void OnNotification(const Notification& notification)
{
isNotificationCallbackCalled = true;
ASSERT_TRUE(notification);
EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notification->GetType());
EXPECT_EQ("Title", notification->GetTexts().title);
sergei 2017/04/21 15:30:33 This is not compilable. In order to run this test
hub 2017/04/21 16:29:32 I realize this code doesn't get built. Will fix th
EXPECT_EQ("message", notification->GetTexts().message);
notification->MarkAsShown();
}
};
#endif
}
TEST_F(NotificationTest, NoNotifications)
{
- EXPECT_FALSE(PeekNotification());
+ EXPECT_TRUE(PeekNotification().IsUndefined());
}
#ifdef NotificationMockWebRequestTest_ENABLED
TEST_F(NotificationMockWebRequestTest, SingleNotification)
{
AdblockPlus::Sleep(5000/*msec*/); // it's a hack
EXPECT_TRUE(isNotificationCallbackCalled);
}
@@ -148,66 +148,65 @@
TEST_F(NotificationTest, AddNotification)
{
AddNotification("{"
"type: 'critical',"
"title: 'testTitle',"
"message: 'testMessage',"
"}");
- NotificationPtr notification = PeekNotification();
- ASSERT_TRUE(notification);
- EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_CRITICAL, notification->GetType());
- EXPECT_EQ("testTitle", notification->GetTexts().title);
- EXPECT_EQ("testMessage", notification->GetTexts().message);
+ Notification notification = PeekNotification();
+ EXPECT_FALSE(notification.IsUndefined());
+ EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_CRITICAL, notification.GetType());
+ EXPECT_EQ("testTitle", notification.GetTexts().title);
+ EXPECT_EQ("testMessage", notification.GetTexts().message);
}
TEST_F(NotificationTest, FilterByUrl)
{
AddNotification("{ id: 'no-filter', type: 'critical' }");
AddNotification("{ id: 'www.com', type: 'information',"
"urlFilters:['||www.com$document']"
"}");
AddNotification("{ id: 'www.de', type: 'question',"
"urlFilters:['||www.de$document']"
"}");
- NotificationPtr notification = PeekNotification();
- ASSERT_TRUE(notification);
- EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_CRITICAL, notification->GetType());
+ Notification notification = PeekNotification();
+ EXPECT_FALSE(notification.IsUndefined());
+ EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_CRITICAL, notification.GetType());
notification = PeekNotification("http://www.de");
- ASSERT_TRUE(notification);
- EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_QUESTION, notification->GetType());
+ EXPECT_FALSE(notification.IsUndefined());
+ EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_QUESTION, notification.GetType());
notification = PeekNotification("http://www.com");
- ASSERT_TRUE(notification);
- EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notification->GetType());
+ EXPECT_FALSE(notification.IsUndefined());
+ EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notification.GetType());
}
TEST_F(NotificationTest, MarkAsShown)
{
AddNotification("{ id: 'id', type: 'question' }");
- EXPECT_TRUE(PeekNotification());
- NotificationPtr notification = PeekNotification();
- ASSERT_TRUE(notification);
- notification->MarkAsShown();
- EXPECT_FALSE(PeekNotification());
+ EXPECT_FALSE(PeekNotification().IsUndefined());
+ Notification notification = PeekNotification();
+ notification.MarkAsShown();
+ EXPECT_TRUE(PeekNotification().IsUndefined());
}
TEST_F(NotificationTest, NoLinks)
{
AddNotification("{ id: 'id'}");
- NotificationPtr notification = PeekNotification();
- ASSERT_TRUE(notification);
- EXPECT_EQ(0u, notification->GetLinks().size());
+ Notification notification = PeekNotification();
+ EXPECT_FALSE(notification.IsUndefined());
+ EXPECT_EQ(0u, notification.GetLinks().size());
}
TEST_F(NotificationTest, Links)
{
AddNotification("{ id: 'id', links: ['link1', 'link2'] }");
- NotificationPtr notification = PeekNotification();
- ASSERT_TRUE(notification);
- std::vector<std::string> notificationLinks = notification->GetLinks();
+ Notification notification = PeekNotification();
+ EXPECT_FALSE(notification.IsUndefined());
+ std::vector<std::string> notificationLinks = notification.GetLinks();
ASSERT_EQ(2u, notificationLinks.size());
EXPECT_EQ("link1", notificationLinks[0]);
EXPECT_EQ("link2", notificationLinks[1]);
}
« include/AdblockPlus/Notification.h ('K') | « src/FilterEngine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld