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

Delta Between Two Patch Sets: test/FilterEngine.cpp

Issue 10291009: Disable side-effects in filter engine tests (Closed)
Left Patch Set: Created April 26, 2013, 12:14 p.m.
Right Patch Set: Fixed the other TODO in tests Created April 26, 2013, 12:44 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 #include "BaseJsTest.h" 1 #include "BaseJsTest.h"
2 #include "../src/Thread.h"
3 2
4 namespace 3 namespace
5 { 4 {
6 typedef std::tr1::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr; 5 typedef std::tr1::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr;
7
8 // This file system implementation never does anything - makes sure
9 // FilterEngine doesn't do any I/O during test and the corresponding
10 // callbacks are never called.
11 class LazyFileSystem : public AdblockPlus::FileSystem
12 {
13 std::tr1::shared_ptr<std::istream> Read(const std::string& path) const
14 {
15 while (true)
16 AdblockPlus::Sleep(100000);
17 return std::tr1::shared_ptr<std::istream>();
18 }
19
20 void Write(const std::string& path,
21 std::tr1::shared_ptr<std::ostream> content)
22 {
23 while (true)
24 AdblockPlus::Sleep(100000);
25 }
26
27 void Move(const std::string& fromPath, const std::string& toPath)
28 {
29 while (true)
30 AdblockPlus::Sleep(100000);
31 }
32
33 void Remove(const std::string& path)
34 {
35 while (true)
36 AdblockPlus::Sleep(100000);
37 }
38
39 StatResult Stat(const std::string& path) const
40 {
41 while (true)
42 AdblockPlus::Sleep(100000);
43 return StatResult();
44 }
45 };
46
47 // This web request implementation never does anything - makes sure
48 // FilterEngine doesn't cause any net traffic during test and the
49 // corresponding callbacks are never called.
50 class LazyWebRequest : public AdblockPlus::WebRequest
51 {
52 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::H eaderList& requestHeaders) const
53 {
54 while (true)
55 AdblockPlus::Sleep(100000);
56 return AdblockPlus::ServerResponse();
57 }
58 };
59 6
60 class FilterEngineTest : public BaseJsTest 7 class FilterEngineTest : public BaseJsTest
61 { 8 {
62 protected: 9 protected:
63 FilterEnginePtr filterEngine; 10 FilterEnginePtr filterEngine;
64 11
65 void SetUp() 12 void SetUp()
66 { 13 {
67 BaseJsTest::SetUp(); 14 BaseJsTest::SetUp();
68 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem)); 15 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem));
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 ASSERT_TRUE(match6); 136 ASSERT_TRUE(match6);
190 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetType()); 137 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetType());
191 138
192 AdblockPlus::FilterPtr match7 = filterEngine->Matches("http://example.org/tpba nner.gif", "IMAGE", "http://example.com/"); 139 AdblockPlus::FilterPtr match7 = filterEngine->Matches("http://example.org/tpba nner.gif", "IMAGE", "http://example.com/");
193 ASSERT_TRUE(match7); 140 ASSERT_TRUE(match7);
194 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetType()); 141 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetType());
195 142
196 AdblockPlus::FilterPtr match8 = filterEngine->Matches("http://example.org/fpba nner.gif", "IMAGE", "http://example.com/"); 143 AdblockPlus::FilterPtr match8 = filterEngine->Matches("http://example.org/fpba nner.gif", "IMAGE", "http://example.com/");
197 ASSERT_FALSE(match8); 144 ASSERT_FALSE(match8);
198 } 145 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld