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

Side by Side Diff: test/Prefs.cpp

Issue 29371607: Issue #3593 - Make isolate a fully internal member of the engine
Patch Set: improve unit tests to go with isolate change Created Jan. 16, 2017, 3:53 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/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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 14 matching lines...) Expand all
25 typedef std::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr; 25 typedef std::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr;
26 26
27 class TestFileSystem : public LazyFileSystem 27 class TestFileSystem : public LazyFileSystem
28 { 28 {
29 public: 29 public:
30 std::string prefsContents; 30 std::string prefsContents;
31 31
32 std::shared_ptr<std::istream> Read(const std::string& path) const 32 std::shared_ptr<std::istream> Read(const std::string& path) const
33 { 33 {
34 if (path == "prefs.json" && !prefsContents.empty()) 34 if (path == "prefs.json" && !prefsContents.empty())
35 return std::shared_ptr<std::istream>(new std::istringstream(prefsContent s)); 35 return std::make_shared<std::istringstream>(prefsContents);
36 36
37 return LazyFileSystem::Read(path); 37 return LazyFileSystem::Read(path);
38 } 38 }
39 39
40 void Write(const std::string& path, std::shared_ptr<std::istream> content) 40 void Write(const std::string& path, std::shared_ptr<std::istream> content)
41 { 41 {
42 if (path == "prefs.json") 42 if (path == "prefs.json")
43 { 43 {
44 std::stringstream ss; 44 std::stringstream ss;
45 ss << content->rdbuf(); 45 ss << content->rdbuf();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 jsValuePrefs[entry->first] = jsEngine->NewValue(entry->second); 108 jsValuePrefs[entry->first] = jsEngine->NewValue(entry->second);
109 } 109 }
110 // Use a new filter engine 110 // Use a new filter engine
111 filterEngine = std::make_shared<AdblockPlus::FilterEngine>(jsEngine, jsVal uePrefs); 111 filterEngine = std::make_shared<AdblockPlus::FilterEngine>(jsEngine, jsVal uePrefs);
112 } 112 }
113 113
114 void Destroy() 114 void Destroy()
115 { 115 {
116 filterEngine.reset(); 116 filterEngine.reset();
117 ToInternal(jsEngine)->WaitForQuietScheduler(); 117 ToInternal(jsEngine)->WaitForQuietScheduler();
118 EXPECT_EQ(1, jsEngine.use_count());
118 jsEngine.reset(); 119 jsEngine.reset();
119 EXPECT_EQ(0, jsEngine.use_count());
120 } 120 }
121 }; 121 };
122 } 122 }
123 123
124 TEST_F(PrefsTest, PrefsGetSet) 124 TEST_F(PrefsTest, PrefsGetSet)
125 { 125 {
126 ASSERT_EQ("patterns.ini", filterEngine->GetPref("patternsfile")->AsString()); 126 ASSERT_EQ("patterns.ini", filterEngine->GetPref("patternsfile")->AsString());
127 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval")->AsInt()); 127 ASSERT_EQ(24, filterEngine->GetPref("patternsbackupinterval")->AsInt());
128 ASSERT_TRUE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool()); 128 ASSERT_TRUE(filterEngine->GetPref("subscriptions_autoupdate")->AsBool());
129 ASSERT_TRUE(filterEngine->GetPref("foobar")->IsUndefined()); 129 ASSERT_TRUE(filterEngine->GetPref("foobar")->IsUndefined());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 224
225 std::this_thread::sleep_for(std::chrono::milliseconds(100)); 225 std::this_thread::sleep_for(std::chrono::milliseconds(100));
226 226
227 ASSERT_FALSE(fileSystem->prefsContents.empty()); 227 ASSERT_FALSE(fileSystem->prefsContents.empty());
228 228
229 Reset(preconfiguredPrefs); 229 Reset(preconfiguredPrefs);
230 230
231 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool()); 231 ASSERT_TRUE(filterEngine->GetPref("suppress_first_run_page")->IsBool());
232 ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page")->AsBool()); 232 ASSERT_FALSE(filterEngine->GetPref("suppress_first_run_page")->AsBool());
233 } 233 }
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