michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests that urls are correctly sorted when added to the sources widget. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html"; michael@0: michael@0: let gTab, gDebuggee, gPanel, gDebugger; michael@0: let gSources, gUtils; michael@0: michael@0: function test() { michael@0: initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { michael@0: gTab = aTab; michael@0: gDebuggee = aDebuggee; michael@0: gPanel = aPanel; michael@0: gDebugger = gPanel.panelWin; michael@0: gSources = gDebugger.DebuggerView.Sources; michael@0: gUtils = gDebugger.SourceUtils; michael@0: michael@0: waitForSourceShown(gPanel, ".html").then(() => { michael@0: addSourceAndCheckOrder(1, () => { michael@0: addSourceAndCheckOrder(2, () => { michael@0: addSourceAndCheckOrder(3, () => { michael@0: closeDebuggerAndFinish(gPanel); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function addSourceAndCheckOrder(aMethod, aCallback) { michael@0: gSources.empty(); michael@0: gSources.suppressSelectionEvents = true; michael@0: michael@0: let urls = [ michael@0: { href: "ici://some.address.com/random/", leaf: "subrandom/" }, michael@0: { href: "ni://another.address.org/random/subrandom/", leaf: "page.html" }, michael@0: { href: "san://interesting.address.gro/random/", leaf: "script.js" }, michael@0: { href: "si://interesting.address.moc/random/", leaf: "script.js" }, michael@0: { href: "si://interesting.address.moc/random/", leaf: "x/script.js" }, michael@0: { href: "si://interesting.address.moc/random/", leaf: "x/y/script.js?a=1" }, michael@0: { href: "si://interesting.address.moc/random/x/", leaf: "y/script.js?a=1&b=2" }, michael@0: { href: "si://interesting.address.moc/random/x/y/", leaf: "script.js?a=1&b=2&c=3" } michael@0: ]; michael@0: michael@0: urls.sort(function(a, b) { michael@0: return Math.random() - 0.5; michael@0: }); michael@0: michael@0: switch (aMethod) { michael@0: case 1: michael@0: for (let { href, leaf } of urls) { michael@0: let url = href + leaf; michael@0: let label = gUtils.getSourceLabel(url); michael@0: let dummy = document.createElement("label"); michael@0: gSources.push([dummy, url], { michael@0: staged: true, michael@0: attachment: { michael@0: label: label michael@0: } michael@0: }); michael@0: } michael@0: gSources.commit({ sorted: true }); michael@0: break; michael@0: michael@0: case 2: michael@0: for (let { href, leaf } of urls) { michael@0: let url = href + leaf; michael@0: let label = gUtils.getSourceLabel(url); michael@0: let dummy = document.createElement("label"); michael@0: gSources.push([dummy, url], { michael@0: staged: false, michael@0: attachment: { michael@0: label: label michael@0: } michael@0: }); michael@0: } michael@0: break; michael@0: michael@0: case 3: michael@0: let i = 0 michael@0: for (; i < urls.length / 2; i++) { michael@0: let { href, leaf } = urls[i]; michael@0: let url = href + leaf; michael@0: let label = gUtils.getSourceLabel(url); michael@0: let dummy = document.createElement("label"); michael@0: gSources.push([dummy, url], { michael@0: staged: true, michael@0: attachment: { michael@0: label: label michael@0: } michael@0: }); michael@0: } michael@0: gSources.commit({ sorted: true }); michael@0: michael@0: for (; i < urls.length; i++) { michael@0: let { href, leaf } = urls[i]; michael@0: let url = href + leaf; michael@0: let label = gUtils.getSourceLabel(url); michael@0: let dummy = document.createElement("label"); michael@0: gSources.push([dummy, url], { michael@0: staged: false, michael@0: attachment: { michael@0: label: label michael@0: } michael@0: }); michael@0: } michael@0: break; michael@0: } michael@0: michael@0: checkSourcesOrder(aMethod); michael@0: aCallback(); michael@0: } michael@0: michael@0: function checkSourcesOrder(aMethod) { michael@0: let attachments = gSources.attachments; michael@0: michael@0: for (let i = 0; i < attachments.length - 1; i++) { michael@0: let first = attachments[i].label; michael@0: let second = attachments[i + 1].label; michael@0: ok(first < second, michael@0: "Using method " + aMethod + ", " + michael@0: "the sources weren't in the correct order: " + first + " vs. " + second); michael@0: } michael@0: } michael@0: michael@0: registerCleanupFunction(function() { michael@0: gTab = null; michael@0: gDebuggee = null; michael@0: gPanel = null; michael@0: gDebugger = null; michael@0: gSources = null; michael@0: gUtils = null; michael@0: });