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

Side by Side Diff: test/FilterEngine.cpp

Issue 10291009: Disable side-effects in filter engine tests (Closed)
Patch Set: Created April 26, 2013, 12:14 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "BaseJsTest.h" 1 #include "BaseJsTest.h"
2 #include "../src/Thread.h"
2 3
3 namespace 4 namespace
4 { 5 {
5 typedef std::tr1::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr; 6 typedef std::tr1::shared_ptr<AdblockPlus::FilterEngine> FilterEnginePtr;
6 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
7 class FilterEngineTest : public BaseJsTest 60 class FilterEngineTest : public BaseJsTest
8 { 61 {
9 protected: 62 protected:
10 FilterEnginePtr filterEngine; 63 FilterEnginePtr filterEngine;
11 64
12 void SetUp() 65 void SetUp()
13 { 66 {
14 BaseJsTest::SetUp(); 67 BaseJsTest::SetUp();
15 // TODO: Don't use the default ErrorCallback/WebRequest 68 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem));
69 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest));
16 jsEngine->SetErrorCallback(AdblockPlus::ErrorCallbackPtr(new AdblockPlus:: DefaultErrorCallback)); 70 jsEngine->SetErrorCallback(AdblockPlus::ErrorCallbackPtr(new AdblockPlus:: DefaultErrorCallback));
17 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new AdblockPlus::Defaul tWebRequest));
18 filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine)); 71 filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine));
19 } 72 }
20 }; 73 };
21 } 74 }
22 75
23 TEST_F(FilterEngineTest, FilterCreation) 76 TEST_F(FilterEngineTest, FilterCreation)
24 { 77 {
25 AdblockPlus::FilterPtr filter1 = filterEngine->GetFilter("foo"); 78 AdblockPlus::FilterPtr filter1 = filterEngine->GetFilter("foo");
26 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetType()); 79 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetType());
27 AdblockPlus::FilterPtr filter2 = filterEngine->GetFilter("@@foo"); 80 AdblockPlus::FilterPtr filter2 = filterEngine->GetFilter("@@foo");
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 ASSERT_TRUE(match6); 189 ASSERT_TRUE(match6);
137 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetType()); 190 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetType());
138 191
139 AdblockPlus::FilterPtr match7 = filterEngine->Matches("http://example.org/tpba nner.gif", "IMAGE", "http://example.com/"); 192 AdblockPlus::FilterPtr match7 = filterEngine->Matches("http://example.org/tpba nner.gif", "IMAGE", "http://example.com/");
140 ASSERT_TRUE(match7); 193 ASSERT_TRUE(match7);
141 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetType()); 194 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, match6->GetType());
142 195
143 AdblockPlus::FilterPtr match8 = filterEngine->Matches("http://example.org/fpba nner.gif", "IMAGE", "http://example.com/"); 196 AdblockPlus::FilterPtr match8 = filterEngine->Matches("http://example.org/fpba nner.gif", "IMAGE", "http://example.com/");
144 ASSERT_FALSE(match8); 197 ASSERT_FALSE(match8);
145 } 198 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld