forked from googlearchive/code-prettify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-ie-compat-matrix.html
More file actions
110 lines (91 loc) · 2.91 KB
/
Copy pathdebug-ie-compat-matrix.html
File metadata and controls
110 lines (91 loc) · 2.91 KB
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
<style>
code {
white-space: pre; padding: 0; margin: 0; display: block
}
</style>
<code id="one-line"
>one short line,</code>
<hr>
<code id="two-lines"
>one giant leap for
cross-browser compatibility</code>
<hr>
<code id="two-lines-mutated"
>two turtledoves
a partridge in a pear tree
zero fencepost errors</code>
<hr>
<p id="error" style="white-space: pre"></p>
<script>
// Function under test
var matrix;
(function () {
var table = {
quirks: { "6": "\r", "7": "\r", "8": "\r", "9": "\r", "10": "\n" },
standards: { "6": "\r", "7": "\r", "8": "\r", "9": "\n", "10": "\n" }
};
matrix = function (quirksMode, ieMajorVersionNumber) {
if ("boolean" !== typeof quirksMode) {
throw new Error(quirksMode);
} else if ("number" !== typeof ieMajorVersionNumber
|| !table.quirks.hasOwnProperty(+ieMajorVersionNumber)) {
throw new Error(ieMajorVersionNumber);
}
return table[quirksMode ? "quirks" : "standards"][ieMajorVersionNumber];
};
})();
</script>
<script>
// Configuration we're testing.
var quirksMode;
var ieMajorVersionNumber;
quirksMode = document.compatMode == "BackCompat";
ieMajorVersionNumber = navigator.userAgent.match(/MSIE\s(\d+)/) || NaN;
if (ieMajorVersionNumber) {
ieMajorVersionNumber = +ieMajorVersionNumber[1];
}
</script>
<script>
(function () {
// DOM elements.
var oneLine = document.getElementById("one-line");
var twoLines = document.getElementById("two-lines");
var twoLinesMutated = document.getElementById("two-lines-mutated");
var originalHeight = twoLinesMutated.offsetHeight;
// If the matrix cell being tested is correct, the following should
// end up true.
var pass = false;
var reason = "unknown";
// The DOM subtree to modify.
var textNode = twoLinesMutated.firstChild;
if (textNode.nodeType !== 3 /* TEXT */ || textNode.nextSibling) {
reason = "unexpected DOM structure"; // Maybe not normalized.
} else {
// Perform the action we are testing.
try {
textNode.nodeValue = twoLines.firstChild.nodeValue.replace
/\r\n?|\n/g, matrix(quirksMode, ieMajorVersionNumber);
} catch (ex) {
reason = String(ex);
}
// Check it against known good DOM subtrees.
if (Math.abs(twoLinesMutated.offsetHeight - twoLines.offsetHeight) <= 1) {
pass = true;
} else if (Math.abs(twoLinesMutated.offsetHeight - oneLine.offsetHeight) <= 1) {
reason = "newlines not preserved";
} else {
// offsetHeight should trigger layout, but might not have???
}
}
document.title += " : " + pass ? "PASS" : "FAIL";
if (!pass) {
document.getElementById("error").appendChild(document.createTextNode(
"quirksMode is " + quirksMode +
"\nieMajorVersionNumber is " + ieMajorVersionNumber +
"\nheight was " + originalHeight +
"\nheight is " + twoLinesMutated.offsetHeight +
"\nexpected " + twoLines.offsetHeight +
"\nreason=" + reason));
}
})();
</script>