toolkit/devtools/server/tests/unit/test_blackboxing-01.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * Test basic black boxing.
michael@0 6 */
michael@0 7
michael@0 8 var gDebuggee;
michael@0 9 var gClient;
michael@0 10 var gThreadClient;
michael@0 11
michael@0 12 function run_test()
michael@0 13 {
michael@0 14 initTestDebuggerServer();
michael@0 15 gDebuggee = addTestGlobal("test-black-box");
michael@0 16 gClient = new DebuggerClient(DebuggerServer.connectPipe());
michael@0 17 gClient.connect(function() {
michael@0 18 attachTestTabAndResume(gClient, "test-black-box", function(aResponse, aTabClient, aThreadClient) {
michael@0 19 gThreadClient = aThreadClient;
michael@0 20 test_black_box();
michael@0 21 });
michael@0 22 });
michael@0 23 do_test_pending();
michael@0 24 }
michael@0 25
michael@0 26 const BLACK_BOXED_URL = "http://example.com/blackboxme.js";
michael@0 27 const SOURCE_URL = "http://example.com/source.js";
michael@0 28
michael@0 29 function test_black_box()
michael@0 30 {
michael@0 31 gClient.addOneTimeListener("paused", function () {
michael@0 32 gThreadClient.setBreakpoint({
michael@0 33 url: SOURCE_URL,
michael@0 34 line: 2
michael@0 35 }, function (aResponse) {
michael@0 36 do_check_true(!aResponse.error, "Should be able to set breakpoint.");
michael@0 37 gThreadClient.resume(test_black_box_default);
michael@0 38 });
michael@0 39 });
michael@0 40
michael@0 41 Components.utils.evalInSandbox(
michael@0 42 "" + function doStuff(k) { // line 1
michael@0 43 let arg = 15; // line 2 - Step in here
michael@0 44 k(arg); // line 3
michael@0 45 }, // line 4
michael@0 46 gDebuggee,
michael@0 47 "1.8",
michael@0 48 BLACK_BOXED_URL,
michael@0 49 1
michael@0 50 );
michael@0 51
michael@0 52 Components.utils.evalInSandbox(
michael@0 53 "" + function runTest() { // line 1
michael@0 54 doStuff( // line 2 - Break here
michael@0 55 function (n) { // line 3 - Step through `doStuff` to here
michael@0 56 debugger; // line 5
michael@0 57 } // line 6
michael@0 58 ); // line 7
michael@0 59 } // line 8
michael@0 60 + "\n debugger;", // line 9
michael@0 61 gDebuggee,
michael@0 62 "1.8",
michael@0 63 SOURCE_URL,
michael@0 64 1
michael@0 65 );
michael@0 66 }
michael@0 67
michael@0 68 function test_black_box_default() {
michael@0 69 gThreadClient.getSources(function (aResponse) {
michael@0 70 do_check_true(!aResponse.error, "Should be able to get sources.");
michael@0 71
michael@0 72 let sourceClient = gThreadClient.source(
michael@0 73 aResponse.sources.filter(s => s.url == BLACK_BOXED_URL)[0]);
michael@0 74 do_check_true(!sourceClient.isBlackBoxed,
michael@0 75 "By default the source is not black boxed.");
michael@0 76
michael@0 77 // Test that we can step into `doStuff` when we are not black boxed.
michael@0 78 runTest(
michael@0 79 function onSteppedLocation(aLocation) {
michael@0 80 do_check_eq(aLocation.url, BLACK_BOXED_URL,
michael@0 81 "Should step into `doStuff`.");
michael@0 82 do_check_eq(aLocation.line, 2,
michael@0 83 "Should step into `doStuff`.");
michael@0 84 },
michael@0 85 function onDebuggerStatementFrames(aFrames) {
michael@0 86 do_check_true(!aFrames.some(f => f.source.isBlackBoxed));
michael@0 87 },
michael@0 88 test_black_boxing.bind(null, sourceClient)
michael@0 89 );
michael@0 90 });
michael@0 91 }
michael@0 92
michael@0 93 function test_black_boxing(aSourceClient) {
michael@0 94 aSourceClient.blackBox(function (aResponse) {
michael@0 95 do_check_true(!aResponse.error, "Should not get an error black boxing.");
michael@0 96 do_check_true(aSourceClient.isBlackBoxed,
michael@0 97 "The source client should report itself as black boxed correctly.");
michael@0 98
michael@0 99 // Test that we step through `doStuff` when we are black boxed and its frame
michael@0 100 // doesn't show up.
michael@0 101 runTest(
michael@0 102 function onSteppedLocation(aLocation) {
michael@0 103 do_check_eq(aLocation.url, SOURCE_URL,
michael@0 104 "Should step through `doStuff`.");
michael@0 105 do_check_eq(aLocation.line, 3,
michael@0 106 "Should step through `doStuff`.");
michael@0 107 },
michael@0 108 function onDebuggerStatementFrames(aFrames) {
michael@0 109 for (let f of aFrames) {
michael@0 110 if (f.where.url == BLACK_BOXED_URL) {
michael@0 111 do_check_true(f.source.isBlackBoxed, "Should be black boxed");
michael@0 112 } else {
michael@0 113 do_check_true(!f.source.isBlackBoxed, "Should not be black boxed")
michael@0 114 }
michael@0 115 }
michael@0 116 },
michael@0 117 test_unblack_boxing.bind(null, aSourceClient)
michael@0 118 );
michael@0 119 });
michael@0 120 }
michael@0 121
michael@0 122 function test_unblack_boxing(aSourceClient) {
michael@0 123 aSourceClient.unblackBox(function (aResponse) {
michael@0 124 do_check_true(!aResponse.error, "Should not get an error un-black boxing");
michael@0 125 do_check_true(!aSourceClient.isBlackBoxed, "The source is not black boxed.");
michael@0 126
michael@0 127 // Test that we can step into `doStuff` again.
michael@0 128 runTest(
michael@0 129 function onSteppedLocation(aLocation) {
michael@0 130 do_check_eq(aLocation.url, BLACK_BOXED_URL,
michael@0 131 "Should step into `doStuff`.");
michael@0 132 do_check_eq(aLocation.line, 2,
michael@0 133 "Should step into `doStuff`.");
michael@0 134 },
michael@0 135 function onDebuggerStatementFrames(aFrames) {
michael@0 136 do_check_true(!aFrames.some(f => f.source.isBlackBoxed));
michael@0 137 },
michael@0 138 finishClient.bind(null, gClient)
michael@0 139 );
michael@0 140 });
michael@0 141 }
michael@0 142
michael@0 143 function runTest(aOnSteppedLocation, aOnDebuggerStatementFrames, aFinishedCallback) {
michael@0 144 gClient.addOneTimeListener("paused", function (aEvent, aPacket) {
michael@0 145 do_check_eq(aPacket.why.type, "breakpoint");
michael@0 146 gClient.addOneTimeListener("paused", function () {
michael@0 147 gClient.addOneTimeListener("paused", function () {
michael@0 148 getCurrentLocation(function (aLocation) {
michael@0 149 aOnSteppedLocation(aLocation);
michael@0 150 gClient.addOneTimeListener("paused", function (aEvent, aPacket) {
michael@0 151 do_check_eq(aPacket.why.type, "debuggerStatement");
michael@0 152 gThreadClient.getFrames(0, 100, function ({frames}) {
michael@0 153 aOnDebuggerStatementFrames(frames);
michael@0 154 gThreadClient.resume(aFinishedCallback);
michael@0 155 });
michael@0 156 });
michael@0 157 gThreadClient.resume();
michael@0 158 });
michael@0 159 });
michael@0 160 gThreadClient.stepIn();
michael@0 161 });
michael@0 162 gThreadClient.stepIn();
michael@0 163 });
michael@0 164
michael@0 165 gDebuggee.runTest();
michael@0 166 }
michael@0 167
michael@0 168 function getCurrentLocation(aCallback) {
michael@0 169 gThreadClient.getFrames(0, 1, function ({frames, error}) {
michael@0 170 do_check_true(!error, "Should not get an error: " + error);
michael@0 171 let [{where}] = frames;
michael@0 172 aCallback(where);
michael@0 173 });
michael@0 174 }

mercurial