browser/base/content/test/general/healthreport_testRemoteCommands.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/healthreport_testRemoteCommands.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,128 @@
     1.4 +<html>
     1.5 +  <head>
     1.6 +    <meta charset="utf-8">
     1.7 +
     1.8 +<script>
     1.9 +
    1.10 +function init() {
    1.11 +  window.addEventListener("message", function process(e) {doTest(e)}, false);
    1.12 +  doTest();
    1.13 +}
    1.14 +
    1.15 +function checkSubmissionValue(payload, expectedValue) {
    1.16 +  return payload.enabled == expectedValue;
    1.17 +}
    1.18 +
    1.19 +function validatePayload(payload) {
    1.20 +  payload = JSON.parse(payload);
    1.21 +
    1.22 +  // xxxmpc - this is some pretty low-bar validation, but we have plenty of tests of that API elsewhere
    1.23 +  if (!payload.thisPingDate)
    1.24 +    return false;
    1.25 +
    1.26 +  return true;
    1.27 +}
    1.28 +
    1.29 +var tests = [
    1.30 +{
    1.31 +  info: "Checking initial value is enabled",
    1.32 +  event: "RequestCurrentPrefs",
    1.33 +  payloadType: "prefs",
    1.34 +  validateResponse: function(payload) {
    1.35 +    return checkSubmissionValue(payload, true);
    1.36 +  },
    1.37 +},
    1.38 +{
    1.39 +  info: "Verifying disabling works",
    1.40 +  event: "DisableDataSubmission",
    1.41 +  payloadType: "prefs",
    1.42 +  validateResponse: function(payload) {
    1.43 +    return checkSubmissionValue(payload, false);
    1.44 +  },
    1.45 +},
    1.46 +{
    1.47 +  info: "Verifying we're still disabled",
    1.48 +  event: "RequestCurrentPrefs",
    1.49 +  payloadType: "prefs",
    1.50 +  validateResponse: function(payload) {
    1.51 +    return checkSubmissionValue(payload, false);
    1.52 +  },
    1.53 +},
    1.54 +{
    1.55 +  info: "Verifying we can get a payload while submission is disabled",
    1.56 +  event: "RequestCurrentPayload",
    1.57 +  payloadType: "payload",
    1.58 +  validateResponse: function(payload) {
    1.59 +    return validatePayload(payload);
    1.60 +  },
    1.61 +},
    1.62 +{
    1.63 +  info: "Verifying enabling works",
    1.64 +  event: "EnableDataSubmission",
    1.65 +  payloadType: "prefs",
    1.66 +  validateResponse: function(payload) {
    1.67 +    return checkSubmissionValue(payload, true);
    1.68 +  },
    1.69 +},
    1.70 +{
    1.71 +  info: "Verifying we're still re-enabled",
    1.72 +  event: "RequestCurrentPrefs",
    1.73 +  payloadType: "prefs",
    1.74 +  validateResponse: function(payload) {
    1.75 +    return checkSubmissionValue(payload, true);
    1.76 +  },
    1.77 +},
    1.78 +{
    1.79 +  info: "Verifying we can get a payload after re-enabling",
    1.80 +  event: "RequestCurrentPayload",
    1.81 +  payloadType: "payload",
    1.82 +  validateResponse: function(payload) {
    1.83 +    return validatePayload(payload);
    1.84 +  },
    1.85 +},
    1.86 +];
    1.87 +
    1.88 +var currentTest = -1;
    1.89 +function doTest(evt) {
    1.90 +  if (evt) {
    1.91 +    if (currentTest < 0 || !evt.data.content)
    1.92 +      return; // not yet testing
    1.93 +
    1.94 +    var test = tests[currentTest];
    1.95 +    if (evt.data.type != test.payloadType)
    1.96 +      return; // skip unrequested events
    1.97 +
    1.98 +    var error = JSON.stringify(evt.data.content);
    1.99 +    var pass = false;
   1.100 +    try {
   1.101 +      pass = test.validateResponse(evt.data.content)
   1.102 +    } catch (e) {}
   1.103 +    reportResult(test.info, pass, error);
   1.104 +  }
   1.105 +  // start the next test if there are any left
   1.106 +  if (tests[++currentTest])
   1.107 +    sendToBrowser(tests[currentTest].event);
   1.108 +  else
   1.109 +    reportFinished();
   1.110 +}
   1.111 +
   1.112 +function reportResult(info, pass, error) {
   1.113 +  var data = {type: "testResult", info: info, pass: pass, error: error};
   1.114 +  window.parent.postMessage(data, "*");
   1.115 +}
   1.116 +
   1.117 +function reportFinished(cmd) {
   1.118 +  var data = {type: "testsComplete", count: tests.length};
   1.119 +  window.parent.postMessage(data, "*");
   1.120 +}
   1.121 +
   1.122 +function sendToBrowser(type) {
   1.123 +  var event = new CustomEvent("RemoteHealthReportCommand", {detail: {command: type}, bubbles: true});
   1.124 +  document.dispatchEvent(event);
   1.125 +}
   1.126 +
   1.127 +</script>
   1.128 +  </head>
   1.129 +  <body onload="init()">
   1.130 +  </body>
   1.131 +</html>

mercurial