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

Unified Diff: test/FileSystemJsObject.cpp

Issue 29731562: Issue 6477 - separate done and error callbacks in IFileSystem::Read (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git@c0a6434596a83383e37678ef3b6ecef00ed6a261
Patch Set: Created March 23, 2018, 10:58 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/FileSystemJsObject.cpp
diff --git a/test/FileSystemJsObject.cpp b/test/FileSystemJsObject.cpp
index 53a554de17841f5c3aba2c56f37f4cae55308f77..96c07cadc8184a16e000369290ac3e162af7034f 100644
--- a/test/FileSystemJsObject.cpp
+++ b/test/FileSystemJsObject.cpp
@@ -41,14 +41,19 @@ namespace
{
}
- void Read(const std::string& fileName, const ReadCallback& callback) const override
+ void Read(const std::string& fileName, const ReadCallback& callback, const Callback& errorCallback) const override
{
- if (!success)
- {
- callback(IOBuffer(), "Unable to read " + fileName);
- return;
- }
- callback(IOBuffer(contentToRead), "");
+ if (success)
+ try
+ {
+ callback(IOBuffer(contentToRead));
+ }
+ catch (const std::exception& ex)
+ {
+ errorCallback(ex.what());
+ }
+ else
+ errorCallback("Unable to read " + fileName);
}
void Write(const std::string& fileName, const IOBuffer& data,
@@ -108,7 +113,7 @@ namespace
void ReadFile(AdblockPlus::JsEngine& jsEngine, std::string& content,
std::string& error)
{
- jsEngine.Evaluate("let result; _fileSystem.read('', function(r) {result = r})");
+ jsEngine.Evaluate("let result = {}; _fileSystem.read('', function(r) {result.content = r.content;}, function(r) {result.error = r.error;})");
content = jsEngine.Evaluate("result.content").AsString();
error = jsEngine.Evaluate("result.error").AsString();
}
@@ -151,7 +156,7 @@ TEST_F(FileSystemJsObjectTest, ReadError)
std::string error;
ReadFile(GetJsEngine(), content, error);
ASSERT_NE("", error);
- ASSERT_EQ("", content);
+ ASSERT_EQ("undefined", content);
}
TEST_F(FileSystemJsObjectTest, Write)
@@ -276,13 +281,9 @@ namespace
});
jsEngine.Evaluate(R"js(_fileSystem.readFromFile("foo",
(line) => _triggerEvent("onLine", line),
- (error) =>
- {
- if (error)
- _triggerEvent("onDone", error);
- else
- _triggerEvent("onDone");
-});)js");
+ () =>_triggerEvent("onDone"),
+ (error) => _triggerEvent("onDone", error));
+)js");
EXPECT_TRUE(isOnDoneCalled);
}
@@ -392,13 +393,9 @@ _fileSystem.readFromFile("foo",
}
_triggerEvent("onLine", line);
},
- (error) =>
- {
- if (error)
- _triggerEvent("onDone", error);
- else
- _triggerEvent("onDone");
-});)js");
+ () => _triggerEvent("onDone"),
+ (error) => _triggerEvent("onDone", error));
+)js");
EXPECT_EQ(2u, readLines.size());
EXPECT_EQ("Error: my-error at undefined:8", error);
}
« test/BaseJsTest.h ('K') | « test/DefaultFileSystem.cpp ('k') | test/Prefs.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld