Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | * Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 4 | */ |
michael@0 | 5 | |
michael@0 | 6 | // Check that variables view works as expected in the web console. |
michael@0 | 7 | |
michael@0 | 8 | const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-eval-in-stackframe.html"; |
michael@0 | 9 | |
michael@0 | 10 | let gWebConsole, gJSTerm, gVariablesView; |
michael@0 | 11 | |
michael@0 | 12 | function test() |
michael@0 | 13 | { |
michael@0 | 14 | addTab(TEST_URI); |
michael@0 | 15 | browser.addEventListener("load", function onLoad() { |
michael@0 | 16 | browser.removeEventListener("load", onLoad, true); |
michael@0 | 17 | openConsole(null, consoleOpened); |
michael@0 | 18 | }, true); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | function consoleOpened(hud) |
michael@0 | 22 | { |
michael@0 | 23 | gWebConsole = hud; |
michael@0 | 24 | gJSTerm = hud.jsterm; |
michael@0 | 25 | gJSTerm.execute("fooObj", onExecuteFooObj); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function onExecuteFooObj(msg) |
michael@0 | 29 | { |
michael@0 | 30 | ok(msg, "output message found"); |
michael@0 | 31 | ok(msg.textContent.contains('{ testProp: "testValue" }'), "message text check"); |
michael@0 | 32 | |
michael@0 | 33 | let anchor = msg.querySelector("a"); |
michael@0 | 34 | ok(anchor, "object link found"); |
michael@0 | 35 | |
michael@0 | 36 | gJSTerm.once("variablesview-fetched", onFooObjFetch); |
michael@0 | 37 | |
michael@0 | 38 | executeSoon(() => |
michael@0 | 39 | EventUtils.synthesizeMouse(anchor, 2, 2, {}, gWebConsole.iframeWindow) |
michael@0 | 40 | ); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | function onFooObjFetch(aEvent, aVar) |
michael@0 | 44 | { |
michael@0 | 45 | gVariablesView = aVar._variablesView; |
michael@0 | 46 | ok(gVariablesView, "variables view object"); |
michael@0 | 47 | |
michael@0 | 48 | findVariableViewProperties(aVar, [ |
michael@0 | 49 | { name: "testProp", value: "testValue" }, |
michael@0 | 50 | ], { webconsole: gWebConsole }).then(onTestPropFound); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | function onTestPropFound(aResults) |
michael@0 | 54 | { |
michael@0 | 55 | let prop = aResults[0].matchedProp; |
michael@0 | 56 | ok(prop, "matched the |testProp| property in the variables view"); |
michael@0 | 57 | |
michael@0 | 58 | is(content.wrappedJSObject.fooObj.testProp, aResults[0].value, |
michael@0 | 59 | "|fooObj.testProp| value is correct"); |
michael@0 | 60 | |
michael@0 | 61 | // Check that property value updates work and that jsterm functions can be |
michael@0 | 62 | // used. |
michael@0 | 63 | updateVariablesViewProperty({ |
michael@0 | 64 | property: prop, |
michael@0 | 65 | field: "value", |
michael@0 | 66 | string: "document.title + window.location + $('p')", |
michael@0 | 67 | webconsole: gWebConsole, |
michael@0 | 68 | callback: onFooObjFetchAfterUpdate, |
michael@0 | 69 | }); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | function onFooObjFetchAfterUpdate(aEvent, aVar) |
michael@0 | 73 | { |
michael@0 | 74 | info("onFooObjFetchAfterUpdate"); |
michael@0 | 75 | let para = content.wrappedJSObject.document.querySelector("p"); |
michael@0 | 76 | let expectedValue = content.document.title + content.location + para; |
michael@0 | 77 | |
michael@0 | 78 | findVariableViewProperties(aVar, [ |
michael@0 | 79 | { name: "testProp", value: expectedValue }, |
michael@0 | 80 | ], { webconsole: gWebConsole }).then(onUpdatedTestPropFound); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | function onUpdatedTestPropFound(aResults) |
michael@0 | 84 | { |
michael@0 | 85 | let prop = aResults[0].matchedProp; |
michael@0 | 86 | ok(prop, "matched the updated |testProp| property value"); |
michael@0 | 87 | |
michael@0 | 88 | is(content.wrappedJSObject.fooObj.testProp, aResults[0].value, |
michael@0 | 89 | "|fooObj.testProp| value has been updated"); |
michael@0 | 90 | |
michael@0 | 91 | // Check that property name updates work. |
michael@0 | 92 | updateVariablesViewProperty({ |
michael@0 | 93 | property: prop, |
michael@0 | 94 | field: "name", |
michael@0 | 95 | string: "testUpdatedProp", |
michael@0 | 96 | webconsole: gWebConsole, |
michael@0 | 97 | callback: onFooObjFetchAfterPropRename, |
michael@0 | 98 | }); |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | function onFooObjFetchAfterPropRename(aEvent, aVar) |
michael@0 | 102 | { |
michael@0 | 103 | info("onFooObjFetchAfterPropRename"); |
michael@0 | 104 | |
michael@0 | 105 | let para = content.wrappedJSObject.document.querySelector("p"); |
michael@0 | 106 | let expectedValue = content.document.title + content.location + para; |
michael@0 | 107 | |
michael@0 | 108 | // Check that the new value is in the variables view. |
michael@0 | 109 | findVariableViewProperties(aVar, [ |
michael@0 | 110 | { name: "testUpdatedProp", value: expectedValue }, |
michael@0 | 111 | ], { webconsole: gWebConsole }).then(onRenamedTestPropFound); |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | function onRenamedTestPropFound(aResults) |
michael@0 | 115 | { |
michael@0 | 116 | let prop = aResults[0].matchedProp; |
michael@0 | 117 | ok(prop, "matched the renamed |testProp| property"); |
michael@0 | 118 | |
michael@0 | 119 | ok(!content.wrappedJSObject.fooObj.testProp, |
michael@0 | 120 | "|fooObj.testProp| has been deleted"); |
michael@0 | 121 | is(content.wrappedJSObject.fooObj.testUpdatedProp, aResults[0].value, |
michael@0 | 122 | "|fooObj.testUpdatedProp| is correct"); |
michael@0 | 123 | |
michael@0 | 124 | // Check that property value updates that cause exceptions are reported in |
michael@0 | 125 | // the web console output. |
michael@0 | 126 | updateVariablesViewProperty({ |
michael@0 | 127 | property: prop, |
michael@0 | 128 | field: "value", |
michael@0 | 129 | string: "foobarzFailure()", |
michael@0 | 130 | webconsole: gWebConsole, |
michael@0 | 131 | callback: onPropUpdateError, |
michael@0 | 132 | }); |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | function onPropUpdateError(aEvent, aVar) |
michael@0 | 136 | { |
michael@0 | 137 | info("onPropUpdateError"); |
michael@0 | 138 | |
michael@0 | 139 | let para = content.wrappedJSObject.document.querySelector("p"); |
michael@0 | 140 | let expectedValue = content.document.title + content.location + para; |
michael@0 | 141 | |
michael@0 | 142 | // Make sure the property did not change. |
michael@0 | 143 | findVariableViewProperties(aVar, [ |
michael@0 | 144 | { name: "testUpdatedProp", value: expectedValue }, |
michael@0 | 145 | ], { webconsole: gWebConsole }).then(onRenamedTestPropFoundAgain); |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | function onRenamedTestPropFoundAgain(aResults) |
michael@0 | 149 | { |
michael@0 | 150 | let prop = aResults[0].matchedProp; |
michael@0 | 151 | ok(prop, "matched the renamed |testProp| property again"); |
michael@0 | 152 | |
michael@0 | 153 | let outputNode = gWebConsole.outputNode; |
michael@0 | 154 | |
michael@0 | 155 | waitForMessages({ |
michael@0 | 156 | webconsole: gWebConsole, |
michael@0 | 157 | messages: [{ |
michael@0 | 158 | name: "exception in property update reported in the web console output", |
michael@0 | 159 | text: "foobarzFailure", |
michael@0 | 160 | category: CATEGORY_OUTPUT, |
michael@0 | 161 | severity: SEVERITY_ERROR, |
michael@0 | 162 | }], |
michael@0 | 163 | }).then(testPropDelete.bind(null, prop)); |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | function testPropDelete(aProp) |
michael@0 | 167 | { |
michael@0 | 168 | gVariablesView.window.focus(); |
michael@0 | 169 | aProp.focus(); |
michael@0 | 170 | |
michael@0 | 171 | executeSoon(() => { |
michael@0 | 172 | EventUtils.synthesizeKey("VK_DELETE", {}, gVariablesView.window); |
michael@0 | 173 | gWebConsole = gJSTerm = gVariablesView = null; |
michael@0 | 174 | }); |
michael@0 | 175 | |
michael@0 | 176 | waitForSuccess({ |
michael@0 | 177 | name: "property deleted", |
michael@0 | 178 | timeout: 60000, |
michael@0 | 179 | validatorFn: () => !("testUpdatedProp" in content.wrappedJSObject.fooObj), |
michael@0 | 180 | successFn: finishTest, |
michael@0 | 181 | failureFn: finishTest, |
michael@0 | 182 | }); |
michael@0 | 183 | } |