diff options
Diffstat (limited to 'testing/web-platform/tests/FileAPI/BlobURL')
6 files changed, 281 insertions, 0 deletions
diff --git a/testing/web-platform/tests/FileAPI/BlobURL/support/file_test1.js b/testing/web-platform/tests/FileAPI/BlobURL/support/file_test1.js new file mode 100644 index 000000000..349835849 --- /dev/null +++ b/testing/web-platform/tests/FileAPI/BlobURL/support/file_test1.js @@ -0,0 +1 @@ +var test_result = 'test1_OK';
\ No newline at end of file diff --git a/testing/web-platform/tests/FileAPI/BlobURL/support/file_test2.txt b/testing/web-platform/tests/FileAPI/BlobURL/support/file_test2.txt new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/testing/web-platform/tests/FileAPI/BlobURL/support/file_test2.txt diff --git a/testing/web-platform/tests/FileAPI/BlobURL/support/file_test3.html b/testing/web-platform/tests/FileAPI/BlobURL/support/file_test3.html new file mode 100644 index 000000000..fa234cb9f --- /dev/null +++ b/testing/web-platform/tests/FileAPI/BlobURL/support/file_test3.html @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title>Test file</title> + <style> + body { + margin: 0; + } + .block { + height: 5000px; + } + </style> + <script> + window.test_result = 'test3_OK'; + </script> +</head> +<body> + <a id="block1"></a> + <div class="block"></div> + + <a id="block2"></a> + <div class="block"></div> +</body> +</html> diff --git a/testing/web-platform/tests/FileAPI/BlobURL/test1-manual.html b/testing/web-platform/tests/FileAPI/BlobURL/test1-manual.html new file mode 100644 index 000000000..8da42cf64 --- /dev/null +++ b/testing/web-platform/tests/FileAPI/BlobURL/test1-manual.html @@ -0,0 +1,122 @@ +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title>Blob and File reference URL Test(1)</title> + <link rel=help href="http://dev.w3.org/2006/webapi/FileAPI/#convenienceAPI"> + <link rel=author title="Breezewish" href="mailto:me@breeswish.org"> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> +</head> +<body> + <form name="upload"> + <input type="file" id="fileChooser"> + </form> + + <div> + <p>Test steps:</p> + <ol> + <li>Download the <a href="support/file_test1.js">file</a>.</li> + <li>Select the file in the file inputbox to run the test.</li> + </ol> + </div> + + <div id="log"></div> + + <script> + + var fileChooser = document.querySelector('#fileChooser'); + + setup({explicit_done: true}); + setup({explicit_timeout: true}); + + //Run the test when user selects a file + + on_event(fileChooser, 'change', function() { + + var testCount = 10000; + + test(function() { + + var list = [], file = fileChooser.files[0]; + + for (var i = 0; i <= testCount; i++) { + list.push(window.URL.createObjectURL(file)); + } + + list.sort(); + + for (var i = 0; i < testCount; i++) { + assert_not_equals(list[i], list[i+1], 'generated Blob URL should be unique'); + } + + }, 'Check whether generated Blob/File URL is unique (Notice: only generate for ' + testCount + ' times)'); + + + async_test(function(t) { + + var url = URL.createObjectURL(fileChooser.files[0]); + var expected_file_content = "var test_result = 'test1_OK';"; + + var xhr = new XMLHttpRequest(); + xhr.open('GET', url, true); + xhr.onreadystatechange = t.step_func(function() { + switch (xhr.readyState) { + case xhr.DONE: + assert_equals(xhr.status, 200, 'status code should be 200'); + assert_equals(xhr.responseText, expected_file_content); + t.done(); + return; + } + }); + + xhr.send(); + + }, 'Check whether Blob/File URL could be used in XHR requests and could get expected data'); + + async_test(function(t) { + + var url = URL.createObjectURL(fileChooser.files[0]); + var expected_run_result = "test1_OK"; + + //expected file content: + // var test_result = 'test1_OK'; + + var e = document.createElement('script'); + e.setAttribute('type', 'text/javascript'); + e.setAttribute('src', url); + e.onload = t.step_func_done(function() { + assert_equals(test_result, expected_run_result); + }); + + document.body.appendChild(e); + + }, 'Check whether Blob/File URL could be used in tags src like <script>'); + + async_test(function(t) { + + var url = URL.createObjectURL(fileChooser.files[0]); + URL.revokeObjectURL(url); + + var xhr = new XMLHttpRequest(); + xhr.open('GET', url, true); + xhr.onreadystatechange = t.step_func(function() { + switch (xhr.readyState) { + case xhr.DONE: + assert_equals(xhr.status, 500, 'status code should be 500 if Blob URI is revoked.'); + t.done(); + return; + } + }); + + xhr.send(); + + }, 'Check whether revokeObjectURL works well'); + + done(); + + }); + + </script> +</body> +</html> diff --git a/testing/web-platform/tests/FileAPI/BlobURL/test2-manual.html b/testing/web-platform/tests/FileAPI/BlobURL/test2-manual.html new file mode 100644 index 000000000..07fb27ef8 --- /dev/null +++ b/testing/web-platform/tests/FileAPI/BlobURL/test2-manual.html @@ -0,0 +1,62 @@ +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title>Blob and File reference URL Test(2)</title> + <link rel=help href="http://dev.w3.org/2006/webapi/FileAPI/#convenienceAPI"> + <link rel=author title="Breezewish" href="mailto:me@breeswish.org"> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> +</head> +<body> + <form name="upload"> + <input type="file" id="fileChooser"><br><input type="button" id="start" value="start"> + </form> + + <div> + <p>Test steps:</p> + <ol> + <li>Download the <a href="support/file_test2.txt">file</a>.</li> + <li>Select the file in the file inputbox.</li> + <li>Delete the file.</li> + <li>Click the 'start' button.</li> + </ol> + </div> + + <div id="log"></div> + + <script> + + var fileChooser = document.querySelector('#fileChooser'); + + setup({explicit_done: true}); + setup({explicit_timeout: true}); + + on_event(document.querySelector('#start'), 'click', function() { + + async_test(function(t) { + + var url = URL.createObjectURL(fileChooser.files[0]); + + var xhr = new XMLHttpRequest(); + xhr.open('GET', url, true); + xhr.onreadystatechange = t.step_func(function() { + switch (xhr.readyState) { + case xhr.DONE: + assert_equals(xhr.status, 500, 'status code should be 500.'); + t.done(); + return; + } + }); + + xhr.send(); + + }, 'Check whether the browser response 500 in XHR if the selected file which File/Blob URL refered is not found'); + + done(); + + }); + + </script> +</body> +</html> diff --git a/testing/web-platform/tests/FileAPI/BlobURL/test3-manual.html b/testing/web-platform/tests/FileAPI/BlobURL/test3-manual.html new file mode 100644 index 000000000..ce020a7b7 --- /dev/null +++ b/testing/web-platform/tests/FileAPI/BlobURL/test3-manual.html @@ -0,0 +1,71 @@ +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title>Blob and File reference URL Test(3)</title> + <link rel=help href="http://dev.w3.org/2006/webapi/FileAPI/#convenienceAPI"> + <link rel=author title="Breezewish" href="mailto:me@breeswish.org"> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> +</head> +<body> + <form name="upload"> + <input type="file" id="fileChooser"> + </form> + + <div> + <p>Test steps:</p> + <ol> + <li>Download the <a href="support/file_test3.html">file</a>.</li> + <li>Select the file in the file inputbox and the test will start.</li> + </ol> + </div> + + <div id="log"></div> + + <script> + + var fileChooser = document.querySelector('#fileChooser'); + + setup({explicit_done: true}); + setup({explicit_timeout: true}); + + on_event(fileChooser, 'change', function() { + + async_test(function(t) { + + var url = URL.createObjectURL(fileChooser.files[0]); + + var e = document.createElement('iframe'); + e.setAttribute('src', url); + e.setAttribute('style', 'display:none;'); + document.body.appendChild(e); + + e.contentWindow.document.body.onload = t.step_func_done(function() { + assert_equals(e.contentWindow.test_result, 'test3_OK'); + }); + + }, 'Check whether the iframe content could be accessed when using Blob/File URL in the same origin.'); + + async_test(function(t) { + + var url = URL.createObjectURL(fileChooser.files[0]); + url += '#block2'; + + var e = document.createElement('iframe'); + e.setAttribute('src', url); + document.body.appendChild(e); + + e.contentWindow.document.body.onload = t.step_func_done(function() { + assert_equals(e.contentWindow.scrollY, 5000); + }); + + }, 'Check whether the Blob/File URL fragment is implemented.'); + + done(); + + }); + + </script> +</body> +</html> |