browser/devtools/debugger/test/browser_dbg_breakpoints-contextmenu.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/debugger/test/browser_dbg_breakpoints-contextmenu.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,327 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Test if the context menu associated with each breakpoint does what it should.
     1.9 + */
    1.10 +
    1.11 +const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
    1.12 +
    1.13 +function test() {
    1.14 +  // Debug test slaves are a bit slow at this test.
    1.15 +  requestLongerTimeout(2);
    1.16 +
    1.17 +  let gTab, gDebuggee, gPanel, gDebugger;
    1.18 +  let gSources, gBreakpoints;
    1.19 +
    1.20 +  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    1.21 +    gTab = aTab;
    1.22 +    gDebuggee = aDebuggee;
    1.23 +    gPanel = aPanel;
    1.24 +    gDebugger = gPanel.panelWin;
    1.25 +    gSources = gDebugger.DebuggerView.Sources;
    1.26 +    gBreakpoints = gDebugger.DebuggerController.Breakpoints;
    1.27 +
    1.28 +    waitForSourceShown(gPanel, "-01.js")
    1.29 +      .then(performTestWhileNotPaused)
    1.30 +      .then(performTestWhilePaused)
    1.31 +      .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
    1.32 +      .then(null, aError => {
    1.33 +        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    1.34 +      });
    1.35 +  });
    1.36 +
    1.37 +  function addBreakpoints() {
    1.38 +    return promise.resolve(null)
    1.39 +      .then(() => gPanel.addBreakpoint({ url: gSources.values[0], line: 5 }))
    1.40 +      .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 6 }))
    1.41 +      .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 7 }))
    1.42 +      .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 8 }))
    1.43 +      .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 9 }))
    1.44 +      .then(() => ensureThreadClientState(gPanel, "resumed"));
    1.45 +  }
    1.46 +
    1.47 +  function performTestWhileNotPaused() {
    1.48 +    info("Performing test while not paused...");
    1.49 +
    1.50 +    return addBreakpoints()
    1.51 +      .then(initialChecks)
    1.52 +      .then(() => checkBreakpointToggleSelf(0))
    1.53 +      .then(() => checkBreakpointToggleOthers(0))
    1.54 +      .then(() => checkBreakpointToggleSelf(1))
    1.55 +      .then(() => checkBreakpointToggleOthers(1))
    1.56 +      .then(() => checkBreakpointToggleSelf(2))
    1.57 +      .then(() => checkBreakpointToggleOthers(2))
    1.58 +      .then(() => checkBreakpointToggleSelf(3))
    1.59 +      .then(() => checkBreakpointToggleOthers(3))
    1.60 +      .then(() => checkBreakpointToggleSelf(4))
    1.61 +      .then(() => checkBreakpointToggleOthers(4))
    1.62 +      .then(testDeleteAll);
    1.63 +  }
    1.64 +
    1.65 +  function performTestWhilePaused() {
    1.66 +    info("Performing test while paused...");
    1.67 +
    1.68 +    return addBreakpoints()
    1.69 +      .then(initialChecks)
    1.70 +      .then(pauseAndCheck)
    1.71 +      .then(() => checkBreakpointToggleSelf(0))
    1.72 +      .then(() => checkBreakpointToggleOthers(0))
    1.73 +      .then(() => checkBreakpointToggleSelf(1))
    1.74 +      .then(() => checkBreakpointToggleOthers(1))
    1.75 +      .then(() => checkBreakpointToggleSelf(2))
    1.76 +      .then(() => checkBreakpointToggleOthers(2))
    1.77 +      .then(() => checkBreakpointToggleSelf(3))
    1.78 +      .then(() => checkBreakpointToggleOthers(3))
    1.79 +      .then(() => checkBreakpointToggleSelf(4))
    1.80 +      .then(() => checkBreakpointToggleOthers(4))
    1.81 +      .then(testDeleteAll);
    1.82 +  }
    1.83 +
    1.84 +  function pauseAndCheck() {
    1.85 +    let finished = waitForSourceAndCaretAndScopes(gPanel, "-01.js", 5).then(() => {
    1.86 +      is(gSources.selectedValue, EXAMPLE_URL + "code_script-switching-01.js",
    1.87 +        "The currently selected source is incorrect (3).");
    1.88 +      is(gSources.selectedIndex, 0,
    1.89 +        "The currently selected source is incorrect (4).");
    1.90 +      ok(isCaretPos(gPanel, 5),
    1.91 +        "The editor location is correct after pausing.");
    1.92 +    });
    1.93 +
    1.94 +    is(gSources.selectedValue, EXAMPLE_URL + "code_script-switching-02.js",
    1.95 +      "The currently selected source is incorrect (1).");
    1.96 +    is(gSources.selectedIndex, 1,
    1.97 +      "The currently selected source is incorrect (2).");
    1.98 +    ok(isCaretPos(gPanel, 9),
    1.99 +      "The editor location is correct before pausing.");
   1.100 +
   1.101 +    // Spin the event loop before causing the debuggee to pause, to allow
   1.102 +    // this function to return first.
   1.103 +    executeSoon(() => {
   1.104 +      EventUtils.sendMouseEvent({ type: "click" },
   1.105 +        gDebuggee.document.querySelector("button"),
   1.106 +        gDebuggee);
   1.107 +    });
   1.108 +
   1.109 +    return finished;
   1.110 +  }
   1.111 +
   1.112 +  function initialChecks() {
   1.113 +    for (let source of gSources) {
   1.114 +      for (let breakpoint of source) {
   1.115 +        ok(gBreakpoints._getAdded(breakpoint.attachment),
   1.116 +          "All breakpoint items should have corresponding promises (1).");
   1.117 +        ok(!gBreakpoints._getRemoving(breakpoint.attachment),
   1.118 +          "All breakpoint items should have corresponding promises (2).");
   1.119 +        ok(breakpoint.attachment.actor,
   1.120 +          "All breakpoint items should have corresponding promises (3).");
   1.121 +        is(!!breakpoint.attachment.disabled, false,
   1.122 +          "All breakpoints should initially be enabled.");
   1.123 +
   1.124 +        let prefix = "bp-cMenu-"; // "breakpoints context menu"
   1.125 +        let identifier = gBreakpoints.getIdentifier(breakpoint.attachment);
   1.126 +        let enableSelfId = prefix + "enableSelf-" + identifier + "-menuitem";
   1.127 +        let disableSelfId = prefix + "disableSelf-" + identifier + "-menuitem";
   1.128 +
   1.129 +        is(gDebugger.document.getElementById(enableSelfId).getAttribute("hidden"), "true",
   1.130 +          "The 'Enable breakpoint' context menu item should initially be hidden'.");
   1.131 +        ok(!gDebugger.document.getElementById(disableSelfId).hasAttribute("hidden"),
   1.132 +          "The 'Disable breakpoint' context menu item should initially not be hidden'.");
   1.133 +        is(breakpoint.attachment.view.checkbox.getAttribute("checked"), "true",
   1.134 +          "All breakpoints should initially have a checked checkbox.");
   1.135 +      }
   1.136 +    }
   1.137 +  }
   1.138 +
   1.139 +  function checkBreakpointToggleSelf(aIndex) {
   1.140 +    let deferred = promise.defer();
   1.141 +
   1.142 +    EventUtils.sendMouseEvent({ type: "click" },
   1.143 +      gDebugger.document.querySelectorAll(".dbg-breakpoint")[aIndex],
   1.144 +      gDebugger);
   1.145 +
   1.146 +    let selectedBreakpoint = gSources._selectedBreakpointItem;
   1.147 +
   1.148 +    ok(gBreakpoints._getAdded(selectedBreakpoint.attachment),
   1.149 +      "There should be a breakpoint client available (1).");
   1.150 +    ok(!gBreakpoints._getRemoving(selectedBreakpoint.attachment),
   1.151 +      "There should be a breakpoint client available (2).");
   1.152 +    ok(selectedBreakpoint.attachment.actor,
   1.153 +      "There should be a breakpoint client available (3).");
   1.154 +    is(!!selectedBreakpoint.attachment.disabled, false,
   1.155 +      "The breakpoint should not be disabled yet (" + aIndex + ").");
   1.156 +
   1.157 +    gBreakpoints._getAdded(selectedBreakpoint.attachment).then(aBreakpointClient => {
   1.158 +      ok(aBreakpointClient,
   1.159 +        "There should be a breakpoint client available as a promise.");
   1.160 +    });
   1.161 +
   1.162 +    let prefix = "bp-cMenu-"; // "breakpoints context menu"
   1.163 +    let identifier = gBreakpoints.getIdentifier(selectedBreakpoint.attachment);
   1.164 +    let enableSelfId = prefix + "enableSelf-" + identifier + "-menuitem";
   1.165 +    let disableSelfId = prefix + "disableSelf-" + identifier + "-menuitem";
   1.166 +
   1.167 +    is(gDebugger.document.getElementById(enableSelfId).getAttribute("hidden"), "true",
   1.168 +      "The 'Enable breakpoint' context menu item should be hidden'.");
   1.169 +    ok(!gDebugger.document.getElementById(disableSelfId).hasAttribute("hidden"),
   1.170 +      "The 'Disable breakpoint' context menu item should not be hidden'.");
   1.171 +
   1.172 +    ok(isCaretPos(gPanel, selectedBreakpoint.attachment.line),
   1.173 +      "The source editor caret position was incorrect (" + aIndex + ").");
   1.174 +
   1.175 +    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_REMOVED).then(() => {
   1.176 +      ok(!gBreakpoints._getAdded(selectedBreakpoint.attachment),
   1.177 +        "There should be no breakpoint client available (4).");
   1.178 +
   1.179 +      waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_ADDED).then(() => {
   1.180 +        ok(gBreakpoints._getAdded(selectedBreakpoint.attachment),
   1.181 +          "There should be a breakpoint client available (5).");
   1.182 +
   1.183 +        deferred.resolve();
   1.184 +      });
   1.185 +
   1.186 +      // Test re-disabling this breakpoint.
   1.187 +      gSources._onEnableSelf(selectedBreakpoint.attachment);
   1.188 +      is(selectedBreakpoint.attachment.disabled, false,
   1.189 +        "The current breakpoint should now be enabled.")
   1.190 +
   1.191 +      is(gDebugger.document.getElementById(enableSelfId).getAttribute("hidden"), "true",
   1.192 +        "The 'Enable breakpoint' context menu item should be hidden'.");
   1.193 +      ok(!gDebugger.document.getElementById(disableSelfId).hasAttribute("hidden"),
   1.194 +        "The 'Disable breakpoint' context menu item should not be hidden'.");
   1.195 +      ok(selectedBreakpoint.attachment.view.checkbox.hasAttribute("checked"),
   1.196 +        "The breakpoint should now be checked.");
   1.197 +    });
   1.198 +
   1.199 +    // Test disabling this breakpoint.
   1.200 +    gSources._onDisableSelf(selectedBreakpoint.attachment);
   1.201 +    is(selectedBreakpoint.attachment.disabled, true,
   1.202 +      "The current breakpoint should now be disabled.")
   1.203 +
   1.204 +    ok(!gDebugger.document.getElementById(enableSelfId).hasAttribute("hidden"),
   1.205 +      "The 'Enable breakpoint' context menu item should not be hidden'.");
   1.206 +    is(gDebugger.document.getElementById(disableSelfId).getAttribute("hidden"), "true",
   1.207 +      "The 'Disable breakpoint' context menu item should be hidden'.");
   1.208 +    ok(!selectedBreakpoint.attachment.view.checkbox.hasAttribute("checked"),
   1.209 +      "The breakpoint should now be unchecked.");
   1.210 +
   1.211 +    return deferred.promise;
   1.212 +  }
   1.213 +
   1.214 +  function checkBreakpointToggleOthers(aIndex) {
   1.215 +    let deferred = promise.defer();
   1.216 +
   1.217 +    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_REMOVED, 4).then(() => {
   1.218 +      let selectedBreakpoint = gSources._selectedBreakpointItem;
   1.219 +
   1.220 +      ok(gBreakpoints._getAdded(selectedBreakpoint.attachment),
   1.221 +        "There should be a breakpoint client available (6).");
   1.222 +      ok(!gBreakpoints._getRemoving(selectedBreakpoint.attachment),
   1.223 +        "There should be a breakpoint client available (7).");
   1.224 +      ok(selectedBreakpoint.attachment.actor,
   1.225 +        "There should be a breakpoint client available (8).");
   1.226 +      is(!!selectedBreakpoint.attachment.disabled, false,
   1.227 +        "The targetted breakpoint should not have been disabled (" + aIndex + ").");
   1.228 +
   1.229 +      for (let source of gSources) {
   1.230 +        for (let otherBreakpoint of source) {
   1.231 +          if (otherBreakpoint != selectedBreakpoint) {
   1.232 +            ok(!gBreakpoints._getAdded(otherBreakpoint.attachment),
   1.233 +              "There should be no breakpoint client for a disabled breakpoint (9).");
   1.234 +            is(otherBreakpoint.attachment.disabled, true,
   1.235 +              "Non-targetted breakpoints should have been disabled (10).");
   1.236 +          }
   1.237 +        }
   1.238 +      }
   1.239 +
   1.240 +      waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_ADDED, 4).then(() => {
   1.241 +        for (let source of gSources) {
   1.242 +          for (let someBreakpoint of source) {
   1.243 +            ok(gBreakpoints._getAdded(someBreakpoint.attachment),
   1.244 +              "There should be a breakpoint client for all enabled breakpoints (11).");
   1.245 +            is(someBreakpoint.attachment.disabled, false,
   1.246 +              "All breakpoints should now have been enabled (12).");
   1.247 +          }
   1.248 +        }
   1.249 +
   1.250 +        waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_REMOVED, 5).then(() => {
   1.251 +          for (let source of gSources) {
   1.252 +            for (let someBreakpoint of source) {
   1.253 +              ok(!gBreakpoints._getAdded(someBreakpoint.attachment),
   1.254 +                "There should be no breakpoint client for a disabled breakpoint (13).");
   1.255 +              is(someBreakpoint.attachment.disabled, true,
   1.256 +                "All breakpoints should now have been disabled (14).");
   1.257 +            }
   1.258 +          }
   1.259 +
   1.260 +          waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_ADDED, 5).then(() => {
   1.261 +            for (let source of gSources) {
   1.262 +              for (let someBreakpoint of source) {
   1.263 +                ok(gBreakpoints._getAdded(someBreakpoint.attachment),
   1.264 +                  "There should be a breakpoint client for all enabled breakpoints (15).");
   1.265 +                is(someBreakpoint.attachment.disabled, false,
   1.266 +                  "All breakpoints should now have been enabled (16).");
   1.267 +              }
   1.268 +            }
   1.269 +
   1.270 +            // Done.
   1.271 +            deferred.resolve();
   1.272 +          });
   1.273 +
   1.274 +          // Test re-enabling all breakpoints.
   1.275 +          enableAll();
   1.276 +        });
   1.277 +
   1.278 +        // Test disabling all breakpoints.
   1.279 +        disableAll();
   1.280 +      });
   1.281 +
   1.282 +      // Test re-enabling other breakpoints.
   1.283 +      enableOthers();
   1.284 +    });
   1.285 +
   1.286 +    // Test disabling other breakpoints.
   1.287 +    disableOthers();
   1.288 +
   1.289 +    return deferred.promise;
   1.290 +  }
   1.291 +
   1.292 +  function testDeleteAll() {
   1.293 +    let deferred = promise.defer();
   1.294 +
   1.295 +    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_REMOVED, 5).then(() => {
   1.296 +      ok(!gSources._selectedBreakpointItem,
   1.297 +        "There should be no breakpoint available after removing all breakpoints.");
   1.298 +
   1.299 +      for (let source of gSources) {
   1.300 +        for (let otherBreakpoint of source) {
   1.301 +          ok(false, "It's a trap!");
   1.302 +        }
   1.303 +      }
   1.304 +
   1.305 +      // Done.
   1.306 +      deferred.resolve()
   1.307 +    });
   1.308 +
   1.309 +    // Test deleting all breakpoints.
   1.310 +    deleteAll();
   1.311 +
   1.312 +    return deferred.promise;
   1.313 +  }
   1.314 +
   1.315 +  function disableOthers() {
   1.316 +    gSources._onDisableOthers(gSources._selectedBreakpointItem.attachment);
   1.317 +  }
   1.318 +  function enableOthers() {
   1.319 +    gSources._onEnableOthers(gSources._selectedBreakpointItem.attachment);
   1.320 +  }
   1.321 +  function disableAll() {
   1.322 +    gSources._onDisableAll();
   1.323 +  }
   1.324 +  function enableAll() {
   1.325 +    gSources._onEnableAll();
   1.326 +  }
   1.327 +  function deleteAll() {
   1.328 +    gSources._onDeleteAll();
   1.329 +  }
   1.330 +}

mercurial