OLD | NEW |
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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #include "BaseJsTest.h" | 18 #include "BaseJsTest.h" |
19 | 19 |
20 using namespace AdblockPlus; | 20 using namespace AdblockPlus; |
21 | 21 |
22 // This define enables NotificationMockWebRequestTest but to run it | 22 // This define enables NotificationMockWebRequestTest but to run it |
23 // one need to set INITIAL_DELAY to about 2000 msec in notification.js. | 23 // one need to set INITIAL_DELAY to about 2000 msec in notification.js. |
24 //#define NotificationMockWebRequestTest_ENABLED | 24 //#define NotificationMockWebRequestTest_ENABLED |
25 | 25 |
26 namespace | 26 namespace |
27 { | 27 { |
28 typedef std::tr1::shared_ptr<FilterEngine> FilterEnginePtr; | 28 typedef std::shared_ptr<FilterEngine> FilterEnginePtr; |
29 | 29 |
30 class NotificationTest : public BaseJsTest | 30 class NotificationTest : public BaseJsTest |
31 { | 31 { |
32 protected: | 32 protected: |
33 FilterEnginePtr filterEngine; | 33 FilterEnginePtr filterEngine; |
34 void SetUp() | 34 void SetUp() |
35 { | 35 { |
36 BaseJsTest::SetUp(); | 36 BaseJsTest::SetUp(); |
37 jsEngine->SetFileSystem(FileSystemPtr(new LazyFileSystem())); | 37 jsEngine->SetFileSystem(FileSystemPtr(new LazyFileSystem())); |
38 jsEngine->SetWebRequest(WebRequestPtr(new LazyWebRequest())); | 38 jsEngine->SetWebRequest(WebRequestPtr(new LazyWebRequest())); |
39 jsEngine->SetLogSystem(LogSystemPtr(new DefaultLogSystem())); | 39 jsEngine->SetLogSystem(LogSystemPtr(new DefaultLogSystem())); |
40 filterEngine.reset(new FilterEngine(jsEngine)); | 40 filterEngine.reset(new FilterEngine(jsEngine)); |
41 } | 41 } |
42 | 42 |
43 void AddNotification(const std::string& notification) | 43 void AddNotification(const std::string& notification) |
44 { | 44 { |
45 jsEngine->Evaluate("(function()" | 45 jsEngine->Evaluate("(function()" |
46 "{" | 46 "{" |
47 "require('notification').Notification.addNotification(" + notification +
");" | 47 "require('notification').Notification.addNotification(" + notification +
");" |
48 "})();"); | 48 "})();"); |
49 } | 49 } |
50 | 50 |
51 NotificationPtr PeekNotification(const std::string& url = std::string()) | 51 NotificationPtr PeekNotification(const std::string& url = std::string()) |
52 { | 52 { |
53 NotificationPtr retValue; | 53 NotificationPtr retValue; |
54 filterEngine->SetShowNotificationCallback(std::tr1::bind( | 54 filterEngine->SetShowNotificationCallback(std::bind( |
55 &NotificationTest::NotificationAvailableCallback, | 55 &NotificationTest::NotificationAvailableCallback, |
56 std::tr1::placeholders::_1, std::tr1::ref(retValue))); | 56 std::placeholders::_1, std::ref(retValue))); |
57 filterEngine->ShowNextNotification(url); | 57 filterEngine->ShowNextNotification(url); |
58 filterEngine->RemoveShowNotificationCallback(); | 58 filterEngine->RemoveShowNotificationCallback(); |
59 return retValue; | 59 return retValue; |
60 } | 60 } |
61 | 61 |
62 static void NotificationAvailableCallback(const NotificationPtr& src, Notifi
cationPtr& dst) | 62 static void NotificationAvailableCallback(const NotificationPtr& src, Notifi
cationPtr& dst) |
63 { | 63 { |
64 EXPECT_TRUE(src); | 64 EXPECT_TRUE(src); |
65 dst = src; | 65 dst = src; |
66 } | 66 } |
(...skipping 26 matching lines...) Expand all Loading... |
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 bool isNotificationCallbackCalled; |
98 void SetUp() | 98 void SetUp() |
99 { | 99 { |
100 BaseJsTest::SetUp(); | 100 BaseJsTest::SetUp(); |
101 isNotificationCallbackCalled = false; | 101 isNotificationCallbackCalled = false; |
102 jsEngine->SetFileSystem( | 102 jsEngine->SetFileSystem( |
103 std::tr1::shared_ptr<LazyFileSystem>(new LazyFileSystem())); | 103 std::shared_ptr<LazyFileSystem>(new LazyFileSystem())); |
104 const char* responseJsonText = "{" | 104 const char* responseJsonText = "{" |
105 "\"notifications\": [{" | 105 "\"notifications\": [{" |
106 "\"id\": \"some id\"," | 106 "\"id\": \"some id\"," |
107 "\"type\": \"information\"," | 107 "\"type\": \"information\"," |
108 "\"message\": {" | 108 "\"message\": {" |
109 "\"en-US\": \"message\"" | 109 "\"en-US\": \"message\"" |
110 "}," | 110 "}," |
111 "\"title\": \"Title\"" | 111 "\"title\": \"Title\"" |
112 "}]" | 112 "}]" |
113 "}"; | 113 "}"; |
114 jsEngine->SetWebRequest(std::tr1::shared_ptr<MockWebRequest>( | 114 jsEngine->SetWebRequest(std::shared_ptr<MockWebRequest>( |
115 new MockWebRequest(responseJsonText))); | 115 new MockWebRequest(responseJsonText))); |
116 jsEngine->SetLogSystem(LogSystemPtr(new DefaultLogSystem())); | 116 jsEngine->SetLogSystem(LogSystemPtr(new DefaultLogSystem())); |
117 filterEngine.reset(new FilterEngine(jsEngine)); | 117 filterEngine.reset(new FilterEngine(jsEngine)); |
118 filterEngine->SetShowNotificationCallback( | 118 filterEngine->SetShowNotificationCallback( |
119 std::bind(&NotificationMockWebRequestTest::OnNotification, | 119 std::bind(&NotificationMockWebRequestTest::OnNotification, |
120 this, std::tr1::placeholders::_1)); | 120 this, std::placeholders::_1)); |
121 } | 121 } |
122 | 122 |
123 void OnNotification(const NotificationPtr& notification) | 123 void OnNotification(const NotificationPtr& notification) |
124 { | 124 { |
125 isNotificationCallbackCalled = true; | 125 isNotificationCallbackCalled = true; |
126 ASSERT_TRUE(notification); | 126 ASSERT_TRUE(notification); |
127 EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notification->G
etType()); | 127 EXPECT_EQ(NotificationType::NOTIFICATION_TYPE_INFORMATION, notification->G
etType()); |
128 EXPECT_EQ("Title", notification->GetTitle()); | 128 EXPECT_EQ("Title", notification->GetTitle()); |
129 EXPECT_EQ("message", notification->GetMessageString()); | 129 EXPECT_EQ("message", notification->GetMessageString()); |
130 notification->MarkAsShown(); | 130 notification->MarkAsShown(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 TEST_F(NotificationTest, Links) | 204 TEST_F(NotificationTest, Links) |
205 { | 205 { |
206 AddNotification("{ id: 'id', links: ['link1', 'link2'] }"); | 206 AddNotification("{ id: 'id', links: ['link1', 'link2'] }"); |
207 NotificationPtr notification = PeekNotification(); | 207 NotificationPtr notification = PeekNotification(); |
208 ASSERT_TRUE(notification); | 208 ASSERT_TRUE(notification); |
209 std::vector<std::string> notificationLinks = notification->GetLinks(); | 209 std::vector<std::string> notificationLinks = notification->GetLinks(); |
210 ASSERT_EQ(2, notificationLinks.size()); | 210 ASSERT_EQ(2, notificationLinks.size()); |
211 EXPECT_EQ("link1", notificationLinks[0]); | 211 EXPECT_EQ("link1", notificationLinks[0]); |
212 EXPECT_EQ("link2", notificationLinks[1]); | 212 EXPECT_EQ("link2", notificationLinks[1]); |
213 } | 213 } |
OLD | NEW |