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