Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: LayoutTests/fast/canvas/script-tests/canvas-lineDash-input-sequence.js

Issue 19969004: Update toNativeArray() / toRefPtrNativeArray() do not match Web IDL specification (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Take feedback into consideration Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: LayoutTests/fast/canvas/script-tests/canvas-lineDash-input-sequence.js
diff --git a/LayoutTests/fast/canvas/script-tests/canvas-lineDash-input-sequence.js b/LayoutTests/fast/canvas/script-tests/canvas-lineDash-input-sequence.js
new file mode 100644
index 0000000000000000000000000000000000000000..8a52dd1ec5cd7eee647666d4b13e6d16bf582272
--- /dev/null
+++ b/LayoutTests/fast/canvas/script-tests/canvas-lineDash-input-sequence.js
@@ -0,0 +1,67 @@
+description("Test that setLineDash converts input argument into a Web IDL sequence");
+
+var canvas = document.createElement('canvas');
+document.body.appendChild(canvas);
+canvas.setAttribute('width', '700');
+canvas.setAttribute('height', '700');
+var ctx = canvas.getContext('2d');
+
+var arrayValues = [5, 15, 25];
+
+function createTestArray(arrayType) {
+ var array;
+ if (arrayType == Object) {
+ // Test a "sequence" (Object with length property).
+ array = {length: arrayValues.length};
+ } else {
+ array = new arrayType(arrayValues.length);
+ }
+
+ for (var i = 0; i < arrayValues.length; ++i)
+ array[i] = arrayValues[i]
+ return array;
+}
+
+var lineDash;
+var inputArray;
+function checkLineDash(testArray, shouldFail) {
+ inputArray = testArray;
+ // Reset line dash.
+ ctx.setLineDash([]);
+ // Set line dash.
+ if (shouldFail) {
+ shouldThrow("ctx.setLineDash(inputArray)", "'TypeError: Type error'");
+ } else {
+ ctx.setLineDash(inputArray);
+ lineDash = ctx.getLineDash();
+ for (var i = 0; i < arrayValues.length; ++i)
+ shouldBe("lineDash[" + i + "]", "" + arrayValues[i]);
+ }
+}
+
+var arrayTypes = [Array, Int8Array, Int16Array, Int32Array, Uint8Array, Uint16Array, Uint32Array, Float32Array, Float64Array, Uint8ClampedArray, Object];
+
+// Success cases.
+for (var i = 0; i < arrayTypes.length; ++i) {
+ debug("* Test passing a " + arrayTypes[i].name + " as input.");
+ checkLineDash(createTestArray(arrayTypes[i]), false);
+}
+
+// Failure cases.
+debug("* Test passing a Date as input.");
+checkLineDash(new Date(), true);
+debug("* Test passing a RegExp as input.");
+checkLineDash(new RegExp(), true);
+debug("* Test passing an Object without length as input.");
+checkLineDash({test: 1}, true);
+debug("* Test passing a Number as input.");
+checkLineDash(3, true);
+debug("* Test passing a String as input.");
+checkLineDash("Test", true);
+debug("* Test passing a Boolean as input.");
+checkLineDash(true, true);
+debug("* Test passing null as input.");
+checkLineDash(null, true);
+debug("* Test passing undefined as input.");
+checkLineDash(undefined, true);
+

Powered by Google App Engine
This is Rietveld 408576698