| Index: LayoutTests/inspector-protocol/layout-fonts/resources/style-matching-test.js
|
| diff --git a/LayoutTests/inspector-protocol/layout-fonts/resources/layout-font-test.js b/LayoutTests/inspector-protocol/layout-fonts/resources/style-matching-test.js
|
| similarity index 51%
|
| copy from LayoutTests/inspector-protocol/layout-fonts/resources/layout-font-test.js
|
| copy to LayoutTests/inspector-protocol/layout-fonts/resources/style-matching-test.js
|
| index cc36025e089b76e92b05a4272cee78c1959b9426..126038ab9959fb94fe763ec03fcd3014da8584d2 100644
|
| --- a/LayoutTests/inspector-protocol/layout-fonts/resources/layout-font-test.js
|
| +++ b/LayoutTests/inspector-protocol/layout-fonts/resources/style-matching-test.js
|
| @@ -5,6 +5,14 @@ function test()
|
| var testSelectors = [];
|
| var collectedFontUsage = {};
|
|
|
| + var weights = [ 'onehundred', 'twohundred', 'threehundred',
|
| + 'fourhundred', 'fivehundred', 'sixhundred',
|
| + 'sevenhundred', 'eighthundred', 'ninehundred' ]
|
| +
|
| + var weightsHumanReadable = [ "Thin", "Extra Light", "Light",
|
| + "Normal", "Medium", "Semi Bold",
|
| + "Bold", "Extra Bold", "Black" ]
|
| +
|
| InspectorTest.requestDocumentNodeId(onDocumentNodeId);
|
|
|
| function onDocumentNodeId(nodeId)
|
| @@ -69,31 +77,63 @@ function test()
|
| }
|
| }
|
|
|
| - function collectResults(response)
|
| + function weightEqual(selectorWeight, fontWeight)
|
| {
|
| - var usedFonts = response.fonts;
|
| - usedFonts.sort(function(a, b) {
|
| - return b.glyphCount - a.glyphCount;
|
| - });
|
| - collectedFontUsage[documentNodeSelector] = usedFonts;
|
| + return weights.indexOf(selectorWeight) == weightsHumanReadable.indexOf(fontWeight);
|
| }
|
| -};
|
|
|
| + function compareSelectorToFontname(selector, usedFontName)
|
| + {
|
| + // A selector of the form "expanded_italic_sixhundred"
|
| + // needs to be matched to a font name:
|
| + // "CSSMatchingTest Expanded Italic Semi Bold".
|
| + var fontStretchStyleWeight = /CSSMatchingTest (\w*) (\w*) (.*)/.exec(usedFontName);
|
| + var fontStrech = fontStretchStyleWeight[1];
|
| + var fontStyle = fontStretchStyleWeight[2];
|
| + var fontWeight = fontStretchStyleWeight[3];
|
| +
|
| + var selectorStretchStyleWeight = selector.substr(1).split("_");
|
| + var selectorStrech = selectorStretchStyleWeight[0];
|
| + var selectorStyle = selectorStretchStyleWeight[1];
|
| + var selectorWeight = selectorStretchStyleWeight[2];
|
| +
|
| + var mismatchDescription = "";
|
| +
|
| + if (fontStrech.toLowerCase() != selectorStrech.toLowerCase()) {
|
| + mismatchDescription += "Stretch differs, " +
|
| + "requested vs actual: " +
|
| + selectorStrech + ", " +
|
| + fontStrech + "\n";
|
| + }
|
| +
|
| + if (fontStyle.toLowerCase() != selectorStyle.toLowerCase()) {
|
| + mismatchDescription += "Style differs, " +
|
| + "requested vs actual: " +
|
| + selectorStyle + ", " +
|
| + fontStyle + "\n";
|
| + }
|
|
|
| -function formatResult(selector, resultForSelector)
|
| -{
|
| - var resultFormatted = selector + ":\n";
|
| - for (var i = 0; i < resultForSelector.length; i++) {
|
| - resultFormatted += '"' + resultForSelector[i].familyName + '"' +
|
| - " : " +
|
| - resultForSelector[i].glyphCount;
|
| - if (i + 1 < resultForSelector.length)
|
| - resultFormatted += ",\n";
|
| - else
|
| - resultFormatted += "\n\n";
|
| + if (!weightEqual(selectorWeight, fontWeight)) {
|
| + mismatchDescription += "Weight differs, " +
|
| + selectorWeight + ", " +
|
| + fontWeight + "\n";
|
| + }
|
| +
|
| + if (mismatchDescription.length) {
|
| + mismatchDescription = "FAIL\n" + mismatchDescription;
|
| + } else {
|
| + mismatchDescription = "PASS\n";
|
| + }
|
| + return mismatchDescription;
|
| }
|
| - return resultFormatted;
|
| -}
|
| +
|
| + function collectResults(response)
|
| + {
|
| + collectedFontUsage[documentNodeSelector] = compareSelectorToFontname(
|
| + documentNodeSelector,
|
| + response.fonts[0].familyName);
|
| + }
|
| +};
|
|
|
| function injectCollectedResultsInPage(results)
|
| {
|
| @@ -101,7 +141,7 @@ function injectCollectedResultsInPage(results)
|
| var testNode = document.querySelector(nodeSelector);
|
| var resultElement = document.createElement("div");
|
| var resultTextPre = document.createElement("pre");
|
| - var resultText = formatResult(nodeSelector, results[nodeSelector]);
|
| + var resultText = nodeSelector + "\n" + results[nodeSelector] + "\n";
|
| var resultTextNode = document.createTextNode(resultText);
|
| resultTextPre.appendChild(resultTextNode);
|
| resultElement.appendChild(resultTextPre);
|
|
|