browser/devtools/webconsole/test/browser_console_variables_view.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webconsole/test/browser_console_variables_view.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,183 @@
     1.4 +/*
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.7 + */
     1.8 +
     1.9 +// Check that variables view works as expected in the web console.
    1.10 +
    1.11 +const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-eval-in-stackframe.html";
    1.12 +
    1.13 +let gWebConsole, gJSTerm, gVariablesView;
    1.14 +
    1.15 +function test()
    1.16 +{
    1.17 +  addTab(TEST_URI);
    1.18 +  browser.addEventListener("load", function onLoad() {
    1.19 +    browser.removeEventListener("load", onLoad, true);
    1.20 +    openConsole(null, consoleOpened);
    1.21 +  }, true);
    1.22 +}
    1.23 +
    1.24 +function consoleOpened(hud)
    1.25 +{
    1.26 +  gWebConsole = hud;
    1.27 +  gJSTerm = hud.jsterm;
    1.28 +  gJSTerm.execute("fooObj", onExecuteFooObj);
    1.29 +}
    1.30 +
    1.31 +function onExecuteFooObj(msg)
    1.32 +{
    1.33 +  ok(msg, "output message found");
    1.34 +  ok(msg.textContent.contains('{ testProp: "testValue" }'), "message text check");
    1.35 +
    1.36 +  let anchor = msg.querySelector("a");
    1.37 +  ok(anchor, "object link found");
    1.38 +
    1.39 +  gJSTerm.once("variablesview-fetched", onFooObjFetch);
    1.40 +
    1.41 +  executeSoon(() =>
    1.42 +    EventUtils.synthesizeMouse(anchor, 2, 2, {}, gWebConsole.iframeWindow)
    1.43 +  );
    1.44 +}
    1.45 +
    1.46 +function onFooObjFetch(aEvent, aVar)
    1.47 +{
    1.48 +  gVariablesView = aVar._variablesView;
    1.49 +  ok(gVariablesView, "variables view object");
    1.50 +
    1.51 +  findVariableViewProperties(aVar, [
    1.52 +    { name: "testProp", value: "testValue" },
    1.53 +  ], { webconsole: gWebConsole }).then(onTestPropFound);
    1.54 +}
    1.55 +
    1.56 +function onTestPropFound(aResults)
    1.57 +{
    1.58 +  let prop = aResults[0].matchedProp;
    1.59 +  ok(prop, "matched the |testProp| property in the variables view");
    1.60 +
    1.61 +  is(content.wrappedJSObject.fooObj.testProp, aResults[0].value,
    1.62 +     "|fooObj.testProp| value is correct");
    1.63 +
    1.64 +  // Check that property value updates work and that jsterm functions can be
    1.65 +  // used.
    1.66 +  updateVariablesViewProperty({
    1.67 +    property: prop,
    1.68 +    field: "value",
    1.69 +    string: "document.title + window.location + $('p')",
    1.70 +    webconsole: gWebConsole,
    1.71 +    callback: onFooObjFetchAfterUpdate,
    1.72 +  });
    1.73 +}
    1.74 +
    1.75 +function onFooObjFetchAfterUpdate(aEvent, aVar)
    1.76 +{
    1.77 +  info("onFooObjFetchAfterUpdate");
    1.78 +  let para = content.wrappedJSObject.document.querySelector("p");
    1.79 +  let expectedValue = content.document.title + content.location + para;
    1.80 +
    1.81 +  findVariableViewProperties(aVar, [
    1.82 +    { name: "testProp", value: expectedValue },
    1.83 +  ], { webconsole: gWebConsole }).then(onUpdatedTestPropFound);
    1.84 +}
    1.85 +
    1.86 +function onUpdatedTestPropFound(aResults)
    1.87 +{
    1.88 +  let prop = aResults[0].matchedProp;
    1.89 +  ok(prop, "matched the updated |testProp| property value");
    1.90 +
    1.91 +  is(content.wrappedJSObject.fooObj.testProp, aResults[0].value,
    1.92 +     "|fooObj.testProp| value has been updated");
    1.93 +
    1.94 +  // Check that property name updates work.
    1.95 +  updateVariablesViewProperty({
    1.96 +    property: prop,
    1.97 +    field: "name",
    1.98 +    string: "testUpdatedProp",
    1.99 +    webconsole: gWebConsole,
   1.100 +    callback: onFooObjFetchAfterPropRename,
   1.101 +  });
   1.102 +}
   1.103 +
   1.104 +function onFooObjFetchAfterPropRename(aEvent, aVar)
   1.105 +{
   1.106 +  info("onFooObjFetchAfterPropRename");
   1.107 +
   1.108 +  let para = content.wrappedJSObject.document.querySelector("p");
   1.109 +  let expectedValue = content.document.title + content.location + para;
   1.110 +
   1.111 +  // Check that the new value is in the variables view.
   1.112 +  findVariableViewProperties(aVar, [
   1.113 +    { name: "testUpdatedProp", value: expectedValue },
   1.114 +  ], { webconsole: gWebConsole }).then(onRenamedTestPropFound);
   1.115 +}
   1.116 +
   1.117 +function onRenamedTestPropFound(aResults)
   1.118 +{
   1.119 +  let prop = aResults[0].matchedProp;
   1.120 +  ok(prop, "matched the renamed |testProp| property");
   1.121 +
   1.122 +  ok(!content.wrappedJSObject.fooObj.testProp,
   1.123 +     "|fooObj.testProp| has been deleted");
   1.124 +  is(content.wrappedJSObject.fooObj.testUpdatedProp, aResults[0].value,
   1.125 +     "|fooObj.testUpdatedProp| is correct");
   1.126 +
   1.127 +  // Check that property value updates that cause exceptions are reported in
   1.128 +  // the web console output.
   1.129 +  updateVariablesViewProperty({
   1.130 +    property: prop,
   1.131 +    field: "value",
   1.132 +    string: "foobarzFailure()",
   1.133 +    webconsole: gWebConsole,
   1.134 +    callback: onPropUpdateError,
   1.135 +  });
   1.136 +}
   1.137 +
   1.138 +function onPropUpdateError(aEvent, aVar)
   1.139 +{
   1.140 +  info("onPropUpdateError");
   1.141 +
   1.142 +  let para = content.wrappedJSObject.document.querySelector("p");
   1.143 +  let expectedValue = content.document.title + content.location + para;
   1.144 +
   1.145 +  // Make sure the property did not change.
   1.146 +  findVariableViewProperties(aVar, [
   1.147 +    { name: "testUpdatedProp", value: expectedValue },
   1.148 +  ], { webconsole: gWebConsole }).then(onRenamedTestPropFoundAgain);
   1.149 +}
   1.150 +
   1.151 +function onRenamedTestPropFoundAgain(aResults)
   1.152 +{
   1.153 +  let prop = aResults[0].matchedProp;
   1.154 +  ok(prop, "matched the renamed |testProp| property again");
   1.155 +
   1.156 +  let outputNode = gWebConsole.outputNode;
   1.157 +
   1.158 +  waitForMessages({
   1.159 +    webconsole: gWebConsole,
   1.160 +    messages: [{
   1.161 +      name: "exception in property update reported in the web console output",
   1.162 +      text: "foobarzFailure",
   1.163 +      category: CATEGORY_OUTPUT,
   1.164 +      severity: SEVERITY_ERROR,
   1.165 +    }],
   1.166 +  }).then(testPropDelete.bind(null, prop));
   1.167 +}
   1.168 +
   1.169 +function testPropDelete(aProp)
   1.170 +{
   1.171 +  gVariablesView.window.focus();
   1.172 +  aProp.focus();
   1.173 +
   1.174 +  executeSoon(() => {
   1.175 +    EventUtils.synthesizeKey("VK_DELETE", {}, gVariablesView.window);
   1.176 +    gWebConsole = gJSTerm = gVariablesView = null;
   1.177 +  });
   1.178 +
   1.179 +  waitForSuccess({
   1.180 +    name: "property deleted",
   1.181 +    timeout: 60000,
   1.182 +    validatorFn: () => !("testUpdatedProp" in content.wrappedJSObject.fooObj),
   1.183 +    successFn: finishTest,
   1.184 +    failureFn: finishTest,
   1.185 +  });
   1.186 +}

mercurial