| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 bool eventCallbackCalled; | 44 bool eventCallbackCalled; |
| 45 AdblockPlus::JsValueList eventCallbackParams; | 45 AdblockPlus::JsValueList eventCallbackParams; |
| 46 bool updateCallbackCalled; | 46 bool updateCallbackCalled; |
| 47 std::string updateError; | 47 std::string updateError; |
| 48 | 48 |
| 49 void SetUp() | 49 void SetUp() |
| 50 { | 50 { |
| 51 eventCallbackCalled = false; | 51 eventCallbackCalled = false; |
| 52 updateCallbackCalled = false; | 52 updateCallbackCalled = false; |
| 53 Reset(); | |
| 54 } | 53 } |
| 55 | 54 |
| 56 void Reset() | 55 void CreateFilterEngine() |
| 57 { | 56 { |
| 58 JsEngineCreationParameters jsEngineParams; | 57 JsEngineCreationParameters jsEngineParams; |
| 59 jsEngineParams.appInfo = appInfo; | 58 jsEngineParams.appInfo = appInfo; |
| 60 jsEngineParams.logSystem.reset(new LazyLogSystem()); | 59 jsEngineParams.logSystem.reset(new LazyLogSystem()); |
| 61 jsEngineParams.fileSystem.reset(new LazyFileSystem()); | 60 jsEngineParams.fileSystem.reset(new LazyFileSystem()); |
| 62 jsEngineParams.timer = DelayedTimer::New(timerTasks); | 61 jsEngineParams.timer = DelayedTimer::New(timerTasks); |
| 63 jsEngineParams.webRequest = DelayedWebRequest::New(webRequestTasks); | 62 jsEngineParams.webRequest = DelayedWebRequest::New(webRequestTasks); |
| 64 jsEngine = CreateJsEngine(std::move(jsEngineParams)); | 63 jsEngine = CreateJsEngine(std::move(jsEngineParams)); |
| 65 jsEngine->SetEventCallback("updateAvailable", [this](JsValueList&& params) | 64 jsEngine->SetEventCallback("updateAvailable", [this](JsValueList&& params) |
| 66 { | 65 { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 TEST_F(UpdateCheckTest, RequestFailure) | 103 TEST_F(UpdateCheckTest, RequestFailure) |
| 105 { | 104 { |
| 106 webRequestResponse.status = IWebRequest::NS_ERROR_FAILURE; | 105 webRequestResponse.status = IWebRequest::NS_ERROR_FAILURE; |
| 107 | 106 |
| 108 appInfo.name = "1"; | 107 appInfo.name = "1"; |
| 109 appInfo.version = "3"; | 108 appInfo.version = "3"; |
| 110 appInfo.application = "4"; | 109 appInfo.application = "4"; |
| 111 appInfo.applicationVersion = "2"; | 110 appInfo.applicationVersion = "2"; |
| 112 appInfo.developmentBuild = false; | 111 appInfo.developmentBuild = false; |
| 113 | 112 |
| 114 Reset(); | 113 CreateFilterEngine(); |
| 115 ForceUpdateCheck(); | 114 ForceUpdateCheck(); |
| 116 | 115 |
| 117 auto requestUrl = ProcessPendingUpdateWebRequest(); | 116 auto requestUrl = ProcessPendingUpdateWebRequest(); |
| 118 | 117 |
| 119 ASSERT_FALSE(eventCallbackCalled); | 118 ASSERT_FALSE(eventCallbackCalled); |
| 120 ASSERT_TRUE(updateCallbackCalled); | 119 ASSERT_TRUE(updateCallbackCalled); |
| 121 ASSERT_FALSE(updateError.empty()); | 120 ASSERT_FALSE(updateError.empty()); |
| 122 | 121 |
| 123 std::string expectedUrl(filterEngine->GetPref("update_url_release").AsString()
); | 122 std::string expectedUrl(filterEngine->GetPref("update_url_release").AsString()
); |
| 124 std::string platform = jsEngine->Evaluate("require('info').platform").AsString
(); | 123 std::string platform = jsEngine->Evaluate("require('info').platform").AsString
(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 141 webRequestResponse.status = IWebRequest::NS_OK; | 140 webRequestResponse.status = IWebRequest::NS_OK; |
| 142 webRequestResponse.responseStatus = 200; | 141 webRequestResponse.responseStatus = 200; |
| 143 webRequestResponse.responseText = "{\"1\": {\"version\":\"3.1\",\"url\":\"http
s://foo.bar/\"}}"; | 142 webRequestResponse.responseText = "{\"1\": {\"version\":\"3.1\",\"url\":\"http
s://foo.bar/\"}}"; |
| 144 | 143 |
| 145 appInfo.name = "1"; | 144 appInfo.name = "1"; |
| 146 appInfo.version = "3"; | 145 appInfo.version = "3"; |
| 147 appInfo.application = "4"; | 146 appInfo.application = "4"; |
| 148 appInfo.applicationVersion = "2"; | 147 appInfo.applicationVersion = "2"; |
| 149 appInfo.developmentBuild = true; | 148 appInfo.developmentBuild = true; |
| 150 | 149 |
| 151 Reset(); | 150 CreateFilterEngine(); |
| 152 ForceUpdateCheck(); | 151 ForceUpdateCheck(); |
| 153 | 152 |
| 154 auto requestUrl = ProcessPendingUpdateWebRequest(); | 153 auto requestUrl = ProcessPendingUpdateWebRequest(); |
| 155 | 154 |
| 156 ASSERT_TRUE(eventCallbackCalled); | 155 ASSERT_TRUE(eventCallbackCalled); |
| 157 ASSERT_EQ(1u, eventCallbackParams.size()); | 156 ASSERT_EQ(1u, eventCallbackParams.size()); |
| 158 ASSERT_EQ("https://foo.bar/", eventCallbackParams[0].AsString()); | 157 ASSERT_EQ("https://foo.bar/", eventCallbackParams[0].AsString()); |
| 159 ASSERT_TRUE(updateCallbackCalled); | 158 ASSERT_TRUE(updateCallbackCalled); |
| 160 ASSERT_TRUE(updateError.empty()); | 159 ASSERT_TRUE(updateError.empty()); |
| 161 | 160 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 180 webRequestResponse.status = IWebRequest::NS_OK; | 179 webRequestResponse.status = IWebRequest::NS_OK; |
| 181 webRequestResponse.responseStatus = 200; | 180 webRequestResponse.responseStatus = 200; |
| 182 webRequestResponse.responseText = "{\"1/4\": {\"version\":\"3.1\",\"url\":\"ht
tps://foo.bar/\"}}"; | 181 webRequestResponse.responseText = "{\"1/4\": {\"version\":\"3.1\",\"url\":\"ht
tps://foo.bar/\"}}"; |
| 183 | 182 |
| 184 appInfo.name = "1"; | 183 appInfo.name = "1"; |
| 185 appInfo.version = "3"; | 184 appInfo.version = "3"; |
| 186 appInfo.application = "4"; | 185 appInfo.application = "4"; |
| 187 appInfo.applicationVersion = "2"; | 186 appInfo.applicationVersion = "2"; |
| 188 appInfo.developmentBuild = true; | 187 appInfo.developmentBuild = true; |
| 189 | 188 |
| 190 Reset(); | 189 CreateFilterEngine(); |
| 191 ForceUpdateCheck(); | 190 ForceUpdateCheck(); |
| 192 | 191 |
| 193 ProcessPendingUpdateWebRequest(); | 192 ProcessPendingUpdateWebRequest(); |
| 194 | 193 |
| 195 ASSERT_TRUE(eventCallbackCalled); | 194 ASSERT_TRUE(eventCallbackCalled); |
| 196 ASSERT_EQ(1u, eventCallbackParams.size()); | 195 ASSERT_EQ(1u, eventCallbackParams.size()); |
| 197 ASSERT_EQ("https://foo.bar/", eventCallbackParams[0].AsString()); | 196 ASSERT_EQ("https://foo.bar/", eventCallbackParams[0].AsString()); |
| 198 ASSERT_TRUE(updateError.empty()); | 197 ASSERT_TRUE(updateError.empty()); |
| 199 } | 198 } |
| 200 | 199 |
| 201 TEST_F(UpdateCheckTest, WrongApplication) | 200 TEST_F(UpdateCheckTest, WrongApplication) |
| 202 { | 201 { |
| 203 webRequestResponse.status = IWebRequest::NS_OK; | 202 webRequestResponse.status = IWebRequest::NS_OK; |
| 204 webRequestResponse.responseStatus = 200; | 203 webRequestResponse.responseStatus = 200; |
| 205 webRequestResponse.responseText = "{\"1/3\": {\"version\":\"3.1\",\"url\":\"ht
tps://foo.bar/\"}}"; | 204 webRequestResponse.responseText = "{\"1/3\": {\"version\":\"3.1\",\"url\":\"ht
tps://foo.bar/\"}}"; |
| 206 | 205 |
| 207 appInfo.name = "1"; | 206 appInfo.name = "1"; |
| 208 appInfo.version = "3"; | 207 appInfo.version = "3"; |
| 209 appInfo.application = "4"; | 208 appInfo.application = "4"; |
| 210 appInfo.applicationVersion = "2"; | 209 appInfo.applicationVersion = "2"; |
| 211 appInfo.developmentBuild = true; | 210 appInfo.developmentBuild = true; |
| 212 | 211 |
| 213 Reset(); | 212 CreateFilterEngine(); |
| 214 ForceUpdateCheck(); | 213 ForceUpdateCheck(); |
| 215 | 214 |
| 216 ProcessPendingUpdateWebRequest(); | 215 ProcessPendingUpdateWebRequest(); |
| 217 | 216 |
| 218 ASSERT_FALSE(eventCallbackCalled); | 217 ASSERT_FALSE(eventCallbackCalled); |
| 219 ASSERT_TRUE(updateCallbackCalled); | 218 ASSERT_TRUE(updateCallbackCalled); |
| 220 ASSERT_TRUE(updateError.empty()); | 219 ASSERT_TRUE(updateError.empty()); |
| 221 } | 220 } |
| 222 | 221 |
| 223 TEST_F(UpdateCheckTest, WrongVersion) | 222 TEST_F(UpdateCheckTest, WrongVersion) |
| 224 { | 223 { |
| 225 webRequestResponse.status = IWebRequest::NS_OK; | 224 webRequestResponse.status = IWebRequest::NS_OK; |
| 226 webRequestResponse.responseStatus = 200; | 225 webRequestResponse.responseStatus = 200; |
| 227 webRequestResponse.responseText = "{\"1\": {\"version\":\"3\",\"url\":\"https:
//foo.bar/\"}}"; | 226 webRequestResponse.responseText = "{\"1\": {\"version\":\"3\",\"url\":\"https:
//foo.bar/\"}}"; |
| 228 | 227 |
| 229 appInfo.name = "1"; | 228 appInfo.name = "1"; |
| 230 appInfo.version = "3"; | 229 appInfo.version = "3"; |
| 231 appInfo.application = "4"; | 230 appInfo.application = "4"; |
| 232 appInfo.applicationVersion = "2"; | 231 appInfo.applicationVersion = "2"; |
| 233 appInfo.developmentBuild = true; | 232 appInfo.developmentBuild = true; |
| 234 | 233 |
| 235 Reset(); | 234 CreateFilterEngine(); |
| 236 ForceUpdateCheck(); | 235 ForceUpdateCheck(); |
| 237 | 236 |
| 238 ProcessPendingUpdateWebRequest(); | 237 ProcessPendingUpdateWebRequest(); |
| 239 | 238 |
| 240 ASSERT_FALSE(eventCallbackCalled); | 239 ASSERT_FALSE(eventCallbackCalled); |
| 241 ASSERT_TRUE(updateCallbackCalled); | 240 ASSERT_TRUE(updateCallbackCalled); |
| 242 ASSERT_TRUE(updateError.empty()); | 241 ASSERT_TRUE(updateError.empty()); |
| 243 } | 242 } |
| 244 | 243 |
| 245 TEST_F(UpdateCheckTest, WrongURL) | 244 TEST_F(UpdateCheckTest, WrongURL) |
| 246 { | 245 { |
| 247 webRequestResponse.status = IWebRequest::NS_OK; | 246 webRequestResponse.status = IWebRequest::NS_OK; |
| 248 webRequestResponse.responseStatus = 200; | 247 webRequestResponse.responseStatus = 200; |
| 249 webRequestResponse.responseText = "{\"1\": {\"version\":\"3.1\",\"url\":\"http
://insecure/\"}}"; | 248 webRequestResponse.responseText = "{\"1\": {\"version\":\"3.1\",\"url\":\"http
://insecure/\"}}"; |
| 250 | 249 |
| 251 appInfo.name = "1"; | 250 appInfo.name = "1"; |
| 252 appInfo.version = "3"; | 251 appInfo.version = "3"; |
| 253 appInfo.application = "4"; | 252 appInfo.application = "4"; |
| 254 appInfo.applicationVersion = "2"; | 253 appInfo.applicationVersion = "2"; |
| 255 appInfo.developmentBuild = true; | 254 appInfo.developmentBuild = true; |
| 256 | 255 |
| 257 Reset(); | 256 CreateFilterEngine(); |
| 258 ForceUpdateCheck(); | 257 ForceUpdateCheck(); |
| 259 | 258 |
| 260 ProcessPendingUpdateWebRequest(); | 259 ProcessPendingUpdateWebRequest(); |
| 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 } |
| OLD | NEW |