编写功能测试,HTML5 视频标签
Writing a Feature Test, HTML5 Video Tag
我目前正在为 HTML5 视频标签周围的浏览器编写功能测试。我正在使用 Typescript(JavaScript 的一个版本)。我团队中的某个人刚刚问了一个很好的问题:功能测试(我根据 Dan Stringer 的 this great article 编写的)是否真的有效?
是否需要设置 video
标签的 src
属性才能使功能失效?或者,它是否就像尝试将 video
标记添加到 DOM 一样简单(我所做的)?
export function DoesBrowserSupportHTML5VideoAndFileType(fileType : string) {
var mimeType = "video/" + fileType,
videoElement = document.createElement("video");
if (typeof videoElement.canPlayType === "function") {
// ... Do some mime-type evaluations
// and return accordingly
}
return false; // default
}
显然,这目前没有被 try-catch
声明包围;但是,我需要设置源属性吗?
Does the src attribute of the videotag need to be set for the feature to fail
完全没有。
然而基于src
最终播放可能仍然失败(可能只是实际文件的错误)。
我目前正在为 HTML5 视频标签周围的浏览器编写功能测试。我正在使用 Typescript(JavaScript 的一个版本)。我团队中的某个人刚刚问了一个很好的问题:功能测试(我根据 Dan Stringer 的 this great article 编写的)是否真的有效?
是否需要设置 video
标签的 src
属性才能使功能失效?或者,它是否就像尝试将 video
标记添加到 DOM 一样简单(我所做的)?
export function DoesBrowserSupportHTML5VideoAndFileType(fileType : string) {
var mimeType = "video/" + fileType,
videoElement = document.createElement("video");
if (typeof videoElement.canPlayType === "function") {
// ... Do some mime-type evaluations
// and return accordingly
}
return false; // default
}
显然,这目前没有被 try-catch
声明包围;但是,我需要设置源属性吗?
Does the src attribute of the videotag need to be set for the feature to fail
完全没有。
然而基于src
最终播放可能仍然失败(可能只是实际文件的错误)。