OLD | NEW |
1 function test() | 1 function test() |
2 { | 2 { |
3 var documentNodeId; | 3 var documentNodeId; |
4 var documentNodeSelector; | 4 var documentNodeSelector; |
5 var testSelectors = []; | 5 var testSelectors = []; |
6 var collectedFontUsage = {}; | 6 var collectedFontUsage = {}; |
7 | 7 |
| 8 var weights = [ 'onehundred', 'twohundred', 'threehundred', |
| 9 'fourhundred', 'fivehundred', 'sixhundred', |
| 10 'sevenhundred', 'eighthundred', 'ninehundred' ] |
| 11 |
| 12 var weightsHumanReadable = [ "Thin", "Extra Light", "Light", |
| 13 "Normal", "Medium", "Semi Bold", |
| 14 "Bold", "Extra Bold", "Black" ] |
| 15 |
8 InspectorTest.requestDocumentNodeId(onDocumentNodeId); | 16 InspectorTest.requestDocumentNodeId(onDocumentNodeId); |
9 | 17 |
10 function onDocumentNodeId(nodeId) | 18 function onDocumentNodeId(nodeId) |
11 { | 19 { |
12 documentNodeId = nodeId; | 20 documentNodeId = nodeId; |
13 | 21 |
14 InspectorTest.evaluateInInspectedPage( | 22 InspectorTest.evaluateInInspectedPage( |
15 'JSON.stringify(' + | 23 'JSON.stringify(' + |
16 'Array.prototype.map.call(' + | 24 'Array.prototype.map.call(' + |
17 'document.querySelectorAll(".test *"),' + | 25 'document.querySelectorAll(".test *"),' + |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 InspectorTest.sendCommandOrDie("CSS.getPlatformFontsForNode", { node
Id: nodeId }, onGotComputedFonts); | 70 InspectorTest.sendCommandOrDie("CSS.getPlatformFontsForNode", { node
Id: nodeId }, onGotComputedFonts); |
63 } | 71 } |
64 | 72 |
65 function onGotComputedFonts(response) | 73 function onGotComputedFonts(response) |
66 { | 74 { |
67 collectResults(response); | 75 collectResults(response); |
68 testNextPageElement(); | 76 testNextPageElement(); |
69 } | 77 } |
70 } | 78 } |
71 | 79 |
| 80 function weightEqual(selectorWeight, fontWeight) |
| 81 { |
| 82 return weights.indexOf(selectorWeight) == weightsHumanReadable.indexOf(f
ontWeight); |
| 83 } |
| 84 |
| 85 function compareSelectorToFontname(selector, usedFontName) |
| 86 { |
| 87 // A selector of the form "expanded_italic_sixhundred" |
| 88 // needs to be matched to a font name: |
| 89 // "CSSMatchingTest Expanded Italic Semi Bold". |
| 90 var fontStretchStyleWeight = /CSSMatchingTest (\w*) (\w*) (.*)/.exec(use
dFontName); |
| 91 var fontStrech = fontStretchStyleWeight[1]; |
| 92 var fontStyle = fontStretchStyleWeight[2]; |
| 93 var fontWeight = fontStretchStyleWeight[3]; |
| 94 |
| 95 var selectorStretchStyleWeight = selector.substr(1).split("_"); |
| 96 var selectorStrech = selectorStretchStyleWeight[0]; |
| 97 var selectorStyle = selectorStretchStyleWeight[1]; |
| 98 var selectorWeight = selectorStretchStyleWeight[2]; |
| 99 |
| 100 var mismatchDescription = ""; |
| 101 |
| 102 if (fontStrech.toLowerCase() != selectorStrech.toLowerCase()) { |
| 103 mismatchDescription += "Stretch differs, " + |
| 104 "requested vs actual: " + |
| 105 selectorStrech + ", " + |
| 106 fontStrech + "\n"; |
| 107 } |
| 108 |
| 109 if (fontStyle.toLowerCase() != selectorStyle.toLowerCase()) { |
| 110 mismatchDescription += "Style differs, " + |
| 111 "requested vs actual: " + |
| 112 selectorStyle + ", " + |
| 113 fontStyle + "\n"; |
| 114 } |
| 115 |
| 116 if (!weightEqual(selectorWeight, fontWeight)) { |
| 117 mismatchDescription += "Weight differs, " + |
| 118 selectorWeight + ", " + |
| 119 fontWeight + "\n"; |
| 120 } |
| 121 |
| 122 if (mismatchDescription.length) { |
| 123 mismatchDescription = "FAIL\n" + mismatchDescription; |
| 124 } else { |
| 125 mismatchDescription = "PASS\n"; |
| 126 } |
| 127 return mismatchDescription; |
| 128 } |
| 129 |
72 function collectResults(response) | 130 function collectResults(response) |
73 { | 131 { |
74 var usedFonts = response.fonts; | 132 collectedFontUsage[documentNodeSelector] = compareSelectorToFontname( |
75 usedFonts.sort(function(a, b) { | 133 documentNodeSelector, |
76 return b.glyphCount - a.glyphCount; | 134 response.fonts[0].familyName); |
77 }); | |
78 collectedFontUsage[documentNodeSelector] = usedFonts; | |
79 } | 135 } |
80 }; | 136 }; |
81 | 137 |
82 | |
83 function formatResult(selector, resultForSelector) | |
84 { | |
85 var resultFormatted = selector + ":\n"; | |
86 for (var i = 0; i < resultForSelector.length; i++) { | |
87 resultFormatted += '"' + resultForSelector[i].familyName + '"' + | |
88 " : " + | |
89 resultForSelector[i].glyphCount; | |
90 if (i + 1 < resultForSelector.length) | |
91 resultFormatted += ",\n"; | |
92 else | |
93 resultFormatted += "\n\n"; | |
94 } | |
95 return resultFormatted; | |
96 } | |
97 | |
98 function injectCollectedResultsInPage(results) | 138 function injectCollectedResultsInPage(results) |
99 { | 139 { |
100 for (nodeSelector in results) { | 140 for (nodeSelector in results) { |
101 var testNode = document.querySelector(nodeSelector); | 141 var testNode = document.querySelector(nodeSelector); |
102 var resultElement = document.createElement("div"); | 142 var resultElement = document.createElement("div"); |
103 var resultTextPre = document.createElement("pre"); | 143 var resultTextPre = document.createElement("pre"); |
104 var resultText = formatResult(nodeSelector, results[nodeSelector]); | 144 var resultText = nodeSelector + "\n" + results[nodeSelector] + "\n"; |
105 var resultTextNode = document.createTextNode(resultText); | 145 var resultTextNode = document.createTextNode(resultText); |
106 resultTextPre.appendChild(resultTextNode); | 146 resultTextPre.appendChild(resultTextNode); |
107 resultElement.appendChild(resultTextPre); | 147 resultElement.appendChild(resultTextPre); |
108 testNode.parentNode.insertBefore(resultElement, testNode.nextSibling); | 148 testNode.parentNode.insertBefore(resultElement, testNode.nextSibling); |
109 } | 149 } |
110 } | 150 } |
111 | 151 |
112 window.addEventListener("DOMContentLoaded", function () { | 152 window.addEventListener("DOMContentLoaded", function () { |
113 runTest(); | 153 runTest(); |
114 }, false); | 154 }, false); |
OLD | NEW |