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

Side by Side Diff: test/FilterEngine.cpp

Issue 4578638519336960: Issue 1296 - Add SetUpdateAvailableCallback (Closed)
Patch Set: Created Sept. 18, 2014, 3:12 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
« src/FilterEngine.cpp ('K') | « src/FilterEngine.cpp ('k') | 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 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 30 matching lines...) Expand all
41 BaseJsTest::SetUp(); 41 BaseJsTest::SetUp();
42 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new FileSystem)); 42 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new FileSystem));
43 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest)); 43 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new LazyWebRequest));
44 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LogSystem)); 44 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LogSystem));
45 filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine)); 45 filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine));
46 } 46 }
47 }; 47 };
48 48
49 typedef FilterEngineTestGeneric<LazyFileSystem, AdblockPlus::DefaultLogSystem> FilterEngineTest; 49 typedef FilterEngineTestGeneric<LazyFileSystem, AdblockPlus::DefaultLogSystem> FilterEngineTest;
50 typedef FilterEngineTestGeneric<VeryLazyFileSystem, LazyLogSystem> FilterEngin eTestNoData; 50 typedef FilterEngineTestGeneric<VeryLazyFileSystem, LazyLogSystem> FilterEngin eTestNoData;
51
52 class UpdaterTest : public ::testing::Test
53 {
54 protected:
55 class MockWebRequest : public AdblockPlus::WebRequest
56 {
57 public:
58 AdblockPlus::ServerResponse response;
59
60 AdblockPlus::ServerResponse GET(const std::string& url,
61 const AdblockPlus::HeaderList& requestHeaders) const
62 {
63 return response;
64 }
65 };
66
67 MockWebRequest* mockWebRequest;
68 FilterEnginePtr filterEngine;
69
70 void SetUp()
71 {
72 AdblockPlus::AppInfo appInfo;
73 appInfo.name = "test";
74 appInfo.version = "1.0.1";
75 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo);
76 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem));
77 mockWebRequest = new MockWebRequest;
78 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(mockWebRequest));
79 filterEngine = FilterEnginePtr(new AdblockPlus::FilterEngine(jsEngine));
80 }
81 };
82
83 struct MockUpdateAvailableCallback
84 {
85 MockUpdateAvailableCallback(int& timesCalled) : timesCalled(timesCalled) {}
86
87 void operator()(const std::string&)
88 {
89 timesCalled++;
90 }
91
92 private:
93 // We currently cannot store timesCalled in the functor, see:
94 // https://issues.adblockplus.org/ticket/1378.
95 int& timesCalled;
96 };
97
98 // Workaround for https://issues.adblockplus.org/ticket/1397.
99 void NoOpUpdaterCallback(const std::string&) {}
51 } 100 }
52 101
53 TEST_F(FilterEngineTest, FilterCreation) 102 TEST_F(FilterEngineTest, FilterCreation)
54 { 103 {
55 AdblockPlus::FilterPtr filter1 = filterEngine->GetFilter("foo"); 104 AdblockPlus::FilterPtr filter1 = filterEngine->GetFilter("foo");
56 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetType()); 105 ASSERT_EQ(AdblockPlus::Filter::TYPE_BLOCKING, filter1->GetType());
57 AdblockPlus::FilterPtr filter2 = filterEngine->GetFilter("@@foo"); 106 AdblockPlus::FilterPtr filter2 = filterEngine->GetFilter("@@foo");
58 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetType()); 107 ASSERT_EQ(AdblockPlus::Filter::TYPE_EXCEPTION, filter2->GetType());
59 AdblockPlus::FilterPtr filter3 = filterEngine->GetFilter("example.com##foo"); 108 AdblockPlus::FilterPtr filter3 = filterEngine->GetFilter("example.com##foo");
60 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3->GetType()); 109 ASSERT_EQ(AdblockPlus::Filter::TYPE_ELEMHIDE, filter3->GetType());
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 353
305 TEST_F(FilterEngineTest, FirstRunFlag) 354 TEST_F(FilterEngineTest, FirstRunFlag)
306 { 355 {
307 ASSERT_FALSE(filterEngine->IsFirstRun()); 356 ASSERT_FALSE(filterEngine->IsFirstRun());
308 } 357 }
309 358
310 TEST_F(FilterEngineTestNoData, FirstRunFlag) 359 TEST_F(FilterEngineTestNoData, FirstRunFlag)
311 { 360 {
312 ASSERT_TRUE(filterEngine->IsFirstRun()); 361 ASSERT_TRUE(filterEngine->IsFirstRun());
313 } 362 }
363
364 TEST_F(UpdaterTest, SetRemoveUpdateAvailableCallback)
365 {
366 mockWebRequest->response.status = 0;
367 mockWebRequest->response.responseStatus = 200;
368 mockWebRequest->response.responseText = "\
369 {\
370 \"test\": {\
371 \"version\": \"1.0.2\",\
372 \"url\": \"https://downloads.adblockplus.org/test-1.0.2.tar.gz?update\"\
373 }\
374 }";
375
376 int timesCalled = 0;
377 MockUpdateAvailableCallback mockUpdateAvailableCallback(timesCalled);
378
379 filterEngine->SetUpdateAvailableCallback(mockUpdateAvailableCallback);
380 filterEngine->ForceUpdateCheck(&NoOpUpdaterCallback);
381 AdblockPlus::Sleep(100);
382 ASSERT_EQ(1, timesCalled);
383
384 filterEngine->RemoveUpdateAvailableCallback();
385 filterEngine->ForceUpdateCheck(&NoOpUpdaterCallback);
386 AdblockPlus::Sleep(100);
387 ASSERT_EQ(1, timesCalled);
388 }
OLDNEW
« src/FilterEngine.cpp ('K') | « src/FilterEngine.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld