| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 class UpdateCheckTest : public ::testing::Test | 47 class UpdateCheckTest : public ::testing::Test |
| 48 { | 48 { |
| 49 protected: | 49 protected: |
| 50 AdblockPlus::AppInfo appInfo; | 50 AdblockPlus::AppInfo appInfo; |
| 51 TestWebRequest* webRequest; | 51 TestWebRequest* webRequest; |
| 52 AdblockPlus::WebRequestPtr webRequestPtr; | 52 AdblockPlus::WebRequestPtr webRequestPtr; |
| 53 AdblockPlus::JsEnginePtr jsEngine; | 53 AdblockPlus::JsEnginePtr jsEngine; |
| 54 FilterEnginePtr filterEngine; | 54 FilterEnginePtr filterEngine; |
| 55 | 55 |
| 56 bool eventCallbackCalled; | 56 bool eventCallbackCalled; |
| 57 AdblockPlus::JsConstValueList eventCallbackParams; | 57 AdblockPlus::JsValueList eventCallbackParams; |
| 58 bool updateCallbackCalled; | 58 bool updateCallbackCalled; |
| 59 std::string updateError; | 59 std::string updateError; |
| 60 | 60 |
| 61 void SetUp() | 61 void SetUp() |
| 62 { | 62 { |
| 63 webRequest = new TestWebRequest(); | 63 webRequest = new TestWebRequest(); |
| 64 webRequestPtr.reset(webRequest); | 64 webRequestPtr.reset(webRequest); |
| 65 | 65 |
| 66 eventCallbackCalled = false; | 66 eventCallbackCalled = false; |
| 67 updateCallbackCalled = false; | 67 updateCallbackCalled = false; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 79 | 79 |
| 80 filterEngine = AdblockPlus::FilterEngine::Create(jsEngine); | 80 filterEngine = AdblockPlus::FilterEngine::Create(jsEngine); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void ForceUpdateCheck() | 83 void ForceUpdateCheck() |
| 84 { | 84 { |
| 85 filterEngine->ForceUpdateCheck( | 85 filterEngine->ForceUpdateCheck( |
| 86 std::bind(&UpdateCheckTest::UpdateCallback, this, std::placeholders::_
1)); | 86 std::bind(&UpdateCheckTest::UpdateCallback, this, std::placeholders::_
1)); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void EventCallback(const AdblockPlus::JsConstValueList& params) | 89 void EventCallback(const AdblockPlus::JsValueList& params) |
| 90 { | 90 { |
| 91 eventCallbackCalled = true; | 91 eventCallbackCalled = true; |
| 92 eventCallbackParams = params; | 92 eventCallbackParams = params; |
| 93 } | 93 } |
| 94 | 94 |
| 95 void UpdateCallback(const std::string& error) | 95 void UpdateCallback(const std::string& error) |
| 96 { | 96 { |
| 97 updateCallbackCalled = true; | 97 updateCallbackCalled = true; |
| 98 updateError = error; | 98 updateError = error; |
| 99 } | 99 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 112 | 112 |
| 113 Reset(); | 113 Reset(); |
| 114 ForceUpdateCheck(); | 114 ForceUpdateCheck(); |
| 115 | 115 |
| 116 AdblockPlus::Sleep(100); | 116 AdblockPlus::Sleep(100); |
| 117 | 117 |
| 118 ASSERT_FALSE(eventCallbackCalled); | 118 ASSERT_FALSE(eventCallbackCalled); |
| 119 ASSERT_TRUE(updateCallbackCalled); | 119 ASSERT_TRUE(updateCallbackCalled); |
| 120 ASSERT_FALSE(updateError.empty()); | 120 ASSERT_FALSE(updateError.empty()); |
| 121 | 121 |
| 122 std::string expectedUrl(filterEngine->GetPref("update_url_release")->AsString(
)); | 122 std::string expectedUrl(filterEngine->GetPref("update_url_release").AsString()
); |
| 123 std::string platform = jsEngine->Evaluate("require('info').platform")->AsStrin
g(); | 123 std::string platform = jsEngine->Evaluate("require('info').platform")->AsStrin
g(); |
| 124 std::string platformVersion = jsEngine->Evaluate("require('info').platformVers
ion")->AsString(); | 124 std::string platformVersion = jsEngine->Evaluate("require('info').platformVers
ion")->AsString(); |
| 125 | 125 |
| 126 FindAndReplace(expectedUrl, "%NAME%", appInfo.name); | 126 FindAndReplace(expectedUrl, "%NAME%", appInfo.name); |
| 127 FindAndReplace(expectedUrl, "%TYPE%", "1"); // manual update | 127 FindAndReplace(expectedUrl, "%TYPE%", "1"); // manual update |
| 128 expectedUrl += "&addonName=" + appInfo.name + | 128 expectedUrl += "&addonName=" + appInfo.name + |
| 129 "&addonVersion=" + appInfo.version + | 129 "&addonVersion=" + appInfo.version + |
| 130 "&application=" + appInfo.application + | 130 "&application=" + appInfo.application + |
| 131 "&applicationVersion=" + appInfo.applicationVersion + | 131 "&applicationVersion=" + appInfo.applicationVersion + |
| 132 "&platform=" + platform + | 132 "&platform=" + platform + |
| (...skipping 14 matching lines...) Expand all Loading... |
| 147 appInfo.applicationVersion = "2"; | 147 appInfo.applicationVersion = "2"; |
| 148 appInfo.developmentBuild = true; | 148 appInfo.developmentBuild = true; |
| 149 | 149 |
| 150 Reset(); | 150 Reset(); |
| 151 ForceUpdateCheck(); | 151 ForceUpdateCheck(); |
| 152 | 152 |
| 153 AdblockPlus::Sleep(100); | 153 AdblockPlus::Sleep(100); |
| 154 | 154 |
| 155 ASSERT_TRUE(eventCallbackCalled); | 155 ASSERT_TRUE(eventCallbackCalled); |
| 156 ASSERT_EQ(1u, eventCallbackParams.size()); | 156 ASSERT_EQ(1u, eventCallbackParams.size()); |
| 157 ASSERT_EQ("https://foo.bar/", eventCallbackParams[0]->AsString()); | 157 ASSERT_EQ("https://foo.bar/", eventCallbackParams[0].AsString()); |
| 158 ASSERT_TRUE(updateCallbackCalled); | 158 ASSERT_TRUE(updateCallbackCalled); |
| 159 ASSERT_TRUE(updateError.empty()); | 159 ASSERT_TRUE(updateError.empty()); |
| 160 | 160 |
| 161 std::string expectedUrl(filterEngine->GetPref("update_url_devbuild")->AsString
()); | 161 std::string expectedUrl(filterEngine->GetPref("update_url_devbuild").AsString(
)); |
| 162 std::string platform = jsEngine->Evaluate("require('info').platform")->AsStrin
g(); | 162 std::string platform = jsEngine->Evaluate("require('info').platform")->AsStrin
g(); |
| 163 std::string platformVersion = jsEngine->Evaluate("require('info').platformVers
ion")->AsString(); | 163 std::string platformVersion = jsEngine->Evaluate("require('info').platformVers
ion")->AsString(); |
| 164 | 164 |
| 165 FindAndReplace(expectedUrl, "%NAME%", appInfo.name); | 165 FindAndReplace(expectedUrl, "%NAME%", appInfo.name); |
| 166 FindAndReplace(expectedUrl, "%TYPE%", "1"); // manual update | 166 FindAndReplace(expectedUrl, "%TYPE%", "1"); // manual update |
| 167 expectedUrl += "&addonName=" + appInfo.name + | 167 expectedUrl += "&addonName=" + appInfo.name + |
| 168 "&addonVersion=" + appInfo.version + | 168 "&addonVersion=" + appInfo.version + |
| 169 "&application=" + appInfo.application + | 169 "&application=" + appInfo.application + |
| 170 "&applicationVersion=" + appInfo.applicationVersion + | 170 "&applicationVersion=" + appInfo.applicationVersion + |
| 171 "&platform=" + platform + | 171 "&platform=" + platform + |
| (...skipping 14 matching lines...) Expand all Loading... |
| 186 appInfo.applicationVersion = "2"; | 186 appInfo.applicationVersion = "2"; |
| 187 appInfo.developmentBuild = true; | 187 appInfo.developmentBuild = true; |
| 188 | 188 |
| 189 Reset(); | 189 Reset(); |
| 190 ForceUpdateCheck(); | 190 ForceUpdateCheck(); |
| 191 | 191 |
| 192 AdblockPlus::Sleep(100); | 192 AdblockPlus::Sleep(100); |
| 193 | 193 |
| 194 ASSERT_TRUE(eventCallbackCalled); | 194 ASSERT_TRUE(eventCallbackCalled); |
| 195 ASSERT_EQ(1u, eventCallbackParams.size()); | 195 ASSERT_EQ(1u, eventCallbackParams.size()); |
| 196 ASSERT_EQ("https://foo.bar/", eventCallbackParams[0]->AsString()); | 196 ASSERT_EQ("https://foo.bar/", eventCallbackParams[0].AsString()); |
| 197 ASSERT_TRUE(updateCallbackCalled); | 197 ASSERT_TRUE(updateCallbackCalled); |
| 198 ASSERT_TRUE(updateError.empty()); | 198 ASSERT_TRUE(updateError.empty()); |
| 199 } | 199 } |
| 200 | 200 |
| 201 TEST_F(UpdateCheckTest, WrongApplication) | 201 TEST_F(UpdateCheckTest, WrongApplication) |
| 202 { | 202 { |
| 203 webRequest->response.status = AdblockPlus::WebRequest::NS_OK; | 203 webRequest->response.status = AdblockPlus::WebRequest::NS_OK; |
| 204 webRequest->response.responseStatus = 200; | 204 webRequest->response.responseStatus = 200; |
| 205 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/\"}}"; |
| 206 | 206 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 | 256 |
| 257 Reset(); | 257 Reset(); |
| 258 ForceUpdateCheck(); | 258 ForceUpdateCheck(); |
| 259 | 259 |
| 260 AdblockPlus::Sleep(100); | 260 AdblockPlus::Sleep(100); |
| 261 | 261 |
| 262 ASSERT_FALSE(eventCallbackCalled); | 262 ASSERT_FALSE(eventCallbackCalled); |
| 263 ASSERT_TRUE(updateCallbackCalled); | 263 ASSERT_TRUE(updateCallbackCalled); |
| 264 ASSERT_FALSE(updateError.empty()); | 264 ASSERT_FALSE(updateError.empty()); |
| 265 } | 265 } |
| OLD | NEW |