browser/devtools/debugger/test/browser_dbg_sources-sorting.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/debugger/test/browser_dbg_sources-sorting.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,137 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Tests that urls are correctly sorted when added to the sources widget.
     1.9 + */
    1.10 +
    1.11 +const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
    1.12 +
    1.13 +let gTab, gDebuggee, gPanel, gDebugger;
    1.14 +let gSources, gUtils;
    1.15 +
    1.16 +function test() {
    1.17 +  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    1.18 +    gTab = aTab;
    1.19 +    gDebuggee = aDebuggee;
    1.20 +    gPanel = aPanel;
    1.21 +    gDebugger = gPanel.panelWin;
    1.22 +    gSources = gDebugger.DebuggerView.Sources;
    1.23 +    gUtils = gDebugger.SourceUtils;
    1.24 +
    1.25 +    waitForSourceShown(gPanel, ".html").then(() => {
    1.26 +      addSourceAndCheckOrder(1, () => {
    1.27 +        addSourceAndCheckOrder(2, () => {
    1.28 +          addSourceAndCheckOrder(3, () => {
    1.29 +            closeDebuggerAndFinish(gPanel);
    1.30 +          });
    1.31 +        });
    1.32 +      });
    1.33 +    });
    1.34 +  });
    1.35 +}
    1.36 +
    1.37 +function addSourceAndCheckOrder(aMethod, aCallback) {
    1.38 +  gSources.empty();
    1.39 +  gSources.suppressSelectionEvents = true;
    1.40 +
    1.41 +  let urls = [
    1.42 +    { href: "ici://some.address.com/random/", leaf: "subrandom/" },
    1.43 +    { href: "ni://another.address.org/random/subrandom/", leaf: "page.html" },
    1.44 +    { href: "san://interesting.address.gro/random/", leaf: "script.js" },
    1.45 +    { href: "si://interesting.address.moc/random/", leaf: "script.js" },
    1.46 +    { href: "si://interesting.address.moc/random/", leaf: "x/script.js" },
    1.47 +    { href: "si://interesting.address.moc/random/", leaf: "x/y/script.js?a=1" },
    1.48 +    { href: "si://interesting.address.moc/random/x/", leaf: "y/script.js?a=1&b=2" },
    1.49 +    { href: "si://interesting.address.moc/random/x/y/", leaf: "script.js?a=1&b=2&c=3" }
    1.50 +  ];
    1.51 +
    1.52 +  urls.sort(function(a, b) {
    1.53 +    return Math.random() - 0.5;
    1.54 +  });
    1.55 +
    1.56 +  switch (aMethod) {
    1.57 +    case 1:
    1.58 +      for (let { href, leaf } of urls) {
    1.59 +        let url = href + leaf;
    1.60 +        let label = gUtils.getSourceLabel(url);
    1.61 +        let dummy = document.createElement("label");
    1.62 +        gSources.push([dummy, url], {
    1.63 +          staged: true,
    1.64 +          attachment: {
    1.65 +            label: label
    1.66 +          }
    1.67 +        });
    1.68 +      }
    1.69 +      gSources.commit({ sorted: true });
    1.70 +      break;
    1.71 +
    1.72 +    case 2:
    1.73 +      for (let { href, leaf } of urls) {
    1.74 +        let url = href + leaf;
    1.75 +        let label = gUtils.getSourceLabel(url);
    1.76 +        let dummy = document.createElement("label");
    1.77 +        gSources.push([dummy, url], {
    1.78 +          staged: false,
    1.79 +          attachment: {
    1.80 +            label: label
    1.81 +          }
    1.82 +        });
    1.83 +      }
    1.84 +      break;
    1.85 +
    1.86 +    case 3:
    1.87 +      let i = 0
    1.88 +      for (; i < urls.length / 2; i++) {
    1.89 +        let { href, leaf } = urls[i];
    1.90 +        let url = href + leaf;
    1.91 +        let label = gUtils.getSourceLabel(url);
    1.92 +        let dummy = document.createElement("label");
    1.93 +        gSources.push([dummy, url], {
    1.94 +          staged: true,
    1.95 +          attachment: {
    1.96 +            label: label
    1.97 +          }
    1.98 +        });
    1.99 +      }
   1.100 +      gSources.commit({ sorted: true });
   1.101 +
   1.102 +      for (; i < urls.length; i++) {
   1.103 +        let { href, leaf } = urls[i];
   1.104 +        let url = href + leaf;
   1.105 +        let label = gUtils.getSourceLabel(url);
   1.106 +        let dummy = document.createElement("label");
   1.107 +        gSources.push([dummy, url], {
   1.108 +          staged: false,
   1.109 +          attachment: {
   1.110 +            label: label
   1.111 +          }
   1.112 +        });
   1.113 +      }
   1.114 +      break;
   1.115 +  }
   1.116 +
   1.117 +  checkSourcesOrder(aMethod);
   1.118 +  aCallback();
   1.119 +}
   1.120 +
   1.121 +function checkSourcesOrder(aMethod) {
   1.122 +  let attachments = gSources.attachments;
   1.123 +
   1.124 +  for (let i = 0; i < attachments.length - 1; i++) {
   1.125 +    let first = attachments[i].label;
   1.126 +    let second = attachments[i + 1].label;
   1.127 +    ok(first < second,
   1.128 +      "Using method " + aMethod + ", " +
   1.129 +      "the sources weren't in the correct order: " + first + " vs. " + second);
   1.130 +  }
   1.131 +}
   1.132 +
   1.133 +registerCleanupFunction(function() {
   1.134 +  gTab = null;
   1.135 +  gDebuggee = null;
   1.136 +  gPanel = null;
   1.137 +  gDebugger = null;
   1.138 +  gSources = null;
   1.139 +  gUtils = null;
   1.140 +});

mercurial