| LEFT | RIGHT |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 * |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 updateError = error; | 98 updateError = error; |
| 99 } | 99 } |
| 100 }; | 100 }; |
| 101 } | 101 } |
| 102 | 102 |
| 103 TEST_F(UpdateCheckTest, RequestFailure) | 103 TEST_F(UpdateCheckTest, RequestFailure) |
| 104 { | 104 { |
| 105 webRequest->response.status = AdblockPlus::WebRequest::NS_ERROR_FAILURE; | 105 webRequest->response.status = AdblockPlus::WebRequest::NS_ERROR_FAILURE; |
| 106 | 106 |
| 107 appInfo.name = "1"; | 107 appInfo.name = "1"; |
| 108 appInfo.id = "2"; | 108 appInfo.version = "3"; |
| 109 appInfo.version = "3"; | 109 appInfo.application = "4"; |
| 110 appInfo.application = "4"; | 110 appInfo.applicationVersion = "2"; |
| 111 appInfo.applicationVersion = "5"; | |
| 112 appInfo.developmentBuild = false; | 111 appInfo.developmentBuild = false; |
| 113 | 112 |
| 114 Reset(); | 113 Reset(); |
| 115 ForceUpdateCheck(); | 114 ForceUpdateCheck(); |
| 116 | 115 |
| 117 AdblockPlus::Sleep(100); | 116 AdblockPlus::Sleep(100); |
| 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")->AsStrin
g(); | 123 std::string platform = jsEngine->Evaluate("require('info').platform")->AsStrin
g(); |
| 125 std::string platformVersion = jsEngine->Evaluate("require('info').platformVers
ion")->AsString(); | 124 std::string platformVersion = jsEngine->Evaluate("require('info').platformVers
ion")->AsString(); |
| 126 | 125 |
| 127 FindAndReplace(expectedUrl, "%NAME%", appInfo.name); | 126 FindAndReplace(expectedUrl, "%NAME%", appInfo.name); |
| 128 FindAndReplace(expectedUrl, "%TYPE%", "1"); // manual update | 127 FindAndReplace(expectedUrl, "%TYPE%", "1"); // manual update |
| 129 expectedUrl += "&addonName=" + appInfo.name + | 128 expectedUrl += "&addonName=" + appInfo.name + |
| 130 "&addonVersion=" + appInfo.version + | 129 "&addonVersion=" + appInfo.version + |
| 131 "&application=" + appInfo.application + | 130 "&application=" + appInfo.application + |
| 132 "&applicationVersion=" + appInfo.applicationVersion + | 131 "&applicationVersion=" + appInfo.applicationVersion + |
| 133 "&platform=" + platform + | 132 "&platform=" + platform + |
| 134 "&platformVersion=" + platformVersion + | 133 "&platformVersion=" + platformVersion + |
| 135 "&lastVersion=0"; | 134 "&lastVersion=0&downloadCount=0"; |
| 136 ASSERT_EQ(expectedUrl, previousRequestUrl); | 135 ASSERT_EQ(expectedUrl, previousRequestUrl); |
| 137 } | 136 } |
| 138 | 137 |
| 139 TEST_F(UpdateCheckTest, UpdateAvailable) | 138 TEST_F(UpdateCheckTest, UpdateAvailable) |
| 140 { | 139 { |
| 141 webRequest->response.status = AdblockPlus::WebRequest::NS_OK; | 140 webRequest->response.status = AdblockPlus::WebRequest::NS_OK; |
| 142 webRequest->response.responseStatus = 200; | 141 webRequest->response.responseStatus = 200; |
| 143 webRequest->response.responseText = "{\"1\": {\"version\":\"3.1\",\"url\":\"ht
tps://foo.bar/\"}}"; | 142 webRequest->response.responseText = "{\"1\": {\"version\":\"3.1\",\"url\":\"ht
tps://foo.bar/\"}}"; |
| 144 | 143 |
| 145 appInfo.name = "1"; | 144 appInfo.name = "1"; |
| 146 appInfo.id = "2"; | 145 appInfo.version = "3"; |
| 147 appInfo.version = "3"; | 146 appInfo.application = "4"; |
| 148 appInfo.application = "4"; | 147 appInfo.applicationVersion = "2"; |
| 149 appInfo.applicationVersion = "5"; | |
| 150 appInfo.developmentBuild = true; | 148 appInfo.developmentBuild = true; |
| 151 | 149 |
| 152 Reset(); | 150 Reset(); |
| 153 ForceUpdateCheck(); | 151 ForceUpdateCheck(); |
| 154 | 152 |
| 155 AdblockPlus::Sleep(100); | 153 AdblockPlus::Sleep(100); |
| 156 | 154 |
| 157 ASSERT_TRUE(eventCallbackCalled); | 155 ASSERT_TRUE(eventCallbackCalled); |
| 158 ASSERT_EQ(1u, eventCallbackParams.size()); | 156 ASSERT_EQ(1u, eventCallbackParams.size()); |
| 159 ASSERT_EQ("https://foo.bar/", eventCallbackParams[0]->AsString()); | 157 ASSERT_EQ("https://foo.bar/", eventCallbackParams[0]->AsString()); |
| 160 ASSERT_TRUE(updateCallbackCalled); | 158 ASSERT_TRUE(updateCallbackCalled); |
| 161 ASSERT_TRUE(updateError.empty()); | 159 ASSERT_TRUE(updateError.empty()); |
| 162 | 160 |
| 163 std::string expectedUrl(filterEngine->GetPref("update_url_devbuild")->AsString
()); | 161 std::string expectedUrl(filterEngine->GetPref("update_url_devbuild")->AsString
()); |
| 164 std::string platform = jsEngine->Evaluate("require('info').platform")->AsStrin
g(); | 162 std::string platform = jsEngine->Evaluate("require('info').platform")->AsStrin
g(); |
| 165 std::string platformVersion = jsEngine->Evaluate("require('info').platformVers
ion")->AsString(); | 163 std::string platformVersion = jsEngine->Evaluate("require('info').platformVers
ion")->AsString(); |
| 166 | 164 |
| 167 FindAndReplace(expectedUrl, "%NAME%", appInfo.name); | 165 FindAndReplace(expectedUrl, "%NAME%", appInfo.name); |
| 168 FindAndReplace(expectedUrl, "%TYPE%", "1"); // manual update | 166 FindAndReplace(expectedUrl, "%TYPE%", "1"); // manual update |
| 169 expectedUrl += "&addonName=" + appInfo.name + | 167 expectedUrl += "&addonName=" + appInfo.name + |
| 170 "&addonVersion=" + appInfo.version + | 168 "&addonVersion=" + appInfo.version + |
| 171 "&application=" + appInfo.application + | 169 "&application=" + appInfo.application + |
| 172 "&applicationVersion=" + appInfo.applicationVersion + | 170 "&applicationVersion=" + appInfo.applicationVersion + |
| 173 "&platform=" + platform + | 171 "&platform=" + platform + |
| 174 "&platformVersion=" + platformVersion + | 172 "&platformVersion=" + platformVersion + |
| 175 "&lastVersion=0"; | 173 "&lastVersion=0&downloadCount=0"; |
| 176 ASSERT_EQ(expectedUrl, previousRequestUrl); | 174 ASSERT_EQ(expectedUrl, previousRequestUrl); |
| 177 } | 175 } |
| 178 | 176 |
| 179 TEST_F(UpdateCheckTest, ApplicationUpdateAvailable) | 177 TEST_F(UpdateCheckTest, ApplicationUpdateAvailable) |
| 180 { | 178 { |
| 181 webRequest->response.status = AdblockPlus::WebRequest::NS_OK; | 179 webRequest->response.status = AdblockPlus::WebRequest::NS_OK; |
| 182 webRequest->response.responseStatus = 200; | 180 webRequest->response.responseStatus = 200; |
| 183 webRequest->response.responseText = "{\"1/4\": {\"version\":\"3.1\",\"url\":\"
https://foo.bar/\"}}"; | 181 webRequest->response.responseText = "{\"1/4\": {\"version\":\"3.1\",\"url\":\"
https://foo.bar/\"}}"; |
| 184 | 182 |
| 185 appInfo.name = "1"; | 183 appInfo.name = "1"; |
| 186 appInfo.id = "2"; | 184 appInfo.version = "3"; |
| 187 appInfo.version = "3"; | 185 appInfo.application = "4"; |
| 188 appInfo.application = "4"; | 186 appInfo.applicationVersion = "2"; |
| 189 appInfo.applicationVersion = "5"; | |
| 190 appInfo.developmentBuild = true; | 187 appInfo.developmentBuild = true; |
| 191 | 188 |
| 192 Reset(); | 189 Reset(); |
| 193 ForceUpdateCheck(); | 190 ForceUpdateCheck(); |
| 194 | 191 |
| 195 AdblockPlus::Sleep(100); | 192 AdblockPlus::Sleep(100); |
| 196 | 193 |
| 197 ASSERT_TRUE(eventCallbackCalled); | 194 ASSERT_TRUE(eventCallbackCalled); |
| 198 ASSERT_EQ(1u, eventCallbackParams.size()); | 195 ASSERT_EQ(1u, eventCallbackParams.size()); |
| 199 ASSERT_EQ("https://foo.bar/", eventCallbackParams[0]->AsString()); | 196 ASSERT_EQ("https://foo.bar/", eventCallbackParams[0]->AsString()); |
| 200 ASSERT_TRUE(updateCallbackCalled); | 197 ASSERT_TRUE(updateCallbackCalled); |
| 201 ASSERT_TRUE(updateError.empty()); | 198 ASSERT_TRUE(updateError.empty()); |
| 202 } | 199 } |
| 203 | 200 |
| 204 TEST_F(UpdateCheckTest, WrongApplication) | 201 TEST_F(UpdateCheckTest, WrongApplication) |
| 205 { | 202 { |
| 206 webRequest->response.status = AdblockPlus::WebRequest::NS_OK; | 203 webRequest->response.status = AdblockPlus::WebRequest::NS_OK; |
| 207 webRequest->response.responseStatus = 200; | 204 webRequest->response.responseStatus = 200; |
| 208 webRequest->response.responseText = "{\"1/3\": {\"version\":\"3.1\",\"url\":\"
https://foo.bar/\"}}"; | 205 webRequest->response.responseText = "{\"1/3\": {\"version\":\"3.1\",\"url\":\"
https://foo.bar/\"}}"; |
| 209 | 206 |
| 210 appInfo.name = "1"; | 207 appInfo.name = "1"; |
| 211 appInfo.id = "2"; | 208 appInfo.version = "3"; |
| 212 appInfo.version = "3"; | 209 appInfo.application = "4"; |
| 213 appInfo.application = "4"; | 210 appInfo.applicationVersion = "2"; |
| 214 appInfo.applicationVersion = "5"; | |
| 215 appInfo.developmentBuild = true; | 211 appInfo.developmentBuild = true; |
| 216 | 212 |
| 217 Reset(); | 213 Reset(); |
| 218 ForceUpdateCheck(); | 214 ForceUpdateCheck(); |
| 219 | 215 |
| 220 AdblockPlus::Sleep(100); | 216 AdblockPlus::Sleep(100); |
| 221 | 217 |
| 222 ASSERT_FALSE(eventCallbackCalled); | 218 ASSERT_FALSE(eventCallbackCalled); |
| 223 ASSERT_TRUE(updateCallbackCalled); | 219 ASSERT_TRUE(updateCallbackCalled); |
| 224 ASSERT_TRUE(updateError.empty()); | 220 ASSERT_TRUE(updateError.empty()); |
| 225 } | 221 } |
| 226 | 222 |
| 227 TEST_F(UpdateCheckTest, WrongVersion) | 223 TEST_F(UpdateCheckTest, WrongVersion) |
| 228 { | 224 { |
| 229 webRequest->response.status = AdblockPlus::WebRequest::NS_OK; | 225 webRequest->response.status = AdblockPlus::WebRequest::NS_OK; |
| 230 webRequest->response.responseStatus = 200; | 226 webRequest->response.responseStatus = 200; |
| 231 webRequest->response.responseText = "{\"1\": {\"version\":\"3\",\"url\":\"http
s://foo.bar/\"}}"; | 227 webRequest->response.responseText = "{\"1\": {\"version\":\"3\",\"url\":\"http
s://foo.bar/\"}}"; |
| 232 | 228 |
| 233 appInfo.name = "1"; | 229 appInfo.name = "1"; |
| 234 appInfo.id = "2"; | 230 appInfo.version = "3"; |
| 235 appInfo.version = "3"; | 231 appInfo.application = "4"; |
| 236 appInfo.application = "4"; | 232 appInfo.applicationVersion = "2"; |
| 237 appInfo.applicationVersion = "5"; | |
| 238 appInfo.developmentBuild = true; | 233 appInfo.developmentBuild = true; |
| 239 | 234 |
| 240 Reset(); | 235 Reset(); |
| 241 ForceUpdateCheck(); | 236 ForceUpdateCheck(); |
| 242 | 237 |
| 243 AdblockPlus::Sleep(100); | 238 AdblockPlus::Sleep(100); |
| 244 | 239 |
| 245 ASSERT_FALSE(eventCallbackCalled); | 240 ASSERT_FALSE(eventCallbackCalled); |
| 246 ASSERT_TRUE(updateCallbackCalled); | 241 ASSERT_TRUE(updateCallbackCalled); |
| 247 ASSERT_TRUE(updateError.empty()); | 242 ASSERT_TRUE(updateError.empty()); |
| 248 } | 243 } |
| 249 | 244 |
| 250 TEST_F(UpdateCheckTest, WrongURL) | 245 TEST_F(UpdateCheckTest, WrongURL) |
| 251 { | 246 { |
| 252 webRequest->response.status = AdblockPlus::WebRequest::NS_OK; | 247 webRequest->response.status = AdblockPlus::WebRequest::NS_OK; |
| 253 webRequest->response.responseStatus = 200; | 248 webRequest->response.responseStatus = 200; |
| 254 webRequest->response.responseText = "{\"1\": {\"version\":\"3.1\",\"url\":\"ht
tp://insecure/\"}}"; | 249 webRequest->response.responseText = "{\"1\": {\"version\":\"3.1\",\"url\":\"ht
tp://insecure/\"}}"; |
| 255 | 250 |
| 256 appInfo.name = "1"; | 251 appInfo.name = "1"; |
| 257 appInfo.id = "2"; | 252 appInfo.version = "3"; |
| 258 appInfo.version = "3"; | 253 appInfo.application = "4"; |
| 259 appInfo.application = "4"; | 254 appInfo.applicationVersion = "2"; |
| 260 appInfo.applicationVersion = "5"; | |
| 261 appInfo.developmentBuild = true; | 255 appInfo.developmentBuild = true; |
| 262 | 256 |
| 263 Reset(); | 257 Reset(); |
| 264 ForceUpdateCheck(); | 258 ForceUpdateCheck(); |
| 265 | 259 |
| 266 AdblockPlus::Sleep(100); | 260 AdblockPlus::Sleep(100); |
| 267 | 261 |
| 268 ASSERT_FALSE(eventCallbackCalled); | 262 ASSERT_FALSE(eventCallbackCalled); |
| 269 ASSERT_TRUE(updateCallbackCalled); | 263 ASSERT_TRUE(updateCallbackCalled); |
| 270 ASSERT_FALSE(updateError.empty()); | 264 ASSERT_FALSE(updateError.empty()); |
| 271 } | 265 } |
| LEFT | RIGHT |