Bug 1614360 - Added test case. r=dom-workers-and-storage-reviewers,ttung

Differential Revision: https://phabricator.services.mozilla.com/D62775

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Simon Giesecke 2020-02-18 10:42:48 +00:00
parent 8be644ba9e
commit e089b04d9a
4 changed files with 65 additions and 0 deletions

View File

@ -413,6 +413,23 @@ function expectingUpgrade(request) {
});
}
function expectingError(request, errorName) {
return new Promise(function(resolve, reject) {
request.onerror = function(event) {
is(errorName, event.target.error.name, "Correct exception type");
resolve(event);
};
request.onsuccess = function(event) {
ok(false, "Got success, but did not expect it!");
reject(event);
};
request.onupgradeneeded = function(event) {
ok(false, "Got upgrade, but did not expect it!");
reject(event);
};
});
}
function workerScript() {
"use strict";

View File

@ -44,6 +44,7 @@ support-files =
unit/test_deleteDatabase_onblocked_duringVersionChange.js
unit/test_event_source.js
unit/test_filehandle_append_read_data.js
unit/test_filehandle_read_beyond_eof_exception.js
unit/test_getAll.js
unit/test_globalObjects_ipc.js
unit/test_globalObjects_other.js
@ -183,6 +184,7 @@ skip-if = toolkit == 'android' && !is_fennec
[test_filehandle_ordering.html]
[test_filehandle_overlapping.html]
[test_filehandle_progress_events.html]
[test_filehandle_read_beyond_eof_exception.html]
[test_filehandle_readonly_exceptions.html]
[test_filehandle_request_readyState.html]
[test_filehandle_serialization.html]

View File

@ -0,0 +1,20 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<html>
<head>
<title>File Handle Test</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="text/javascript" src="unit/test_filehandle_read_beyond_eof_exception.js"></script>
<script type="text/javascript" src="file.js"></script>
<script type="text/javascript" src="helpers.js"></script>
</head>
<body onload="runTest();"></body>
</html>

View File

@ -0,0 +1,26 @@
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
/* import-globals-from ../helpers.js */
var disableWorkerTest = "FileHandle doesn't work in workers yet";
async function testSteps() {
const name = "test_filehandle_read_beyond_eof_exception.js";
info("Opening database");
let dbRequest = indexedDB.open(name);
await expectingUpgrade(dbRequest);
let event = await expectingSuccess(dbRequest);
info("Creating file");
const file = event.target.result.createMutableFile("F");
event = await expectingSuccess(file);
info("Opening and reading from empty file");
const handle = event.target.result.open("readonly");
const fileRequest = handle.readAsArrayBuffer(8);
await expectingError(fileRequest, "UnknownError");
}