Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/WebRequest.cpp

Issue 29499621: Issue 4983 - Get rid of Sleep() in the WebRequest test (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created July 27, 2017, 10:18 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/JsEngine.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/WebRequest.cpp
diff --git a/test/WebRequest.cpp b/test/WebRequest.cpp
index a445d93dff10272639fc6d8dc5caf4c6ef8c7c04..4d54be47a69d1e3c1a1b2a955cb5bf30d1679c59 100644
--- a/test/WebRequest.cpp
+++ b/test/WebRequest.cpp
@@ -25,7 +25,7 @@ using namespace AdblockPlus;
namespace
{
- class DefaultWebRequestTest : public ::testing::Test
+ class BaseWebRequestTest : public ::testing::Test
{
protected:
void SetUp()
@@ -38,10 +38,7 @@ namespace
jsEngine = CreateJsEngine(std::move(jsEngineParams));
}
- virtual WebRequestPtr CreateWebRequest()
- {
- return CreateDefaultWebRequest();
- }
+ virtual WebRequestPtr CreateWebRequest() = 0;
virtual LogSystemPtr CreateLogSystem()
{
@@ -52,9 +49,30 @@ namespace
LazyFileSystem* fileSystem;
};
- class MockWebRequestTest : public DefaultWebRequestTest
+ class DefaultWebRequestTest : public BaseWebRequestTest
+ {
+ WebRequestPtr CreateWebRequest() override
+ {
+ return CreateDefaultWebRequest([this](const SchedulerTask& task)
+ {
+ webRequestTasks.emplace_back(task);
+ });
+ }
+ std::list<SchedulerTask> webRequestTasks;
+ protected:
+ void WaitForVariable(const std::string& variable, const AdblockPlus::JsEnginePtr& jsEngine)
+ {
+ while (jsEngine->Evaluate(variable).IsUndefined() && !webRequestTasks.empty())
+ {
+ (*webRequestTasks.begin())();
+ webRequestTasks.pop_front();
+ }
+ }
+ };
+
+ class MockWebRequestTest : public BaseWebRequestTest
{
- virtual WebRequestPtr CreateWebRequest() override
+ WebRequestPtr CreateWebRequest() override
{
return DelayedWebRequest::New(webRequestTasks);
}
@@ -127,15 +145,6 @@ namespace
");
return url;
}
-
- void WaitForVariable(const std::string& variable, const AdblockPlus::JsEnginePtr& jsEngine)
- {
- do
- {
- AdblockPlus::Sleep(60);
- } while (jsEngine->Evaluate(variable).IsUndefined());
- }
-
}
TEST_F(MockWebRequestTest, BadCall)
« no previous file with comments | « src/JsEngine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld