browser/devtools/app-manager/test/test_app_validator.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/app-manager/test/test_app_validator.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,174 @@
     1.4 +<!DOCTYPE html>
     1.5 +
     1.6 +<html>
     1.7 +
     1.8 +  <head>
     1.9 +    <meta charset="utf8">
    1.10 +    <title></title>
    1.11 +
    1.12 +    <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +    <script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"></script>
    1.14 +    <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
    1.15 +  </head>
    1.16 +
    1.17 +  <body>
    1.18 +
    1.19 +    <script type="application/javascript;version=1.8">
    1.20 +    const Cu = Components.utils;
    1.21 +    const Cc = Components.classes;
    1.22 +    const Ci = Components.interfaces;
    1.23 +    Cu.import("resource://testing-common/httpd.js");
    1.24 +    const {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
    1.25 +    const {require} = devtools;
    1.26 +
    1.27 +    const {AppValidator} = require("devtools/app-manager/app-validator");
    1.28 +    const {Services} = Cu.import("resource://gre/modules/Services.jsm");
    1.29 +    const nsFile = Components.Constructor("@mozilla.org/file/local;1",
    1.30 +                                           "nsILocalFile", "initWithPath");
    1.31 +    const cr = Cc["@mozilla.org/chrome/chrome-registry;1"]
    1.32 +                 .getService(Ci.nsIChromeRegistry);
    1.33 +    const strings = Services.strings.createBundle("chrome://browser/locale/devtools/app-manager.properties");
    1.34 +    let httpserver, origin;
    1.35 +
    1.36 +    window.onload = function() {
    1.37 +      SimpleTest.waitForExplicitFinish();
    1.38 +
    1.39 +      httpserver = new HttpServer();
    1.40 +      httpserver.start(-1);
    1.41 +      origin = "http://localhost:" + httpserver.identity.primaryPort + "/";
    1.42 +
    1.43 +      next();
    1.44 +    }
    1.45 +
    1.46 +    function createHosted(path) {
    1.47 +      let dirPath = getTestFilePath("validator/" + path);
    1.48 +      httpserver.registerDirectory("/", nsFile(dirPath));
    1.49 +      return new AppValidator({
    1.50 +        type: "hosted",
    1.51 +        location: origin + "/manifest.webapp"
    1.52 +      });
    1.53 +    }
    1.54 +
    1.55 +    function createPackaged(path) {
    1.56 +      let dirPath = getTestFilePath("validator/" + path);
    1.57 +      return new AppValidator({
    1.58 +        type: "packaged",
    1.59 +        location: dirPath
    1.60 +      });
    1.61 +    }
    1.62 +
    1.63 +    function next() {
    1.64 +      let test = tests.shift();
    1.65 +      if (test) {
    1.66 +        try {
    1.67 +          test();
    1.68 +        } catch(e) {
    1.69 +          console.error("exception", String(e), e, e.stack);
    1.70 +        }
    1.71 +      } else {
    1.72 +        httpserver.stop(function() {
    1.73 +          SimpleTest.finish();
    1.74 +        });
    1.75 +      }
    1.76 +    }
    1.77 +
    1.78 +    let tests =  [
    1.79 +      // Test a 100% valid example
    1.80 +      function () {
    1.81 +        let validator = createHosted("valid");
    1.82 +        validator.validate().then(() => {
    1.83 +            is(validator.errors.length, 0, "valid app got no error");
    1.84 +            is(validator.warnings.length, 0, "valid app got no warning");
    1.85 +
    1.86 +            next();
    1.87 +          });
    1.88 +      },
    1.89 +
    1.90 +      function () {
    1.91 +        let validator = createPackaged("valid");
    1.92 +        validator.validate().then(() => {
    1.93 +            is(validator.errors.length, 0, "valid packaged app got no error");
    1.94 +            is(validator.warnings.length, 0, "valid packaged app got no warning");
    1.95 +
    1.96 +            next();
    1.97 +          });
    1.98 +      },
    1.99 +
   1.100 +      // Test a launch path that returns a 404
   1.101 +      function () {
   1.102 +        let validator = createHosted("wrong-launch-path");
   1.103 +        validator.validate().then(() => {
   1.104 +            is(validator.errors.length, 1, "app with non-existant launch path got an error");
   1.105 +            is(validator.errors[0], strings.formatStringFromName("validator.accessFailedLaunchPathBadHttpCode", [origin + "wrong-path.html", 404], 2),
   1.106 +               "with the right error message");
   1.107 +            is(validator.warnings.length, 0, "but no warning");
   1.108 +            next();
   1.109 +          });
   1.110 +      },
   1.111 +      function () {
   1.112 +        let validator = createPackaged("wrong-launch-path");
   1.113 +        validator.validate().then(() => {
   1.114 +            is(validator.errors.length, 1, "app with wrong path got an error");
   1.115 +            let file = nsFile(validator.project.location);
   1.116 +            file.append("wrong-path.html");
   1.117 +            let url = Services.io.newFileURI(file);
   1.118 +            is(validator.errors[0], strings.formatStringFromName("validator.accessFailedLaunchPath", [url.spec], 1),
   1.119 +               "with the expected message");
   1.120 +            is(validator.warnings.length, 0, "but no warning");
   1.121 +
   1.122 +            next();
   1.123 +          });
   1.124 +      },
   1.125 +
   1.126 +      // Test when using a non-absolute path for launch_path
   1.127 +      function () {
   1.128 +        let validator = createHosted("non-absolute-path");
   1.129 +        validator.validate().then(() => {
   1.130 +            is(validator.errors.length, 1, "app with non absolute path got an error");
   1.131 +            is(validator.errors[0], strings.formatStringFromName("validator.nonAbsoluteLaunchPath", ["non-absolute.html"], 1),
   1.132 +               "with expected message");
   1.133 +            is(validator.warnings.length, 0, "but no warning");
   1.134 +            next();
   1.135 +          });
   1.136 +      },
   1.137 +      function () {
   1.138 +        let validator = createPackaged("non-absolute-path");
   1.139 +        validator.validate().then(() => {
   1.140 +            is(validator.errors.length, 1, "app with non absolute path got an error");
   1.141 +            is(validator.errors[0], strings.formatStringFromName("validator.nonAbsoluteLaunchPath", ["non-absolute.html"], 1),
   1.142 +               "with expected message");
   1.143 +            is(validator.warnings.length, 0, "but no warning");
   1.144 +            next();
   1.145 +          });
   1.146 +      },
   1.147 +
   1.148 +      // Test multiple failures (missing name [error] and icon [warning])
   1.149 +      function () {
   1.150 +        let validator = createHosted("no-name-or-icon");
   1.151 +        validator.validate().then(() => {
   1.152 +          checkNoNameOrIcon(validator);
   1.153 +        });
   1.154 +      },
   1.155 +      function () {
   1.156 +        let validator = createPackaged("no-name-or-icon");
   1.157 +        validator.validate().then(() => {
   1.158 +          checkNoNameOrIcon(validator);
   1.159 +        });
   1.160 +      }
   1.161 +    ];
   1.162 +
   1.163 +    function checkNoNameOrIcon(validator) {
   1.164 +      is(validator.errors.length, 1, "app with no name has an error");
   1.165 +      is(validator.errors[0],
   1.166 +         strings.GetStringFromName("validator.missNameManifestProperty"),
   1.167 +         "with expected message");
   1.168 +      is(validator.warnings.length, 1, "app with no icon has a warning");
   1.169 +      is(validator.warnings[0],
   1.170 +         strings.GetStringFromName("validator.missIconsManifestProperty"),
   1.171 +         "with expected message");
   1.172 +      next();
   1.173 +    }
   1.174 +
   1.175 +    </script>
   1.176 +  </body>
   1.177 +</html>

mercurial