Mock div.style through document.createElement hack instead of exposing method in vendorPrefix.js
This commit is contained in:
@@ -126,9 +126,6 @@ OpenLayers.Util.vendorPrefix = (function() {
|
|||||||
|
|
||||||
// used for testing
|
// used for testing
|
||||||
cssCache: cssCache,
|
cssCache: cssCache,
|
||||||
jsCache: jsCache,
|
jsCache: jsCache
|
||||||
_mockStyle: function(mock) {
|
|
||||||
divStyle = mock;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}());
|
}());
|
||||||
@@ -3,6 +3,14 @@
|
|||||||
<head>
|
<head>
|
||||||
<title>vendorPrefix.js Tests</title>
|
<title>vendorPrefix.js Tests</title>
|
||||||
<script>
|
<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
|
// dependencies for tests
|
||||||
var OpenLayers = [
|
var OpenLayers = [
|
||||||
@@ -19,21 +27,7 @@
|
|||||||
*/
|
*/
|
||||||
function test_vendor_prefixes(t) {
|
function test_vendor_prefixes(t) {
|
||||||
t.plan(20);
|
t.plan(20);
|
||||||
var o = {
|
var err;
|
||||||
prop: null,
|
|
||||||
val: null
|
|
||||||
}, err;
|
|
||||||
|
|
||||||
/*var orgCreateElement = document.createElement;
|
|
||||||
// wrap document.createElement to control property values
|
|
||||||
document.createElement = function(type) {
|
|
||||||
var el = orgCreateElement.call(document, type);
|
|
||||||
// Since o is an object we can change prop for each test
|
|
||||||
if(o.prop) {
|
|
||||||
el.style[o.prop] = o.val;
|
|
||||||
}
|
|
||||||
return el;
|
|
||||||
};*/
|
|
||||||
|
|
||||||
function clearCache(type) {
|
function clearCache(type) {
|
||||||
var cache = OpenLayers.Util.vendorPrefix[type.replace("style", "js") + "Cache"];
|
var cache = OpenLayers.Util.vendorPrefix[type.replace("style", "js") + "Cache"];
|
||||||
@@ -42,20 +36,27 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setStyleMockProp(prop, value) {
|
||||||
|
if (prop && value === undefined) {
|
||||||
|
delete style[prop];
|
||||||
|
} else if (prop) {
|
||||||
|
style[prop] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function curryTestPrefix(type) {
|
function curryTestPrefix(type) {
|
||||||
return function(standardProp, expectedPrefix, msg) {
|
return function(standardProp, expectedPrefix, msg) {
|
||||||
var prefixedProp, err;
|
var prefixedProp, err;
|
||||||
try {
|
try {
|
||||||
clearCache(type);
|
clearCache(type);
|
||||||
var fakeStyle = { cssText: "" };
|
setStyleMockProp(expectedPrefix, "");
|
||||||
if (o.prop != null) {
|
|
||||||
fakeStyle[o.prop] = o.val;
|
|
||||||
}
|
|
||||||
OpenLayers.Util.vendorPrefix._mockStyle(fakeStyle);
|
|
||||||
prefixedProp = OpenLayers.Util.vendorPrefix[type](standardProp);
|
prefixedProp = OpenLayers.Util.vendorPrefix[type](standardProp);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
err = e;
|
err = e;
|
||||||
|
} finally {
|
||||||
|
setStyleMockProp(expectedPrefix, undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!err) {
|
if(!err) {
|
||||||
t.eq(prefixedProp, expectedPrefix, msg);
|
t.eq(prefixedProp, expectedPrefix, msg);
|
||||||
} else {
|
} else {
|
||||||
@@ -66,33 +67,24 @@
|
|||||||
var testDomPrefix = curryTestPrefix("style"),
|
var testDomPrefix = curryTestPrefix("style"),
|
||||||
testCssPrefix = curryTestPrefix("css");
|
testCssPrefix = curryTestPrefix("css");
|
||||||
|
|
||||||
o.prop = undefined;
|
|
||||||
o.val = undefined;
|
|
||||||
testDomPrefix("unsupported", null, "DOM vendor prefix - unsupported");
|
testDomPrefix("unsupported", null, "DOM vendor prefix - unsupported");
|
||||||
testCssPrefix("unsupported", null, "CSS vendor prefix - unsupported");
|
testCssPrefix("unsupported", null, "CSS vendor prefix - unsupported");
|
||||||
|
|
||||||
o.prop = "test";
|
|
||||||
o.val = "";
|
|
||||||
testDomPrefix("test", "test", "DOM vendor prefix - single word");
|
testDomPrefix("test", "test", "DOM vendor prefix - single word");
|
||||||
testCssPrefix("test", "test", "CSS vendor prefix - single word");
|
testCssPrefix("test", "test", "CSS vendor prefix - single word");
|
||||||
|
|
||||||
o.prop = "testMultiWord";
|
|
||||||
testDomPrefix("testMultiWord", "testMultiWord", "DOM vendor prefix - multiple words");
|
testDomPrefix("testMultiWord", "testMultiWord", "DOM vendor prefix - multiple words");
|
||||||
testCssPrefix("test-multi-word", "test-multi-word", "CSS vendor prefix - multiple words");
|
testCssPrefix("test-multi-word", "test-multi-word", "CSS vendor prefix - multiple words");
|
||||||
|
|
||||||
o.prop = "WebkitMultiWord";
|
|
||||||
testDomPrefix("multiWord", "WebkitMultiWord", "DOM vendor prefix - multiple words for WebKit");
|
testDomPrefix("multiWord", "WebkitMultiWord", "DOM vendor prefix - multiple words for WebKit");
|
||||||
testCssPrefix("multi-word", "-webkit-multi-word", "CSS vendor prefix - multiple words for WebKit");
|
testCssPrefix("multi-word", "-webkit-multi-word", "CSS vendor prefix - multiple words for WebKit");
|
||||||
|
|
||||||
o.prop = "MozMultiWord";
|
|
||||||
testDomPrefix("multiWord", "MozMultiWord", "DOM vendor prefix - multiple words for Mozilla");
|
testDomPrefix("multiWord", "MozMultiWord", "DOM vendor prefix - multiple words for Mozilla");
|
||||||
testCssPrefix("multi-word", "-moz-multi-word", "CSS vendor prefix - multiple words for Mozilla");
|
testCssPrefix("multi-word", "-moz-multi-word", "CSS vendor prefix - multiple words for Mozilla");
|
||||||
|
|
||||||
o.prop = "OMultiWord";
|
|
||||||
testDomPrefix("multiWord", "OMultiWord", "DOM vendor prefix - multiple words for Opera");
|
testDomPrefix("multiWord", "OMultiWord", "DOM vendor prefix - multiple words for Opera");
|
||||||
testCssPrefix("multi-word", "-o-multi-word", "CSS vendor prefix - multiple words for Opera");
|
testCssPrefix("multi-word", "-o-multi-word", "CSS vendor prefix - multiple words for Opera");
|
||||||
|
|
||||||
o.prop = "msMultiWord";
|
|
||||||
testDomPrefix("multiWord", "msMultiWord", "DOM vendor prefix - multiple words for Internet Explorer");
|
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");
|
testCssPrefix("multi-word", "-ms-multi-word", "CSS vendor prefix - multiple words for Internet Explorer");
|
||||||
|
|
||||||
@@ -116,7 +108,7 @@
|
|||||||
t.eq( OpenLayers.Util.vendorPrefix.js( { "webkitTest": true }, "test" ), "webkitTest", "Standard object property");
|
t.eq( OpenLayers.Util.vendorPrefix.js( { "webkitTest": true }, "test" ), "webkitTest", "Standard object property");
|
||||||
|
|
||||||
// unwrap document.createElement
|
// unwrap document.createElement
|
||||||
//document.createElement = orgCreateElement;
|
document.createElement = orgCreateElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user