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

Unified Diff: test/Notification.cpp

Issue 29317074: Issue 2693 - Update adblockplus dependency (Closed)
Patch Set: fix according to comments and update revision Created June 26, 2015, 2:19 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/FilterEngine.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
diff --git a/test/Notification.cpp b/test/Notification.cpp
index 490881f07b698e7f02d3eb849c2143d08fe7f508..6997be7cc2b28580515dbd56beb7fbc777ccef3d 100644
--- a/test/Notification.cpp
+++ b/test/Notification.cpp
@@ -47,6 +47,23 @@ namespace
"require('notification').Notification.addNotification(" + notification + ");"
"})();");
}
+
+ NotificationPtr PeekNotification(const std::string& url = std::string())
+ {
+ NotificationPtr retValue;
+ filterEngine->SetShowNotificationCallback(std::tr1::bind(
+ &NotificationTest::NotificationAvailableCallback,
+ std::tr1::placeholders::_1, std::tr1::ref(retValue)));
+ filterEngine->ShowNextNotification(url);
+ filterEngine->RemoveShowNotificationCallback();
+ return retValue;
+ }
+
+ static void NotificationAvailableCallback(const NotificationPtr& src, NotificationPtr& dst)
+ {
+ EXPECT_TRUE(src);
+ dst = src;
+ }
};
class MockWebRequest : public WebRequest
@@ -103,22 +120,24 @@ namespace
TEST_F(NotificationTest, NoNotifications)
{
- NotificationPtr notification = filterEngine->GetNextNotificationToShow();
- EXPECT_EQ(NULL, notification.get());
+ EXPECT_FALSE(PeekNotification());
}
#ifdef NotificationMockWebRequestTest_ENABLED
TEST_F(NotificationMockWebRequestTest, SingleNotification)
{
+ bool isNotificationCallbackCalled = false;
+ filterEngine->SetNotificationAvailableCallback([&isNotificationCallbackCalled](const NotificationPtr& notification)
Felix Dahlke 2015/06/30 19:45:32 Still C++03 here :)
sergei 2015/07/01 11:46:09 Done.
+ {
+ isNotificationCallbackCalled = true;
+ ASSERT_TRUE(notification);
+ EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notification->GetType());
+ EXPECT_EQ("Title", notification->GetTitle());
+ EXPECT_EQ("message", notification->GetMessageString());
+ notification->MarkAsShown();
+ });
AdblockPlus::Sleep(5000/*msec*/); // it's a hack
- NotificationPtr notification = filterEngine->GetNextNotificationToShow();
- // try another one immediately to avoid queuing of the next notification by
- // the timer.
- EXPECT_EQ(NULL, filterEngine->GetNextNotificationToShow().get());
- ASSERT_TRUE(notification);
- EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notification->GetType());
- EXPECT_EQ("Title", notification->GetTitle());
- EXPECT_EQ("message", notification->GetMessageString());
+ EXPECT_TRUE(isNotificationCallbackCalled);
}
#endif
@@ -129,7 +148,7 @@ TEST_F(NotificationTest, AddNotification)
"title: 'testTitle',"
"message: 'testMessage',"
"}");
- NotificationPtr notification = filterEngine->GetNextNotificationToShow();
+ NotificationPtr notification = PeekNotification();
ASSERT_TRUE(notification);
EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_CRITICAL, notification->GetType());
EXPECT_EQ("testTitle", notification->GetTitle());
@@ -140,21 +159,21 @@ TEST_F(NotificationTest, FilterByUrl)
{
AddNotification("{ id: 'no-filter', type: 'critical' }");
AddNotification("{ id: 'www.com', type: 'information',"
- "urlFilters:['http://www.com']"
+ "urlFilters:['||www.com$document']"
"}");
AddNotification("{ id: 'www.de', type: 'question',"
- "urlFilters:['http://www.de']"
+ "urlFilters:['||www.de$document']"
"}");
- NotificationPtr notification = filterEngine->GetNextNotificationToShow();
+ NotificationPtr notification = PeekNotification();
ASSERT_TRUE(notification);
EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_CRITICAL, notification->GetType());
- notification = filterEngine->GetNextNotificationToShow("http://www.de");
+ notification = PeekNotification("http://www.de");
ASSERT_TRUE(notification);
EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_QUESTION, notification->GetType());
- notification = filterEngine->GetNextNotificationToShow("http://www.com");
+ notification = PeekNotification("http://www.com");
ASSERT_TRUE(notification);
EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notification->GetType());
}
@@ -162,30 +181,28 @@ TEST_F(NotificationTest, FilterByUrl)
TEST_F(NotificationTest, MarkAsShown)
{
AddNotification("{ id: 'id', type: 'question' }");
- NotificationPtr notification = filterEngine->GetNextNotificationToShow();
- EXPECT_TRUE(notification);
- notification = filterEngine->GetNextNotificationToShow();
+ EXPECT_TRUE(PeekNotification());
+ NotificationPtr notification = PeekNotification();
ASSERT_TRUE(notification);
notification->MarkAsShown();
- EXPECT_EQ(NULL, filterEngine->GetNextNotificationToShow().get());
+ EXPECT_FALSE(PeekNotification());
}
TEST_F(NotificationTest, NoLinks)
{
AddNotification("{ id: 'id'}");
- NotificationPtr notification = filterEngine->GetNextNotificationToShow();
+ NotificationPtr notification = PeekNotification();
ASSERT_TRUE(notification);
- std::vector<std::string> notificationLinks = notification->GetLinks();
- EXPECT_EQ(0, notificationLinks.size());
+ EXPECT_EQ(0, notification->GetLinks().size());
}
TEST_F(NotificationTest, Links)
{
AddNotification("{ id: 'id', links: ['link1', 'link2'] }");
- NotificationPtr notification = filterEngine->GetNextNotificationToShow();
+ NotificationPtr notification = PeekNotification();
ASSERT_TRUE(notification);
std::vector<std::string> notificationLinks = notification->GetLinks();
ASSERT_EQ(2, notificationLinks.size());
EXPECT_EQ("link1", notificationLinks[0]);
EXPECT_EQ("link2", notificationLinks[1]);
-}
+}
Felix Dahlke 2015/06/30 19:45:32 Nit: Was a newline at EOF added here, or removed?
sergei 2015/07/01 11:46:09 I guess it was removed, so I've added '\n' here.
« include/AdblockPlus/FilterEngine.h ('K') | « src/FilterEngine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld