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

Side by Side Diff: test/UpdateCheck.cpp

Issue 29500602: Issue 5450 - introduce the Platform class (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: rebase Created July 31, 2017, 12: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
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
(...skipping 20 matching lines...) Expand all
31 source.replace(pos, find.size(), replace); 31 source.replace(pos, find.size(), replace);
32 } 32 }
33 33
34 class UpdateCheckTest : public ::testing::Test 34 class UpdateCheckTest : public ::testing::Test
35 { 35 {
36 protected: 36 protected:
37 AdblockPlus::AppInfo appInfo; 37 AdblockPlus::AppInfo appInfo;
38 AdblockPlus::ServerResponse webRequestResponse; 38 AdblockPlus::ServerResponse webRequestResponse;
39 DelayedWebRequest::SharedTasks webRequestTasks; 39 DelayedWebRequest::SharedTasks webRequestTasks;
40 DelayedTimer::SharedTasks timerTasks; 40 DelayedTimer::SharedTasks timerTasks;
41 std::unique_ptr<Platform> platform;
41 FilterEnginePtr filterEngine; 42 FilterEnginePtr filterEngine;
42 43
43 bool eventCallbackCalled; 44 bool eventCallbackCalled;
44 AdblockPlus::JsValueList eventCallbackParams; 45 AdblockPlus::JsValueList eventCallbackParams;
45 bool updateCallbackCalled; 46 bool updateCallbackCalled;
46 std::string updateError; 47 std::string updateError;
47 48
48 void SetUp() 49 void SetUp()
49 { 50 {
50 eventCallbackCalled = false; 51 eventCallbackCalled = false;
51 updateCallbackCalled = false; 52 updateCallbackCalled = false;
52 } 53 }
53 54
54 void CreateFilterEngine() 55 void CreateFilterEngine()
55 { 56 {
56 JsEngineCreationParameters jsEngineParams;
57 jsEngineParams.appInfo = appInfo;
58 LazyFileSystem* fileSystem; 57 LazyFileSystem* fileSystem;
59 jsEngineParams.logSystem.reset(new LazyLogSystem()); 58 ThrowingPlatformCreationParameters platformParams;
60 jsEngineParams.fileSystem.reset(fileSystem = new LazyFileSystem()); 59 platformParams.logSystem.reset(new LazyLogSystem());
61 jsEngineParams.timer = DelayedTimer::New(timerTasks); 60 platformParams.timer = DelayedTimer::New(timerTasks);
62 jsEngineParams.webRequest = DelayedWebRequest::New(webRequestTasks); 61 platformParams.fileSystem.reset(fileSystem = new LazyFileSystem());
63 auto jsEngine = CreateJsEngine(std::move(jsEngineParams)); 62 platformParams.webRequest = DelayedWebRequest::New(webRequestTasks);
64 jsEngine->SetEventCallback("updateAvailable", [this](JsValueList&& params) 63 platform.reset(new Platform(std::move(platformParams)));
64 platform->SetUpJsEngine(appInfo);
65 platform->GetJsEngine()->SetEventCallback("updateAvailable", [this](JsValu eList&& params)
65 { 66 {
66 eventCallbackCalled = true; 67 eventCallbackCalled = true;
67 eventCallbackParams = std::move(params); 68 eventCallbackParams = std::move(params);
68 }); 69 });
69 70
70 filterEngine = ::CreateFilterEngine(*fileSystem, jsEngine); 71 filterEngine = ::CreateFilterEngine(*fileSystem, platform->GetJsEngine());
71 } 72 }
72 73
73 // Returns a URL or the empty string if there is no such request. 74 // Returns a URL or the empty string if there is no such request.
74 std::string ProcessPendingUpdateWebRequest() 75 std::string ProcessPendingUpdateWebRequest()
75 { 76 {
76 auto ii = webRequestTasks->begin(); 77 auto ii = webRequestTasks->begin();
77 while (ii != webRequestTasks->end()) 78 while (ii != webRequestTasks->end())
78 { 79 {
79 if (ii->url.find("update.json") != std::string::npos) 80 if (ii->url.find("update.json") != std::string::npos)
80 { 81 {
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 ForceUpdateCheck(); 300 ForceUpdateCheck();
300 301
301 // ensure that the was the corresponding request 302 // ensure that the was the corresponding request
302 EXPECT_FALSE(ProcessPendingUpdateWebRequest().empty()); 303 EXPECT_FALSE(ProcessPendingUpdateWebRequest().empty());
303 304
304 EXPECT_FALSE(eventCallbackCalled); 305 EXPECT_FALSE(eventCallbackCalled);
305 EXPECT_EQ(1, timesCalled); 306 EXPECT_EQ(1, timesCalled);
306 307
307 // previous handler is not restored 308 // previous handler is not restored
308 EXPECT_FALSE(eventCallbackCalled); 309 EXPECT_FALSE(eventCallbackCalled);
309 } 310 }
OLDNEW
« include/AdblockPlus/Platform.h ('K') | « test/Prefs.cpp ('k') | test/WebRequest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld