haikuwebkit/LayoutTests/storage/indexeddb/structured-clone-image-data...

94 lines
3.1 KiB
HTML
Raw Permalink Normal View History

Support serializing ImageData object colorSpace property in SerializedScriptValue https://bugs.webkit.org/show_bug.cgi?id=225854 Reviewed by Chris Dumez. Source/WebCore: Test: storage/indexeddb/structured-clone-image-data-display-p3.html Update SerializedScriptValue schema to version 8 and add serialization of the colorSpace property. * bindings/js/SerializedScriptValue.cpp: (WebCore::PredefinedColorSpaceTag): Add copy of the PredefinedColorSpace values that are guaranteed to stay consistent forever. (WebCore::CloneSerializer::dumpIfTerminal): Add encoding of the colorSpace when serializing ImageData. (WebCore::CloneSerializer::write): (WebCore::CloneDeserializer::read): Add coders for PredefinedColorSpaceTag. (WebCore::CloneDeserializer::getJSValue): Replace multiple overloads with one perfect forwarding overload which does what we want and works with r-values. (WebCore::CloneDeserializer::readImageBitmap): Use auto in two places. (WebCore::CloneDeserializer::readTerminal): Add decoding of the colorSpace when deserializing ImageData. For prior versions, the colorSpace defaults to sRGB, which was the only color space supported. LayoutTests: Updates existing tests for new serialization version (version 8) and support for serializing color space in ImageData. To avoid multiple result files due to lack of support for display-p3, testing that the display-p3 color space is serialized correctly was put into its own test that is skipped on non-supporting platforms. * platform/glib/TestExpectations: * platform/win/TestExpectations: Skip structured-clone-image-data-display-p3.html on platforms that don't support display-p3 color spaces. * fast/storage/serialized-script-value.html: Bump version to version 8. * storage/indexeddb/resources/structured-clone.js: * storage/indexeddb/structured-clone-expected.txt: Add tests for ImageData colorSpace round tripping. * storage/indexeddb/structured-clone-image-data-display-p3-expected.txt: Added. * storage/indexeddb/structured-clone-image-data-display-p3.html: Added. Add test for ImageData display-p3 colorSpace round tripping as its own test to allow targetted skipping by non-supporting platforms. Canonical link: https://commits.webkit.org/237802@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@277574 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-05-16 22:00:30 +00:00
<html>
<head>
<script src="../../resources/js-test.js"></script>
<script src="resources/shared.js"></script>
</head>
<body>
<script>
description("Test structured clone of ImageData with a display-p3 colorSpace.");
indexedDBTest(prepareDatabase, startTests);
function prepareDatabase()
{
db = event.target.result;
evalAndLog("store = db.createObjectStore('storeName')");
debug("This index is not used, but evaluating key path on each put() call will exercise (de)serialization:");
evalAndLog("store.createIndex('indexName', 'dummyKeyPath')");
}
function testValue(value, callback)
{
// One transaction per test, since some tests require asynchronous
// operations to verify the result (e.g. via FileReader)
evalAndLog("transaction = db.transaction('storeName', 'readwrite')");
transaction.onerror = unexpectedErrorCallback;
transaction.onabort = unexpectedAbortCallback;
evalAndLog("store = transaction.objectStore('storeName')");
self.value = value;
request = evalAndLog("store.put(value, 'key')");
request.onerror = unexpectedErrorCallback;
request.onsuccess = function(e) {
request = evalAndLog("store.get('key')");
request.onerror = unexpectedErrorCallback;
request.onsuccess = function(e) {
callback(request.result);
};
};
}
// Identity testing, sensitive to NaN and -0
function is(x, y) {
if (x === y) {
return x !== 0 || 1 / x === 1 / y;
}
return x !== x && y !== y;
}
function arrayCompare(a, b) {
if (a.length !== b.length) {
return false;
}
for (var i = 0; i < a.length; ++i) {
if (!is(a[i], b[i])) {
return false;
}
}
return true;
}
function startTests()
{
debug("");
debug(`Testing ImageData: { colorSpace: "display-p3" }`);
evalAndLog("canvas = document.createElement('canvas')");
evalAndLog("canvas.width = 8");
evalAndLog("canvas.height = 8");
evalAndLog(`test_data = canvas.getContext('2d').getImageData(0, 0, 8, 8, { colorSpace: "display-p3" })`);
for (var i = 0; i < 256; ++i) {
test_data.data[i] = i;
}
testValue(test_data, function(result) {
self.result = result;
shouldBeTrue("test_data !== result");
shouldBeEqualToString("Object.prototype.toString.call(result)", "[object ImageData]");
shouldBe("result.width", "test_data.width");
shouldBe("result.height", "test_data.height");
shouldBe("result.data.length", "test_data.data.length");
shouldBe("result.colorSpace", "test_data.colorSpace");
if (arrayCompare(test_data.data, result.data)) {
testPassed("result data matches");
} else {
testFailed("result data doesn't match");
}
finishJSTest();
});
}
</script>
</body>
</html>