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

Side by Side Diff: test/FilterEngine.cpp

Issue 4756164013195264: Issue 1376 - Add tests for SetFilterChangeCallback (Closed)
Patch Set: Rebased, use GetFilter() Created May 29, 2015, 11:05 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 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 51
52 struct MockFilterChangeCallback
53 {
54 MockFilterChangeCallback(int& timesCalled) : timesCalled(timesCalled) {}
55
56 void operator()(const std::string&, const AdblockPlus::JsValuePtr)
57 {
58 timesCalled++;
59 }
60
61 private:
62 int& timesCalled;
63 };
64
52 class UpdaterTest : public ::testing::Test 65 class UpdaterTest : public ::testing::Test
53 { 66 {
54 protected: 67 protected:
55 class MockWebRequest : public AdblockPlus::WebRequest 68 class MockWebRequest : public AdblockPlus::WebRequest
56 { 69 {
57 public: 70 public:
58 AdblockPlus::ServerResponse response; 71 AdblockPlus::ServerResponse response;
59 72
60 AdblockPlus::ServerResponse GET(const std::string& url, 73 AdblockPlus::ServerResponse GET(const std::string& url,
61 const AdblockPlus::HeaderList& requestHeaders) const 74 const AdblockPlus::HeaderList& requestHeaders) const
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 TEST_F(FilterEngineTest, FirstRunFlag) 367 TEST_F(FilterEngineTest, FirstRunFlag)
355 { 368 {
356 ASSERT_FALSE(filterEngine->IsFirstRun()); 369 ASSERT_FALSE(filterEngine->IsFirstRun());
357 } 370 }
358 371
359 TEST_F(FilterEngineTestNoData, FirstRunFlag) 372 TEST_F(FilterEngineTestNoData, FirstRunFlag)
360 { 373 {
361 ASSERT_TRUE(filterEngine->IsFirstRun()); 374 ASSERT_TRUE(filterEngine->IsFirstRun());
362 } 375 }
363 376
377 TEST_F(FilterEngineTest, SetRemoveFilterChangeCallback)
378 {
379 int timesCalled = 0;
380 MockFilterChangeCallback mockFilterChangeCallback(timesCalled);
381
382 filterEngine->SetFilterChangeCallback(mockFilterChangeCallback);
383 filterEngine->GetFilter("foo")->AddToList();
384 ASSERT_EQ(2, timesCalled);
sergei 2015/08/06 08:09:37 Nit: it could be a good practice to use EXPECT_* w
sergei 2015/08/06 08:09:37 It would be also good to test when timesCalled is
Felix Dahlke 2015/08/13 14:17:50 Hm, you're right, I think I should use it more oft
Felix Dahlke 2015/08/13 14:17:50 That's not really possible - it's called two times
385
386 filterEngine->RemoveFilterChangeCallback();
387 filterEngine->GetFilter("foo")->RemoveFromList();
388 ASSERT_EQ(2, timesCalled);
389 }
390
364 TEST_F(UpdaterTest, SetRemoveUpdateAvailableCallback) 391 TEST_F(UpdaterTest, SetRemoveUpdateAvailableCallback)
365 { 392 {
366 mockWebRequest->response.status = 0; 393 mockWebRequest->response.status = 0;
367 mockWebRequest->response.responseStatus = 200; 394 mockWebRequest->response.responseStatus = 200;
368 mockWebRequest->response.responseText = "\ 395 mockWebRequest->response.responseText = "\
369 {\ 396 {\
370 \"test\": {\ 397 \"test\": {\
371 \"version\": \"1.0.2\",\ 398 \"version\": \"1.0.2\",\
372 \"url\": \"https://downloads.adblockplus.org/test-1.0.2.tar.gz?update\"\ 399 \"url\": \"https://downloads.adblockplus.org/test-1.0.2.tar.gz?update\"\
373 }\ 400 }\
374 }"; 401 }";
375 402
376 int timesCalled = 0; 403 int timesCalled = 0;
377 MockUpdateAvailableCallback mockUpdateAvailableCallback(timesCalled); 404 MockUpdateAvailableCallback mockUpdateAvailableCallback(timesCalled);
378 405
379 filterEngine->SetUpdateAvailableCallback(mockUpdateAvailableCallback); 406 filterEngine->SetUpdateAvailableCallback(mockUpdateAvailableCallback);
380 filterEngine->ForceUpdateCheck(&NoOpUpdaterCallback); 407 filterEngine->ForceUpdateCheck(&NoOpUpdaterCallback);
381 AdblockPlus::Sleep(100); 408 AdblockPlus::Sleep(100);
382 ASSERT_EQ(1, timesCalled); 409 ASSERT_EQ(1, timesCalled);
383 410
384 filterEngine->RemoveUpdateAvailableCallback(); 411 filterEngine->RemoveUpdateAvailableCallback();
385 filterEngine->ForceUpdateCheck(&NoOpUpdaterCallback); 412 filterEngine->ForceUpdateCheck(&NoOpUpdaterCallback);
386 AdblockPlus::Sleep(100); 413 AdblockPlus::Sleep(100);
387 ASSERT_EQ(1, timesCalled); 414 ASSERT_EQ(1, timesCalled);
388 } 415 }
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