netwerk/test/mochitests/test_accept_header.html
author Edwin Gao <egao@mozilla.com>
Wed, 13 Mar 2019 19:47:25 +0000
changeset 463893 15c16889e3b7f6e871a518b5f3254459ed5e0213
parent 454703 a9ff8ccd4e3ddb1c53267f98a75a64a3a74f87bb
child 469640 c9c0c6f2eed54a187e124942e53c3660b4cf17d8
permissions -rw-r--r--
Bug 1531590, 1531598, 1534811, 1336075, 1531571, 1531572, 1531572, 1531574, 1534855, 1534857, 1535082 - skip tests in mochitest-dev-tools and mochitest-browser-chrome suites for windows10-aarch64 r=jmaher Bug 1531598 - disable browser_markup_copy_image_data.js Bug 1531598 - disable browser_markup_links_04.js Bug 1531598 - disable browser_inspector_menu-01-sensitivity.js Bug 1534811 - disable accessible/tests/browser/general Bug 1336075 - disable browser_largeAllocation_non_win32.js Bug 1531571 - disable browser_jsterm_context_menu_labels.js Bug 1531572 - disable browser_jsterm_helper_dollar_x.js Bug 1531573 - disable browser_jsterm_no_input_and_tab_key_pressed.js Bug 1531574 - disable browser_jsterm_syntax_highlight_output.js Bug 1534855 - disable accessible/tests/browser/ Bug 1534857 - disable browser_ext_slow_script.js Bug 1535082 - disable browser_jsterm_helper_dollar_dollar.js Differential Revision: https://phabricator.services.mozilla.com/D23369

<!DOCTYPE HTML>
<html>
<head>
  <title>Accept header</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script>
SimpleTest.requestCompleteLog();

// All the requests are sent to test_accept_header.sjs which will return
// different content based on the queryString. When the queryString is 'get',
// test_accept_header.sjs returns a JSON object with the latest request and its
// accept header value.

function test_last_request_and_continue(query, expected) {
  fetch("test_accept_header.sjs?get").then(r => r.json()).then(json => {
    is(json.type, query, "Expected: " + query);
    is(json.accept, expected, "Accept header: " + expected);
    next();
  });
}

function test_iframe() {
  let ifr = document.createElement("iframe");
  ifr.src = "test_accept_header.sjs?iframe";
  ifr.onload = () => {
    test_last_request_and_continue("iframe", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
  };
  document.body.appendChild(ifr);
}

function test_image() {
  let i = new Image();
  i.src = "test_accept_header.sjs?image";
  i.onload = function() {
    // Fetch spec says we should have: "image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5"
    test_last_request_and_continue("image", "image/webp,*/*");
  }
}

function test_style() {
  let head = document.getElementsByTagName("head")[0];
  let link = document.createElement("link");
  link.rel = "stylesheet";
  link.type = "text/css";
  link.href = "test_accept_header.sjs?style";
  link.onload = () => {
    test_last_request_and_continue("style", "text/css,*/*;q=0.1");
  };
  head.appendChild(link);
}

function test_worker() {
  let w = new Worker("test_accept_header.sjs?worker");
  w.onmessage = function() {
    test_last_request_and_continue("worker", "*/*");
  }
}

let tests = [
  test_iframe,
  test_image,
  test_style,
  test_worker,
];

function next() {
  if (tests.length == 0) {
    SimpleTest.finish();
    return;
  }

  let test = tests.shift();
  test();
}

SimpleTest.waitForExplicitFinish();

SpecialPowers.pushPrefEnv({ "set": [
  [ "dom.enable_performance_observer", true ]
]}, next);

</script>
</body>
</html>