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

Side by Side Diff: test/FileSystemJsObject.cpp

Issue 29499580: Noissue - remove unnecessary sleeps in FileSystemJsObject tests (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created July 27, 2017, 8:50 a.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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 if (!success) 111 if (!success)
112 throw std::runtime_error("Unable to stat " + path); 112 throw std::runtime_error("Unable to stat " + path);
113 return path; 113 return path;
114 } 114 }
115 }; 115 };
116 116
117 void ReadFile(AdblockPlus::JsEnginePtr jsEngine, std::string& content, 117 void ReadFile(AdblockPlus::JsEnginePtr jsEngine, std::string& content,
118 std::string& error) 118 std::string& error)
119 { 119 {
120 jsEngine->Evaluate("_fileSystem.read('', function(r) {result = r})"); 120 jsEngine->Evaluate("_fileSystem.read('', function(r) {result = r})");
121 AdblockPlus::Sleep(50);
122 content = jsEngine->Evaluate("result.content").AsString(); 121 content = jsEngine->Evaluate("result.content").AsString();
123 error = jsEngine->Evaluate("result.error").AsString(); 122 error = jsEngine->Evaluate("result.error").AsString();
124 } 123 }
125 124
126 typedef std::shared_ptr<MockFileSystem> MockFileSystemPtr; 125 typedef std::shared_ptr<MockFileSystem> MockFileSystemPtr;
127 126
128 class FileSystemJsObjectTest : public BaseJsTest 127 class FileSystemJsObjectTest : public BaseJsTest
129 { 128 {
130 protected: 129 protected:
131 MockFileSystemPtr mockFileSystem; 130 MockFileSystemPtr mockFileSystem;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 std::string content; 162 std::string content;
164 std::string error; 163 std::string error;
165 ReadFile(jsEngine, content, error); 164 ReadFile(jsEngine, content, error);
166 ASSERT_NE("", error); 165 ASSERT_NE("", error);
167 ASSERT_EQ("", content); 166 ASSERT_EQ("", content);
168 } 167 }
169 168
170 TEST_F(FileSystemJsObjectTest, Write) 169 TEST_F(FileSystemJsObjectTest, Write)
171 { 170 {
172 jsEngine->Evaluate("_fileSystem.write('foo', 'bar', function(e) {error = e})") ; 171 jsEngine->Evaluate("_fileSystem.write('foo', 'bar', function(e) {error = e})") ;
173 AdblockPlus::Sleep(50);
174 ASSERT_EQ("foo", mockFileSystem->lastWrittenPath); 172 ASSERT_EQ("foo", mockFileSystem->lastWrittenPath);
175 ASSERT_EQ((AdblockPlus::IFileSystem::IOBuffer{'b', 'a', 'r'}), 173 ASSERT_EQ((AdblockPlus::IFileSystem::IOBuffer{'b', 'a', 'r'}),
176 mockFileSystem->lastWrittenContent); 174 mockFileSystem->lastWrittenContent);
177 ASSERT_TRUE(jsEngine->Evaluate("error").IsUndefined()); 175 ASSERT_TRUE(jsEngine->Evaluate("error").IsUndefined());
178 } 176 }
179 177
180 TEST_F(FileSystemJsObjectTest, WriteIllegalArguments) 178 TEST_F(FileSystemJsObjectTest, WriteIllegalArguments)
181 { 179 {
182 ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.write()")); 180 ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.write()"));
183 ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.write('', '', '')")); 181 ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.write('', '', '')"));
184 } 182 }
185 183
186 TEST_F(FileSystemJsObjectTest, WriteError) 184 TEST_F(FileSystemJsObjectTest, WriteError)
187 { 185 {
188 mockFileSystem->success = false; 186 mockFileSystem->success = false;
189 jsEngine->Evaluate("_fileSystem.write('foo', 'bar', function(e) {error = e})") ; 187 jsEngine->Evaluate("_fileSystem.write('foo', 'bar', function(e) {error = e})") ;
190 AdblockPlus::Sleep(50);
191 ASSERT_NE("", jsEngine->Evaluate("error").AsString()); 188 ASSERT_NE("", jsEngine->Evaluate("error").AsString());
192 } 189 }
193 190
194 TEST_F(FileSystemJsObjectTest, Move) 191 TEST_F(FileSystemJsObjectTest, Move)
195 { 192 {
196 jsEngine->Evaluate("_fileSystem.move('foo', 'bar', function(e) {error = e})"); 193 jsEngine->Evaluate("_fileSystem.move('foo', 'bar', function(e) {error = e})");
197 AdblockPlus::Sleep(50);
198 ASSERT_EQ("foo", mockFileSystem->movedFrom); 194 ASSERT_EQ("foo", mockFileSystem->movedFrom);
199 ASSERT_EQ("bar", mockFileSystem->movedTo); 195 ASSERT_EQ("bar", mockFileSystem->movedTo);
200 ASSERT_TRUE(jsEngine->Evaluate("error").IsUndefined()); 196 ASSERT_TRUE(jsEngine->Evaluate("error").IsUndefined());
201 } 197 }
202 198
203 TEST_F(FileSystemJsObjectTest, MoveIllegalArguments) 199 TEST_F(FileSystemJsObjectTest, MoveIllegalArguments)
204 { 200 {
205 ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.move()")); 201 ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.move()"));
206 ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.move('', '', '')")); 202 ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.move('', '', '')"));
207 } 203 }
208 204
209 TEST_F(FileSystemJsObjectTest, MoveError) 205 TEST_F(FileSystemJsObjectTest, MoveError)
210 { 206 {
211 mockFileSystem->success = false; 207 mockFileSystem->success = false;
212 jsEngine->Evaluate("_fileSystem.move('foo', 'bar', function(e) {error = e})"); 208 jsEngine->Evaluate("_fileSystem.move('foo', 'bar', function(e) {error = e})");
213 AdblockPlus::Sleep(50);
214 ASSERT_FALSE(jsEngine->Evaluate("error").IsUndefined()); 209 ASSERT_FALSE(jsEngine->Evaluate("error").IsUndefined());
215 } 210 }
216 211
217 TEST_F(FileSystemJsObjectTest, Remove) 212 TEST_F(FileSystemJsObjectTest, Remove)
218 { 213 {
219 jsEngine->Evaluate("_fileSystem.remove('foo', function(e) {error = e})"); 214 jsEngine->Evaluate("_fileSystem.remove('foo', function(e) {error = e})");
220 AdblockPlus::Sleep(50);
221 ASSERT_EQ("foo", mockFileSystem->removedPath); 215 ASSERT_EQ("foo", mockFileSystem->removedPath);
222 ASSERT_TRUE(jsEngine->Evaluate("error").IsUndefined()); 216 ASSERT_TRUE(jsEngine->Evaluate("error").IsUndefined());
223 } 217 }
224 218
225 TEST_F(FileSystemJsObjectTest, RemoveIllegalArguments) 219 TEST_F(FileSystemJsObjectTest, RemoveIllegalArguments)
226 { 220 {
227 ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.remove()")); 221 ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.remove()"));
228 ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.remove('', '')")); 222 ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.remove('', '')"));
229 } 223 }
230 224
231 TEST_F(FileSystemJsObjectTest, RemoveError) 225 TEST_F(FileSystemJsObjectTest, RemoveError)
232 { 226 {
233 mockFileSystem->success = false; 227 mockFileSystem->success = false;
234 jsEngine->Evaluate("_fileSystem.remove('foo', function(e) {error = e})"); 228 jsEngine->Evaluate("_fileSystem.remove('foo', function(e) {error = e})");
235 AdblockPlus::Sleep(50);
236 ASSERT_NE("", jsEngine->Evaluate("error").AsString()); 229 ASSERT_NE("", jsEngine->Evaluate("error").AsString());
237 } 230 }
238 231
239 TEST_F(FileSystemJsObjectTest, Stat) 232 TEST_F(FileSystemJsObjectTest, Stat)
240 { 233 {
241 mockFileSystem->statExists = true; 234 mockFileSystem->statExists = true;
242 mockFileSystem->statIsDirectory= false; 235 mockFileSystem->statIsDirectory= false;
243 mockFileSystem->statIsFile = true; 236 mockFileSystem->statIsFile = true;
244 mockFileSystem->statLastModified = 1337; 237 mockFileSystem->statLastModified = 1337;
245 jsEngine->Evaluate("_fileSystem.stat('foo', function(r) {result = r})"); 238 jsEngine->Evaluate("_fileSystem.stat('foo', function(r) {result = r})");
246 AdblockPlus::Sleep(50);
247 ASSERT_EQ("foo", mockFileSystem->statPath); 239 ASSERT_EQ("foo", mockFileSystem->statPath);
248 ASSERT_TRUE(jsEngine->Evaluate("result.error").IsUndefined()); 240 ASSERT_TRUE(jsEngine->Evaluate("result.error").IsUndefined());
249 ASSERT_TRUE(jsEngine->Evaluate("result.exists").AsBool()); 241 ASSERT_TRUE(jsEngine->Evaluate("result.exists").AsBool());
250 ASSERT_FALSE(jsEngine->Evaluate("result.isDirectory").AsBool()); 242 ASSERT_FALSE(jsEngine->Evaluate("result.isDirectory").AsBool());
251 ASSERT_TRUE(jsEngine->Evaluate("result.isFile").AsBool()); 243 ASSERT_TRUE(jsEngine->Evaluate("result.isFile").AsBool());
252 ASSERT_EQ(1337, jsEngine->Evaluate("result.lastModified").AsInt()); 244 ASSERT_EQ(1337, jsEngine->Evaluate("result.lastModified").AsInt());
253 } 245 }
254 246
255 TEST_F(FileSystemJsObjectTest, StatIllegalArguments) 247 TEST_F(FileSystemJsObjectTest, StatIllegalArguments)
256 { 248 {
257 ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.stat()")); 249 ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.stat()"));
258 ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.stat('', '')")); 250 ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.stat('', '')"));
259 } 251 }
260 252
261 TEST_F(FileSystemJsObjectTest, StatError) 253 TEST_F(FileSystemJsObjectTest, StatError)
262 { 254 {
263 mockFileSystem->success = false; 255 mockFileSystem->success = false;
264 jsEngine->Evaluate("_fileSystem.stat('foo', function(r) {result = r})"); 256 jsEngine->Evaluate("_fileSystem.stat('foo', function(r) {result = r})");
265 AdblockPlus::Sleep(50);
266 ASSERT_FALSE(jsEngine->Evaluate("result.error").IsUndefined()); 257 ASSERT_FALSE(jsEngine->Evaluate("result.error").IsUndefined());
267 } 258 }
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