From d6e7f333d81345295fa87d7b905c87a4a415b39f Mon Sep 17 00:00:00 2001 From: Shian-Yow Wu Date: Fri, 6 Jun 2014 13:34:31 +0800 Subject: [PATCH] Bug 1008126 - Part 2: Test cases. r=bent --- content/base/test/file_bug1008126_worker.js | 162 ++++++++++++++++++++ content/base/test/mochitest.ini | 3 + content/base/test/test_bug1008126.html | 56 +++++++ 3 files changed, 221 insertions(+) create mode 100644 content/base/test/file_bug1008126_worker.js create mode 100644 content/base/test/test_bug1008126.html diff --git a/content/base/test/file_bug1008126_worker.js b/content/base/test/file_bug1008126_worker.js new file mode 100644 index 00000000000..d2f98570492 --- /dev/null +++ b/content/base/test/file_bug1008126_worker.js @@ -0,0 +1,162 @@ +/** + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +var gJar1 = "jar:http://example.org/tests/content/base/test/file_bug945152.jar!/data_1.txt"; +var gJar2 = "jar:http://example.org/tests/content/base/test/file_bug945152.jar!/data_2.txt"; +var gPaddingChar = "."; +var gPaddingSize = 10000; +var gPadding = ""; +for (var i = 0; i < gPaddingSize; i++) { + gPadding += gPaddingChar; +} +var gData1 = "TEST_DATA_1:ABCDEFGHIJKLMNOPQRSTUVWXYZ" + gPadding; +var gData2 = "TEST_DATA_2:1234567890" + gPadding; + +function ok(a, msg) { + postMessage({type: "status", status: !!a, msg: msg }); +} + +function is(a, b, msg) { + postMessage({type: "status", status: a === b, msg: msg }); +} + +function checkData(xhr, data, mapped, cb) { + var ct = xhr.getResponseHeader("Content-Type"); + if (mapped) { + ok(ct.indexOf("mem-mapped") != -1, "Data is memory-mapped"); + } else { + ok(ct.indexOf("mem-mapped") == -1, "Data is not memory-mapped"); + } + ok(xhr.response, "Data is non-null"); + var str = String.fromCharCode.apply(null, Uint8Array(xhr.response)); + ok(str == data, "Data is correct"); + cb(); +} + +self.onmessage = function onmessage(event) { + + var xhr = new XMLHttpRequest({mozAnon: true, mozSystem: true}); + + function reset_event_hander() { + xhr.onerror = function(e) { + ok(false, "Error: " + e.error + "\n"); + }; + xhr.onprogress = null; + xhr.onreadystatechange = null; + xhr.onload = null; + xhr.onloadend = null; + } + + function test_chunked_arraybuffer() { + ok(true, "Test chunked arraybuffer"); + + var lastIndex = 0; + xhr.onprogress = function(event) { + if (xhr.response) { + var str = String.fromCharCode.apply(null, Uint8Array(xhr.response)); + ok(str.length == gData1.length, "Data size is correct"); + ok(str == gData1.substr(lastIndex, str.length), "Data chunk is correct"); + } + lastIndex += str.length; + }; + xhr.onload = runTests; + xhr.open("GET", gJar1, true); + xhr.responseType = "moz-chunked-arraybuffer"; + xhr.send(); + } + + var readystatechangeCount = 0; + var loadCount = 0; + var loadendCount = 0; + + function checkEventCount(cb) { + ok(readystatechangeCount == 1 && loadCount == 1 && loadendCount == 1, + "Saw all expected events"); + cb(); + } + + function test_multiple_events() { + ok(true, "Test multiple events"); + xhr.abort(); + + xhr.onreadystatechange = function() { + if (xhr.readyState == xhr.DONE) { + readystatechangeCount++; + checkData(xhr, gData2, false, function() {} ); + } + }; + xhr.onload = function() { + loadCount++; + checkData(xhr, gData2, false, function() {} ); + }; + xhr.onloadend = function() { + loadendCount++; + checkData(xhr, gData2, false, function() {} ); + }; + xhr.open("GET", gJar2, false); + xhr.responseType = "arraybuffer"; + xhr.send(); + checkEventCount(runTests); + } + + function test_sync_xhr_data1() { + ok(true, "Test sync XHR with data1"); + xhr.open("GET", gJar1, false); + xhr.responseType = "arraybuffer"; + xhr.send(); + checkData(xhr, gData1, true, runTests); + } + + function test_sync_xhr_data2() { + ok(true, "Test sync XHR with data2"); + xhr.open("GET", gJar2, false); + xhr.responseType = "arraybuffer"; + xhr.send(); + checkData(xhr, gData2, false, runTests); + } + + function test_async_xhr_data1() { + ok(true, "Test async XHR with data1"); + xhr.onload = function() { + checkData(xhr, gData1, true, runTests); + }; + xhr.open("GET", gJar1, true); + xhr.responseType = "arraybuffer"; + xhr.send(); + } + + function test_async_xhr_data2() { + ok(true, "Test async XHR with data2"); + xhr.onload = function() { + checkData(xhr, gData2, false, runTests); + }; + xhr.open("GET", gJar2, true); + xhr.responseType = "arraybuffer"; + xhr.send(); + } + + var tests = [ + test_chunked_arraybuffer, + test_multiple_events, + test_sync_xhr_data1, + test_sync_xhr_data2, + test_async_xhr_data1, + test_async_xhr_data2 + ]; + + function runTests() { + if (!tests.length) { + postMessage({type: "finish" }); + return; + } + + reset_event_hander(); + + var test = tests.shift(); + test(); + } + + runTests(); +}; diff --git a/content/base/test/mochitest.ini b/content/base/test/mochitest.ini index 5d009879743..062b0a0ec61 100644 --- a/content/base/test/mochitest.ini +++ b/content/base/test/mochitest.ini @@ -142,6 +142,7 @@ support-files = file_bug907892.html file_bug945152.jar file_bug945152_worker.js + file_bug1008126_worker.js file_general_document.html file_html_in_xhr.html file_html_in_xhr.sjs @@ -555,6 +556,8 @@ skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s #needs plugin suppor [test_bug927196.html] [test_bug945152.html] run-if = os == 'linux' +[test_bug1008126.html] +run-if = os == 'linux' [test_caretPositionFromPoint.html] [test_classList.html] # This test fails on the Mac for some reason diff --git a/content/base/test/test_bug1008126.html b/content/base/test/test_bug1008126.html new file mode 100644 index 00000000000..fc58d6d841d --- /dev/null +++ b/content/base/test/test_bug1008126.html @@ -0,0 +1,56 @@ + + + + + + + Test for Bug 1008126 + + + + +Mozilla Bug 1008126 +

+ +
+
+
+ +