Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain testCSSProperty() results #2051

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 64 additions & 5 deletions static/resources/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,23 @@
return (mustReturnTruthy ? !!returnValue : true) && accessed;
}

/**
* Converts a value to JSON-like representation.
* @param {any} value - The value to convert
* @returns {string} The jsonified valued
*/
function jsonify(value) {
if ("JSON" in window && JSON.stringify) {
return JSON.stringify(value);
}

if (typeof value == "string") {
return '"' + value + '"';
}

return stringify(value);
}

/**
* Test a CSS property for support
* @param {string} name - The CSS property name
Expand All @@ -600,27 +617,69 @@

// Use CSS.supports if available
if ("CSS" in window && window.CSS.supports) {
return window.CSS.supports(name, value);
var result = window.CSS.supports(name, value);
return {
result: result,
message:
"CSS.supports(" +
jsonify(name) +
", " +
jsonify(value) +
") returned " +
jsonify(result)
};
}

// Use div.style fallback
var div = document.createElement("div");

if ("style" in div) {
var actualValue;
// Use .setProperty() if supported
if ("setProperty" in div.style) {
div.style.setProperty(name, value, "");
return div.style.getPropertyValue(name) == value;
actualValue = div.style.getPropertyValue(name);

return {
result: actualValue == value,
message:
"getPropertyValue(" +
jsonify(name) +
") returned " +
jsonify(actualValue) +
" after setProperty(" +
jsonify(name) +
", " +
jsonify(value) +
")"
};
}

// Use getter/setter fallback
if (name in div.style) {
div.style[name] = value;
return div.style[name] == value;
actualValue = div.style[name];

return {
result: actualValue == value,
message:
"div.style[" +
jsonify(name) +
"] returned " +
jsonify(actualValue) +
" after setting to " +
jsonify(value) +
""
};
} else {
return {
result: null,
message: jsonify(name) + " not found in div.style"
};
}
} else {
return { result: null, message: jsonify("style") + " not found in div" };
}

return { result: null, message: "Detection methods are not supported" };
}

/**
Expand Down