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: address comments Created July 1, 2015, 11:43 a.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
« no previous file with comments | « 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..3a3d90ef088c0bb063fa90379cb45c2d74122fef 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
@@ -80,6 +97,7 @@ namespace
void SetUp()
{
BaseJsTest::SetUp();
+ isNotificationCallbackCalled = false;
jsEngine->SetFileSystem(
std::tr1::shared_ptr<LazyFileSystem>(new LazyFileSystem()));
const char* responseJsonText = "{"
@@ -96,29 +114,35 @@ namespace
new MockWebRequest(responseJsonText)));
jsEngine->SetLogSystem(LogSystemPtr(new DefaultLogSystem()));
filterEngine.reset(new FilterEngine(jsEngine));
+ filterEngine->SetShowNotificationCallback(
+ std::bind(&NotificationMockWebRequestTest::onNotification,
+ this, std::tr1::placeholders::_1));
}
+
+ void onNotification(const NotificationPtr& notification)
Felix Dahlke 2015/07/02 13:23:13 Nit: Function names should start with an upper cas
+ {
+ 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();
+ }
+ bool isNotificationCallbackCalled;
Felix Dahlke 2015/07/02 13:23:13 Optional nit: Possibly just personal preference, b
};
#endif
}
TEST_F(NotificationTest, NoNotifications)
{
- NotificationPtr notification = filterEngine->GetNextNotificationToShow();
- EXPECT_EQ(NULL, notification.get());
+ EXPECT_FALSE(PeekNotification());
}
#ifdef NotificationMockWebRequestTest_ENABLED
TEST_F(NotificationMockWebRequestTest, SingleNotification)
{
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 +153,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 +164,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,27 +186,25 @@ 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());
« no previous file with comments | « src/FilterEngine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld