Bug 1607172 - Automatically fix ESLint issues in non-third party dom/media/webvtt/ files. r=jya

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mark Banner 2020-01-21 20:46:20 +00:00
parent 9e27a54a24
commit 3596e824db
3 changed files with 161 additions and 88 deletions

View File

@ -2,22 +2,18 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const {WebVTT} = ChromeUtils.import("resource://gre/modules/vtt.jsm");
const { WebVTT } = ChromeUtils.import("resource://gre/modules/vtt.jsm");
function WebVTTParserWrapper()
{
function WebVTTParserWrapper() {
// Nothing
}
WebVTTParserWrapper.prototype =
{
loadParser: function(window)
{
this.parser = new WebVTT.Parser(window, new TextDecoder("utf8"));
WebVTTParserWrapper.prototype = {
loadParser(window) {
this.parser = new WebVTT.Parser(window, new TextDecoder("utf8"));
},
parse: function(data)
{
parse(data) {
// We can safely translate the string data to a Uint8Array as we are
// guaranteed character codes only from \u0000 => \u00ff
var buffer = new Uint8Array(data.length);
@ -28,34 +24,30 @@ WebVTTParserWrapper.prototype =
this.parser.parse(buffer);
},
flush: function()
{
flush() {
this.parser.flush();
},
watch: function(callback)
{
watch(callback) {
this.parser.oncue = callback.onCue;
this.parser.onregion = callback.onRegion;
this.parser.onparsingerror = function(e) {
// Passing the just the error code back is enough for our needs.
callback.onParsingError(("code" in e) ? e.code : -1);
callback.onParsingError("code" in e ? e.code : -1);
};
},
cancel: function() {
cancel() {
this.parser.oncue = null;
this.parser.onregion = null;
this.parser.onparsingerror = null;
},
convertCueToDOMTree: function(window, cue)
{
convertCueToDOMTree(window, cue) {
return WebVTT.convertCueToDOMTree(window, cue.text);
},
processCues: function(window, cues, overlay, controls)
{
processCues(window, cues, overlay, controls) {
WebVTT.processCues(window, cues, overlay, controls);
},

View File

@ -1,68 +1,146 @@
"use strict";
const {WebVTT} = ChromeUtils.import("resource://gre/modules/vtt.jsm");
const { WebVTT } = ChromeUtils.import("resource://gre/modules/vtt.jsm");
let fakeWindow = {
VTTCue: function() {},
VTTRegion: function() {},
VTTCue() {},
VTTRegion() {},
};
// We have a better parser check in WPT. Here I want to check that incomplete
// lines are correctly parsable.
let tests = [
// Signature
{ input: [ "WEBVTT" ], cue: 0, region: 0 },
{ input: [ "", "WE", "BVT", "T" ], cue: 0, region: 0 },
{ input: [ "WEBVTT - This file has no cues." ], cue: 0, region: 0 },
{ input: [ "WEBVTT", " - ", "This file has no cues." ], cue: 0, region: 0 },
{ input: ["WEBVTT"], cue: 0, region: 0 },
{ input: ["", "WE", "BVT", "T"], cue: 0, region: 0 },
{ input: ["WEBVTT - This file has no cues."], cue: 0, region: 0 },
{ input: ["WEBVTT", " - ", "This file has no cues."], cue: 0, region: 0 },
// Body with IDs
{ input: [ "WEB", "VTT - This file has cues.\n", "\n", "14\n",
"00:01:14", ".815 --> 00:0", "1:18.114\n", "- What?\n", "- Where are we now?\n", "\n",
"15\n", "00:01:18.171 --> 00:01:20.991\n", "- T", "his is big bat country.\n", "\n",
"16\n", "00:01:21.058 --> 00:01:23.868\n", "- [ Bat", "s Screeching ]\n",
"- They won't get in your hair. They're after the bug", "s.\n", ],
cue: 3, region: 0 },
{
input: [
"WEB",
"VTT - This file has cues.\n",
"\n",
"14\n",
"00:01:14",
".815 --> 00:0",
"1:18.114\n",
"- What?\n",
"- Where are we now?\n",
"\n",
"15\n",
"00:01:18.171 --> 00:01:20.991\n",
"- T",
"his is big bat country.\n",
"\n",
"16\n",
"00:01:21.058 --> 00:01:23.868\n",
"- [ Bat",
"s Screeching ]\n",
"- They won't get in your hair. They're after the bug",
"s.\n",
],
cue: 3,
region: 0,
},
// Body without IDs
{ input: [ "WEBVTT - This file has c", "ues.\n", "\n",
"00:01:14.815 --> 00:01:18.114\n", "- What?\n", "- Where are we now?\n", "\n",
"00:01:18.171 --> 00:01:2", "0.991\n", "- ", "This is big bat country.\n", "\n",
"00:01:21.058 --> 00:01:23.868\n", "- [ Bats S", "creeching ]\n",
"- They won't get in your hair. They're after the bugs.\n", ],
cue: 3, region: 0 },
{
input: [
"WEBVTT - This file has c",
"ues.\n",
"\n",
"00:01:14.815 --> 00:01:18.114\n",
"- What?\n",
"- Where are we now?\n",
"\n",
"00:01:18.171 --> 00:01:2",
"0.991\n",
"- ",
"This is big bat country.\n",
"\n",
"00:01:21.058 --> 00:01:23.868\n",
"- [ Bats S",
"creeching ]\n",
"- They won't get in your hair. They're after the bugs.\n",
],
cue: 3,
region: 0,
},
// Note
{ input: [ "WEBVTT - This file has no cues.\n", "\n", "NOTE what" ],
cue: 0, region: 0 },
{
input: ["WEBVTT - This file has no cues.\n", "\n", "NOTE what"],
cue: 0,
region: 0,
},
// Regions - This vtt is taken from a WPT
{ input: [ "WE", "BVTT\n", "\n", "REGION\n", "id:0\n", "\n", "REGION\n", "id:1\n",
"region", "an", "chor:0%,0%\n", "\n", "R", "EGION\n", "id:2\n",
"regionanchor:18446744073709552000%,18446744", "073709552000%\n", "\n",
"REGION\n", "id:3\n", "regionanchor: 100%,100%\n", "regio", "nanchor :100%,100%\n",
"regionanchor:100% ,100%\n", "regionanchor:100%, 100%\n",
"regionanchor:100 %,100%\n", "regionanchor:10", "0%,100 %\n", "\n",
"00:00:00.000 --> 00:00:01.000", " region:0\n", "text\n", "\n",
"00:00:00.000 --> 00:00:01.000 region:1\n", "text\n", "\n",
"00:00:00.000 --> 00:00:01.000 region:3\n", "text\n" ], cue: 3, region: 4 },
{
input: [
"WE",
"BVTT\n",
"\n",
"REGION\n",
"id:0\n",
"\n",
"REGION\n",
"id:1\n",
"region",
"an",
"chor:0%,0%\n",
"\n",
"R",
"EGION\n",
"id:2\n",
"regionanchor:18446744073709552000%,18446744",
"073709552000%\n",
"\n",
"REGION\n",
"id:3\n",
"regionanchor: 100%,100%\n",
"regio",
"nanchor :100%,100%\n",
"regionanchor:100% ,100%\n",
"regionanchor:100%, 100%\n",
"regionanchor:100 %,100%\n",
"regionanchor:10",
"0%,100 %\n",
"\n",
"00:00:00.000 --> 00:00:01.000",
" region:0\n",
"text\n",
"\n",
"00:00:00.000 --> 00:00:01.000 region:1\n",
"text\n",
"\n",
"00:00:00.000 --> 00:00:01.000 region:3\n",
"text\n",
],
cue: 3,
region: 4,
},
];
function run_test() {
tests.forEach(test => {
let parser = new WebVTT.Parser(fakeWindow, null);
ok(!!parser, "Ok... this is a good starting point");
let cue = 0;
parser.oncue = () => { ++cue; };
parser.oncue = () => {
++cue;
};
let region = 0;
parser.onregion = () => { ++region; };
parser.onregion = () => {
++region;
};
parser.onparsingerror = () => {
ok(false, "No error accepted");
}
};
test.input.forEach(input => {
parser.parse(new TextEncoder().encode(input));

View File

@ -1,25 +1,26 @@
#!/usr/bin/env node
var gift = require('gift'),
fs = require('fs'),
argv = require('optimist')
.usage('Update vtt.jsm with the latest from a vtt.js directory.\nUsage:' +
' $0 -d [dir]')
.demand('d')
.options('d', {
alias: 'dir',
describe: 'Path to WebVTT directory.'
})
.options('r', {
alias: 'rev',
describe: 'Revision to update to.',
default: 'master'
})
.options('w', {
alias: 'write',
describe: 'Path to file to write to.',
default: "./vtt.jsm"
})
.argv;
var gift = require("gift"),
fs = require("fs"),
argv = require("optimist")
.usage(
"Update vtt.jsm with the latest from a vtt.js directory.\nUsage:" +
" $0 -d [dir]"
)
.demand("d")
.options("d", {
alias: "dir",
describe: "Path to WebVTT directory.",
})
.options("r", {
alias: "rev",
describe: "Revision to update to.",
default: "master",
})
.options("w", {
alias: "write",
describe: "Path to file to write to.",
default: "./vtt.jsm",
}).argv;
var repo = gift(argv.d);
repo.status(function(err, status) {
@ -29,27 +30,29 @@ repo.status(function(err, status) {
}
repo.checkout(argv.r, function() {
repo.commits(argv.r, 1, function(err, commits) {
var vttjs = fs.readFileSync(argv.d + "/lib/vtt.js", 'utf8');
var vttjs = fs.readFileSync(argv.d + "/lib/vtt.js", "utf8");
// Remove settings for VIM and Emacs.
vttjs = vttjs.replace(/\/\* -\*-.*-\*- \*\/\n/, '');
vttjs = vttjs.replace(/\/\* vim:.* \*\/\n/, '');
vttjs = vttjs.replace(/\/\* -\*-.*-\*- \*\/\n/, "");
vttjs = vttjs.replace(/\/\* vim:.* \*\/\n/, "");
// Concatenate header and vttjs code.
vttjs =
'/* This Source Code Form is subject to the terms of the Mozilla Public\n' +
' * License, v. 2.0. If a copy of the MPL was not distributed with this\n' +
' * file, You can obtain one at http://mozilla.org/MPL/2.0/. */\n\n' +
"/* This Source Code Form is subject to the terms of the Mozilla Public\n" +
" * License, v. 2.0. If a copy of the MPL was not distributed with this\n" +
" * file, You can obtain one at http://mozilla.org/MPL/2.0/. */\n\n" +
'this.EXPORTED_SYMBOLS = ["WebVTT"];\n\n' +
'/**\n' +
' * Code below is vtt.js the JS WebVTT implementation.\n' +
' * Current source code can be found at http://github.com/mozilla/vtt.js\n' +
' *\n' +
' * Code taken from commit ' + commits[0].id + '\n' +
' */\n' +
"/**\n" +
" * Code below is vtt.js the JS WebVTT implementation.\n" +
" * Current source code can be found at http://github.com/mozilla/vtt.js\n" +
" *\n" +
" * Code taken from commit " +
commits[0].id +
"\n" +
" */\n" +
vttjs;
fs.writeFileSync(argv.w, vttjs);
});
});
});
});