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

Side by Side Diff: test/Prefs.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/Notification.cpp ('k') | test/UpdateCheck.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 <sstream> 18 #include <sstream>
19 19
20 #include "../src/Thread.h" 20 #include "../src/Thread.h"
21 #include "BaseJsTest.h" 21 #include "BaseJsTest.h"
22 22
23 using namespace AdblockPlus;
24
23 namespace 25 namespace
24 { 26 {
25 typedef std::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr; 27 typedef std::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr;
26 28
27 class TestFileSystem : public LazyFileSystem 29 class TestFileSystem : public LazyFileSystem
28 { 30 {
29 public: 31 public:
30 std::string prefsContents; 32 std::string prefsContents;
31 33
32 std::shared_ptr<std::istream> Read(const std::string& path) const 34 std::shared_ptr<std::istream> Read(const std::string& path) const
(...skipping 25 matching lines...) Expand all
58 return result; 60 return result;
59 } 61 }
60 62
61 return LazyFileSystem::Stat(path); 63 return LazyFileSystem::Stat(path);
62 } 64 }
63 }; 65 };
64 66
65 class PrefsTest : public ::testing::Test 67 class PrefsTest : public ::testing::Test
66 { 68 {
67 protected: 69 protected:
68 TestFileSystem* fileSystem; 70 std::shared_ptr<TestFileSystem> fileSystem;
69 AdblockPlus::FileSystemPtr fileSystemPtr;
70 AdblockPlus::JsEnginePtr jsEngine; 71 AdblockPlus::JsEnginePtr jsEngine;
71 72
72 void SetUp() 73 void SetUp()
73 { 74 {
74 fileSystem = new TestFileSystem(); 75 fileSystem = std::make_shared<TestFileSystem>();
75 fileSystemPtr.reset(fileSystem);
76
77 ResetJsEngine(); 76 ResetJsEngine();
78 } 77 }
79 78
80 void ResetJsEngine() 79 void ResetJsEngine()
81 { 80 {
82 jsEngine = CreateJsEngine(); 81 JsEngineCreationParameters jsEngineParams;
83 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem)); 82 jsEngineParams.fileSystem = fileSystem;
84 jsEngine->SetFileSystem(fileSystemPtr); 83 jsEngineParams.webRequest.reset(new NoopWebRequest());
85 jsEngine->SetWebRequest(std::make_shared<LazyWebRequest>()); 84 jsEngineParams.logSystem.reset(new LazyLogSystem());
85 jsEngineParams.timer.reset(new NoopTimer());
86 jsEngine = CreateJsEngine(std::move(jsEngineParams));
86 } 87 }
87 88
88 FilterEnginePtr CreateFilterEngine(const AdblockPlus::FilterEngine::Prefs& p reconfiguredPrefs = 89 FilterEnginePtr CreateFilterEngine(const AdblockPlus::FilterEngine::Prefs& p reconfiguredPrefs =
89 AdblockPlus::FilterEngine::Prefs()) 90 AdblockPlus::FilterEngine::Prefs())
90 { 91 {
91 AdblockPlus::FilterEngine::CreationParameters createParams; 92 AdblockPlus::FilterEngine::CreationParameters createParams;
92 createParams.preconfiguredPrefs = preconfiguredPrefs; 93 createParams.preconfiguredPrefs = preconfiguredPrefs;
93 return AdblockPlus::FilterEngine::Create(jsEngine, createParams); 94 return AdblockPlus::FilterEngine::Create(jsEngine, createParams);
94 } 95 }
95 }; 96 };
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 { 209 {
209 ResetJsEngine(); 210 ResetJsEngine();
210 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs; 211 AdblockPlus::FilterEngine::Prefs preconfiguredPrefs;
211 preconfiguredPrefs.emplace("suppress_first_run_page", jsEngine->NewValue(tru e)); 212 preconfiguredPrefs.emplace("suppress_first_run_page", jsEngine->NewValue(tru e));
212 auto filterEngine = CreateFilterEngine(preconfiguredPrefs); 213 auto filterEngine = CreateFilterEngine(preconfiguredPrefs);
213 214
214 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page").IsBool()); 215 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page").IsBool());
215 ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page").AsBool()); 216 ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page").AsBool());
216 } 217 }
217 } 218 }
OLDNEW
« no previous file with comments | « test/Notification.cpp ('k') | test/UpdateCheck.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld