File: test_install_errors.xul

package info (click to toggle)
wine-gecko-2.24 2.24%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 740,092 kB
  • ctags: 688,789
  • sloc: cpp: 3,160,639; ansic: 1,619,153; python: 164,084; java: 128,022; asm: 114,527; xml: 69,863; sh: 55,281; makefile: 49,648; perl: 20,454; objc: 2,344; yacc: 2,066; pascal: 995; lex: 982; exp: 449; php: 244; lisp: 228; awk: 211; sed: 61; csh: 21; ada: 16; ruby: 3
file content (235 lines) | stat: -rw-r--r-- 7,254 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?xml version="1.0"?>

<!-- Any copyright is dedicated to the Public Domain.
   - http://creativecommons.org/publicdomain/zero/1.0/ -->

<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>

<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        title="Mozilla Bug 741549">
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
  <script type="application/javascript" src="head.js"/>
  <!-- test results are displayed in the html:body -->
  <body xmlns="http://www.w3.org/1999/xhtml">
  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=741549"
     target="_blank">Mozilla Bug 741549</a>
  </body>

<script>

var steps = [
  noArgs,
  parseError,
  invalidManifest,
  permissionDenied,
  invalidContent,
  installPackageNotImplemented,
  invalidLaunchPath,
  invalidLaunchPath2,
  invalidEntryPoint,
  invalidLocaleEntryPoint,
  invalidActivityHref,
  invalidActivityHref2,
  invalidMessage,
  fileURL,
  originNotAllowed,
  originAllowed,
];

runAll(steps);

function noArgs(next) {
  try {
    navigator.mozApps.install();
  } catch (e) {
    is(e.message, "Not enough arguments \[mozIDOMApplicationRegistry.install\]",
       "install without arguments throws exception");
    next();
  }
}

function parseError(next) {
  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/json_syntax_error.webapp";

  navigator.mozApps.install(url, null).onerror = function onInstallError() {
    is(this.error.name, "MANIFEST_PARSE_ERROR", "manifest with syntax error");
    next();
  };
}

function invalidManifest(next) {
  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/missing_required_field.webapp";

  navigator.mozApps.install(url, null).onerror = function onInstallError() {
    is(this.error.name, "INVALID_MANIFEST", "manifest missing required field");
    next();
  };
}

function permissionDenied(next) {
  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/no_delegated_install.webapp";

  confirmNextInstall();
  var request = navigator.mozApps.install(url, null);

  request.onerror = function onInstallError() {
    is(this.error.name, "DENIED", "manifest without installs_allowed_from");
    next();
  };

  request.onsuccess = function onInstall() {
    todo(false, "manifest without installs_allowed_from fails");
    navigator.mozApps.mgmt.uninstall(this.result).onsuccess = function onUninstall() {
      next();
    };
  };
}

function invalidContent(next) {
  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/bad_content_type.webapp";

  var request = navigator.mozApps.install(url, null);

  request.onerror = function onInstallError() {
    is(this.error.name, "INVALID_MANIFEST", "manifest with bad content type");
    next();
  };

  request.onsuccess = function onInstall() {
    ok(false, "manifest with bad content type should fail");
    navigator.mozApps.mgmt.uninstall(this.result).onsuccess = function onUninstall() {
      next();
    };
  };
}

function invalidLaunchPath(next) {
  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_launch_path.webapp";

  navigator.mozApps.install(url, null).onerror = function onInstallError() {
    is(this.error.name, "INVALID_MANIFEST", "Invalid Manifest");
    next();
  };
}

function invalidLaunchPath2(next) {
  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_launch_path2.webapp";

  navigator.mozApps.install(url, null).onerror = function onInstallError() {
    is(this.error.name, "INVALID_MANIFEST", "Invalid Manifest");
    next();
  };
}

function invalidEntryPoint(next) {
  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_entry_point.webapp";

  navigator.mozApps.install(url, null).onerror = function onInstallError() {
    is(this.error.name, "INVALID_MANIFEST", "manifest missing required field");
    next();
  };
}

function invalidLocaleEntryPoint(next) {
  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_locale_entry_point.webapp";

  navigator.mozApps.install(url, null).onerror = function onInstallError() {
    is(this.error.name, "INVALID_MANIFEST", "manifest missing required field");
    next();
  };
}

function invalidActivityHref(next) {
  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_activity_href.webapp";

  navigator.mozApps.install(url, null).onerror = function onInstallError() {
    is(this.error.name, "INVALID_MANIFEST", "Manifest has non-relative URI for activity href");
    next();
  };
}

function invalidActivityHref2(next) {
  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_activity_href2.webapp";

  navigator.mozApps.install(url, null).onerror = function onInstallError() {
    is(this.error.name, "INVALID_MANIFEST", "Manifest has data: URI for activity href");
    next();
  };
}

function invalidMessage(next) {
  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_message.webapp";

  navigator.mozApps.install(url, null).onerror = function onInstallError() {
    is(this.error.name, "INVALID_MANIFEST", "Manifest has absolute message href");
    next();
  };
}

function installPackageNotImplemented(next) {
  ok(!("installPackage" in navigator.mozApps),
     "installPackage not in navigator.mozApps");
  next();
}

function fileURL(next) {
  try {
    navigator.mozApps.install("file:///nonexistent");
    ok(false,
       "attempt to install nonexistent file: URL doesn't throw exception");
  } catch(ex) {
    is(ex.message, "INVALID_URL_SCHEME: 'file'; must be 'http' or 'https'",
       "attempt to install nonexistent file: URL throws exception");
  }

  try {
    navigator.mozApps.install("file:///");
    ok(false, "attempt to install existent file: URL doesn't throw exception");
  } catch(ex) {
    is(ex.message, "INVALID_URL_SCHEME: 'file'; must be 'http' or 'https'",
       "attempt to install existent file: URL throws exception");
  }

  next();
}

function originNotAllowed(next) {
  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/installs_allowed_from_example.com.webapp";

  var request = navigator.mozApps.install(url, null);

  request.onerror = function onInstallError() {
    is(this.error.name, "INSTALL_FROM_DENIED", "origin is not in installs_allowed_from");
    next();
  };

  request.onsuccess = function onInstall() {
    ok(false, "test should fail because of installs_allowed_from");
    navigator.mozApps.mgmt.uninstall(this.result).onsuccess = function onUninstall() {
      next();
    };
  };
}

function originAllowed(next) {
  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/installs_allowed_from_chrome_mochitests.webapp";

  confirmNextInstall();
  var request = navigator.mozApps.install(url, null);

  request.onerror = function onInstallError() {
    ok(false, "installation error: " + this.error.name);
    next();
  };

  request.onsuccess = function onInstall() {
    ok(true, "test origin is in installs_allowed_from");
    navigator.mozApps.mgmt.uninstall(this.result).onsuccess = function onUninstall() {
      next();
    };
  };
}

</script>
</window>