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

Side by Side Diff: test/UpdateCheck.cpp

Issue 29422625: Issue 5189 - use r-value references when objects should be transferred (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created April 26, 2017, 2:14 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') | no next file » | 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 <functional> 18 #include <functional>
19 19
20 #include "BaseJsTest.h" 20 #include "BaseJsTest.h"
21 21
22 using namespace AdblockPlus;
23
22 namespace 24 namespace
23 { 25 {
24 typedef std::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr; 26 typedef std::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr;
25 27
26 void FindAndReplace(std::string& source, const std::string& find, const std::s tring& replace) 28 void FindAndReplace(std::string& source, const std::string& find, const std::s tring& replace)
27 { 29 {
28 for (size_t pos = 0; (pos = source.find(find), pos) != std::string::npos; po s += replace.size()) 30 for (size_t pos = 0; (pos = source.find(find), pos) != std::string::npos; po s += replace.size())
29 source.replace(pos, find.size(), replace); 31 source.replace(pos, find.size(), replace);
30 } 32 }
31 33
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 updateCallbackCalled = false; 69 updateCallbackCalled = false;
68 Reset(); 70 Reset();
69 } 71 }
70 72
71 void Reset() 73 void Reset()
72 { 74 {
73 jsEngine = CreateJsEngine(appInfo); 75 jsEngine = CreateJsEngine(appInfo);
74 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem)); 76 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem));
75 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem)); 77 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem));
76 jsEngine->SetWebRequest(webRequestPtr); 78 jsEngine->SetWebRequest(webRequestPtr);
77 jsEngine->SetEventCallback("updateAvailable", 79 jsEngine->SetEventCallback("updateAvailable", [this](JsValueList&& params)
78 std::bind(&UpdateCheckTest::EventCallback, this, std::placeholders::_1 )); 80 {
81 eventCallbackCalled = true;
82 eventCallbackParams = std::move(params);
83 });
79 84
80 filterEngine = AdblockPlus::FilterEngine::Create(jsEngine); 85 filterEngine = AdblockPlus::FilterEngine::Create(jsEngine);
81 } 86 }
82 87
83 void ForceUpdateCheck() 88 void ForceUpdateCheck()
84 { 89 {
85 filterEngine->ForceUpdateCheck( 90 filterEngine->ForceUpdateCheck(
86 std::bind(&UpdateCheckTest::UpdateCallback, this, std::placeholders::_ 1)); 91 std::bind(&UpdateCheckTest::UpdateCallback, this, std::placeholders::_ 1));
87 } 92 }
88 93
89 void EventCallback(const AdblockPlus::JsValueList& params)
90 {
91 eventCallbackCalled = true;
92 eventCallbackParams = params;
93 }
94
95 void UpdateCallback(const std::string& error) 94 void UpdateCallback(const std::string& error)
96 { 95 {
97 updateCallbackCalled = true; 96 updateCallbackCalled = true;
98 updateError = error; 97 updateError = error;
99 } 98 }
100 }; 99 };
101 } 100 }
102 101
103 TEST_F(UpdateCheckTest, RequestFailure) 102 TEST_F(UpdateCheckTest, RequestFailure)
104 { 103 {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 255
257 Reset(); 256 Reset();
258 ForceUpdateCheck(); 257 ForceUpdateCheck();
259 258
260 AdblockPlus::Sleep(100); 259 AdblockPlus::Sleep(100);
261 260
262 ASSERT_FALSE(eventCallbackCalled); 261 ASSERT_FALSE(eventCallbackCalled);
263 ASSERT_TRUE(updateCallbackCalled); 262 ASSERT_TRUE(updateCallbackCalled);
264 ASSERT_FALSE(updateError.empty()); 263 ASSERT_FALSE(updateError.empty());
265 } 264 }
OLDNEW
« no previous file with comments | « test/Notification.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld