summaryrefslogtreecommitdiffstats
path: root/comm/calendar/test/unit/test_webcal.js
blob: 77d9576f4b8d966191e2d7dc5fcc18625a2a9a1b (plain)
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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
var { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");

function run_test() {
  let httpserv = new HttpServer();
  httpserv.registerPrefixHandler("/", {
    handle(request, response) {
      response.setStatusLine(request.httpVersion, 200, "OK");
      equal(request.path, "/test_webcal");
    },
  });
  httpserv.start(-1);

  let baseUri = "://localhost:" + httpserv.identity.primaryPort + "/test_webcal";
  add_test(check_webcal_uri.bind(null, "webcal" + baseUri));
  // TODO webcals needs bug 466524 to be fixed
  // add_test(check_webcal_uri.bind(null, "webcals" + baseUri));
  add_test(() => httpserv.stop(run_next_test));

  // Now lets go...
  run_next_test();
}

function check_webcal_uri(aUri) {
  let uri = Services.io.newURI(aUri);

  let channel = Services.io.newChannelFromURI(
    uri,
    null,
    Services.scriptSecurityManager.getSystemPrincipal(),
    null,
    Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
    Ci.nsIContentPolicy.TYPE_OTHER
  );

  NetUtil.asyncFetch(channel, (data, status, request) => {
    ok(Components.isSuccessCode(status));
    run_next_test();
  });
}