| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 serverResponse.responseText = responseText; | 87 serverResponse.responseText = responseText; |
| 88 return serverResponse; | 88 return serverResponse; |
| 89 } | 89 } |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 #ifdef NotificationMockWebRequestTest_ENABLED | 92 #ifdef NotificationMockWebRequestTest_ENABLED |
| 93 class NotificationMockWebRequestTest : public BaseJsTest | 93 class NotificationMockWebRequestTest : public BaseJsTest |
| 94 { | 94 { |
| 95 protected: | 95 protected: |
| 96 FilterEnginePtr filterEngine; | 96 FilterEnginePtr filterEngine; |
| 97 bool isNotificationCallbackCalled; | |
| 97 void SetUp() | 98 void SetUp() |
| 98 { | 99 { |
| 99 BaseJsTest::SetUp(); | 100 BaseJsTest::SetUp(); |
| 101 isNotificationCallbackCalled = false; | |
| 100 jsEngine->SetFileSystem( | 102 jsEngine->SetFileSystem( |
| 101 std::tr1::shared_ptr<LazyFileSystem>(new LazyFileSystem())); | 103 std::tr1::shared_ptr<LazyFileSystem>(new LazyFileSystem())); |
| 102 const char* responseJsonText = "{" | 104 const char* responseJsonText = "{" |
| 103 "\"notifications\": [{" | 105 "\"notifications\": [{" |
| 104 "\"id\": \"some id\"," | 106 "\"id\": \"some id\"," |
| 105 "\"type\": \"information\"," | 107 "\"type\": \"information\"," |
| 106 "\"message\": {" | 108 "\"message\": {" |
| 107 "\"en-US\": \"message\"" | 109 "\"en-US\": \"message\"" |
| 108 "}," | 110 "}," |
| 109 "\"title\": \"Title\"" | 111 "\"title\": \"Title\"" |
| 110 "}]" | 112 "}]" |
| 111 "}"; | 113 "}"; |
| 112 jsEngine->SetWebRequest(std::tr1::shared_ptr<MockWebRequest>( | 114 jsEngine->SetWebRequest(std::tr1::shared_ptr<MockWebRequest>( |
| 113 new MockWebRequest(responseJsonText))); | 115 new MockWebRequest(responseJsonText))); |
| 114 jsEngine->SetLogSystem(LogSystemPtr(new DefaultLogSystem())); | 116 jsEngine->SetLogSystem(LogSystemPtr(new DefaultLogSystem())); |
| 115 filterEngine.reset(new FilterEngine(jsEngine)); | 117 filterEngine.reset(new FilterEngine(jsEngine)); |
| 118 filterEngine->SetShowNotificationCallback( | |
| 119 std::bind(&NotificationMockWebRequestTest::OnNotification, | |
| 120 this, std::tr1::placeholders::_1)); | |
| 121 } | |
| 122 | |
| 123 void OnNotification(const NotificationPtr& notification) | |
| 124 { | |
| 125 isNotificationCallbackCalled = true; | |
| 126 ASSERT_TRUE(notification); | |
| 127 EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notification->G etType()); | |
| 128 EXPECT_EQ("Title", notification->GetTitle()); | |
| 129 EXPECT_EQ("message", notification->GetMessageString()); | |
| 130 notification->MarkAsShown(); | |
| 116 } | 131 } |
| 117 }; | 132 }; |
| 118 #endif | 133 #endif |
| 119 } | 134 } |
| 120 | 135 |
| 121 TEST_F(NotificationTest, NoNotifications) | 136 TEST_F(NotificationTest, NoNotifications) |
| 122 { | 137 { |
| 123 EXPECT_FALSE(PeekNotification()); | 138 EXPECT_FALSE(PeekNotification()); |
| 124 } | 139 } |
| 125 | 140 |
| 126 #ifdef NotificationMockWebRequestTest_ENABLED | 141 #ifdef NotificationMockWebRequestTest_ENABLED |
| 127 TEST_F(NotificationMockWebRequestTest, SingleNotification) | 142 TEST_F(NotificationMockWebRequestTest, SingleNotification) |
| 128 { | 143 { |
| 129 bool isNotificationCallbackCalled = false; | |
| 130 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.
| |
| 131 { | |
| 132 isNotificationCallbackCalled = true; | |
| 133 ASSERT_TRUE(notification); | |
| 134 EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notification->Get Type()); | |
| 135 EXPECT_EQ("Title", notification->GetTitle()); | |
| 136 EXPECT_EQ("message", notification->GetMessageString()); | |
| 137 notification->MarkAsShown(); | |
| 138 }); | |
| 139 AdblockPlus::Sleep(5000/*msec*/); // it's a hack | 144 AdblockPlus::Sleep(5000/*msec*/); // it's a hack |
| 140 EXPECT_TRUE(isNotificationCallbackCalled); | 145 EXPECT_TRUE(isNotificationCallbackCalled); |
| 141 } | 146 } |
| 142 #endif | 147 #endif |
| 143 | 148 |
| 144 TEST_F(NotificationTest, AddNotification) | 149 TEST_F(NotificationTest, AddNotification) |
| 145 { | 150 { |
| 146 AddNotification("{" | 151 AddNotification("{" |
| 147 "type: 'critical'," | 152 "type: 'critical'," |
| 148 "title: 'testTitle'," | 153 "title: 'testTitle'," |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 | 203 |
| 199 TEST_F(NotificationTest, Links) | 204 TEST_F(NotificationTest, Links) |
| 200 { | 205 { |
| 201 AddNotification("{ id: 'id', links: ['link1', 'link2'] }"); | 206 AddNotification("{ id: 'id', links: ['link1', 'link2'] }"); |
| 202 NotificationPtr notification = PeekNotification(); | 207 NotificationPtr notification = PeekNotification(); |
| 203 ASSERT_TRUE(notification); | 208 ASSERT_TRUE(notification); |
| 204 std::vector<std::string> notificationLinks = notification->GetLinks(); | 209 std::vector<std::string> notificationLinks = notification->GetLinks(); |
| 205 ASSERT_EQ(2, notificationLinks.size()); | 210 ASSERT_EQ(2, notificationLinks.size()); |
| 206 EXPECT_EQ("link1", notificationLinks[0]); | 211 EXPECT_EQ("link1", notificationLinks[0]); |
| 207 EXPECT_EQ("link2", notificationLinks[1]); | 212 EXPECT_EQ("link2", notificationLinks[1]); |
| 208 } | 213 } |
|
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.
| |
| LEFT | RIGHT |