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

Unified Diff: test/FilterEngine.cpp

Issue 10291009: Disable side-effects in filter engine tests (Closed)
Patch Set: Created April 26, 2013, 12:14 p.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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/FilterEngine.cpp
===================================================================
--- a/test/FilterEngine.cpp
+++ b/test/FilterEngine.cpp
@@ -1,25 +1,78 @@
#include "BaseJsTest.h"
+#include "../src/Thread.h"
namespace
{
typedef std::tr1::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr;
+ // This file system implementation never does anything - makes sure
+ // FilterEngine doesn't do any I/O during test and the corresponding
+ // callbacks are never called.
+ class LazyFileSystem : public AdblockPlus::FileSystem
+ {
+ std::tr1::shared_ptr<std::istream> Read(const std::string& path) const
+ {
+ while (true)
+ AdblockPlus::Sleep(100000);
+ return std::tr1::shared_ptr<std::istream>();
+ }
+
+ void Write(const std::string& path,
+ std::tr1::shared_ptr<std::ostream> content)
+ {
+ while (true)
+ AdblockPlus::Sleep(100000);
+ }
+
+ void Move(const std::string& fromPath, const std::string& toPath)
+ {
+ while (true)
+ AdblockPlus::Sleep(100000);
+ }
+
+ void Remove(const std::string& path)
+ {
+ while (true)
+ AdblockPlus::Sleep(100000);
+ }
+
+ StatResult Stat(const std::string& path) const
+ {
+ while (true)
+ AdblockPlus::Sleep(100000);
+ return StatResult();
+ }
+ };
+
+ // This web request implementation never does anything - makes sure
+ // FilterEngine doesn't cause any net traffic during test and the
+ // corresponding callbacks are never called.
+ class LazyWebRequest : public AdblockPlus::WebRequest
+ {
+ AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::HeaderList& requestHeaders) const
+ {
+ while (true)
+ AdblockPlus::Sleep(100000);
+ return AdblockPlus::ServerResponse();
+ }
+ };
+
class FilterEngineTest : public BaseJsTest
{
protected:
FilterEnginePtr filterEngine;
void SetUp()
{
BaseJsTest::SetUp();
- // TODO: Don't use the default ErrorCallback/WebRequest
+ jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem));
+ jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest));
jsEngine->SetErrorCallback(AdblockPlus::ErrorCallbackPtr(new AdblockPlus::DefaultErrorCallback));
- jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new AdblockPlus::DefaultWebRequest));
filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine));
}
};
}
TEST_F(FilterEngineTest, FilterCreation)
{
AdblockPlus::FilterPtr filter1 = filterEngine->GetFilter("foo");
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld