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

Side by Side Diff: test/Notification.cpp

Issue 29508591: Issue 5450 - don't expose std::shared_ptr<FilterEngine> (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: rebase Created Aug. 7, 2017, 1:08 p.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/FilterEngine.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;
29
30 class NotificationTest : public BaseJsTest 28 class NotificationTest : public BaseJsTest
31 { 29 {
32 protected: 30 protected:
33 FilterEnginePtr filterEngine;
34 void SetUp() 31 void SetUp()
35 { 32 {
36 LazyFileSystem* fileSystem; 33 LazyFileSystem* fileSystem;
37 ThrowingPlatformCreationParameters platformParams; 34 ThrowingPlatformCreationParameters platformParams;
38 platformParams.timer.reset(new NoopTimer()); 35 platformParams.timer.reset(new NoopTimer());
39 platformParams.fileSystem.reset(fileSystem = new LazyFileSystem()); 36 platformParams.fileSystem.reset(fileSystem = new LazyFileSystem());
40 platformParams.webRequest.reset(new NoopWebRequest()); 37 platformParams.webRequest.reset(new NoopWebRequest());
41 platform.reset(new Platform(std::move(platformParams))); 38 platform.reset(new Platform(std::move(platformParams)));
42 filterEngine = CreateFilterEngine(*fileSystem, *platform); 39 CreateFilterEngine(*fileSystem, *platform);
43 } 40 }
44 41
45 void AddNotification(const std::string& notification) 42 void AddNotification(const std::string& notification)
46 { 43 {
47 GetJsEngine().Evaluate("(function()" 44 GetJsEngine().Evaluate("(function()"
48 "{" 45 "{"
49 "require('notification').Notification.addNotification(" + notification + ");" 46 "require('notification').Notification.addNotification(" + notification + ");"
50 "})();"); 47 "})();");
51 } 48 }
52 49
53 std::unique_ptr<Notification> PeekNotification(const std::string& url = std: :string()) 50 std::unique_ptr<Notification> PeekNotification(const std::string& url = std: :string())
54 { 51 {
55 std::unique_ptr<Notification> retValue; 52 std::unique_ptr<Notification> retValue;
56 filterEngine->SetShowNotificationCallback( 53 auto& filterEngine = platform->GetFilterEngine();
54 filterEngine.SetShowNotificationCallback(
57 [&retValue](Notification&& notification) { 55 [&retValue](Notification&& notification) {
58 retValue.reset(new Notification(std::move(notification))); 56 retValue.reset(new Notification(std::move(notification)));
59 }); 57 });
60 filterEngine->ShowNextNotification(url); 58 filterEngine.ShowNextNotification(url);
61 filterEngine->RemoveShowNotificationCallback(); 59 filterEngine.RemoveShowNotificationCallback();
62 return retValue; 60 return retValue;
63 } 61 }
64 }; 62 };
65 63
66 class MockWebRequest : public IWebRequest 64 class MockWebRequest : public IWebRequest
67 { 65 {
68 public: 66 public:
69 std::string responseText; 67 std::string responseText;
70 explicit MockWebRequest(const std::string& notification) 68 explicit MockWebRequest(const std::string& notification)
71 : responseText(notification) 69 : responseText(notification)
(...skipping 11 matching lines...) Expand all
83 serverResponse.responseStatus = 200; 81 serverResponse.responseStatus = 200;
84 serverResponse.responseText = responseText; 82 serverResponse.responseText = responseText;
85 getCallback(serverResponse); 83 getCallback(serverResponse);
86 } 84 }
87 }; 85 };
88 86
89 #ifdef NotificationMockWebRequestTest_ENABLED 87 #ifdef NotificationMockWebRequestTest_ENABLED
90 class NotificationMockWebRequestTest : public BaseJsTest 88 class NotificationMockWebRequestTest : public BaseJsTest
91 { 89 {
92 protected: 90 protected:
93 FilterEnginePtr filterEngine;
94 bool isNotificationCallbackCalled; 91 bool isNotificationCallbackCalled;
95 void SetUp() 92 void SetUp()
96 { 93 {
97 BaseJsTest::SetUp(); 94 BaseJsTest::SetUp();
98 isNotificationCallbackCalled = false; 95 isNotificationCallbackCalled = false;
99 jsEngine->SetFileSystem( 96 jsEngine->SetFileSystem(
100 std::shared_ptr<LazyFileSystem>(new LazyFileSystem())); 97 std::shared_ptr<LazyFileSystem>(new LazyFileSystem()));
101 const char* responseJsonText = "{" 98 const char* responseJsonText = "{"
102 "\"notifications\": [{" 99 "\"notifications\": [{"
103 "\"id\": \"some id\"," 100 "\"id\": \"some id\","
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 TEST_F(NotificationTest, Links) 193 TEST_F(NotificationTest, Links)
197 { 194 {
198 AddNotification("{ id: 'id', links: ['link1', 'link2'] }"); 195 AddNotification("{ id: 'id', links: ['link1', 'link2'] }");
199 auto notification = PeekNotification(); 196 auto notification = PeekNotification();
200 ASSERT_TRUE(notification); 197 ASSERT_TRUE(notification);
201 std::vector<std::string> notificationLinks = notification->GetLinks(); 198 std::vector<std::string> notificationLinks = notification->GetLinks();
202 ASSERT_EQ(2u, notificationLinks.size()); 199 ASSERT_EQ(2u, notificationLinks.size());
203 EXPECT_EQ("link1", notificationLinks[0]); 200 EXPECT_EQ("link1", notificationLinks[0]);
204 EXPECT_EQ("link2", notificationLinks[1]); 201 EXPECT_EQ("link2", notificationLinks[1]);
205 } 202 }
OLDNEW
« no previous file with comments | « test/FilterEngine.cpp ('k') | test/Prefs.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld