toolkit/devtools/server/tests/unit/test_sourcemaps-09.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.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /**
     5  * Check that source maps and breakpoints work with minified javascript.
     6  */
     8 var gDebuggee;
     9 var gClient;
    10 var gThreadClient;
    12 Components.utils.import('resource:///modules/devtools/SourceMap.jsm');
    14 function run_test()
    15 {
    16   initTestDebuggerServer();
    17   gDebuggee = addTestGlobal("test-source-map");
    18   gClient = new DebuggerClient(DebuggerServer.connectPipe());
    19   gClient.connect(function() {
    20     attachTestTabAndResume(gClient, "test-source-map", function(aResponse, aTabClient, aThreadClient) {
    21       gThreadClient = aThreadClient;
    22       test_minified();
    23     });
    24   });
    25   do_test_pending();
    26 }
    28 function test_minified()
    29 {
    30   let newSourceFired = false;
    32   gClient.addOneTimeListener("newSource", function _onNewSource(aEvent, aPacket) {
    33     do_check_eq(aEvent, "newSource");
    34     do_check_eq(aPacket.type, "newSource");
    35     do_check_true(!!aPacket.source);
    37     do_check_eq(aPacket.source.url, "http://example.com/foo.js",
    38                 "The new source should be foo.js");
    39     do_check_eq(aPacket.source.url.indexOf("foo.min.js"), -1,
    40                 "The new source should not be the minified file");
    42     newSourceFired = true;
    43   });
    45   gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
    46     do_check_eq(aEvent, "paused");
    47     do_check_eq(aPacket.why.type, "debuggerStatement");
    49     const location = {
    50       url: "http://example.com/foo.js",
    51       line: 5
    52     };
    54     gThreadClient.setBreakpoint(location, function (aResponse, bpClient) {
    55       do_check_true(!aResponse.error);
    56       testHitBreakpoint();
    57     });
    58   });
    60   // This is the original foo.js, which was then minified with uglifyjs version
    61   // 2.2.5 and the "--mangle" option.
    62   //
    63   // (function () {
    64   //   debugger;
    65   //   function foo(n) {
    66   //     var bar = n + n;
    67   //     var unused = null;
    68   //     return bar;
    69   //   }
    70   //   for (var i = 0; i < 10; i++) {
    71   //     foo(i);
    72   //   }
    73   // }());
    75   let code = '(function(){debugger;function r(r){var n=r+r;var u=null;return n}for(var n=0;n<10;n++){r(n)}})();\n//# sourceMappingURL=data:text/json,{"file":"foo.min.js","version":3,"sources":["foo.js"],"names":["foo","n","bar","unused","i"],"mappings":"CAAC,WACC,QACA,SAASA,GAAIC,GACX,GAAIC,GAAMD,EAAIA,CACd,IAAIE,GAAS,IACb,OAAOD,GAET,IAAK,GAAIE,GAAI,EAAGA,EAAI,GAAIA,IAAK,CAC3BJ,EAAII"}';
    77   Components.utils.evalInSandbox(code, gDebuggee, "1.8",
    78                                  "http://example.com/foo.min.js", 1);
    79 }
    81 function testHitBreakpoint(timesHit=0) {
    82   gClient.addOneTimeListener("paused", function (aEvent, aPacket) {
    83     ++timesHit;
    85     do_check_eq(aEvent, "paused");
    86     do_check_eq(aPacket.why.type, "breakpoint");
    88     if (timesHit === 10) {
    89       gThreadClient.resume(() => finishClient(gClient));
    90     } else {
    91       testHitBreakpoint(timesHit);
    92     }
    93   });
    95   gThreadClient.resume();
    96 }

mercurial