michael@0: /* -*- Mode: js; js-indent-level: 2; -*- */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Test the functionality of the BreakpointStore object. michael@0: michael@0: function run_test() michael@0: { michael@0: Cu.import("resource://gre/modules/jsdebugger.jsm"); michael@0: addDebuggerToGlobal(this); michael@0: let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"] michael@0: .getService(Components.interfaces.mozIJSSubScriptLoader); michael@0: loader.loadSubScript("resource://gre/modules/devtools/server/actors/script.js"); michael@0: michael@0: test_has_breakpoint(); michael@0: test_bug_754251(); michael@0: test_add_breakpoint(); michael@0: test_remove_breakpoint(); michael@0: test_find_breakpoints(); michael@0: } michael@0: michael@0: function test_has_breakpoint() { michael@0: let bpStore = new BreakpointStore(); michael@0: let location = { michael@0: url: "http://example.com/foo.js", michael@0: line: 3 michael@0: }; michael@0: let columnLocation = { michael@0: url: "http://example.com/bar.js", michael@0: line: 5, michael@0: column: 15 michael@0: }; michael@0: michael@0: // Shouldn't have breakpoint michael@0: do_check_eq(null, bpStore.hasBreakpoint(location), michael@0: "Breakpoint not added and shouldn't exist."); michael@0: michael@0: bpStore.addBreakpoint(location); michael@0: do_check_true(!!bpStore.hasBreakpoint(location), michael@0: "Breakpoint added but not found in Breakpoint Store."); michael@0: michael@0: bpStore.removeBreakpoint(location); michael@0: do_check_eq(null, bpStore.hasBreakpoint(location), michael@0: "Breakpoint removed but still exists."); michael@0: michael@0: // Same checks for breakpoint with a column michael@0: do_check_eq(null, bpStore.hasBreakpoint(columnLocation), michael@0: "Breakpoint with column not added and shouldn't exist."); michael@0: michael@0: bpStore.addBreakpoint(columnLocation); michael@0: do_check_true(!!bpStore.hasBreakpoint(columnLocation), michael@0: "Breakpoint with column added but not found in Breakpoint Store."); michael@0: michael@0: bpStore.removeBreakpoint(columnLocation); michael@0: do_check_eq(null, bpStore.hasBreakpoint(columnLocation), michael@0: "Breakpoint with column removed but still exists in Breakpoint Store."); michael@0: } michael@0: michael@0: // Note: Removing this test will regress bug 754251. See comment above michael@0: // ThreadActor.breakpointStore. michael@0: function test_bug_754251() { michael@0: let instance1 = new ThreadActor(); michael@0: let instance2 = new ThreadActor(); michael@0: do_check_true(instance1.breakpointStore instanceof BreakpointStore); michael@0: do_check_eq(instance1.breakpointStore, ThreadActor.breakpointStore); michael@0: do_check_eq(instance2.breakpointStore, ThreadActor.breakpointStore); michael@0: } michael@0: michael@0: function test_add_breakpoint() { michael@0: // Breakpoint with column michael@0: let bpStore = new BreakpointStore(); michael@0: let location = { michael@0: url: "http://example.com/foo.js", michael@0: line: 10, michael@0: column: 9 michael@0: }; michael@0: bpStore.addBreakpoint(location); michael@0: do_check_true(!!bpStore.hasBreakpoint(location), michael@0: "We should have the column breakpoint we just added"); michael@0: michael@0: // Breakpoint without column (whole line breakpoint) michael@0: location = { michael@0: url: "http://example.com/bar.js", michael@0: line: 103 michael@0: }; michael@0: bpStore.addBreakpoint(location); michael@0: do_check_true(!!bpStore.hasBreakpoint(location), michael@0: "We should have the whole line breakpoint we just added"); michael@0: } michael@0: michael@0: function test_remove_breakpoint() { michael@0: // Breakpoint with column michael@0: let bpStore = new BreakpointStore(); michael@0: let location = { michael@0: url: "http://example.com/foo.js", michael@0: line: 10, michael@0: column: 9 michael@0: }; michael@0: bpStore.addBreakpoint(location); michael@0: bpStore.removeBreakpoint(location); michael@0: do_check_eq(bpStore.hasBreakpoint(location), null, michael@0: "We should not have the column breakpoint anymore"); michael@0: michael@0: // Breakpoint without column (whole line breakpoint) michael@0: location = { michael@0: url: "http://example.com/bar.js", michael@0: line: 103 michael@0: }; michael@0: bpStore.addBreakpoint(location); michael@0: bpStore.removeBreakpoint(location); michael@0: do_check_eq(bpStore.hasBreakpoint(location), null, michael@0: "We should not have the whole line breakpoint anymore"); michael@0: } michael@0: michael@0: function test_find_breakpoints() { michael@0: let bps = [ michael@0: { url: "foo.js", line: 10 }, michael@0: { url: "foo.js", line: 10, column: 3 }, michael@0: { url: "foo.js", line: 10, column: 10 }, michael@0: { url: "foo.js", line: 23, column: 89 }, michael@0: { url: "bar.js", line: 10, column: 1 }, michael@0: { url: "bar.js", line: 20, column: 5 }, michael@0: { url: "bar.js", line: 30, column: 34 }, michael@0: { url: "bar.js", line: 40, column: 56 } michael@0: ]; michael@0: michael@0: let bpStore = new BreakpointStore(); michael@0: michael@0: for (let bp of bps) { michael@0: bpStore.addBreakpoint(bp); michael@0: } michael@0: michael@0: // All breakpoints michael@0: michael@0: let bpSet = Set(bps); michael@0: for (let bp of bpStore.findBreakpoints()) { michael@0: bpSet.delete(bp); michael@0: } michael@0: do_check_eq(bpSet.size, 0, michael@0: "Should be able to iterate over all breakpoints"); michael@0: michael@0: // Breakpoints by URL michael@0: michael@0: bpSet = Set(bps.filter(bp => { return bp.url === "foo.js" })); michael@0: for (let bp of bpStore.findBreakpoints({ url: "foo.js" })) { michael@0: bpSet.delete(bp); michael@0: } michael@0: do_check_eq(bpSet.size, 0, michael@0: "Should be able to filter the iteration by url"); michael@0: michael@0: // Breakpoints by URL and line michael@0: michael@0: bpSet = Set(bps.filter(bp => { return bp.url === "foo.js" && bp.line === 10; })); michael@0: let first = true; michael@0: for (let bp of bpStore.findBreakpoints({ url: "foo.js", line: 10 })) { michael@0: if (first) { michael@0: do_check_eq(bp.column, undefined, michael@0: "Should always get the whole line breakpoint first"); michael@0: first = false; michael@0: } else { michael@0: do_check_neq(bp.column, undefined, michael@0: "Should not get the whole line breakpoint any time other than first."); michael@0: } michael@0: bpSet.delete(bp); michael@0: } michael@0: do_check_eq(bpSet.size, 0, michael@0: "Should be able to filter the iteration by url and line"); michael@0: }