Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=147777
5 -->
6 <head>
7 <title>Test for Bug 147777</title>
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <script type="application/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=147777">Mozilla Bug 147777</a>
14 <pre id="test">
15 <script type="application/javascript">
17 /** Test for Bug 147777 **/
19 // Because link-coloring for visited links is asynchronous, running
20 // reftests that involve link coloring requires that we poll for the
21 // correct result until all links are styled correctly.
23 // A requirement of these reftests is that the reference rendering is
24 // styled correctly when loaded. We only poll for the tests.
26 var gTests = [
27 // there's also an implicit "load visited-page.html" at the start,
28 // thanks to the code below.
30 // IMPORTANT NOTE: For these tests, the test and reference are not
31 // snapshotted in the same way. The REFERENCE (second file) is
32 // assumed to be complete when loaded, but we poll for visited link
33 // coloring on the TEST (first file) until the test passes.
34 "== pseudo-classes-02.svg pseudo-classes-02-ref.svg",
35 "!= color-on-link-1-ref.html color-on-visited-1-ref.html",
36 "== color-on-link-1.html color-on-link-1-ref.html",
37 "== color-on-link-before-1.html color-on-link-1-ref.html",
38 "== color-on-visited-1.html color-on-visited-1-ref.html",
39 "== color-on-visited-before-1.html color-on-visited-1-ref.html",
40 "!= content-color-on-link-before-1-ref.html content-color-on-visited-before-1-ref.html",
41 "== content-color-on-link-before-1.html content-color-on-link-before-1-ref.html",
42 "== content-color-on-visited-before-1.html content-color-on-visited-before-1-ref.html",
43 "== content-on-link-before-1.html content-before-1-ref.html",
44 "== content-on-visited-before-1.html content-before-1-ref.html",
45 "== color-on-text-decoration-1.html color-on-text-decoration-1-ref.html",
46 "== color-on-bullets-1.html color-on-bullets-1-ref.html",
47 // NOTE: background-color is tested by all the selector tests (and
48 // also color-choice-1) and therefore doesn't have its own tests.
49 // FIXME: Maybe add a test for selection colors (foreground and
50 // background), if possible.
51 "== width-on-link-1.html width-1-ref.html",
52 "== width-on-visited-1.html width-1-ref.html",
53 "== border-1.html border-1-ref.html",
54 "== border-2a.html border-2-ref.html",
55 "== border-2b.html border-2-ref.html",
56 // FIXME: Commented out because of dynamic change handling bugs in
57 // border-collapse tables that mean we get an incorrect rendering when
58 // the asynchronous restyle-from-history arrives.
59 //"== border-collapse-1.html border-collapse-1-ref.html",
60 "== outline-1.html outline-1-ref.html",
61 "== column-rule-1.html column-rule-1-ref.html",
62 "!= column-rule-1.html column-rule-1-notref.html",
63 "== color-choice-1.html color-choice-1-ref.html",
64 "== selector-descendant-1.html selector-descendant-1-ref.html",
65 "== selector-descendant-2.xhtml selector-descendant-2-ref.xhtml",
66 "== selector-child-1.html selector-child-1-ref.html",
67 "== selector-child-2.xhtml selector-child-2-ref.xhtml",
68 "== selector-adj-sibling-1.html selector-adj-sibling-1-ref.html",
69 "== selector-adj-sibling-2.html selector-adj-sibling-2-ref.html",
70 "== selector-any-sibling-1.html selector-any-sibling-1-ref.html",
71 "== selector-any-sibling-2.html selector-any-sibling-2-ref.html",
72 "== subject-of-selector-descendant-1.html subject-of-selector-1-ref.html",
73 "== subject-of-selector-descendant-2.xhtml subject-of-selector-descendant-2-ref.xhtml",
74 "== subject-of-selector-child-1.html subject-of-selector-1-ref.html",
75 "== subject-of-selector-adj-sibling-1.html subject-of-selector-1-ref.html",
76 "== subject-of-selector-any-sibling-1.html subject-of-selector-1-ref.html",
77 "== inherit-keyword-1.xhtml inherit-keyword-1-ref.html",
78 "!= svg-image-visited-1-helper.svg lime100x100.svg",
79 "!= svg-image-visited-2-helper.svg lime100x100.svg",
80 // FIXME: commented out because dynamic changes on the non-first-line
81 // part of the test don't work right when the link becomes visited.
82 //"== first-line-1.html first-line-1-ref.html",
83 "== white-to-transparent-1.html white-to-transparent-1-ref.html",
84 "== link-root-1.xhtml link-root-1-ref.xhtml",
85 "== mathml-links.html mathml-links-ref.html",
86 ];
88 // Maintain a reference count of how many things we're waiting for until
89 // we can say the tests are done.
90 var gDelayCount = 0;
91 function AddFinishDependency()
92 { ++gDelayCount; }
93 function RemoveFinishDependency()
94 { if (--gDelayCount == 0) SimpleTest.finish(); }
96 // We record the maximum number of times we had to look at a test before
97 // it switched to the passing state (though we assume it's 10 to start
98 // rather than 0 so that we have a reasonable default). Then we make a
99 // test "time out" if it takes more than gTimeoutFactor times that
100 // amount of time. This allows us to report a test failure rather than
101 // making a test failure just show up as a timeout.
102 var gMaxPassingTries = 10;
103 var gTimeoutFactor = 10;
105 function loadVisitedPage()
106 {
107 var element = document.createElement("iframe");
108 element.addEventListener("load", visitedPageLoad, false);
109 element.src = "css-visited/visited-page.html";
110 document.body.appendChild(element);
111 AddFinishDependency();
112 }
114 function visitedPageLoad()
115 {
116 for (var i = 0; i < gTests.length; ++i) {
117 startTest(i);
118 }
119 RemoveFinishDependency();
120 }
122 function takeSnapshot(iframe_element)
123 {
124 return snapshotWindow(iframe_element.contentWindow, false);
125 }
127 function passes(op, shot1, shot2)
128 {
129 var [correct, s1, s2] = compareSnapshots(shot1, shot2, op == "==");
130 return correct;
131 }
133 function startTest(i)
134 {
135 var testLine = gTests[i];
136 var splitData = testLine.split(" ");
137 var testData =
138 { op: splitData[0], test: splitData[1], reference: splitData[2] };
139 var tries = 0;
141 // Maintain state specific to this test in the closure exposed to all
142 // the functions nested inside this one.
144 function startIframe(url)
145 {
146 var element = document.createElement("iframe");
147 element.addEventListener("load", handleLoad, false);
148 // smaller than normal reftests, but enough for these
149 element.setAttribute("style", "width: 30em; height: 10em");
150 element.src = "css-visited/" + url;
151 document.body.appendChild(element);
152 function handleLoad(event)
153 {
154 iframe.loaded = true;
155 if (iframe == reference) {
156 reference.snapshot = takeSnapshot(element);
157 }
158 var other = (iframe == test) ? reference : test;
159 if (other.loaded) {
160 // Always wait at least 100ms, so that any test that switches
161 // from passing to failing when the asynchronous link coloring
162 // happens should fail at least some of the time.
163 setTimeout(checkTest, 100);
164 }
165 }
166 function checkTest()
167 {
168 var test_snapshot = takeSnapshot(test.element);
169 if (passes(testData.op, test_snapshot, reference.snapshot)) {
170 if (tries > gMaxPassingTries) {
171 gMaxPassingTries = tries;
172 }
173 report(true);
174 } else {
175 ++tries;
176 if (tries > gMaxPassingTries * gTimeoutFactor) {
177 info("Giving up after " + tries + " tries, " +
178 "maxp=" + gMaxPassingTries +
179 "fact=" + gTimeoutFactor);
180 report(false);
181 } else {
182 // Links might not have been colored yet. Try again in 100ms.
183 setTimeout(checkTest, 100);
184 }
185 }
186 }
187 function report(result)
188 {
189 ok(result, "(" + i + ") " +
190 testData.op + " " + testData.test + " " + testData.reference);
191 RemoveFinishDependency();
192 }
193 var iframe = { element: element, loaded: false };
195 return iframe;
196 }
198 AddFinishDependency();
199 var test = startIframe(testData.test);
200 var reference = startIframe(testData.reference);
201 }
203 SimpleTest.waitForExplicitFinish();
204 loadVisitedPage();
206 </script>
207 </pre>
208 </body>
209 </html>