browser/devtools/debugger/test/browser_dbg_sources-sorting.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  * Tests that urls are correctly sorted when added to the sources widget.
     6  */
     8 const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
    10 let gTab, gDebuggee, gPanel, gDebugger;
    11 let gSources, gUtils;
    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     gSources = gDebugger.DebuggerView.Sources;
    20     gUtils = gDebugger.SourceUtils;
    22     waitForSourceShown(gPanel, ".html").then(() => {
    23       addSourceAndCheckOrder(1, () => {
    24         addSourceAndCheckOrder(2, () => {
    25           addSourceAndCheckOrder(3, () => {
    26             closeDebuggerAndFinish(gPanel);
    27           });
    28         });
    29       });
    30     });
    31   });
    32 }
    34 function addSourceAndCheckOrder(aMethod, aCallback) {
    35   gSources.empty();
    36   gSources.suppressSelectionEvents = true;
    38   let urls = [
    39     { href: "ici://some.address.com/random/", leaf: "subrandom/" },
    40     { href: "ni://another.address.org/random/subrandom/", leaf: "page.html" },
    41     { href: "san://interesting.address.gro/random/", leaf: "script.js" },
    42     { href: "si://interesting.address.moc/random/", leaf: "script.js" },
    43     { href: "si://interesting.address.moc/random/", leaf: "x/script.js" },
    44     { href: "si://interesting.address.moc/random/", leaf: "x/y/script.js?a=1" },
    45     { href: "si://interesting.address.moc/random/x/", leaf: "y/script.js?a=1&b=2" },
    46     { href: "si://interesting.address.moc/random/x/y/", leaf: "script.js?a=1&b=2&c=3" }
    47   ];
    49   urls.sort(function(a, b) {
    50     return Math.random() - 0.5;
    51   });
    53   switch (aMethod) {
    54     case 1:
    55       for (let { href, leaf } of urls) {
    56         let url = href + leaf;
    57         let label = gUtils.getSourceLabel(url);
    58         let dummy = document.createElement("label");
    59         gSources.push([dummy, url], {
    60           staged: true,
    61           attachment: {
    62             label: label
    63           }
    64         });
    65       }
    66       gSources.commit({ sorted: true });
    67       break;
    69     case 2:
    70       for (let { href, leaf } of urls) {
    71         let url = href + leaf;
    72         let label = gUtils.getSourceLabel(url);
    73         let dummy = document.createElement("label");
    74         gSources.push([dummy, url], {
    75           staged: false,
    76           attachment: {
    77             label: label
    78           }
    79         });
    80       }
    81       break;
    83     case 3:
    84       let i = 0
    85       for (; i < urls.length / 2; i++) {
    86         let { href, leaf } = urls[i];
    87         let url = href + leaf;
    88         let label = gUtils.getSourceLabel(url);
    89         let dummy = document.createElement("label");
    90         gSources.push([dummy, url], {
    91           staged: true,
    92           attachment: {
    93             label: label
    94           }
    95         });
    96       }
    97       gSources.commit({ sorted: true });
    99       for (; i < urls.length; i++) {
   100         let { href, leaf } = urls[i];
   101         let url = href + leaf;
   102         let label = gUtils.getSourceLabel(url);
   103         let dummy = document.createElement("label");
   104         gSources.push([dummy, url], {
   105           staged: false,
   106           attachment: {
   107             label: label
   108           }
   109         });
   110       }
   111       break;
   112   }
   114   checkSourcesOrder(aMethod);
   115   aCallback();
   116 }
   118 function checkSourcesOrder(aMethod) {
   119   let attachments = gSources.attachments;
   121   for (let i = 0; i < attachments.length - 1; i++) {
   122     let first = attachments[i].label;
   123     let second = attachments[i + 1].label;
   124     ok(first < second,
   125       "Using method " + aMethod + ", " +
   126       "the sources weren't in the correct order: " + first + " vs. " + second);
   127   }
   128 }
   130 registerCleanupFunction(function() {
   131   gTab = null;
   132   gDebuggee = null;
   133   gPanel = null;
   134   gDebugger = null;
   135   gSources = null;
   136   gUtils = null;
   137 });

mercurial