Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
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 | // Test the functionality of the BreakpointStore object. |
michael@0 | 6 | |
michael@0 | 7 | function run_test() |
michael@0 | 8 | { |
michael@0 | 9 | Cu.import("resource://gre/modules/jsdebugger.jsm"); |
michael@0 | 10 | addDebuggerToGlobal(this); |
michael@0 | 11 | let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"] |
michael@0 | 12 | .getService(Components.interfaces.mozIJSSubScriptLoader); |
michael@0 | 13 | loader.loadSubScript("resource://gre/modules/devtools/server/actors/script.js"); |
michael@0 | 14 | |
michael@0 | 15 | test_has_breakpoint(); |
michael@0 | 16 | test_bug_754251(); |
michael@0 | 17 | test_add_breakpoint(); |
michael@0 | 18 | test_remove_breakpoint(); |
michael@0 | 19 | test_find_breakpoints(); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | function test_has_breakpoint() { |
michael@0 | 23 | let bpStore = new BreakpointStore(); |
michael@0 | 24 | let location = { |
michael@0 | 25 | url: "http://example.com/foo.js", |
michael@0 | 26 | line: 3 |
michael@0 | 27 | }; |
michael@0 | 28 | let columnLocation = { |
michael@0 | 29 | url: "http://example.com/bar.js", |
michael@0 | 30 | line: 5, |
michael@0 | 31 | column: 15 |
michael@0 | 32 | }; |
michael@0 | 33 | |
michael@0 | 34 | // Shouldn't have breakpoint |
michael@0 | 35 | do_check_eq(null, bpStore.hasBreakpoint(location), |
michael@0 | 36 | "Breakpoint not added and shouldn't exist."); |
michael@0 | 37 | |
michael@0 | 38 | bpStore.addBreakpoint(location); |
michael@0 | 39 | do_check_true(!!bpStore.hasBreakpoint(location), |
michael@0 | 40 | "Breakpoint added but not found in Breakpoint Store."); |
michael@0 | 41 | |
michael@0 | 42 | bpStore.removeBreakpoint(location); |
michael@0 | 43 | do_check_eq(null, bpStore.hasBreakpoint(location), |
michael@0 | 44 | "Breakpoint removed but still exists."); |
michael@0 | 45 | |
michael@0 | 46 | // Same checks for breakpoint with a column |
michael@0 | 47 | do_check_eq(null, bpStore.hasBreakpoint(columnLocation), |
michael@0 | 48 | "Breakpoint with column not added and shouldn't exist."); |
michael@0 | 49 | |
michael@0 | 50 | bpStore.addBreakpoint(columnLocation); |
michael@0 | 51 | do_check_true(!!bpStore.hasBreakpoint(columnLocation), |
michael@0 | 52 | "Breakpoint with column added but not found in Breakpoint Store."); |
michael@0 | 53 | |
michael@0 | 54 | bpStore.removeBreakpoint(columnLocation); |
michael@0 | 55 | do_check_eq(null, bpStore.hasBreakpoint(columnLocation), |
michael@0 | 56 | "Breakpoint with column removed but still exists in Breakpoint Store."); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | // Note: Removing this test will regress bug 754251. See comment above |
michael@0 | 60 | // ThreadActor.breakpointStore. |
michael@0 | 61 | function test_bug_754251() { |
michael@0 | 62 | let instance1 = new ThreadActor(); |
michael@0 | 63 | let instance2 = new ThreadActor(); |
michael@0 | 64 | do_check_true(instance1.breakpointStore instanceof BreakpointStore); |
michael@0 | 65 | do_check_eq(instance1.breakpointStore, ThreadActor.breakpointStore); |
michael@0 | 66 | do_check_eq(instance2.breakpointStore, ThreadActor.breakpointStore); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | function test_add_breakpoint() { |
michael@0 | 70 | // Breakpoint with column |
michael@0 | 71 | let bpStore = new BreakpointStore(); |
michael@0 | 72 | let location = { |
michael@0 | 73 | url: "http://example.com/foo.js", |
michael@0 | 74 | line: 10, |
michael@0 | 75 | column: 9 |
michael@0 | 76 | }; |
michael@0 | 77 | bpStore.addBreakpoint(location); |
michael@0 | 78 | do_check_true(!!bpStore.hasBreakpoint(location), |
michael@0 | 79 | "We should have the column breakpoint we just added"); |
michael@0 | 80 | |
michael@0 | 81 | // Breakpoint without column (whole line breakpoint) |
michael@0 | 82 | location = { |
michael@0 | 83 | url: "http://example.com/bar.js", |
michael@0 | 84 | line: 103 |
michael@0 | 85 | }; |
michael@0 | 86 | bpStore.addBreakpoint(location); |
michael@0 | 87 | do_check_true(!!bpStore.hasBreakpoint(location), |
michael@0 | 88 | "We should have the whole line breakpoint we just added"); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | function test_remove_breakpoint() { |
michael@0 | 92 | // Breakpoint with column |
michael@0 | 93 | let bpStore = new BreakpointStore(); |
michael@0 | 94 | let location = { |
michael@0 | 95 | url: "http://example.com/foo.js", |
michael@0 | 96 | line: 10, |
michael@0 | 97 | column: 9 |
michael@0 | 98 | }; |
michael@0 | 99 | bpStore.addBreakpoint(location); |
michael@0 | 100 | bpStore.removeBreakpoint(location); |
michael@0 | 101 | do_check_eq(bpStore.hasBreakpoint(location), null, |
michael@0 | 102 | "We should not have the column breakpoint anymore"); |
michael@0 | 103 | |
michael@0 | 104 | // Breakpoint without column (whole line breakpoint) |
michael@0 | 105 | location = { |
michael@0 | 106 | url: "http://example.com/bar.js", |
michael@0 | 107 | line: 103 |
michael@0 | 108 | }; |
michael@0 | 109 | bpStore.addBreakpoint(location); |
michael@0 | 110 | bpStore.removeBreakpoint(location); |
michael@0 | 111 | do_check_eq(bpStore.hasBreakpoint(location), null, |
michael@0 | 112 | "We should not have the whole line breakpoint anymore"); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | function test_find_breakpoints() { |
michael@0 | 116 | let bps = [ |
michael@0 | 117 | { url: "foo.js", line: 10 }, |
michael@0 | 118 | { url: "foo.js", line: 10, column: 3 }, |
michael@0 | 119 | { url: "foo.js", line: 10, column: 10 }, |
michael@0 | 120 | { url: "foo.js", line: 23, column: 89 }, |
michael@0 | 121 | { url: "bar.js", line: 10, column: 1 }, |
michael@0 | 122 | { url: "bar.js", line: 20, column: 5 }, |
michael@0 | 123 | { url: "bar.js", line: 30, column: 34 }, |
michael@0 | 124 | { url: "bar.js", line: 40, column: 56 } |
michael@0 | 125 | ]; |
michael@0 | 126 | |
michael@0 | 127 | let bpStore = new BreakpointStore(); |
michael@0 | 128 | |
michael@0 | 129 | for (let bp of bps) { |
michael@0 | 130 | bpStore.addBreakpoint(bp); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | // All breakpoints |
michael@0 | 134 | |
michael@0 | 135 | let bpSet = Set(bps); |
michael@0 | 136 | for (let bp of bpStore.findBreakpoints()) { |
michael@0 | 137 | bpSet.delete(bp); |
michael@0 | 138 | } |
michael@0 | 139 | do_check_eq(bpSet.size, 0, |
michael@0 | 140 | "Should be able to iterate over all breakpoints"); |
michael@0 | 141 | |
michael@0 | 142 | // Breakpoints by URL |
michael@0 | 143 | |
michael@0 | 144 | bpSet = Set(bps.filter(bp => { return bp.url === "foo.js" })); |
michael@0 | 145 | for (let bp of bpStore.findBreakpoints({ url: "foo.js" })) { |
michael@0 | 146 | bpSet.delete(bp); |
michael@0 | 147 | } |
michael@0 | 148 | do_check_eq(bpSet.size, 0, |
michael@0 | 149 | "Should be able to filter the iteration by url"); |
michael@0 | 150 | |
michael@0 | 151 | // Breakpoints by URL and line |
michael@0 | 152 | |
michael@0 | 153 | bpSet = Set(bps.filter(bp => { return bp.url === "foo.js" && bp.line === 10; })); |
michael@0 | 154 | let first = true; |
michael@0 | 155 | for (let bp of bpStore.findBreakpoints({ url: "foo.js", line: 10 })) { |
michael@0 | 156 | if (first) { |
michael@0 | 157 | do_check_eq(bp.column, undefined, |
michael@0 | 158 | "Should always get the whole line breakpoint first"); |
michael@0 | 159 | first = false; |
michael@0 | 160 | } else { |
michael@0 | 161 | do_check_neq(bp.column, undefined, |
michael@0 | 162 | "Should not get the whole line breakpoint any time other than first."); |
michael@0 | 163 | } |
michael@0 | 164 | bpSet.delete(bp); |
michael@0 | 165 | } |
michael@0 | 166 | do_check_eq(bpSet.size, 0, |
michael@0 | 167 | "Should be able to filter the iteration by url and line"); |
michael@0 | 168 | } |