File: test_app_validator.html

package info (click to toggle)
iceweasel 31.6.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 1,368,576 kB
  • sloc: cpp: 3,692,968; ansic: 1,797,194; python: 193,401; java: 180,622; asm: 133,557; xml: 89,288; sh: 71,748; perl: 22,087; makefile: 21,687; objc: 4,014; yacc: 1,995; pascal: 1,292; lex: 950; exp: 449; lisp: 228; awk: 211; php: 113; sed: 43; csh: 31; ada: 16; ruby: 3
file content (174 lines) | stat: -rw-r--r-- 6,169 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>

<html>

  <head>
    <meta charset="utf8">
    <title></title>

    <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    <script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"></script>
    <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
  </head>

  <body>

    <script type="application/javascript;version=1.8">
    const Cu = Components.utils;
    const Cc = Components.classes;
    const Ci = Components.interfaces;
    Cu.import("resource://testing-common/httpd.js");
    const {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
    const {require} = devtools;

    const {AppValidator} = require("devtools/app-manager/app-validator");
    const {Services} = Cu.import("resource://gre/modules/Services.jsm");
    const nsFile = Components.Constructor("@mozilla.org/file/local;1",
                                           "nsILocalFile", "initWithPath");
    const cr = Cc["@mozilla.org/chrome/chrome-registry;1"]
                 .getService(Ci.nsIChromeRegistry);
    const strings = Services.strings.createBundle("chrome://browser/locale/devtools/app-manager.properties");
    let httpserver, origin;

    window.onload = function() {
      SimpleTest.waitForExplicitFinish();

      httpserver = new HttpServer();
      httpserver.start(-1);
      origin = "http://localhost:" + httpserver.identity.primaryPort + "/";

      next();
    }

    function createHosted(path) {
      let dirPath = getTestFilePath("validator/" + path);
      httpserver.registerDirectory("/", nsFile(dirPath));
      return new AppValidator({
        type: "hosted",
        location: origin + "/manifest.webapp"
      });
    }

    function createPackaged(path) {
      let dirPath = getTestFilePath("validator/" + path);
      return new AppValidator({
        type: "packaged",
        location: dirPath
      });
    }

    function next() {
      let test = tests.shift();
      if (test) {
        try {
          test();
        } catch(e) {
          console.error("exception", String(e), e, e.stack);
        }
      } else {
        httpserver.stop(function() {
          SimpleTest.finish();
        });
      }
    }

    let tests =  [
      // Test a 100% valid example
      function () {
        let validator = createHosted("valid");
        validator.validate().then(() => {
            is(validator.errors.length, 0, "valid app got no error");
            is(validator.warnings.length, 0, "valid app got no warning");

            next();
          });
      },

      function () {
        let validator = createPackaged("valid");
        validator.validate().then(() => {
            is(validator.errors.length, 0, "valid packaged app got no error");
            is(validator.warnings.length, 0, "valid packaged app got no warning");

            next();
          });
      },

      // Test a launch path that returns a 404
      function () {
        let validator = createHosted("wrong-launch-path");
        validator.validate().then(() => {
            is(validator.errors.length, 1, "app with non-existant launch path got an error");
            is(validator.errors[0], strings.formatStringFromName("validator.accessFailedLaunchPathBadHttpCode", [origin + "wrong-path.html", 404], 2),
               "with the right error message");
            is(validator.warnings.length, 0, "but no warning");
            next();
          });
      },
      function () {
        let validator = createPackaged("wrong-launch-path");
        validator.validate().then(() => {
            is(validator.errors.length, 1, "app with wrong path got an error");
            let file = nsFile(validator.project.location);
            file.append("wrong-path.html");
            let url = Services.io.newFileURI(file);
            is(validator.errors[0], strings.formatStringFromName("validator.accessFailedLaunchPath", [url.spec], 1),
               "with the expected message");
            is(validator.warnings.length, 0, "but no warning");

            next();
          });
      },

      // Test when using a non-absolute path for launch_path
      function () {
        let validator = createHosted("non-absolute-path");
        validator.validate().then(() => {
            is(validator.errors.length, 1, "app with non absolute path got an error");
            is(validator.errors[0], strings.formatStringFromName("validator.nonAbsoluteLaunchPath", ["non-absolute.html"], 1),
               "with expected message");
            is(validator.warnings.length, 0, "but no warning");
            next();
          });
      },
      function () {
        let validator = createPackaged("non-absolute-path");
        validator.validate().then(() => {
            is(validator.errors.length, 1, "app with non absolute path got an error");
            is(validator.errors[0], strings.formatStringFromName("validator.nonAbsoluteLaunchPath", ["non-absolute.html"], 1),
               "with expected message");
            is(validator.warnings.length, 0, "but no warning");
            next();
          });
      },

      // Test multiple failures (missing name [error] and icon [warning])
      function () {
        let validator = createHosted("no-name-or-icon");
        validator.validate().then(() => {
          checkNoNameOrIcon(validator);
        });
      },
      function () {
        let validator = createPackaged("no-name-or-icon");
        validator.validate().then(() => {
          checkNoNameOrIcon(validator);
        });
      }
    ];

    function checkNoNameOrIcon(validator) {
      is(validator.errors.length, 1, "app with no name has an error");
      is(validator.errors[0],
         strings.GetStringFromName("validator.missNameManifestProperty"),
         "with expected message");
      is(validator.warnings.length, 1, "app with no icon has a warning");
      is(validator.warnings[0],
         strings.GetStringFromName("validator.missIconsManifestProperty"),
         "with expected message");
      next();
    }

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