1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/app-manager/test/browser_manifest_editor.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,188 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 +"use strict"; 1.7 + 1.8 +const {Services} = Cu.import("resource://gre/modules/Services.jsm"); 1.9 + 1.10 +const MANIFEST_EDITOR_ENABLED = "devtools.appmanager.manifestEditor.enabled"; 1.11 + 1.12 +let gManifestWindow, gManifestEditor; 1.13 + 1.14 +function test() { 1.15 + waitForExplicitFinish(); 1.16 + 1.17 + Task.spawn(function() { 1.18 + Services.prefs.setBoolPref(MANIFEST_EDITOR_ENABLED, true); 1.19 + let tab = yield openAppManager(); 1.20 + yield selectProjectsPanel(); 1.21 + yield addSamplePackagedApp(); 1.22 + yield showSampleProjectDetails(); 1.23 + 1.24 + gManifestWindow = getManifestWindow(); 1.25 + gManifestEditor = getProjectsWindow().UI.manifestEditor; 1.26 + yield changeManifestValue("name", "the best app"); 1.27 + yield changeManifestValueBad("name", "the worst app"); 1.28 + yield addNewManifestProperty("developer", "foo", "bar"); 1.29 + yield addNewManifestPropertyBad("developer", "blob", "bob"); 1.30 + yield removeManifestProperty("developer", "foo"); 1.31 + gManifestWindow = null; 1.32 + gManifestEditor = null; 1.33 + 1.34 + yield removeSamplePackagedApp(); 1.35 + yield removeTab(tab); 1.36 + Services.prefs.setBoolPref(MANIFEST_EDITOR_ENABLED, false); 1.37 + finish(); 1.38 + }); 1.39 +} 1.40 + 1.41 +// Wait until the animation from commitHierarchy has completed 1.42 +function waitForUpdate() { 1.43 + return waitForTime(gManifestEditor.editor.lazyEmptyDelay + 1); 1.44 +} 1.45 + 1.46 +function changeManifestValue(key, value) { 1.47 + return Task.spawn(function() { 1.48 + let propElem = gManifestWindow.document 1.49 + .querySelector("[id ^= '" + key + "']"); 1.50 + is(propElem.querySelector(".name").value, key, 1.51 + "Key doesn't match expected value"); 1.52 + 1.53 + let valueElem = propElem.querySelector(".value"); 1.54 + EventUtils.sendMouseEvent({ type: "mousedown" }, valueElem, gManifestWindow); 1.55 + 1.56 + let valueInput = propElem.querySelector(".element-value-input"); 1.57 + valueInput.value = '"' + value + '"'; 1.58 + EventUtils.sendKey("RETURN", gManifestWindow); 1.59 + 1.60 + yield waitForUpdate(); 1.61 + // Elements have all been replaced, re-select them 1.62 + propElem = gManifestWindow.document.querySelector("[id ^= '" + key + "']"); 1.63 + valueElem = propElem.querySelector(".value"); 1.64 + is(valueElem.value, '"' + value + '"', 1.65 + "Value doesn't match expected value"); 1.66 + 1.67 + is(gManifestEditor.manifest[key], value, 1.68 + "Manifest doesn't contain expected value"); 1.69 + }); 1.70 +} 1.71 + 1.72 +function changeManifestValueBad(key, value) { 1.73 + return Task.spawn(function() { 1.74 + let propElem = gManifestWindow.document 1.75 + .querySelector("[id ^= '" + key + "']"); 1.76 + is(propElem.querySelector(".name").value, key, 1.77 + "Key doesn't match expected value"); 1.78 + 1.79 + let valueElem = propElem.querySelector(".value"); 1.80 + EventUtils.sendMouseEvent({ type: "mousedown" }, valueElem, gManifestWindow); 1.81 + 1.82 + let valueInput = propElem.querySelector(".element-value-input"); 1.83 + // Leaving out quotes will result in an error, so no change should be made. 1.84 + valueInput.value = value; 1.85 + EventUtils.sendKey("RETURN", gManifestWindow); 1.86 + 1.87 + yield waitForUpdate(); 1.88 + // Elements have all been replaced, re-select them 1.89 + propElem = gManifestWindow.document.querySelector("[id ^= '" + key + "']"); 1.90 + valueElem = propElem.querySelector(".value"); 1.91 + isnot(valueElem.value, '"' + value + '"', 1.92 + "Value was changed, but it should not have been"); 1.93 + 1.94 + isnot(gManifestEditor.manifest[key], value, 1.95 + "Manifest was changed, but it should not have been"); 1.96 + }); 1.97 +} 1.98 + 1.99 +function addNewManifestProperty(parent, key, value) { 1.100 + return Task.spawn(function() { 1.101 + let parentElem = gManifestWindow.document 1.102 + .querySelector("[id ^= '" + parent + "']"); 1.103 + ok(parentElem, 1.104 + "Found parent element"); 1.105 + let addPropertyElem = parentElem 1.106 + .querySelector(".variables-view-add-property"); 1.107 + ok(addPropertyElem, 1.108 + "Found add-property button"); 1.109 + 1.110 + EventUtils.sendMouseEvent({ type: "mousedown" }, addPropertyElem, gManifestWindow); 1.111 + 1.112 + let nameInput = parentElem.querySelector(".element-name-input"); 1.113 + nameInput.value = key; 1.114 + EventUtils.sendKey("TAB", gManifestWindow); 1.115 + 1.116 + let valueInput = parentElem.querySelector(".element-value-input"); 1.117 + valueInput.value = '"' + value + '"'; 1.118 + EventUtils.sendKey("RETURN", gManifestWindow); 1.119 + 1.120 + yield waitForUpdate(); 1.121 + 1.122 + let newElem = gManifestWindow.document.querySelector("[id ^= '" + key + "']"); 1.123 + let nameElem = newElem.querySelector(".name"); 1.124 + is(nameElem.value, key, 1.125 + "Key doesn't match expected Key"); 1.126 + 1.127 + ok(key in gManifestEditor.manifest[parent], 1.128 + "Manifest doesn't contain expected key"); 1.129 + 1.130 + let valueElem = newElem.querySelector(".value"); 1.131 + is(valueElem.value, '"' + value + '"', 1.132 + "Value doesn't match expected value"); 1.133 + 1.134 + is(gManifestEditor.manifest[parent][key], value, 1.135 + "Manifest doesn't contain expected value"); 1.136 + }); 1.137 +} 1.138 + 1.139 +function addNewManifestPropertyBad(parent, key, value) { 1.140 + return Task.spawn(function() { 1.141 + let parentElem = gManifestWindow.document 1.142 + .querySelector("[id ^= '" + parent + "']"); 1.143 + ok(parentElem, 1.144 + "Found parent element"); 1.145 + let addPropertyElem = parentElem 1.146 + .querySelector(".variables-view-add-property"); 1.147 + ok(addPropertyElem, 1.148 + "Found add-property button"); 1.149 + 1.150 + EventUtils.sendMouseEvent({ type: "mousedown" }, addPropertyElem, gManifestWindow); 1.151 + 1.152 + let nameInput = parentElem.querySelector(".element-name-input"); 1.153 + nameInput.value = key; 1.154 + EventUtils.sendKey("TAB", gManifestWindow); 1.155 + 1.156 + let valueInput = parentElem.querySelector(".element-value-input"); 1.157 + // Leaving out quotes will result in an error, so no change should be made. 1.158 + valueInput.value = value; 1.159 + EventUtils.sendKey("RETURN", gManifestWindow); 1.160 + 1.161 + yield waitForUpdate(); 1.162 + 1.163 + let newElem = gManifestWindow.document.querySelector("[id ^= '" + key + "']"); 1.164 + ok(!newElem, "Key was added, but it should not have been"); 1.165 + ok(!(key in gManifestEditor.manifest[parent]), 1.166 + "Manifest contains key, but it should not"); 1.167 + }); 1.168 +} 1.169 + 1.170 +function removeManifestProperty(parent, key) { 1.171 + info("*** Remove property test ***"); 1.172 + 1.173 + return Task.spawn(function() { 1.174 + let parentElem = gManifestWindow.document 1.175 + .querySelector("[id ^= '" + parent + "']"); 1.176 + ok(parentElem, "Found parent element"); 1.177 + 1.178 + let keyExists = key in gManifestEditor.manifest[parent]; 1.179 + ok(keyExists, 1.180 + "The manifest contains the key under the expected parent"); 1.181 + 1.182 + let newElem = gManifestWindow.document.querySelector("[id ^= '" + key + "']"); 1.183 + let removePropertyButton = newElem.querySelector(".variables-view-delete"); 1.184 + ok(removePropertyButton, "The remove property button was found"); 1.185 + removePropertyButton.click(); 1.186 + 1.187 + yield waitForUpdate(); 1.188 + 1.189 + ok(!(key in gManifestEditor.manifest[parent]), "Property was successfully removed"); 1.190 + }); 1.191 +}