toolkit/devtools/apps/tests/unit/test_webappsActor.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 Cu.import("resource://gre/modules/osfile.jsm");
michael@0 5 const {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
michael@0 6 const {require} = devtools;
michael@0 7 const {installHosted, installPackaged} = require("devtools/app-actor-front");
michael@0 8
michael@0 9 let gAppId = "actor-test";
michael@0 10 const APP_ORIGIN = "app://" + gAppId;
michael@0 11
michael@0 12 add_test(function testLaunchInexistantApp() {
michael@0 13 let request = {type: "launch", manifestURL: "http://foo.com"};
michael@0 14 webappActorRequest(request, function (aResponse) {
michael@0 15 do_check_eq(aResponse.error, "NO_SUCH_APP");
michael@0 16 run_next_test();
michael@0 17 });
michael@0 18 });
michael@0 19
michael@0 20 add_test(function testCloseInexistantApp() {
michael@0 21 let request = {type: "close", manifestURL: "http://foo.com"};
michael@0 22 webappActorRequest(request, function (aResponse) {
michael@0 23 do_check_eq(aResponse.error, "missingParameter");
michael@0 24 do_check_eq(aResponse.message, "No application for http://foo.com");
michael@0 25 run_next_test();
michael@0 26 });
michael@0 27 });
michael@0 28
michael@0 29 // Install a test app
michael@0 30 add_test(function testInstallPackaged() {
michael@0 31 installTestApp("app.zip", gAppId, function () {
michael@0 32 run_next_test();
michael@0 33 });
michael@0 34 });
michael@0 35
michael@0 36 // Now check that the app appear in getAll
michael@0 37 add_test(function testGetAll() {
michael@0 38 let request = {type: "getAll"};
michael@0 39 webappActorRequest(request, function (aResponse) {
michael@0 40 do_check_true("apps" in aResponse);
michael@0 41 let apps = aResponse.apps;
michael@0 42 do_check_true(apps.length > 0);
michael@0 43 for (let i = 0; i < apps.length; i++) {
michael@0 44 let app = apps[i];
michael@0 45 if (app.id == gAppId) {
michael@0 46 do_check_eq(app.name, "Test app");
michael@0 47 do_check_eq(app.manifest.description, "Testing webapps actor");
michael@0 48 do_check_eq(app.manifest.launch_path, "/index.html");
michael@0 49 do_check_eq(app.origin, APP_ORIGIN);
michael@0 50 do_check_eq(app.installOrigin, app.origin);
michael@0 51 do_check_eq(app.manifestURL, app.origin + "/manifest.webapp");
michael@0 52 run_next_test();
michael@0 53 return;
michael@0 54 }
michael@0 55 }
michael@0 56 do_throw("Unable to find the test app by its id");
michael@0 57 });
michael@0 58 });
michael@0 59
michael@0 60 add_test(function testGetApp() {
michael@0 61 let manifestURL = APP_ORIGIN + "/manifest.webapp";
michael@0 62 let request = {type: "getApp", manifestURL: manifestURL};
michael@0 63 webappActorRequest(request, function (aResponse) {
michael@0 64 do_check_true("app" in aResponse);
michael@0 65 let app = aResponse.app;
michael@0 66 do_check_eq(app.id, gAppId);
michael@0 67 do_check_eq(app.name, "Test app");
michael@0 68 do_check_eq(app.manifest.description, "Testing webapps actor");
michael@0 69 do_check_eq(app.manifest.launch_path, "/index.html");
michael@0 70 do_check_eq(app.origin, APP_ORIGIN);
michael@0 71 do_check_eq(app.installOrigin, app.origin);
michael@0 72 do_check_eq(app.manifestURL, app.origin + "/manifest.webapp");
michael@0 73 run_next_test();
michael@0 74 });
michael@0 75 });
michael@0 76
michael@0 77 add_test(function testLaunchApp() {
michael@0 78 let manifestURL = APP_ORIGIN + "/manifest.webapp";
michael@0 79 let startPoint = "/index.html";
michael@0 80 let request = {
michael@0 81 type: "launch",
michael@0 82 manifestURL: manifestURL,
michael@0 83 startPoint: startPoint
michael@0 84 };
michael@0 85 Services.obs.addObserver(function observer(subject, topic, data) {
michael@0 86 Services.obs.removeObserver(observer, topic);
michael@0 87 let json = JSON.parse(data);
michael@0 88 do_check_eq(json.manifestURL, manifestURL);
michael@0 89 do_check_eq(json.startPoint, startPoint);
michael@0 90 run_next_test();
michael@0 91 }, "webapps-launch", false);
michael@0 92
michael@0 93 webappActorRequest(request, function (aResponse) {
michael@0 94 do_check_false("error" in aResponse);
michael@0 95 });
michael@0 96 });
michael@0 97
michael@0 98 add_test(function testCloseApp() {
michael@0 99 let manifestURL = APP_ORIGIN + "/manifest.webapp";
michael@0 100 let request = {
michael@0 101 type: "close",
michael@0 102 manifestURL: manifestURL
michael@0 103 };
michael@0 104 Services.obs.addObserver(function observer(subject, topic, data) {
michael@0 105 Services.obs.removeObserver(observer, topic);
michael@0 106 let json = JSON.parse(data);
michael@0 107 do_check_eq(json.manifestURL, manifestURL);
michael@0 108
michael@0 109 }, "webapps-close", false);
michael@0 110
michael@0 111 webappActorRequest(request, function (aResponse) {
michael@0 112 do_check_false("error" in aResponse);
michael@0 113 run_next_test();
michael@0 114 });
michael@0 115 });
michael@0 116
michael@0 117 // The 128px icon is a single red pixel and the 64px one is a blue one
michael@0 118 // bug 899177: there is a bug with xhr and app:// and jar:// uris
michael@0 119 // that ends up forcing the content type to application/xml
michael@0 120 let red1px = "data:application/xml;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVQI12P4z8AAAAMBAQAY3Y2wAAAAAElFTkSuQmCC";
michael@0 121 let blue1px = "data:application/xml;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVQI12MwZDgHAAFlAQBDpjhLAAAAAElFTkSuQmCC";
michael@0 122
michael@0 123 add_test(function testGetIcon() {
michael@0 124 let manifestURL = APP_ORIGIN + "/manifest.webapp";
michael@0 125 let request = {
michael@0 126 type: "getIconAsDataURL",
michael@0 127 manifestURL: manifestURL
michael@0 128 };
michael@0 129
michael@0 130 webappActorRequest(request, function (aResponse) {
michael@0 131 do_check_false("error" in aResponse);
michael@0 132
michael@0 133 // By default, getIconAsDataURL return the 128x128 icon
michael@0 134 do_check_eq(aResponse.url, red1px);
michael@0 135 run_next_test();
michael@0 136 });
michael@0 137 });
michael@0 138
michael@0 139 add_test(function testGetIconWithCustomSize() {
michael@0 140 let manifestURL = APP_ORIGIN + "/manifest.webapp";
michael@0 141 let request = {
michael@0 142 type: "getIconAsDataURL",
michael@0 143 manifestURL: manifestURL,
michael@0 144 size: 64
michael@0 145 };
michael@0 146
michael@0 147 webappActorRequest(request, function (aResponse) {
michael@0 148 do_check_false("error" in aResponse);
michael@0 149
michael@0 150 do_check_eq(aResponse.url, blue1px);
michael@0 151 run_next_test();
michael@0 152 });
michael@0 153 });
michael@0 154
michael@0 155 add_test(function testUninstall() {
michael@0 156 let manifestURL = APP_ORIGIN + "/manifest.webapp";
michael@0 157 let request = {
michael@0 158 type: "uninstall",
michael@0 159 manifestURL: manifestURL
michael@0 160 };
michael@0 161
michael@0 162 Services.obs.addObserver(function observer(subject, topic, data) {
michael@0 163 Services.obs.removeObserver(observer, topic);
michael@0 164 let json = JSON.parse(data);
michael@0 165 do_check_eq(json.manifestURL, manifestURL);
michael@0 166 do_check_eq(json.origin, APP_ORIGIN);
michael@0 167 do_check_eq(json.id, gAppId);
michael@0 168 run_next_test();
michael@0 169 }, "webapps-uninstall", false);
michael@0 170
michael@0 171 webappActorRequest(request, function (aResponse) {
michael@0 172 do_check_false("error" in aResponse);
michael@0 173 });
michael@0 174 });
michael@0 175
michael@0 176 add_test(function testFileUploadInstall() {
michael@0 177 let packageFile = do_get_file("data/app.zip");
michael@0 178 installPackaged(gClient, gActor, packageFile.path, gAppId)
michael@0 179 .then(function ({ appId }) {
michael@0 180 do_check_eq(appId, gAppId);
michael@0 181 run_next_test();
michael@0 182 }, function (e) {
michael@0 183 do_throw("Failed install uploaded packaged app: " + e.error + ": " + e.message);
michael@0 184 });
michael@0 185 });
michael@0 186
michael@0 187 add_test(function testInstallHosted() {
michael@0 188 gAppId = "hosted-app";
michael@0 189 let metadata = {
michael@0 190 origin: "http://foo.com",
michael@0 191 installOrigin: "http://metadata.foo.com",
michael@0 192 manifestURL: "http://foo.com/metadata/manifest.webapp"
michael@0 193 };
michael@0 194 let manifest = {
michael@0 195 name: "My hosted app"
michael@0 196 };
michael@0 197 installHosted(gClient, gActor, gAppId, metadata, manifest).then(
michael@0 198 function ({ appId }) {
michael@0 199 do_check_eq(appId, gAppId);
michael@0 200 run_next_test();
michael@0 201 },
michael@0 202 function (e) {
michael@0 203 do_throw("Failed installing hosted app: " + e.error + ": " + e.message);
michael@0 204 }
michael@0 205 );
michael@0 206 });
michael@0 207
michael@0 208 add_test(function testCheckHostedApp() {
michael@0 209 let request = {type: "getAll"};
michael@0 210 webappActorRequest(request, function (aResponse) {
michael@0 211 do_check_true("apps" in aResponse);
michael@0 212 let apps = aResponse.apps;
michael@0 213 do_check_true(apps.length > 0);
michael@0 214 for (let i = 0; i < apps.length; i++) {
michael@0 215 let app = apps[i];
michael@0 216 if (app.id == gAppId) {
michael@0 217 do_check_eq(app.name, "My hosted app");
michael@0 218 do_check_eq(app.origin, "http://foo.com");
michael@0 219 do_check_eq(app.installOrigin, "http://metadata.foo.com");
michael@0 220 do_check_eq(app.manifestURL, "http://foo.com/metadata/manifest.webapp");
michael@0 221 run_next_test();
michael@0 222 return;
michael@0 223 }
michael@0 224 }
michael@0 225 do_throw("Unable to find the test app by its id");
michael@0 226 });
michael@0 227 });
michael@0 228
michael@0 229 function run_test() {
michael@0 230 setup();
michael@0 231
michael@0 232 run_next_test();
michael@0 233 }
michael@0 234

mercurial