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 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 }; | 106 }; |
107 | 107 |
108 void ReadFile(AdblockPlus::JsEngine& jsEngine, std::string& content, | 108 void ReadFile(AdblockPlus::JsEngine& jsEngine, std::string& content, |
109 std::string& error) | 109 std::string& error) |
110 { | 110 { |
111 jsEngine.Evaluate("let result; _fileSystem.read('', function(r) {result = r}
)"); | 111 jsEngine.Evaluate("let result; _fileSystem.read('', function(r) {result = r}
)"); |
112 content = jsEngine.Evaluate("result.content").AsString(); | 112 content = jsEngine.Evaluate("result.content").AsString(); |
113 error = jsEngine.Evaluate("result.error").AsString(); | 113 error = jsEngine.Evaluate("result.error").AsString(); |
114 } | 114 } |
115 | 115 |
116 typedef std::shared_ptr<MockFileSystem> MockFileSystemPtr; | |
117 | |
118 class FileSystemJsObjectTest : public BaseJsTest | 116 class FileSystemJsObjectTest : public BaseJsTest |
119 { | 117 { |
120 protected: | 118 protected: |
121 MockFileSystemPtr mockFileSystem; | 119 MockFileSystem* mockFileSystem; |
122 | 120 |
123 void SetUp() | 121 void SetUp() |
124 { | 122 { |
125 mockFileSystem = MockFileSystemPtr(new MockFileSystem()); | |
126 ThrowingPlatformCreationParameters params; | 123 ThrowingPlatformCreationParameters params; |
127 params.fileSystem = mockFileSystem; | 124 params.fileSystem.reset(mockFileSystem = new MockFileSystem()); |
128 platform.reset(new AdblockPlus::Platform(std::move(params))); | 125 platform.reset(new AdblockPlus::Platform(std::move(params))); |
129 } | 126 } |
130 }; | 127 }; |
131 } | 128 } |
132 | 129 |
133 TEST_F(FileSystemJsObjectTest, Read) | 130 TEST_F(FileSystemJsObjectTest, Read) |
134 { | 131 { |
135 mockFileSystem->contentToRead = | 132 mockFileSystem->contentToRead = |
136 AdblockPlus::IFileSystem::IOBuffer{'f', 'o', 'o'}; | 133 AdblockPlus::IFileSystem::IOBuffer{'f', 'o', 'o'}; |
137 std::string content; | 134 std::string content; |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 (error) => | 395 (error) => |
399 { | 396 { |
400 if (error) | 397 if (error) |
401 _triggerEvent("onDone", error); | 398 _triggerEvent("onDone", error); |
402 else | 399 else |
403 _triggerEvent("onDone"); | 400 _triggerEvent("onDone"); |
404 });)js"); | 401 });)js"); |
405 EXPECT_EQ(2u, readLines.size()); | 402 EXPECT_EQ(2u, readLines.size()); |
406 EXPECT_EQ("Error: my-error at undefined:8", error); | 403 EXPECT_EQ("Error: my-error at undefined:8", error); |
407 } | 404 } |
OLD | NEW |