services/common/tests/unit/test_utils_makeURI.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 _("Make sure uri strings are converted to nsIURIs");
michael@0 5 Cu.import("resource://services-common/utils.js");
michael@0 6
michael@0 7 function run_test() {
michael@0 8 _test_makeURI();
michael@0 9 }
michael@0 10
michael@0 11 function _test_makeURI() {
michael@0 12 _("Check http uris");
michael@0 13 let uri1 = "http://mozillalabs.com/";
michael@0 14 do_check_eq(CommonUtils.makeURI(uri1).spec, uri1);
michael@0 15 let uri2 = "http://www.mozillalabs.com/";
michael@0 16 do_check_eq(CommonUtils.makeURI(uri2).spec, uri2);
michael@0 17 let uri3 = "http://mozillalabs.com/path";
michael@0 18 do_check_eq(CommonUtils.makeURI(uri3).spec, uri3);
michael@0 19 let uri4 = "http://mozillalabs.com/multi/path";
michael@0 20 do_check_eq(CommonUtils.makeURI(uri4).spec, uri4);
michael@0 21 let uri5 = "http://mozillalabs.com/?query";
michael@0 22 do_check_eq(CommonUtils.makeURI(uri5).spec, uri5);
michael@0 23 let uri6 = "http://mozillalabs.com/#hash";
michael@0 24 do_check_eq(CommonUtils.makeURI(uri6).spec, uri6);
michael@0 25
michael@0 26 _("Check https uris");
michael@0 27 let uris1 = "https://mozillalabs.com/";
michael@0 28 do_check_eq(CommonUtils.makeURI(uris1).spec, uris1);
michael@0 29 let uris2 = "https://www.mozillalabs.com/";
michael@0 30 do_check_eq(CommonUtils.makeURI(uris2).spec, uris2);
michael@0 31 let uris3 = "https://mozillalabs.com/path";
michael@0 32 do_check_eq(CommonUtils.makeURI(uris3).spec, uris3);
michael@0 33 let uris4 = "https://mozillalabs.com/multi/path";
michael@0 34 do_check_eq(CommonUtils.makeURI(uris4).spec, uris4);
michael@0 35 let uris5 = "https://mozillalabs.com/?query";
michael@0 36 do_check_eq(CommonUtils.makeURI(uris5).spec, uris5);
michael@0 37 let uris6 = "https://mozillalabs.com/#hash";
michael@0 38 do_check_eq(CommonUtils.makeURI(uris6).spec, uris6);
michael@0 39
michael@0 40 _("Check chrome uris");
michael@0 41 let uric1 = "chrome://browser/content/browser.xul";
michael@0 42 do_check_eq(CommonUtils.makeURI(uric1).spec, uric1);
michael@0 43 let uric2 = "chrome://browser/skin/browser.css";
michael@0 44 do_check_eq(CommonUtils.makeURI(uric2).spec, uric2);
michael@0 45 let uric3 = "chrome://browser/locale/browser.dtd";
michael@0 46 do_check_eq(CommonUtils.makeURI(uric3).spec, uric3);
michael@0 47
michael@0 48 _("Check about uris");
michael@0 49 let uria1 = "about:weave";
michael@0 50 do_check_eq(CommonUtils.makeURI(uria1).spec, uria1);
michael@0 51 let uria2 = "about:weave/";
michael@0 52 do_check_eq(CommonUtils.makeURI(uria2).spec, uria2);
michael@0 53 let uria3 = "about:weave/path";
michael@0 54 do_check_eq(CommonUtils.makeURI(uria3).spec, uria3);
michael@0 55 let uria4 = "about:weave/multi/path";
michael@0 56 do_check_eq(CommonUtils.makeURI(uria4).spec, uria4);
michael@0 57 let uria5 = "about:weave/?query";
michael@0 58 do_check_eq(CommonUtils.makeURI(uria5).spec, uria5);
michael@0 59 let uria6 = "about:weave/#hash";
michael@0 60 do_check_eq(CommonUtils.makeURI(uria6).spec, uria6);
michael@0 61
michael@0 62 _("Invalid uris are undefined");
michael@0 63 do_check_eq(CommonUtils.makeURI("mozillalabs.com"), undefined);
michael@0 64 do_check_eq(CommonUtils.makeURI("chrome://badstuff"), undefined);
michael@0 65 do_check_eq(CommonUtils.makeURI("this is a test"), undefined);
michael@0 66 }

mercurial