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

Side by Side Diff: test/Notification.cpp

Issue 29433591: Issue 5180 - start to inject implementation of WebRequest into JsEngine::ctr (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created May 8, 2017, 11:59 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/GlobalJsObject.cpp ('k') | test/Prefs.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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::shared_ptr<FilterEngine> FilterEnginePtr; 28 typedef std::shared_ptr<FilterEngine> FilterEnginePtr;
29 29
30 class NotificationTest : public BaseJsTest 30 class NotificationTest : public ::testing::Test
31 { 31 {
32 protected: 32 protected:
33 FilterEnginePtr filterEngine; 33 FilterEnginePtr filterEngine;
34 void SetUp() 34 void SetUp()
35 { 35 {
36 BaseJsTest::SetUp(); 36 JsEngineCreationParameters jsEngineParams;
37 jsEngine->SetFileSystem(FileSystemPtr(new LazyFileSystem())); 37 jsEngineParams.fileSystem.reset(new LazyFileSystem());
38 jsEngine->SetWebRequest(std::make_shared<LazyWebRequest>()); 38 jsEngineParams.logSystem.reset(new DefaultLogSystem());
39 jsEngine->SetLogSystem(LogSystemPtr(new DefaultLogSystem())); 39 jsEngineParams.timer.reset(new NoopTimer());
40 jsEngineParams.webRequest.reset(new NoopWebRequest());
41 auto jsEngine = CreateJsEngine(std::move(jsEngineParams));
40 filterEngine = FilterEngine::Create(jsEngine); 42 filterEngine = FilterEngine::Create(jsEngine);
41 } 43 }
42 44
43 void AddNotification(const std::string& notification) 45 void AddNotification(const std::string& notification)
44 { 46 {
45 jsEngine->Evaluate("(function()" 47 filterEngine->GetJsEngine()->Evaluate("(function()"
46 "{" 48 "{"
47 "require('notification').Notification.addNotification(" + notification + ");" 49 "require('notification').Notification.addNotification(" + notification + ");"
48 "})();"); 50 "})();");
49 } 51 }
50 52
51 std::unique_ptr<Notification> PeekNotification(const std::string& url = std: :string()) 53 std::unique_ptr<Notification> PeekNotification(const std::string& url = std: :string())
52 { 54 {
53 std::unique_ptr<Notification> retValue; 55 std::unique_ptr<Notification> retValue;
54 filterEngine->SetShowNotificationCallback( 56 filterEngine->SetShowNotificationCallback(
55 [&retValue](Notification&& notification) { 57 [&retValue](Notification&& notification) {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 TEST_F(NotificationTest, Links) 196 TEST_F(NotificationTest, Links)
195 { 197 {
196 AddNotification("{ id: 'id', links: ['link1', 'link2'] }"); 198 AddNotification("{ id: 'id', links: ['link1', 'link2'] }");
197 auto notification = PeekNotification(); 199 auto notification = PeekNotification();
198 ASSERT_TRUE(notification); 200 ASSERT_TRUE(notification);
199 std::vector<std::string> notificationLinks = notification->GetLinks(); 201 std::vector<std::string> notificationLinks = notification->GetLinks();
200 ASSERT_EQ(2u, notificationLinks.size()); 202 ASSERT_EQ(2u, notificationLinks.size());
201 EXPECT_EQ("link1", notificationLinks[0]); 203 EXPECT_EQ("link1", notificationLinks[0]);
202 EXPECT_EQ("link2", notificationLinks[1]); 204 EXPECT_EQ("link2", notificationLinks[1]);
203 } 205 }
OLDNEW
« no previous file with comments | « test/GlobalJsObject.cpp ('k') | test/Prefs.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld