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