1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
<!DOCTYPE html>
<html>
<head>
<title>vendorPrefix.js Tests</title>
<script>
var div = document.createElement("div");
var style = div.style,
orgCreateElement = document.createElement;
// wrap document.createElement to control property values
document.createElement = function(type) {
return div;
};
// dependencies for tests
var OpenLayers = [
"OpenLayers/Util/vendorPrefix.js"
];
</script>
<script src="../OLLoader.js"></script>
<script>
/**
* Test vendor prefixing
*/
function test_vendor_prefixes(t) {
t.plan(20);
var err;
function clearCache(type) {
var cache = OpenLayers.Util.vendorPrefix[type.replace("style", "js") + "Cache"];
for (var key in cache) {
delete cache[key];
}
}
function setStyleMockProp(prop, value) {
if (prop && value === undefined) {
delete style[prop];
} else if (prop) {
style[prop] = value;
}
}
function curryTestPrefix(type) {
return function(standardProp, expectedPrefix, msg) {
var prefixedProp, err;
try {
clearCache(type);
setStyleMockProp(expectedPrefix, "");
prefixedProp = OpenLayers.Util.vendorPrefix[type](standardProp);
} catch(e) {
err = e;
} finally {
setStyleMockProp(expectedPrefix, undefined);
}
if(!err) {
t.eq(prefixedProp, expectedPrefix, msg);
} else {
t.fail("Error when testing " + type.toUpperCase() + " vendor prefix: " + err.message);
}
};
}
var testDomPrefix = curryTestPrefix("style"),
testCssPrefix = curryTestPrefix("css");
testDomPrefix("unsupported", null, "DOM vendor prefix - unsupported");
testCssPrefix("unsupported", null, "CSS vendor prefix - unsupported");
testDomPrefix("test", "test", "DOM vendor prefix - single word");
testCssPrefix("test", "test", "CSS vendor prefix - single word");
testDomPrefix("testMultiWord", "testMultiWord", "DOM vendor prefix - multiple words");
testCssPrefix("test-multi-word", "test-multi-word", "CSS vendor prefix - multiple words");
testDomPrefix("multiWord", "WebkitMultiWord", "DOM vendor prefix - multiple words for WebKit");
testCssPrefix("multi-word", "-webkit-multi-word", "CSS vendor prefix - multiple words for WebKit");
testDomPrefix("multiWord", "MozMultiWord", "DOM vendor prefix - multiple words for Mozilla");
testCssPrefix("multi-word", "-moz-multi-word", "CSS vendor prefix - multiple words for Mozilla");
testDomPrefix("multiWord", "OMultiWord", "DOM vendor prefix - multiple words for Opera");
testCssPrefix("multi-word", "-o-multi-word", "CSS vendor prefix - multiple words for Opera");
testDomPrefix("multiWord", "msMultiWord", "DOM vendor prefix - multiple words for Internet Explorer");
testCssPrefix("multi-word", "-ms-multi-word", "CSS vendor prefix - multiple words for Internet Explorer");
// test vendor prefix on object
clearCache("js");
t.eq( OpenLayers.Util.vendorPrefix.js( {}, "unsupported" ), null, "Standard object property - unsupported");
clearCache("js");
t.eq( OpenLayers.Util.vendorPrefix.js( { "test": true }, "test" ), "test", "Standard object property");
clearCache("js");
t.eq( OpenLayers.Util.vendorPrefix.js( { "oTest": true }, "test" ), "oTest", "Standard object property");
clearCache("js");
t.eq( OpenLayers.Util.vendorPrefix.js( { "msTest": true }, "test" ), "msTest", "Standard object property");
clearCache("js");
t.eq( OpenLayers.Util.vendorPrefix.js( { "mozTest": true }, "test" ), "mozTest", "Standard object property");
clearCache("js");
t.eq( OpenLayers.Util.vendorPrefix.js( { "webkitTest": true }, "test" ), "webkitTest", "Standard object property");
// unwrap document.createElement
document.createElement = orgCreateElement;
}
</script>
</head>
<body></body>
</html>
|