dom/serviceworkers/test/match_all_clients/match_all_controlled.html
author Ben Kelly <ben@wanderview.com>
Fri, 26 Jan 2018 13:08:57 -0800
changeset 456061 5cbdc4e31b0f42029113f1f4bde8d8a6d31a6475
parent 392101 dom/workers/test/serviceworkers/match_all_clients/match_all_controlled.html@f45e73d6c9ff8c902f8b989cb89463fe284fc315
child 462850 49448fdb2c96b17a290395110f3492870ccfebd5
permissions -rw-r--r--
Bug 1430139 P1 Move code, tests, and moz.build rules to dom/serviceworkers. r=asuth

<!--
  Any copyright is dedicated to the Public Domain.
  http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
  <title>Bug 1058311 - controlled page</title>
<script class="testbody" type="text/javascript">
  var re = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
  var frameType = "none";
  var testWindow = parent;

  if (parent != window) {
    frameType = "nested";
  } else if (opener) {
    frameType = "auxiliary";
    testWindow = opener;
  } else if (parent != window) {
    frameType = "top-level";
  } else {
    postResult(false, "Unexpected frameType");
  }

  window.onload = function() {
    navigator.serviceWorker.ready.then(function(swr) {
        swr.active.postMessage("Start");
    });
  }

  function postResult(result, msg) {
    response = {
      result: result,
      message: msg
    };

    testWindow.postMessage(response, "*");
  }

  navigator.serviceWorker.onmessage = function(msg) {
    // worker message;
    result = re.test(msg.data.id);
    postResult(result, "Client id test");

    result = msg.data.url == window.location;
    postResult(result, "Client url test");

    result = msg.data.visibilityState === document.visibilityState;
    postResult(result, "Client visibility test. expected=" +document.visibilityState);

    result = msg.data.focused === document.hasFocus();
    postResult(result, "Client focus test. expected=" + document.hasFocus());

    result = msg.data.frameType === frameType;
    postResult(result, "Client frameType test. expected=" + frameType);

    result = msg.data.type === "window";
    postResult(result, "Client type test. expected=window");

    postResult(true, "DONE");
    window.close();
  };
</script>

</head>
<body>
</body>
</html>