tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug493881.js (3098B)


      1 /**
      2 * Test for Bug 493881: Changes to legacy HTML color properties before the BODY is loaded
      3 * should be ignored. Additionally, after BODY loads, setting any of these properties to undefined
      4 * should cause them to be returned as the string "undefined".
      5 */
      6 
      7 SimpleTest.waitForExplicitFinish();
      8 
      9 var legacyProps = [
     10  "fgColor",
     11  "bgColor",
     12  "linkColor",
     13  "vlinkColor",
     14  "alinkColor",
     15 ];
     16 var testColors = ["blue", "silver", "green", "orange", "red"];
     17 var rgbTestColors = [
     18  "rgb(255, 0, 0)",
     19  "rgb(192, 192, 192)",
     20  "rgb(0, 128, 0)",
     21  "rgb(255, 165, 0)",
     22  "rgb(255, 0, 0)",
     23 ];
     24 var idPropList = [
     25  { id: "plaintext", prop: "color" },
     26  { id: "body", prop: "background-color" },
     27  { id: "nonvisitedlink", prop: "color" },
     28  { id: "visitedlink", prop: "color" },
     29 ];
     30 var initialValues = [];
     31 
     32 function setAndTestProperty(prop, color) {
     33  var initial = document[prop];
     34  document[prop] = color;
     35  is(document[prop], initial, "document[" + prop + "] not ignored before body");
     36  return initial;
     37 }
     38 
     39 /**
     40 * Attempt to set legacy color properties before BODY exists, and verify that such
     41 * attempts are ignored.
     42 */
     43 for (let i = 0; i < legacyProps.length; i++) {
     44  initialValues[i] = setAndTestProperty(legacyProps[i], testColors[i]);
     45 }
     46 
     47 /**
     48 * After BODY loads, run some more tests.
     49 */
     50 addLoadEvent(function () {
     51  // Verify that the legacy color properties still have their original values.
     52  for (let i = 0; i < legacyProps.length; i++) {
     53    is(
     54      document[legacyProps[i]],
     55      initialValues[i],
     56      "document[" + legacyProps[i] + "] altered after body load"
     57    );
     58  }
     59 
     60  // Verify that legacy color properties applied before BODY are really ignored when rendering.
     61  // Save current computed style colors for later use.
     62  for (let i = 0; i < idPropList.length; i++) {
     63    var style = window.getComputedStyle(
     64      document.getElementById(idPropList[i].id)
     65    );
     66    var color = style.getPropertyValue(idPropList[i].prop);
     67    idPropList[i].initialComputedColor = color;
     68    isnot(color, rgbTestColors[i], "element rendered using before-body style");
     69  }
     70  // XXX: Can't get links to visually activate via script events, so can't verify
     71  // that the alinkColor property was not applied.
     72 
     73  // Verify that setting legacy color props to undefined after BODY loads will cause them
     74  // to be read as the string "undefined".
     75  for (let i = 0; i < legacyProps.length; i++) {
     76    document[legacyProps[i]] = undefined;
     77    is(
     78      document[legacyProps[i]],
     79      "undefined",
     80      "Unexpected value of " + legacyProps[i] + " after setting to undefined"
     81    );
     82  }
     83 
     84  // Verify that setting legacy color props to undefined led to result
     85  // of parsing undefined as a color.
     86  for (let i = 0; i < idPropList.length; i++) {
     87    var style = window.getComputedStyle(
     88      document.getElementById(idPropList[i].id)
     89    );
     90    var color = style.getPropertyValue(idPropList[i].prop);
     91    is(
     92      color,
     93      "rgb(0, 239, 14)",
     94      "element's style should get result of parsing undefined as a color"
     95    );
     96  }
     97 
     98  // Mark the test as finished.
     99  setTimeout(SimpleTest.finish, 0);
    100 });