browser/devtools/debugger/test/browser_dbg_scripts-switching-01.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  * Make sure that switching the displayed source in the UI works as advertised.
     6  */
     8 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
    10 let gTab, gDebuggee, gPanel, gDebugger;
    11 let gEditor, gSources;
    13 function test() {
    14   initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    15     gTab = aTab;
    16     gDebuggee = aDebuggee;
    17     gPanel = aPanel;
    18     gDebugger = gPanel.panelWin;
    19     gEditor = gDebugger.DebuggerView.editor;
    20     gSources = gDebugger.DebuggerView.Sources;
    22     ok(gDebugger.document.title.endsWith(EXAMPLE_URL + gLabel1),
    23       "Title with first source is correct.");
    25     waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1)
    26       .then(testSourcesDisplay)
    27       .then(testSwitchPaused1)
    28       .then(testSwitchPaused2)
    29       .then(testSwitchRunning)
    30       .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
    31       .then(null, aError => {
    32         ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    33       });
    35     gDebuggee.firstCall();
    36   });
    37 }
    39 let gLabel1 = "code_script-switching-01.js";
    40 let gLabel2 = "code_script-switching-02.js";
    42 function testSourcesDisplay() {
    43   let deferred = promise.defer();
    45   is(gSources.itemCount, 2,
    46     "Found the expected number of sources.");
    48   is(gSources.items[0].target.querySelector(".dbg-source-item").getAttribute("tooltiptext"),
    49     EXAMPLE_URL + "code_script-switching-01.js",
    50     "The correct tooltip text is displayed for the first source.");
    51   is(gSources.items[1].target.querySelector(".dbg-source-item").getAttribute("tooltiptext"),
    52     EXAMPLE_URL + "code_script-switching-02.js",
    53     "The correct tooltip text is displayed for the second source.");
    55   ok(gSources.containsValue(EXAMPLE_URL + gLabel1),
    56     "First source url is incorrect.");
    57   ok(gSources.containsValue(EXAMPLE_URL + gLabel2),
    58     "Second source url is incorrect.");
    60   ok(gSources.getItemForAttachment(e => e.label == gLabel1),
    61     "First source label is incorrect.");
    62   ok(gSources.getItemForAttachment(e => e.label == gLabel2),
    63     "Second source label is incorrect.");
    65   ok(gSources.selectedItem,
    66     "There should be a selected item in the sources pane.");
    67   is(gSources.selectedValue, EXAMPLE_URL + gLabel2,
    68     "The selected value is the sources pane is incorrect.");
    70   is(gEditor.getText().search(/firstCall/), -1,
    71     "The first source is not displayed.");
    72   is(gEditor.getText().search(/debugger/), 172,
    73     "The second source is displayed.");
    75   ok(gDebugger.document.title.endsWith(EXAMPLE_URL + gLabel2),
    76     "Title with second source is correct.");
    78   ok(isCaretPos(gPanel, 1),
    79     "Editor caret location is correct.");
    81   // The editor's debug location takes a tick to update.
    82   executeSoon(() => {
    83     is(gEditor.getDebugLocation(), 0,
    84       "Editor debugger location is correct.");
    85     ok(gEditor.hasLineClass(0, "debug-line"),
    86       "The debugged line is highlighted appropriately (1).");
    88     waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
    89     gSources.selectedIndex = 0;
    90   });
    92   return deferred.promise;
    93 }
    95 function testSwitchPaused1() {
    96   let deferred = promise.defer();
    98   ok(gSources.selectedItem,
    99     "There should be a selected item in the sources pane.");
   100   is(gSources.selectedValue, EXAMPLE_URL + gLabel1,
   101     "The selected value is the sources pane is incorrect.");
   103   is(gEditor.getText().search(/firstCall/), 118,
   104     "The first source is displayed.");
   105   is(gEditor.getText().search(/debugger/), -1,
   106     "The second source is not displayed.");
   108   // The editor's debug location takes a tick to update.
   109   executeSoon(() => {
   110     ok(isCaretPos(gPanel, 1),
   111       "Editor caret location is correct.");
   112     is(gEditor.getDebugLocation(), null,
   113       "Editor debugger location is correct.");
   114     ok(!gEditor.hasLineClass(5, "debug-line"),
   115       "The debugged line highlight was removed.");
   117     waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
   118     gSources.selectedIndex = 1;
   119   });
   121   return deferred.promise;
   122 }
   124 function testSwitchPaused2() {
   125   let deferred = promise.defer();
   127   ok(gSources.selectedItem,
   128     "There should be a selected item in the sources pane.");
   129   is(gSources.selectedValue, EXAMPLE_URL + gLabel2,
   130     "The selected value is the sources pane is incorrect.");
   132   is(gEditor.getText().search(/firstCall/), -1,
   133     "The first source is not displayed.");
   134   is(gEditor.getText().search(/debugger/), 172,
   135     "The second source is displayed.");
   137   // The editor's debug location takes a tick to update.
   138   executeSoon(() => {
   139     ok(isCaretPos(gPanel, 1),
   140       "Editor caret location is correct.");
   141     is(gEditor.getDebugLocation(), 0,
   142       "Editor debugger location is correct.");
   143     ok(gEditor.hasLineClass(0, "debug-line"),
   144       "The debugged line is highlighted appropriately (2).");
   146     // Step out three times.
   147     waitForThreadEvents(gPanel, "paused").then(() => {
   148       waitForThreadEvents(gPanel, "paused").then(() => {
   149         waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
   150         gDebugger.gThreadClient.stepOut();
   151       });
   152       gDebugger.gThreadClient.stepOut();
   153     });
   154     gDebugger.gThreadClient.stepOut();
   155   });
   157   return deferred.promise;
   158 }
   160 function testSwitchRunning() {
   161   let deferred = promise.defer();
   163   ok(gSources.selectedItem,
   164     "There should be a selected item in the sources pane.");
   165   is(gSources.selectedValue, EXAMPLE_URL + gLabel1,
   166     "The selected value is the sources pane is incorrect.");
   168   is(gEditor.getText().search(/firstCall/), 118,
   169     "The first source is displayed.");
   170   is(gEditor.getText().search(/debugger/), -1,
   171     "The second source is not displayed.");
   173   // The editor's debug location takes a tick to update.
   174   executeSoon(() => {
   175     ok(isCaretPos(gPanel, 1),
   176       "Editor caret location is correct.");
   177     is(gEditor.getDebugLocation(), 0,
   178       "Editor debugger location is correct.");
   179     ok(gEditor.hasLineClass(0, "debug-line"),
   180       "The debugged line is highlighted appropriately (3).");
   182     deferred.resolve();
   183   });
   185   return deferred.promise;
   186 }
   188 registerCleanupFunction(function() {
   189   gTab = null;
   190   gDebuggee = null;
   191   gPanel = null;
   192   gDebugger = null;
   193   gEditor = null;
   194   gSources = null;
   195   gLabel1 = null;
   196   gLabel2 = null;
   197 });

mercurial