OLD | NEW |
| (Empty) |
1 function getPaintOrder(element) | |
2 { | |
3 var divElementsBeforePromote = []; | |
4 var divElementsAfterPromote = []; | |
5 | |
6 var paintOrderListBeforePromote = window.internals.paintOrderListBeforePromote
(element); | |
7 var paintOrderListAfterPromote = window.internals.paintOrderListAfterPromote(e
lement); | |
8 | |
9 for (var i = 0; i < paintOrderListBeforePromote.length; ++i) | |
10 if (paintOrderListBeforePromote[i].nodeName === "DIV") | |
11 divElementsBeforePromote.push(paintOrderListBeforePromote[i]); | |
12 | |
13 for (var i = 0; i < paintOrderListAfterPromote.length; ++i) | |
14 if (paintOrderListAfterPromote[i].nodeName === "DIV") | |
15 divElementsAfterPromote.push(paintOrderListAfterPromote[i]); | |
16 | |
17 return {"beforePromote": divElementsBeforePromote, | |
18 "afterPromote": divElementsAfterPromote}; | |
19 } | |
20 | |
21 function comparePaintOrderLists(oldPaintOrder, newPaintOrder) | |
22 { | |
23 if (oldPaintOrder.length !== newPaintOrder.length) | |
24 return false; | |
25 | |
26 for (var i = 0; i < oldPaintOrder.length; i++) | |
27 if (oldPaintOrder[i] !== newPaintOrder[i]) | |
28 return false; | |
29 | |
30 return true; | |
31 } | |
32 | |
33 function countOccurrencesOfElementInPaintOrderList(paintOrder, element) { | |
34 var occurrenceCount = 0; | |
35 for (var i = 0; i < paintOrder.length; i++) | |
36 if (paintOrder[i] === element) | |
37 occurrenceCount++; | |
38 | |
39 return occurrenceCount; | |
40 } | |
41 | |
42 function compareStackingOrderWithPaintOrder(stackingOrder, paintOrder) | |
43 { | |
44 if (debugMode) { | |
45 write("paint order:") | |
46 for (var i = 0; i < paintOrder.length; i++) | |
47 write(paintOrder[i].id + " " + paintOrder[i].className + " " + paintOrder[
paintOrder.length - i - 1].tagName); | |
48 | |
49 write("stacking order:") | |
50 for (var i = 0; i < stackingOrder.length; i++) | |
51 write(stackingOrder[i].id + " " + stackingOrder[i].className + " " + stack
ingOrder[i].tagName); | |
52 } | |
53 | |
54 if (stackingOrder.length < paintOrder.length) | |
55 return false; | |
56 | |
57 // We expect the stacking order list to contain more than the paint order | |
58 // list sometimes because after we promote, the container's children won't | |
59 // appear in the stacking context's ancestor's lists anymore (which is | |
60 // expected and correct). They'll still be in the stacking order list. | |
61 // The important part is that the order of the things present in the paint | |
62 // order list is preserved in the stacking order list. | |
63 for (var i = 0, j = 0; i < stackingOrder.length && j < paintOrder.length; i++) | |
64 if (stackingOrder[i] === paintOrder[paintOrder.length - j - 1]) | |
65 j++; | |
66 | |
67 if (debugMode) | |
68 write(stackingOrder.length + " " + i + " " + paintOrder.length + " " + j); | |
69 | |
70 return j == paintOrder.length; | |
71 } | |
72 | |
73 function testPaintOrderListPermutation(count) { | |
74 if (!window.internals) | |
75 return; | |
76 | |
77 var container = document.getElementById('container'); | |
78 | |
79 window.internals.setNeedsCompositedScrolling(container, | |
80 window.internals.COMPOSITED_SCROLLING_ALWAYS_OFF); | |
81 | |
82 var oldStackingOrder = getStackingOrder(container); | |
83 var oldPaintOrder = getPaintOrder(container); | |
84 | |
85 window.internals.setNeedsCompositedScrolling(container, | |
86 window.internals.COMPOSITED_SCROLLING_ALWAYS_ON); | |
87 | |
88 var newStackingOrder = getStackingOrder(container); | |
89 var newPaintOrder = getPaintOrder(container); | |
90 | |
91 window.internals.setNeedsCompositedScrolling(container, | |
92 window.internals.DO_NOT_FORCE_COMPOSITED_SCROLLING); | |
93 // The getPaintOrder() function should return a pair of paint orders. | |
94 // One before promotion and one after. This pair of lists should remain | |
95 // identical whether the element is actually currently promoted or not, | |
96 // its purpose is to generate hypothetical pre- and post-lists to | |
97 // determine if the element is promotable. | |
98 if (!comparePaintOrderLists(oldPaintOrder, newPaintOrder)) | |
99 write("iteration " + count + " FAIL - paint order lists not identical before
/after promotion"); | |
100 | |
101 if (!compareStackingOrderWithPaintOrder(oldStackingOrder, oldPaintOrder.before
Promote)) | |
102 write("iteration " + count + " FAIL - paint order list before promote doesn'
t match stacking order"); | |
103 | |
104 if (!compareStackingOrderWithPaintOrder(newStackingOrder, oldPaintOrder.afterP
romote)) | |
105 write("iteration " + count + " FAIL - paint order list after promote doesn't
match stacking order"); | |
106 | |
107 var containerOccurrences = countOccurrencesOfElementInPaintOrderList(oldPaintO
rder.beforePromote, container); | |
108 if (containerOccurrences !== 1) | |
109 write("iteration " + count + " FAIL - paint order list before promote contai
ns " + containerOccurrences + " occurrences of container. Should be exactly 1.")
; | |
110 | |
111 containerOccurrences = countOccurrencesOfElementInPaintOrderList(oldPaintOrder
.afterPromote, container); | |
112 if (containerOccurrences !== 1) | |
113 write("iteration " + count + " FAIL - paint order list after promote contain
s " + containerOccurrences + " occurrences of container. Should be exactly 1."); | |
114 } | |
115 | |
116 function runPaintOrderPermutationSet(permutationSet) { | |
117 runPermutationSet(testPaintOrderListPermutation, permutationSet); | |
118 } | |
OLD | NEW |