OLD | NEW |
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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #include <sstream> | 18 #include <sstream> |
19 #include "BaseJsTest.h" | 19 #include "BaseJsTest.h" |
20 #include "../src/Thread.h" | 20 #include "../src/Thread.h" |
21 | 21 |
22 using namespace AdblockPlus; | 22 using namespace AdblockPlus; |
23 | 23 |
| 24 extern std::string jsSources[]; |
| 25 |
24 namespace | 26 namespace |
25 { | 27 { |
26 class MockFileSystem : public AdblockPlus::IFileSystem | 28 class MockFileSystem : public AdblockPlus::IFileSystem |
27 { | 29 { |
28 public: | 30 public: |
29 bool success; | 31 bool success; |
30 IOBuffer contentToRead; | 32 IOBuffer contentToRead; |
31 std::string lastWrittenFile; | 33 std::string lastWrittenFile; |
32 IOBuffer lastWrittenContent; | 34 IOBuffer lastWrittenContent; |
33 std::string movedFrom; | 35 std::string movedFrom; |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 { | 393 { |
392 throw new Error("my-error"); | 394 throw new Error("my-error"); |
393 } | 395 } |
394 _triggerEvent("onLine", line); | 396 _triggerEvent("onLine", line); |
395 }, | 397 }, |
396 () => _triggerEvent("onDone"), | 398 () => _triggerEvent("onDone"), |
397 (error) => _triggerEvent("onDone", error)); | 399 (error) => _triggerEvent("onDone", error)); |
398 )js"); | 400 )js"); |
399 EXPECT_EQ(2u, readLines.size()); | 401 EXPECT_EQ(2u, readLines.size()); |
400 EXPECT_EQ("Error: my-error at undefined:8", error); | 402 EXPECT_EQ("Error: my-error at undefined:8", error); |
401 } | 403 } |
| 404 |
| 405 TEST_F(FileSystemJsObjectTest, MoveNonExistingFile) |
| 406 { |
| 407 mockFileSystem->success = false; |
| 408 auto& jsEngine = GetJsEngine(); |
| 409 const std::vector<std::string> jsFiles = {"compat.js", "io.js"}; |
| 410 for (int i = 0; !jsSources[i].empty(); i += 2) |
| 411 { |
| 412 if (jsFiles.end() != std::find(jsFiles.begin(), jsFiles.end(), jsSources[i])
) |
| 413 { |
| 414 jsEngine.Evaluate(jsSources[i + 1], jsSources[i]); |
| 415 } |
| 416 } |
| 417 jsEngine.Evaluate(R"js( |
| 418 let hasError = false; |
| 419 let isNextHandlerCalled = false; |
| 420 require("io").IO.renameFile("foo", "bar") |
| 421 .catch((e) => {hasError = e}) |
| 422 .then(() => isNextHandlerCalled = true); |
| 423 )js"); |
| 424 EXPECT_EQ("Unable to move foo to bar", jsEngine.Evaluate("hasError").AsString(
)); |
| 425 EXPECT_TRUE(jsEngine.Evaluate("isNextHandlerCalled").AsBool()); |
| 426 } |
OLD | NEW |