browser/devtools/app-manager/test/browser_manifest_editor.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3 "use strict";
michael@0 4
michael@0 5 const {Services} = Cu.import("resource://gre/modules/Services.jsm");
michael@0 6
michael@0 7 const MANIFEST_EDITOR_ENABLED = "devtools.appmanager.manifestEditor.enabled";
michael@0 8
michael@0 9 let gManifestWindow, gManifestEditor;
michael@0 10
michael@0 11 function test() {
michael@0 12 waitForExplicitFinish();
michael@0 13
michael@0 14 Task.spawn(function() {
michael@0 15 Services.prefs.setBoolPref(MANIFEST_EDITOR_ENABLED, true);
michael@0 16 let tab = yield openAppManager();
michael@0 17 yield selectProjectsPanel();
michael@0 18 yield addSamplePackagedApp();
michael@0 19 yield showSampleProjectDetails();
michael@0 20
michael@0 21 gManifestWindow = getManifestWindow();
michael@0 22 gManifestEditor = getProjectsWindow().UI.manifestEditor;
michael@0 23 yield changeManifestValue("name", "the best app");
michael@0 24 yield changeManifestValueBad("name", "the worst app");
michael@0 25 yield addNewManifestProperty("developer", "foo", "bar");
michael@0 26 yield addNewManifestPropertyBad("developer", "blob", "bob");
michael@0 27 yield removeManifestProperty("developer", "foo");
michael@0 28 gManifestWindow = null;
michael@0 29 gManifestEditor = null;
michael@0 30
michael@0 31 yield removeSamplePackagedApp();
michael@0 32 yield removeTab(tab);
michael@0 33 Services.prefs.setBoolPref(MANIFEST_EDITOR_ENABLED, false);
michael@0 34 finish();
michael@0 35 });
michael@0 36 }
michael@0 37
michael@0 38 // Wait until the animation from commitHierarchy has completed
michael@0 39 function waitForUpdate() {
michael@0 40 return waitForTime(gManifestEditor.editor.lazyEmptyDelay + 1);
michael@0 41 }
michael@0 42
michael@0 43 function changeManifestValue(key, value) {
michael@0 44 return Task.spawn(function() {
michael@0 45 let propElem = gManifestWindow.document
michael@0 46 .querySelector("[id ^= '" + key + "']");
michael@0 47 is(propElem.querySelector(".name").value, key,
michael@0 48 "Key doesn't match expected value");
michael@0 49
michael@0 50 let valueElem = propElem.querySelector(".value");
michael@0 51 EventUtils.sendMouseEvent({ type: "mousedown" }, valueElem, gManifestWindow);
michael@0 52
michael@0 53 let valueInput = propElem.querySelector(".element-value-input");
michael@0 54 valueInput.value = '"' + value + '"';
michael@0 55 EventUtils.sendKey("RETURN", gManifestWindow);
michael@0 56
michael@0 57 yield waitForUpdate();
michael@0 58 // Elements have all been replaced, re-select them
michael@0 59 propElem = gManifestWindow.document.querySelector("[id ^= '" + key + "']");
michael@0 60 valueElem = propElem.querySelector(".value");
michael@0 61 is(valueElem.value, '"' + value + '"',
michael@0 62 "Value doesn't match expected value");
michael@0 63
michael@0 64 is(gManifestEditor.manifest[key], value,
michael@0 65 "Manifest doesn't contain expected value");
michael@0 66 });
michael@0 67 }
michael@0 68
michael@0 69 function changeManifestValueBad(key, value) {
michael@0 70 return Task.spawn(function() {
michael@0 71 let propElem = gManifestWindow.document
michael@0 72 .querySelector("[id ^= '" + key + "']");
michael@0 73 is(propElem.querySelector(".name").value, key,
michael@0 74 "Key doesn't match expected value");
michael@0 75
michael@0 76 let valueElem = propElem.querySelector(".value");
michael@0 77 EventUtils.sendMouseEvent({ type: "mousedown" }, valueElem, gManifestWindow);
michael@0 78
michael@0 79 let valueInput = propElem.querySelector(".element-value-input");
michael@0 80 // Leaving out quotes will result in an error, so no change should be made.
michael@0 81 valueInput.value = value;
michael@0 82 EventUtils.sendKey("RETURN", gManifestWindow);
michael@0 83
michael@0 84 yield waitForUpdate();
michael@0 85 // Elements have all been replaced, re-select them
michael@0 86 propElem = gManifestWindow.document.querySelector("[id ^= '" + key + "']");
michael@0 87 valueElem = propElem.querySelector(".value");
michael@0 88 isnot(valueElem.value, '"' + value + '"',
michael@0 89 "Value was changed, but it should not have been");
michael@0 90
michael@0 91 isnot(gManifestEditor.manifest[key], value,
michael@0 92 "Manifest was changed, but it should not have been");
michael@0 93 });
michael@0 94 }
michael@0 95
michael@0 96 function addNewManifestProperty(parent, key, value) {
michael@0 97 return Task.spawn(function() {
michael@0 98 let parentElem = gManifestWindow.document
michael@0 99 .querySelector("[id ^= '" + parent + "']");
michael@0 100 ok(parentElem,
michael@0 101 "Found parent element");
michael@0 102 let addPropertyElem = parentElem
michael@0 103 .querySelector(".variables-view-add-property");
michael@0 104 ok(addPropertyElem,
michael@0 105 "Found add-property button");
michael@0 106
michael@0 107 EventUtils.sendMouseEvent({ type: "mousedown" }, addPropertyElem, gManifestWindow);
michael@0 108
michael@0 109 let nameInput = parentElem.querySelector(".element-name-input");
michael@0 110 nameInput.value = key;
michael@0 111 EventUtils.sendKey("TAB", gManifestWindow);
michael@0 112
michael@0 113 let valueInput = parentElem.querySelector(".element-value-input");
michael@0 114 valueInput.value = '"' + value + '"';
michael@0 115 EventUtils.sendKey("RETURN", gManifestWindow);
michael@0 116
michael@0 117 yield waitForUpdate();
michael@0 118
michael@0 119 let newElem = gManifestWindow.document.querySelector("[id ^= '" + key + "']");
michael@0 120 let nameElem = newElem.querySelector(".name");
michael@0 121 is(nameElem.value, key,
michael@0 122 "Key doesn't match expected Key");
michael@0 123
michael@0 124 ok(key in gManifestEditor.manifest[parent],
michael@0 125 "Manifest doesn't contain expected key");
michael@0 126
michael@0 127 let valueElem = newElem.querySelector(".value");
michael@0 128 is(valueElem.value, '"' + value + '"',
michael@0 129 "Value doesn't match expected value");
michael@0 130
michael@0 131 is(gManifestEditor.manifest[parent][key], value,
michael@0 132 "Manifest doesn't contain expected value");
michael@0 133 });
michael@0 134 }
michael@0 135
michael@0 136 function addNewManifestPropertyBad(parent, key, value) {
michael@0 137 return Task.spawn(function() {
michael@0 138 let parentElem = gManifestWindow.document
michael@0 139 .querySelector("[id ^= '" + parent + "']");
michael@0 140 ok(parentElem,
michael@0 141 "Found parent element");
michael@0 142 let addPropertyElem = parentElem
michael@0 143 .querySelector(".variables-view-add-property");
michael@0 144 ok(addPropertyElem,
michael@0 145 "Found add-property button");
michael@0 146
michael@0 147 EventUtils.sendMouseEvent({ type: "mousedown" }, addPropertyElem, gManifestWindow);
michael@0 148
michael@0 149 let nameInput = parentElem.querySelector(".element-name-input");
michael@0 150 nameInput.value = key;
michael@0 151 EventUtils.sendKey("TAB", gManifestWindow);
michael@0 152
michael@0 153 let valueInput = parentElem.querySelector(".element-value-input");
michael@0 154 // Leaving out quotes will result in an error, so no change should be made.
michael@0 155 valueInput.value = value;
michael@0 156 EventUtils.sendKey("RETURN", gManifestWindow);
michael@0 157
michael@0 158 yield waitForUpdate();
michael@0 159
michael@0 160 let newElem = gManifestWindow.document.querySelector("[id ^= '" + key + "']");
michael@0 161 ok(!newElem, "Key was added, but it should not have been");
michael@0 162 ok(!(key in gManifestEditor.manifest[parent]),
michael@0 163 "Manifest contains key, but it should not");
michael@0 164 });
michael@0 165 }
michael@0 166
michael@0 167 function removeManifestProperty(parent, key) {
michael@0 168 info("*** Remove property test ***");
michael@0 169
michael@0 170 return Task.spawn(function() {
michael@0 171 let parentElem = gManifestWindow.document
michael@0 172 .querySelector("[id ^= '" + parent + "']");
michael@0 173 ok(parentElem, "Found parent element");
michael@0 174
michael@0 175 let keyExists = key in gManifestEditor.manifest[parent];
michael@0 176 ok(keyExists,
michael@0 177 "The manifest contains the key under the expected parent");
michael@0 178
michael@0 179 let newElem = gManifestWindow.document.querySelector("[id ^= '" + key + "']");
michael@0 180 let removePropertyButton = newElem.querySelector(".variables-view-delete");
michael@0 181 ok(removePropertyButton, "The remove property button was found");
michael@0 182 removePropertyButton.click();
michael@0 183
michael@0 184 yield waitForUpdate();
michael@0 185
michael@0 186 ok(!(key in gManifestEditor.manifest[parent]), "Property was successfully removed");
michael@0 187 });
michael@0 188 }

mercurial