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 13 matching lines...) Expand all Loading... |
24 namespace | 24 namespace |
25 { | 25 { |
26 typedef std::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr; | 26 typedef std::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr; |
27 | 27 |
28 void FindAndReplace(std::string& source, const std::string& find, const std::s
tring& replace) | 28 void FindAndReplace(std::string& source, const std::string& find, const std::s
tring& replace) |
29 { | 29 { |
30 for (size_t pos = 0; (pos = source.find(find), pos) != std::string::npos; po
s += replace.size()) | 30 for (size_t pos = 0; (pos = source.find(find), pos) != std::string::npos; po
s += replace.size()) |
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 BaseJsTest |
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 std::unique_ptr<Platform> platform; | |
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 LazyFileSystem* fileSystem; | 56 LazyFileSystem* fileSystem; |
58 ThrowingPlatformCreationParameters platformParams; | 57 ThrowingPlatformCreationParameters platformParams; |
59 platformParams.logSystem.reset(new LazyLogSystem()); | 58 platformParams.logSystem.reset(new LazyLogSystem()); |
60 platformParams.timer = DelayedTimer::New(timerTasks); | 59 platformParams.timer = DelayedTimer::New(timerTasks); |
61 platformParams.fileSystem.reset(fileSystem = new LazyFileSystem()); | 60 platformParams.fileSystem.reset(fileSystem = new LazyFileSystem()); |
62 platformParams.webRequest = DelayedWebRequest::New(webRequestTasks); | 61 platformParams.webRequest = DelayedWebRequest::New(webRequestTasks); |
63 platform.reset(new Platform(std::move(platformParams))); | 62 platform.reset(new Platform(std::move(platformParams))); |
64 platform->SetUpJsEngine(appInfo); | 63 platform->SetUpJsEngine(appInfo); |
65 platform->GetJsEngine()->SetEventCallback("updateAvailable", [this](JsValu
eList&& params) | 64 GetJsEngine().SetEventCallback("updateAvailable", [this](JsValueList&& par
ams) |
66 { | 65 { |
67 eventCallbackCalled = true; | 66 eventCallbackCalled = true; |
68 eventCallbackParams = std::move(params); | 67 eventCallbackParams = std::move(params); |
69 }); | 68 }); |
70 | 69 |
71 filterEngine = ::CreateFilterEngine(*fileSystem, *platform); | 70 filterEngine = ::CreateFilterEngine(*fileSystem, *platform); |
72 } | 71 } |
73 | 72 |
74 // Returns a URL or the empty string if there is no such request. | 73 // Returns a URL or the empty string if there is no such request. |
75 std::string ProcessPendingUpdateWebRequest() | 74 std::string ProcessPendingUpdateWebRequest() |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 CreateFilterEngine(); | 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 = filterEngine->GetJsEngine()->Evaluate("require('info').
platform").AsString(); | 123 std::string platform = GetJsEngine().Evaluate("require('info').platform").AsSt
ring(); |
125 std::string platformVersion = filterEngine->GetJsEngine()->Evaluate("require('
info').platformVersion").AsString(); | 124 std::string platformVersion = GetJsEngine().Evaluate("require('info').platform
Version").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&downloadCount=0"; | 134 "&lastVersion=0&downloadCount=0"; |
(...skipping 17 matching lines...) Expand all Loading... |
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 |
162 std::string expectedUrl(filterEngine->GetPref("update_url_devbuild").AsString(
)); | 161 std::string expectedUrl(filterEngine->GetPref("update_url_devbuild").AsString(
)); |
163 std::string platform = filterEngine->GetJsEngine()->Evaluate("require('info').
platform").AsString(); | 162 std::string platform = GetJsEngine().Evaluate("require('info').platform").AsSt
ring(); |
164 std::string platformVersion = filterEngine->GetJsEngine()->Evaluate("require('
info').platformVersion").AsString(); | 163 std::string platformVersion = GetJsEngine().Evaluate("require('info').platform
Version").AsString(); |
165 | 164 |
166 FindAndReplace(expectedUrl, "%NAME%", appInfo.name); | 165 FindAndReplace(expectedUrl, "%NAME%", appInfo.name); |
167 FindAndReplace(expectedUrl, "%TYPE%", "1"); // manual update | 166 FindAndReplace(expectedUrl, "%TYPE%", "1"); // manual update |
168 expectedUrl += "&addonName=" + appInfo.name + | 167 expectedUrl += "&addonName=" + appInfo.name + |
169 "&addonVersion=" + appInfo.version + | 168 "&addonVersion=" + appInfo.version + |
170 "&application=" + appInfo.application + | 169 "&application=" + appInfo.application + |
171 "&applicationVersion=" + appInfo.applicationVersion + | 170 "&applicationVersion=" + appInfo.applicationVersion + |
172 "&platform=" + platform + | 171 "&platform=" + platform + |
173 "&platformVersion=" + platformVersion + | 172 "&platformVersion=" + platformVersion + |
174 "&lastVersion=0&downloadCount=0"; | 173 "&lastVersion=0&downloadCount=0"; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 | 300 |
302 // ensure that the was the corresponding request | 301 // ensure that the was the corresponding request |
303 EXPECT_FALSE(ProcessPendingUpdateWebRequest().empty()); | 302 EXPECT_FALSE(ProcessPendingUpdateWebRequest().empty()); |
304 | 303 |
305 EXPECT_FALSE(eventCallbackCalled); | 304 EXPECT_FALSE(eventCallbackCalled); |
306 EXPECT_EQ(1, timesCalled); | 305 EXPECT_EQ(1, timesCalled); |
307 | 306 |
308 // previous handler is not restored | 307 // previous handler is not restored |
309 EXPECT_FALSE(eventCallbackCalled); | 308 EXPECT_FALSE(eventCallbackCalled); |
310 } | 309 } |
OLD | NEW |