browser/devtools/debugger/test/browser_dbg_scripts-switching-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  * Make sure that switching the displayed source in the UI works as advertised.
     6  */
     8 const TAB_URL = EXAMPLE_URL + "doc_script-switching-02.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     waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1)
    23       .then(testSourcesDisplay)
    24       .then(testSwitchPaused1)
    25       .then(testSwitchPaused2)
    26       .then(testSwitchRunning)
    27       .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
    28       .then(null, aError => {
    29         ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    30       });
    32     gDebuggee.firstCall();
    33   });
    34 }
    36 let gLabel1 = "code_script-switching-01.js";
    37 let gLabel2 = "code_script-switching-02.js";
    38 let gParams = "?foo=bar,baz|lol";
    40 function testSourcesDisplay() {
    41   let deferred = promise.defer();
    43   is(gSources.itemCount, 2,
    44     "Found the expected number of sources.");
    46   ok(gSources.containsValue(EXAMPLE_URL + gLabel1),
    47     "First source url is incorrect.");
    48   ok(gSources.containsValue(EXAMPLE_URL + gLabel2 + gParams),
    49     "Second source url is incorrect.");
    51   ok(gSources.getItemForAttachment(e => e.label == gLabel1),
    52     "First source label is incorrect.");
    53   ok(gSources.getItemForAttachment(e => e.label == gLabel2),
    54     "Second source label is incorrect.");
    56   ok(gSources.selectedItem,
    57     "There should be a selected item in the sources pane.");
    58   is(gSources.selectedValue, EXAMPLE_URL + gLabel2 + gParams,
    59     "The selected value is the sources pane is incorrect.");
    61   is(gEditor.getText().search(/firstCall/), -1,
    62     "The first source is not displayed.");
    63   is(gEditor.getText().search(/debugger/), 172,
    64     "The second source is displayed.");
    66   ok(isCaretPos(gPanel, 1),
    67     "Editor caret location is correct.");
    69   // The editor's debug location takes a tick to update.
    70   executeSoon(() => {
    71     is(gEditor.getDebugLocation(), 0,
    72       "Editor debugger location is correct.");
    73     ok(gEditor.hasLineClass(0, "debug-line"),
    74       "The debugged line is highlighted appropriately.");
    76     waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
    77     gSources.selectedItem = e => e.attachment.label == gLabel1;
    78   });
    80   return deferred.promise;
    81 }
    83 function testSwitchPaused1() {
    84   let deferred = promise.defer();
    86   ok(gSources.selectedItem,
    87     "There should be a selected item in the sources pane.");
    88   is(gSources.selectedValue, EXAMPLE_URL + gLabel1,
    89     "The selected value is the sources pane is incorrect.");
    91   is(gEditor.getText().search(/firstCall/), 118,
    92     "The first source is displayed.");
    93   is(gEditor.getText().search(/debugger/), -1,
    94     "The second source is not displayed.");
    96   // The editor's debug location takes a tick to update.
    97   executeSoon(() => {
    98     ok(isCaretPos(gPanel, 1),
    99       "Editor caret location is correct.");
   101     is(gEditor.getDebugLocation(), null,
   102       "Editor debugger location is correct.");
   103     ok(!gEditor.hasLineClass(5, "debug-line"),
   104       "The debugged line highlight was removed.");
   106     waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
   107     gSources.selectedItem = e => e.attachment.label == gLabel2;
   108   });
   110   return deferred.promise;
   111 }
   113 function testSwitchPaused2() {
   114   let deferred = promise.defer();
   116   ok(gSources.selectedItem,
   117     "There should be a selected item in the sources pane.");
   118   is(gSources.selectedValue, EXAMPLE_URL + gLabel2 + gParams,
   119     "The selected value is the sources pane is incorrect.");
   121   is(gEditor.getText().search(/firstCall/), -1,
   122     "The first source is not displayed.");
   123   is(gEditor.getText().search(/debugger/), 172,
   124     "The second source is displayed.");
   126   // The editor's debug location takes a tick to update.
   127   executeSoon(() => {
   128     ok(isCaretPos(gPanel, 1),
   129       "Editor caret location is correct.");
   130     is(gEditor.getDebugLocation(), 0,
   131       "Editor debugger location is correct.");
   132     ok(gEditor.hasLineClass(0, "debug-line"),
   133       "The debugged line is highlighted appropriately.");
   135     // Step out three times.
   136     waitForThreadEvents(gPanel, "paused").then(() => {
   137       waitForThreadEvents(gPanel, "paused").then(() => {
   138         waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(deferred.resolve);
   139         gDebugger.gThreadClient.stepOut();
   140       });
   141       gDebugger.gThreadClient.stepOut();
   142     });
   143     gDebugger.gThreadClient.stepOut();
   144   });
   146   return deferred.promise;
   147 }
   149 function testSwitchRunning() {
   150   let deferred = promise.defer();
   152   ok(gSources.selectedItem,
   153     "There should be a selected item in the sources pane.");
   154   is(gSources.selectedValue, EXAMPLE_URL + gLabel1,
   155     "The selected value is the sources pane is incorrect.");
   157   is(gEditor.getText().search(/firstCall/), 118,
   158     "The first source is displayed.");
   159   is(gEditor.getText().search(/debugger/), -1,
   160     "The second source is not displayed.");
   162   // The editor's debug location takes a tick to update.
   163   executeSoon(() => {
   164     ok(isCaretPos(gPanel, 1),
   165       "Editor caret location is correct.");
   166     is(gEditor.getDebugLocation(), 0,
   167       "Editor debugger location is correct.");
   168     ok(gEditor.hasLineClass(0, "debug-line"),
   169       "The debugged line is highlighted appropriately.");
   171     deferred.resolve();
   172   });
   174   return deferred.promise;
   175 }
   177 registerCleanupFunction(function() {
   178   gTab = null;
   179   gDebuggee = null;
   180   gPanel = null;
   181   gDebugger = null;
   182   gEditor = null;
   183   gSources = null;
   184   gLabel1 = null;
   185   gLabel2 = null;
   186   gParams = null;
   187 });

mercurial