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

Delta Between Two Patch Sets: test/UpdateCheck.cpp

Issue 10800079: Implemented update checking functionality (Closed)
Left Patch Set: Created June 5, 2013, 1:40 p.m.
Right Patch Set: Created June 5, 2013, 6:47 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
« no previous file with change/comment | « test/BaseJsTest.h ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 { 48 {
49 protected: 49 protected:
50 AdblockPlus::AppInfo appInfo; 50 AdblockPlus::AppInfo appInfo;
51 TestWebRequest* webRequest; 51 TestWebRequest* webRequest;
52 AdblockPlus::WebRequestPtr webRequestPtr; 52 AdblockPlus::WebRequestPtr webRequestPtr;
53 AdblockPlus::JsEnginePtr jsEngine; 53 AdblockPlus::JsEnginePtr jsEngine;
54 FilterEnginePtr filterEngine; 54 FilterEnginePtr filterEngine;
55 55
56 bool eventCallbackCalled; 56 bool eventCallbackCalled;
57 AdblockPlus::JsValueList eventCallbackParams; 57 AdblockPlus::JsValueList eventCallbackParams;
58 static bool updateCallbackCalled; 58 bool updateCallbackCalled;
59 static std::string updateError; 59 std::string updateError;
60 60
61 void SetUp() 61 void SetUp()
62 { 62 {
63 webRequest = new TestWebRequest(); 63 webRequest = new TestWebRequest();
64 webRequestPtr.reset(webRequest); 64 webRequestPtr.reset(webRequest);
65 65
66 eventCallbackCalled = false; 66 eventCallbackCalled = false;
67 updateCallbackCalled = false; 67 updateCallbackCalled = false;
68 Reset(); 68 Reset();
69 } 69 }
70 70
71 void Reset() 71 void Reset()
72 { 72 {
73 jsEngine = AdblockPlus::JsEngine::New(appInfo); 73 jsEngine = AdblockPlus::JsEngine::New(appInfo);
74 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem)); 74 jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr(new LazyLogSystem));
75 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem)); 75 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem));
76 jsEngine->SetWebRequest(webRequestPtr); 76 jsEngine->SetWebRequest(webRequestPtr);
77 jsEngine->SetEventCallback("updateAvailable", 77 jsEngine->SetEventCallback("updateAvailable",
78 std::tr1::bind(&UpdateCheckTest::EventCallback, this, std::tr1::placeh olders::_1)); 78 std::tr1::bind(&UpdateCheckTest::EventCallback, this, std::tr1::placeh olders::_1));
79 79
80 filterEngine.reset(new AdblockPlus::FilterEngine(jsEngine)); 80 filterEngine.reset(new AdblockPlus::FilterEngine(jsEngine));
81 } 81 }
82 82
83 void ForceUpdateCheck() 83 void ForceUpdateCheck()
84 { 84 {
85 filterEngine->ForceUpdateCheck(&UpdateCheckTest::UpdateCallback); 85 filterEngine->ForceUpdateCheck(
86 std::tr1::bind(&UpdateCheckTest::UpdateCallback, this, std::tr1::place holders::_1));
86 } 87 }
87 88
88 void EventCallback(AdblockPlus::JsValueList& params) 89 void EventCallback(AdblockPlus::JsValueList& params)
89 { 90 {
90 eventCallbackCalled = true; 91 eventCallbackCalled = true;
91 eventCallbackParams = params; 92 eventCallbackParams = params;
92 } 93 }
93 94
94 // This really shouldn't be static but I couldn't make std::bind() work for it. 95 void UpdateCallback(const std::string& error)
95 static void UpdateCallback(const std::string& error)
96 { 96 {
97 updateCallbackCalled = true; 97 updateCallbackCalled = true;
98 updateError = error; 98 updateError = error;
99 } 99 }
100 }; 100 };
101
102 bool UpdateCheckTest::updateCallbackCalled = false;
103 std::string UpdateCheckTest::updateError;
104 } 101 }
105 102
106 TEST_F(UpdateCheckTest, RequestFailure) 103 TEST_F(UpdateCheckTest, RequestFailure)
107 { 104 {
108 webRequest->response.status = AdblockPlus::WebRequest::NS_ERROR_FAILURE; 105 webRequest->response.status = AdblockPlus::WebRequest::NS_ERROR_FAILURE;
109 106
110 appInfo.name = "1"; 107 appInfo.name = "1";
111 appInfo.id = "2"; 108 appInfo.id = "2";
112 appInfo.version = "3"; 109 appInfo.version = "3";
113 appInfo.platform = "4"; 110 appInfo.platform = "4";
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 242
246 Reset(); 243 Reset();
247 ForceUpdateCheck(); 244 ForceUpdateCheck();
248 245
249 AdblockPlus::Sleep(100); 246 AdblockPlus::Sleep(100);
250 247
251 ASSERT_FALSE(eventCallbackCalled); 248 ASSERT_FALSE(eventCallbackCalled);
252 ASSERT_TRUE(updateCallbackCalled); 249 ASSERT_TRUE(updateCallbackCalled);
253 ASSERT_FALSE(updateError.empty()); 250 ASSERT_FALSE(updateError.empty());
254 } 251 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld