| OLD | NEW |
| 1 /* |
| 2 * Distributed under both the W3C Test Suite License [1] and the W3C |
| 3 * 3-clause BSD License [2]. To contribute to a W3C Test Suite, see the |
| 4 * policies and contribution forms [3]. |
| 5 * |
| 6 * [1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license |
| 7 * [2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license |
| 8 * [3] http://www.w3.org/2004/10/27-testcases |
| 9 * */ |
| 10 |
| 11 /* Source: https://github.com/w3c/web-platform-tests/blob/master/common/vendor-p
refix.js |
| 12 * The file has been modified to always be on (i.e. does not require usePrefixes
=1 to |
| 13 * start replacing prefixes). */ |
| 14 |
| 1 /* Use this script when you want to test APIs that use vendor prefixes | 15 /* Use this script when you want to test APIs that use vendor prefixes |
| 2 and define which objects need to be checked for prefixed versions, à la | 16 and define which objects need to be checked for prefixed versions, à la |
| 3 <script src="vendor-prefix.js" | 17 <script src="vendor-prefix.js" |
| 4 data-prefixed-objects='[{"ancestors":["navigator"], "name":"getUserMedia"}]
' | 18 data-prefixed-objects='[{"ancestors":["navigator"], "name":"getUserMedia"}]
' |
| 5 data-prefixed-prototypes='[{"ancestors":["HTMLMediaElement"],"name":"srcObjec
t"}]'></script> | 19 data-prefixed-prototypes='[{"ancestors":["HTMLMediaElement"],"name":"srcObjec
t"}]'></script> |
| 6 data-prefixed-objects lets prefix objects in the global space | 20 data-prefixed-objects lets prefix objects in the global space |
| 7 data-prefixed-prototypes adds prefixes to interfaces, for objects that | 21 data-prefixed-prototypes adds prefixes to interfaces, for objects that |
| 8 get created during the tests | 22 get created during the tests |
| 9 | 23 |
| 10 NB: vendor prefixes are expected to go away in favor of putting | 24 NB: vendor prefixes are expected to go away in favor of putting |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 vendorPrefixes.forEach(function (prefix) { | 71 vendorPrefixes.forEach(function (prefix) { |
| 58 if (parent[prependPrefix(prefix, obj.name)] !== undefined) { | 72 if (parent[prependPrefix(prefix, obj.name)] !== undefined) { |
| 59 parent[obj.name] = parent[prependPrefix(prefix, obj.name)]; | 73 parent[obj.name] = parent[prependPrefix(prefix, obj.name)]; |
| 60 aliases[obj.ancestors.join(".") + "." + obj.name] = obj.ance
stors.join(".") + "." + prependPrefix(prefix, obj.name); | 74 aliases[obj.ancestors.join(".") + "." + obj.name] = obj.ance
stors.join(".") + "." + prependPrefix(prefix, obj.name); |
| 61 return; | 75 return; |
| 62 } | 76 } |
| 63 }); | 77 }); |
| 64 } | 78 } |
| 65 } | 79 } |
| 66 | 80 |
| 67 if (location.search.indexOf('usePrefixes=1') !== -1) { | 81 // For this version of vendor-prefixes.js, always replace the prefixes. |
| 68 if (document.querySelector("script[data-prefixed-objects]")) { | 82 if (document.querySelector("script[data-prefixed-objects]")) { |
| 69 var prefixObjectsData = document.querySelector("script[data-prefixed
-objects]").dataset["prefixedObjects"]; | 83 var prefixObjectsData = document.querySelector("script[data-prefixed-obj
ects]").dataset["prefixedObjects"]; |
| 70 try { | 84 try { |
| 71 var prefixedObjects = JSON.parse(prefixObjectsData); | 85 var prefixedObjects = JSON.parse(prefixObjectsData); |
| 72 } catch (e) { | 86 } catch (e) { |
| 73 throw "couldn't parse data-prefixed-objects as JSON:" + e; | 87 throw "couldn't parse data-prefixed-objects as JSON:" + e; |
| 74 } | |
| 75 prefixedObjects.forEach(setAlias); | |
| 76 } | 88 } |
| 77 if (document.querySelector("script[data-prefixed-prototypes]")) { | 89 prefixedObjects.forEach(setAlias); |
| 78 var prefixProtoData = document.querySelector("script[data-prefixed-p
rototypes]").dataset["prefixedPrototypes"]; | 90 } |
| 79 try { | 91 if (document.querySelector("script[data-prefixed-prototypes]")) { |
| 80 var prefixedPrototypes = JSON.parse(prefixProtoData); | 92 var prefixProtoData = document.querySelector("script[data-prefixed-proto
types]").dataset["prefixedPrototypes"]; |
| 81 } catch (e) { | 93 try { |
| 82 throw "couldn't parse data-prefixed-prototypes as JSON:" + e; | 94 var prefixedPrototypes = JSON.parse(prefixProtoData); |
| 83 } | 95 } catch (e) { |
| 84 prefixedPrototypes.forEach(setPrototypeAlias); | 96 throw "couldn't parse data-prefixed-prototypes as JSON:" + e; |
| 85 } | 97 } |
| 86 var ul = document.createElement("ul"); | 98 prefixedPrototypes.forEach(setPrototypeAlias); |
| 87 Object.keys(aliases).forEach(function (alias) { | |
| 88 var li = document.createElement("li"); | |
| 89 li.appendChild(document.createTextNode(alias + " has been set to be
an alias of vendor-prefixed " + aliases[alias])); | |
| 90 ul.appendChild(li); | |
| 91 }); | |
| 92 documentingPrefixUsage.appendChild(ul); | |
| 93 } else { | |
| 94 // Document that the test can be run with prefixes enabled | |
| 95 | |
| 96 var a = document.createElement('a'); | |
| 97 var link = ""; | |
| 98 if (location.search) { | |
| 99 link = location.search + "&usePrefixes=1"; | |
| 100 } else { | |
| 101 link = "?usePrefixes=1"; | |
| 102 } | |
| 103 a.setAttribute("href", link); | |
| 104 a.appendChild(document.createTextNode("with vendor prefixes enabled")); | |
| 105 documentingPrefixUsage.appendChild(document.createTextNode("The feature(
s) tested here are known to have been made available via vendor prefixes; you ca
n run this test ")); | |
| 106 documentingPrefixUsage.appendChild(a); | |
| 107 documentingPrefixUsage.appendChild(document.createTextNode(".")); | |
| 108 } | |
| 109 var log = document.getElementById('log'); | |
| 110 if (log) { | |
| 111 log.parentNode.insertBefore(documentingPrefixUsage, log); | |
| 112 } else { | |
| 113 document.body.appendChild(documentingPrefixUsage); | |
| 114 } | 99 } |
| 115 })(); | 100 })(); |
| OLD | NEW |