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

Side by Side Diff: test/FileSystemJsObject.cpp

Issue 29523555: Issue 5552 - use strict mode for all JS in libadblocklus (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: move setting of strict mode to do it once Created Aug. 22, 2017, 7:58 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
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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 result.exists = statExists; 99 result.exists = statExists;
100 result.lastModified = statLastModified; 100 result.lastModified = statLastModified;
101 } 101 }
102 callback(result, error); 102 callback(result, error);
103 } 103 }
104 }; 104 };
105 105
106 void ReadFile(AdblockPlus::JsEngine& jsEngine, std::string& content, 106 void ReadFile(AdblockPlus::JsEngine& jsEngine, std::string& content,
107 std::string& error) 107 std::string& error)
108 { 108 {
109 jsEngine.Evaluate("_fileSystem.read('', function(r) {result = r})"); 109 jsEngine.Evaluate("let result; _fileSystem.read('', function(r) {result = r} )");
110 content = jsEngine.Evaluate("result.content").AsString(); 110 content = jsEngine.Evaluate("result.content").AsString();
111 error = jsEngine.Evaluate("result.error").AsString(); 111 error = jsEngine.Evaluate("result.error").AsString();
112 } 112 }
113 113
114 typedef std::shared_ptr<MockFileSystem> MockFileSystemPtr; 114 typedef std::shared_ptr<MockFileSystem> MockFileSystemPtr;
115 115
116 class FileSystemJsObjectTest : public BaseJsTest 116 class FileSystemJsObjectTest : public BaseJsTest
117 { 117 {
118 protected: 118 protected:
119 MockFileSystemPtr mockFileSystem; 119 MockFileSystemPtr mockFileSystem;
(...skipping 30 matching lines...) Expand all
150 mockFileSystem->success = false; 150 mockFileSystem->success = false;
151 std::string content; 151 std::string content;
152 std::string error; 152 std::string error;
153 ReadFile(GetJsEngine(), content, error); 153 ReadFile(GetJsEngine(), content, error);
154 ASSERT_NE("", error); 154 ASSERT_NE("", error);
155 ASSERT_EQ("", content); 155 ASSERT_EQ("", content);
156 } 156 }
157 157
158 TEST_F(FileSystemJsObjectTest, Write) 158 TEST_F(FileSystemJsObjectTest, Write)
159 { 159 {
160 GetJsEngine().Evaluate("_fileSystem.write('foo', 'bar', function(e) {error = e })"); 160 GetJsEngine().Evaluate("let error = true; _fileSystem.write('foo', 'bar', func tion(e) {error = e})");
161 ASSERT_EQ("foo", mockFileSystem->lastWrittenFile); 161 ASSERT_EQ("foo", mockFileSystem->lastWrittenFile);
162 ASSERT_EQ((AdblockPlus::IFileSystem::IOBuffer{'b', 'a', 'r'}), 162 ASSERT_EQ((AdblockPlus::IFileSystem::IOBuffer{'b', 'a', 'r'}),
163 mockFileSystem->lastWrittenContent); 163 mockFileSystem->lastWrittenContent);
164 ASSERT_TRUE(GetJsEngine().Evaluate("error").IsUndefined()); 164 ASSERT_TRUE(GetJsEngine().Evaluate("error").IsUndefined());
165 } 165 }
166 166
167 TEST_F(FileSystemJsObjectTest, WriteIllegalArguments) 167 TEST_F(FileSystemJsObjectTest, WriteIllegalArguments)
168 { 168 {
169 ASSERT_ANY_THROW(GetJsEngine().Evaluate("_fileSystem.write()")); 169 ASSERT_ANY_THROW(GetJsEngine().Evaluate("_fileSystem.write()"));
170 ASSERT_ANY_THROW(GetJsEngine().Evaluate("_fileSystem.write('', '', '')")); 170 ASSERT_ANY_THROW(GetJsEngine().Evaluate("_fileSystem.write('', '', '')"));
171 } 171 }
172 172
173 TEST_F(FileSystemJsObjectTest, WriteError) 173 TEST_F(FileSystemJsObjectTest, WriteError)
174 { 174 {
175 mockFileSystem->success = false; 175 mockFileSystem->success = false;
176 GetJsEngine().Evaluate("_fileSystem.write('foo', 'bar', function(e) {error = e })"); 176 GetJsEngine().Evaluate("let error = true; _fileSystem.write('foo', 'bar', func tion(e) {error = e})");
177 ASSERT_NE("", GetJsEngine().Evaluate("error").AsString()); 177 ASSERT_NE("", GetJsEngine().Evaluate("error").AsString());
178 } 178 }
179 179
180 TEST_F(FileSystemJsObjectTest, Move) 180 TEST_F(FileSystemJsObjectTest, Move)
181 { 181 {
182 GetJsEngine().Evaluate("_fileSystem.move('foo', 'bar', function(e) {error = e} )"); 182 GetJsEngine().Evaluate("let error = true; _fileSystem.move('foo', 'bar', funct ion(e) {error = e})");
183 ASSERT_EQ("foo", mockFileSystem->movedFrom); 183 ASSERT_EQ("foo", mockFileSystem->movedFrom);
184 ASSERT_EQ("bar", mockFileSystem->movedTo); 184 ASSERT_EQ("bar", mockFileSystem->movedTo);
185 ASSERT_TRUE(GetJsEngine().Evaluate("error").IsUndefined()); 185 ASSERT_TRUE(GetJsEngine().Evaluate("error").IsUndefined());
186 } 186 }
187 187
188 TEST_F(FileSystemJsObjectTest, MoveIllegalArguments) 188 TEST_F(FileSystemJsObjectTest, MoveIllegalArguments)
189 { 189 {
190 ASSERT_ANY_THROW(GetJsEngine().Evaluate("_fileSystem.move()")); 190 ASSERT_ANY_THROW(GetJsEngine().Evaluate("_fileSystem.move()"));
191 ASSERT_ANY_THROW(GetJsEngine().Evaluate("_fileSystem.move('', '', '')")); 191 ASSERT_ANY_THROW(GetJsEngine().Evaluate("_fileSystem.move('', '', '')"));
192 } 192 }
193 193
194 TEST_F(FileSystemJsObjectTest, MoveError) 194 TEST_F(FileSystemJsObjectTest, MoveError)
195 { 195 {
196 mockFileSystem->success = false; 196 mockFileSystem->success = false;
197 GetJsEngine().Evaluate("_fileSystem.move('foo', 'bar', function(e) {error = e} )"); 197 GetJsEngine().Evaluate("let error; _fileSystem.move('foo', 'bar', function(e) {error = e})");
198 ASSERT_FALSE(GetJsEngine().Evaluate("error").IsUndefined()); 198 ASSERT_FALSE(GetJsEngine().Evaluate("error").IsUndefined());
199 } 199 }
200 200
201 TEST_F(FileSystemJsObjectTest, Remove) 201 TEST_F(FileSystemJsObjectTest, Remove)
202 { 202 {
203 GetJsEngine().Evaluate("_fileSystem.remove('foo', function(e) {error = e})"); 203 GetJsEngine().Evaluate("let error = true; _fileSystem.remove('foo', function(e ) {error = e})");
204 ASSERT_EQ("foo", mockFileSystem->removedFile); 204 ASSERT_EQ("foo", mockFileSystem->removedFile);
205 ASSERT_TRUE(GetJsEngine().Evaluate("error").IsUndefined()); 205 ASSERT_TRUE(GetJsEngine().Evaluate("error").IsUndefined());
206 } 206 }
207 207
208 TEST_F(FileSystemJsObjectTest, RemoveIllegalArguments) 208 TEST_F(FileSystemJsObjectTest, RemoveIllegalArguments)
209 { 209 {
210 ASSERT_ANY_THROW(GetJsEngine().Evaluate("_fileSystem.remove()")); 210 ASSERT_ANY_THROW(GetJsEngine().Evaluate("_fileSystem.remove()"));
211 ASSERT_ANY_THROW(GetJsEngine().Evaluate("_fileSystem.remove('', '')")); 211 ASSERT_ANY_THROW(GetJsEngine().Evaluate("_fileSystem.remove('', '')"));
212 } 212 }
213 213
214 TEST_F(FileSystemJsObjectTest, RemoveError) 214 TEST_F(FileSystemJsObjectTest, RemoveError)
215 { 215 {
216 mockFileSystem->success = false; 216 mockFileSystem->success = false;
217 GetJsEngine().Evaluate("_fileSystem.remove('foo', function(e) {error = e})"); 217 GetJsEngine().Evaluate("let error = true; _fileSystem.remove('foo', function(e ) {error = e})");
218 ASSERT_NE("", GetJsEngine().Evaluate("error").AsString()); 218 ASSERT_NE("", GetJsEngine().Evaluate("error").AsString());
219 } 219 }
220 220
221 TEST_F(FileSystemJsObjectTest, Stat) 221 TEST_F(FileSystemJsObjectTest, Stat)
222 { 222 {
223 mockFileSystem->statExists = true; 223 mockFileSystem->statExists = true;
224 mockFileSystem->statLastModified = 1337; 224 mockFileSystem->statLastModified = 1337;
225 GetJsEngine().Evaluate("_fileSystem.stat('foo', function(r) {result = r})"); 225 GetJsEngine().Evaluate("let result; _fileSystem.stat('foo', function(r) {resul t = r})");
226 ASSERT_EQ("foo", mockFileSystem->statFile); 226 ASSERT_EQ("foo", mockFileSystem->statFile);
227 ASSERT_TRUE(GetJsEngine().Evaluate("result.error").IsUndefined()); 227 ASSERT_TRUE(GetJsEngine().Evaluate("result.error").IsUndefined());
228 ASSERT_TRUE(GetJsEngine().Evaluate("result.exists").AsBool()); 228 ASSERT_TRUE(GetJsEngine().Evaluate("result.exists").AsBool());
229 ASSERT_EQ(1337, GetJsEngine().Evaluate("result.lastModified").AsInt()); 229 ASSERT_EQ(1337, GetJsEngine().Evaluate("result.lastModified").AsInt());
230 } 230 }
231 231
232 TEST_F(FileSystemJsObjectTest, StatIllegalArguments) 232 TEST_F(FileSystemJsObjectTest, StatIllegalArguments)
233 { 233 {
234 ASSERT_ANY_THROW(GetJsEngine().Evaluate("_fileSystem.stat()")); 234 ASSERT_ANY_THROW(GetJsEngine().Evaluate("_fileSystem.stat()"));
235 ASSERT_ANY_THROW(GetJsEngine().Evaluate("_fileSystem.stat('', '')")); 235 ASSERT_ANY_THROW(GetJsEngine().Evaluate("_fileSystem.stat('', '')"));
236 } 236 }
237 237
238 TEST_F(FileSystemJsObjectTest, StatError) 238 TEST_F(FileSystemJsObjectTest, StatError)
239 { 239 {
240 mockFileSystem->success = false; 240 mockFileSystem->success = false;
241 GetJsEngine().Evaluate("_fileSystem.stat('foo', function(r) {result = r})"); 241 GetJsEngine().Evaluate("let result; _fileSystem.stat('foo', function(r) {resul t = r})");
242 ASSERT_FALSE(GetJsEngine().Evaluate("result.error").IsUndefined()); 242 ASSERT_FALSE(GetJsEngine().Evaluate("result.error").IsUndefined());
243 } 243 }
OLDNEW
« src/JsEngine.cpp ('K') | « src/JsEngine.cpp ('k') | test/GlobalJsObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld