browser/devtools/debugger/test/browser_dbg_source-maps-02.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /**
     5  * Test that we can toggle between the original and generated sources.
     6  */
     8 const TAB_URL = EXAMPLE_URL + "doc_binary_search.html";
     9 const JS_URL = EXAMPLE_URL + "code_binary_search.js";
    11 let gDebuggee, gPanel, gDebugger, gEditor;
    12 let gSources, gFrames, gPrefs, gOptions;
    14 function test() {
    15   initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    16     gDebuggee = aDebuggee;
    17     gPanel = aPanel;
    18     gDebugger = gPanel.panelWin;
    19     gEditor = gDebugger.DebuggerView.editor;
    20     gSources = gDebugger.DebuggerView.Sources;
    21     gFrames = gDebugger.DebuggerView.StackFrames;
    22     gPrefs = gDebugger.Prefs;
    23     gOptions = gDebugger.DebuggerView.Options;
    25     waitForSourceShown(gPanel, ".coffee")
    26       .then(testToggleGeneratedSource)
    27       .then(testSetBreakpoint)
    28       .then(testToggleOnPause)
    29       .then(testResume)
    30       .then(() => closeDebuggerAndFinish(gPanel))
    31       .then(null, aError => {
    32         ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    33       });
    34   });
    35 }
    37 function testToggleGeneratedSource() {
    38   let finished = waitForSourceShown(gPanel, ".js").then(() => {
    39     is(gPrefs.sourceMapsEnabled, false,
    40       "The source maps pref should have been set to false.");
    41     is(gOptions._showOriginalSourceItem.getAttribute("checked"), "false",
    42       "Source maps should now be disabled.")
    44     is(gSources.selectedValue.indexOf(".coffee"), -1,
    45       "The debugger should not show the source mapped coffee source file.");
    46     isnot(gSources.selectedValue.indexOf(".js"), -1,
    47       "The debugger should show the generated js source file.");
    49     is(gEditor.getText().indexOf("isnt"), -1,
    50       "The debugger's editor should not have the coffee source source displayed.");
    51     is(gEditor.getText().indexOf("function"), 36,
    52       "The debugger's editor should have the JS source displayed.");
    53   });
    55   gOptions._showOriginalSourceItem.setAttribute("checked", "false");
    56   gOptions._toggleShowOriginalSource();
    57   gOptions._onPopupHidden();
    59   return finished;
    60 }
    62 function testSetBreakpoint() {
    63   let deferred = promise.defer();
    65   gDebugger.gThreadClient.setBreakpoint({ url: JS_URL, line: 7 }, aResponse => {
    66     ok(!aResponse.error,
    67       "Should be able to set a breakpoint in a js file.");
    69     gDebugger.gClient.addOneTimeListener("resumed", () => {
    70       waitForCaretAndScopes(gPanel, 7).then(() => {
    71         // Make sure that we have JavaScript stack frames.
    72         is(gFrames.itemCount, 1,
    73           "Should have only one frame.");
    74         is(gFrames.getItemAtIndex(0).attachment.url.indexOf(".coffee"), -1,
    75           "First frame should not be a coffee source frame.");
    76         isnot(gFrames.getItemAtIndex(0).attachment.url.indexOf(".js"), -1,
    77           "First frame should be a JS frame.");
    79         deferred.resolve();
    80       });
    82       // This will cause the breakpoint to be hit, and put us back in the
    83       // paused state.
    84       gDebuggee.binary_search([0, 2, 3, 5, 7, 10], 5);
    85     });
    86   });
    88   return deferred.promise;
    89 }
    91 function testToggleOnPause() {
    92   let finished = waitForSourceAndCaretAndScopes(gPanel, ".coffee", 5).then(() => {
    93     is(gPrefs.sourceMapsEnabled, true,
    94       "The source maps pref should have been set to true.");
    95     is(gOptions._showOriginalSourceItem.getAttribute("checked"), "true",
    96       "Source maps should now be enabled.")
    98     isnot(gSources.selectedValue.indexOf(".coffee"), -1,
    99       "The debugger should show the source mapped coffee source file.");
   100     is(gSources.selectedValue.indexOf(".js"), -1,
   101       "The debugger should not show the generated js source file.");
   103     is(gEditor.getText().indexOf("isnt"), 218,
   104       "The debugger's editor should have the coffee source source displayed.");
   105     is(gEditor.getText().indexOf("function"), -1,
   106       "The debugger's editor should not have the JS source displayed.");
   108     // Make sure that we have coffee source stack frames.
   109     is(gFrames.itemCount, 1,
   110       "Should have only one frame.");
   111     is(gFrames.getItemAtIndex(0).attachment.url.indexOf(".js"), -1,
   112       "First frame should not be a JS frame.");
   113     isnot(gFrames.getItemAtIndex(0).attachment.url.indexOf(".coffee"), -1,
   114       "First frame should be a coffee source frame.");
   115   });
   117   gOptions._showOriginalSourceItem.setAttribute("checked", "true");
   118   gOptions._toggleShowOriginalSource();
   119   gOptions._onPopupHidden();
   121   return finished;
   122 }
   124 function testResume() {
   125   let deferred = promise.defer();
   127   gDebugger.gThreadClient.resume(aResponse => {
   128     ok(!aResponse.error, "Shouldn't get an error resuming.");
   129     is(aResponse.type, "resumed", "Type should be 'resumed'.");
   131     deferred.resolve();
   132   });
   134   return deferred.promise;
   135 }
   137 registerCleanupFunction(function() {
   138   gDebuggee = null;
   139   gPanel = null;
   140   gDebugger = null;
   141   gEditor = null;
   142   gSources = null;
   143   gFrames = null;
   144   gPrefs = null;
   145   gOptions = null;
   146 });

mercurial