OLD | NEW |
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 Loading... |
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 AdblockPlus::JsEnginePtr jsEngine; | |
42 FilterEnginePtr filterEngine; | 41 FilterEnginePtr filterEngine; |
43 | 42 |
44 bool eventCallbackCalled; | 43 bool eventCallbackCalled; |
45 AdblockPlus::JsValueList eventCallbackParams; | 44 AdblockPlus::JsValueList eventCallbackParams; |
46 bool updateCallbackCalled; | 45 bool updateCallbackCalled; |
47 std::string updateError; | 46 std::string updateError; |
48 | 47 |
49 void SetUp() | 48 void SetUp() |
50 { | 49 { |
51 eventCallbackCalled = false; | 50 eventCallbackCalled = false; |
52 updateCallbackCalled = false; | 51 updateCallbackCalled = false; |
53 } | 52 } |
54 | 53 |
55 void CreateFilterEngine() | 54 void CreateFilterEngine() |
56 { | 55 { |
57 JsEngineCreationParameters jsEngineParams; | 56 JsEngineCreationParameters jsEngineParams; |
58 jsEngineParams.appInfo = appInfo; | 57 jsEngineParams.appInfo = appInfo; |
59 jsEngineParams.logSystem.reset(new LazyLogSystem()); | 58 jsEngineParams.logSystem.reset(new LazyLogSystem()); |
60 jsEngineParams.fileSystem.reset(new LazyFileSystem()); | 59 jsEngineParams.fileSystem.reset(new LazyFileSystem()); |
61 jsEngineParams.timer = DelayedTimer::New(timerTasks); | 60 jsEngineParams.timer = DelayedTimer::New(timerTasks); |
62 jsEngineParams.webRequest = DelayedWebRequest::New(webRequestTasks); | 61 jsEngineParams.webRequest = DelayedWebRequest::New(webRequestTasks); |
63 jsEngine = CreateJsEngine(std::move(jsEngineParams)); | 62 auto jsEngine = CreateJsEngine(std::move(jsEngineParams)); |
64 jsEngine->SetEventCallback("updateAvailable", [this](JsValueList&& params) | 63 jsEngine->SetEventCallback("updateAvailable", [this](JsValueList&& params) |
65 { | 64 { |
66 eventCallbackCalled = true; | 65 eventCallbackCalled = true; |
67 eventCallbackParams = std::move(params); | 66 eventCallbackParams = std::move(params); |
68 }); | 67 }); |
69 | 68 |
70 filterEngine = AdblockPlus::FilterEngine::Create(jsEngine); | 69 filterEngine = AdblockPlus::FilterEngine::Create(jsEngine); |
71 } | 70 } |
72 | 71 |
73 // Returns a URL or the empty string if there is no such request. | 72 // Returns a URL or the empty string if there is no such request. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 CreateFilterEngine(); | 112 CreateFilterEngine(); |
114 ForceUpdateCheck(); | 113 ForceUpdateCheck(); |
115 | 114 |
116 auto requestUrl = ProcessPendingUpdateWebRequest(); | 115 auto requestUrl = ProcessPendingUpdateWebRequest(); |
117 | 116 |
118 ASSERT_FALSE(eventCallbackCalled); | 117 ASSERT_FALSE(eventCallbackCalled); |
119 ASSERT_TRUE(updateCallbackCalled); | 118 ASSERT_TRUE(updateCallbackCalled); |
120 ASSERT_FALSE(updateError.empty()); | 119 ASSERT_FALSE(updateError.empty()); |
121 | 120 |
122 std::string expectedUrl(filterEngine->GetPref("update_url_release").AsString()
); | 121 std::string expectedUrl(filterEngine->GetPref("update_url_release").AsString()
); |
123 std::string platform = jsEngine->Evaluate("require('info').platform").AsString
(); | 122 std::string platform = filterEngine->GetJsEngine()->Evaluate("require('info').
platform").AsString(); |
124 std::string platformVersion = jsEngine->Evaluate("require('info').platformVers
ion").AsString(); | 123 std::string platformVersion = filterEngine->GetJsEngine()->Evaluate("require('
info').platformVersion").AsString(); |
125 | 124 |
126 FindAndReplace(expectedUrl, "%NAME%", appInfo.name); | 125 FindAndReplace(expectedUrl, "%NAME%", appInfo.name); |
127 FindAndReplace(expectedUrl, "%TYPE%", "1"); // manual update | 126 FindAndReplace(expectedUrl, "%TYPE%", "1"); // manual update |
128 expectedUrl += "&addonName=" + appInfo.name + | 127 expectedUrl += "&addonName=" + appInfo.name + |
129 "&addonVersion=" + appInfo.version + | 128 "&addonVersion=" + appInfo.version + |
130 "&application=" + appInfo.application + | 129 "&application=" + appInfo.application + |
131 "&applicationVersion=" + appInfo.applicationVersion + | 130 "&applicationVersion=" + appInfo.applicationVersion + |
132 "&platform=" + platform + | 131 "&platform=" + platform + |
133 "&platformVersion=" + platformVersion + | 132 "&platformVersion=" + platformVersion + |
134 "&lastVersion=0&downloadCount=0"; | 133 "&lastVersion=0&downloadCount=0"; |
(...skipping 17 matching lines...) Expand all Loading... |
152 | 151 |
153 auto requestUrl = ProcessPendingUpdateWebRequest(); | 152 auto requestUrl = ProcessPendingUpdateWebRequest(); |
154 | 153 |
155 ASSERT_TRUE(eventCallbackCalled); | 154 ASSERT_TRUE(eventCallbackCalled); |
156 ASSERT_EQ(1u, eventCallbackParams.size()); | 155 ASSERT_EQ(1u, eventCallbackParams.size()); |
157 ASSERT_EQ("https://foo.bar/", eventCallbackParams[0].AsString()); | 156 ASSERT_EQ("https://foo.bar/", eventCallbackParams[0].AsString()); |
158 ASSERT_TRUE(updateCallbackCalled); | 157 ASSERT_TRUE(updateCallbackCalled); |
159 ASSERT_TRUE(updateError.empty()); | 158 ASSERT_TRUE(updateError.empty()); |
160 | 159 |
161 std::string expectedUrl(filterEngine->GetPref("update_url_devbuild").AsString(
)); | 160 std::string expectedUrl(filterEngine->GetPref("update_url_devbuild").AsString(
)); |
162 std::string platform = jsEngine->Evaluate("require('info').platform").AsString
(); | 161 std::string platform = filterEngine->GetJsEngine()->Evaluate("require('info').
platform").AsString(); |
163 std::string platformVersion = jsEngine->Evaluate("require('info').platformVers
ion").AsString(); | 162 std::string platformVersion = filterEngine->GetJsEngine()->Evaluate("require('
info').platformVersion").AsString(); |
164 | 163 |
165 FindAndReplace(expectedUrl, "%NAME%", appInfo.name); | 164 FindAndReplace(expectedUrl, "%NAME%", appInfo.name); |
166 FindAndReplace(expectedUrl, "%TYPE%", "1"); // manual update | 165 FindAndReplace(expectedUrl, "%TYPE%", "1"); // manual update |
167 expectedUrl += "&addonName=" + appInfo.name + | 166 expectedUrl += "&addonName=" + appInfo.name + |
168 "&addonVersion=" + appInfo.version + | 167 "&addonVersion=" + appInfo.version + |
169 "&application=" + appInfo.application + | 168 "&application=" + appInfo.application + |
170 "&applicationVersion=" + appInfo.applicationVersion + | 169 "&applicationVersion=" + appInfo.applicationVersion + |
171 "&platform=" + platform + | 170 "&platform=" + platform + |
172 "&platformVersion=" + platformVersion + | 171 "&platformVersion=" + platformVersion + |
173 "&lastVersion=0&downloadCount=0"; | 172 "&lastVersion=0&downloadCount=0"; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 | 299 |
301 // ensure that the was the corresponding request | 300 // ensure that the was the corresponding request |
302 EXPECT_FALSE(ProcessPendingUpdateWebRequest().empty()); | 301 EXPECT_FALSE(ProcessPendingUpdateWebRequest().empty()); |
303 | 302 |
304 EXPECT_FALSE(eventCallbackCalled); | 303 EXPECT_FALSE(eventCallbackCalled); |
305 EXPECT_EQ(1, timesCalled); | 304 EXPECT_EQ(1, timesCalled); |
306 | 305 |
307 // previous handler is not restored | 306 // previous handler is not restored |
308 EXPECT_FALSE(eventCallbackCalled); | 307 EXPECT_FALSE(eventCallbackCalled); |
309 } | 308 } |
OLD | NEW |