layout/style/test/test_visited_reftests.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial