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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!DOCTYPE html>
     3 <html>
     5   <head>
     6     <meta charset="utf8">
     7     <title></title>
     9     <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    10     <script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"></script>
    11     <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
    12   </head>
    14   <body>
    16     <script type="application/javascript;version=1.8">
    17     const Cu = Components.utils;
    18     const Cc = Components.classes;
    19     const Ci = Components.interfaces;
    20     Cu.import("resource://testing-common/httpd.js");
    21     const {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
    22     const {require} = devtools;
    24     const {AppValidator} = require("devtools/app-manager/app-validator");
    25     const {Services} = Cu.import("resource://gre/modules/Services.jsm");
    26     const nsFile = Components.Constructor("@mozilla.org/file/local;1",
    27                                            "nsILocalFile", "initWithPath");
    28     const cr = Cc["@mozilla.org/chrome/chrome-registry;1"]
    29                  .getService(Ci.nsIChromeRegistry);
    30     const strings = Services.strings.createBundle("chrome://browser/locale/devtools/app-manager.properties");
    31     let httpserver, origin;
    33     window.onload = function() {
    34       SimpleTest.waitForExplicitFinish();
    36       httpserver = new HttpServer();
    37       httpserver.start(-1);
    38       origin = "http://localhost:" + httpserver.identity.primaryPort + "/";
    40       next();
    41     }
    43     function createHosted(path) {
    44       let dirPath = getTestFilePath("validator/" + path);
    45       httpserver.registerDirectory("/", nsFile(dirPath));
    46       return new AppValidator({
    47         type: "hosted",
    48         location: origin + "/manifest.webapp"
    49       });
    50     }
    52     function createPackaged(path) {
    53       let dirPath = getTestFilePath("validator/" + path);
    54       return new AppValidator({
    55         type: "packaged",
    56         location: dirPath
    57       });
    58     }
    60     function next() {
    61       let test = tests.shift();
    62       if (test) {
    63         try {
    64           test();
    65         } catch(e) {
    66           console.error("exception", String(e), e, e.stack);
    67         }
    68       } else {
    69         httpserver.stop(function() {
    70           SimpleTest.finish();
    71         });
    72       }
    73     }
    75     let tests =  [
    76       // Test a 100% valid example
    77       function () {
    78         let validator = createHosted("valid");
    79         validator.validate().then(() => {
    80             is(validator.errors.length, 0, "valid app got no error");
    81             is(validator.warnings.length, 0, "valid app got no warning");
    83             next();
    84           });
    85       },
    87       function () {
    88         let validator = createPackaged("valid");
    89         validator.validate().then(() => {
    90             is(validator.errors.length, 0, "valid packaged app got no error");
    91             is(validator.warnings.length, 0, "valid packaged app got no warning");
    93             next();
    94           });
    95       },
    97       // Test a launch path that returns a 404
    98       function () {
    99         let validator = createHosted("wrong-launch-path");
   100         validator.validate().then(() => {
   101             is(validator.errors.length, 1, "app with non-existant launch path got an error");
   102             is(validator.errors[0], strings.formatStringFromName("validator.accessFailedLaunchPathBadHttpCode", [origin + "wrong-path.html", 404], 2),
   103                "with the right error message");
   104             is(validator.warnings.length, 0, "but no warning");
   105             next();
   106           });
   107       },
   108       function () {
   109         let validator = createPackaged("wrong-launch-path");
   110         validator.validate().then(() => {
   111             is(validator.errors.length, 1, "app with wrong path got an error");
   112             let file = nsFile(validator.project.location);
   113             file.append("wrong-path.html");
   114             let url = Services.io.newFileURI(file);
   115             is(validator.errors[0], strings.formatStringFromName("validator.accessFailedLaunchPath", [url.spec], 1),
   116                "with the expected message");
   117             is(validator.warnings.length, 0, "but no warning");
   119             next();
   120           });
   121       },
   123       // Test when using a non-absolute path for launch_path
   124       function () {
   125         let validator = createHosted("non-absolute-path");
   126         validator.validate().then(() => {
   127             is(validator.errors.length, 1, "app with non absolute path got an error");
   128             is(validator.errors[0], strings.formatStringFromName("validator.nonAbsoluteLaunchPath", ["non-absolute.html"], 1),
   129                "with expected message");
   130             is(validator.warnings.length, 0, "but no warning");
   131             next();
   132           });
   133       },
   134       function () {
   135         let validator = createPackaged("non-absolute-path");
   136         validator.validate().then(() => {
   137             is(validator.errors.length, 1, "app with non absolute path got an error");
   138             is(validator.errors[0], strings.formatStringFromName("validator.nonAbsoluteLaunchPath", ["non-absolute.html"], 1),
   139                "with expected message");
   140             is(validator.warnings.length, 0, "but no warning");
   141             next();
   142           });
   143       },
   145       // Test multiple failures (missing name [error] and icon [warning])
   146       function () {
   147         let validator = createHosted("no-name-or-icon");
   148         validator.validate().then(() => {
   149           checkNoNameOrIcon(validator);
   150         });
   151       },
   152       function () {
   153         let validator = createPackaged("no-name-or-icon");
   154         validator.validate().then(() => {
   155           checkNoNameOrIcon(validator);
   156         });
   157       }
   158     ];
   160     function checkNoNameOrIcon(validator) {
   161       is(validator.errors.length, 1, "app with no name has an error");
   162       is(validator.errors[0],
   163          strings.GetStringFromName("validator.missNameManifestProperty"),
   164          "with expected message");
   165       is(validator.warnings.length, 1, "app with no icon has a warning");
   166       is(validator.warnings[0],
   167          strings.GetStringFromName("validator.missIconsManifestProperty"),
   168          "with expected message");
   169       next();
   170     }
   172     </script>
   173   </body>
   174 </html>

mercurial