Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | /** |
michael@0 | 5 | * Tests that urls are correctly sorted when added to the sources widget. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html"; |
michael@0 | 9 | |
michael@0 | 10 | let gTab, gDebuggee, gPanel, gDebugger; |
michael@0 | 11 | let gSources, gUtils; |
michael@0 | 12 | |
michael@0 | 13 | function test() { |
michael@0 | 14 | initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
michael@0 | 15 | gTab = aTab; |
michael@0 | 16 | gDebuggee = aDebuggee; |
michael@0 | 17 | gPanel = aPanel; |
michael@0 | 18 | gDebugger = gPanel.panelWin; |
michael@0 | 19 | gSources = gDebugger.DebuggerView.Sources; |
michael@0 | 20 | gUtils = gDebugger.SourceUtils; |
michael@0 | 21 | |
michael@0 | 22 | waitForSourceShown(gPanel, ".html").then(() => { |
michael@0 | 23 | addSourceAndCheckOrder(1, () => { |
michael@0 | 24 | addSourceAndCheckOrder(2, () => { |
michael@0 | 25 | addSourceAndCheckOrder(3, () => { |
michael@0 | 26 | closeDebuggerAndFinish(gPanel); |
michael@0 | 27 | }); |
michael@0 | 28 | }); |
michael@0 | 29 | }); |
michael@0 | 30 | }); |
michael@0 | 31 | }); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function addSourceAndCheckOrder(aMethod, aCallback) { |
michael@0 | 35 | gSources.empty(); |
michael@0 | 36 | gSources.suppressSelectionEvents = true; |
michael@0 | 37 | |
michael@0 | 38 | let urls = [ |
michael@0 | 39 | { href: "ici://some.address.com/random/", leaf: "subrandom/" }, |
michael@0 | 40 | { href: "ni://another.address.org/random/subrandom/", leaf: "page.html" }, |
michael@0 | 41 | { href: "san://interesting.address.gro/random/", leaf: "script.js" }, |
michael@0 | 42 | { href: "si://interesting.address.moc/random/", leaf: "script.js" }, |
michael@0 | 43 | { href: "si://interesting.address.moc/random/", leaf: "x/script.js" }, |
michael@0 | 44 | { href: "si://interesting.address.moc/random/", leaf: "x/y/script.js?a=1" }, |
michael@0 | 45 | { href: "si://interesting.address.moc/random/x/", leaf: "y/script.js?a=1&b=2" }, |
michael@0 | 46 | { href: "si://interesting.address.moc/random/x/y/", leaf: "script.js?a=1&b=2&c=3" } |
michael@0 | 47 | ]; |
michael@0 | 48 | |
michael@0 | 49 | urls.sort(function(a, b) { |
michael@0 | 50 | return Math.random() - 0.5; |
michael@0 | 51 | }); |
michael@0 | 52 | |
michael@0 | 53 | switch (aMethod) { |
michael@0 | 54 | case 1: |
michael@0 | 55 | for (let { href, leaf } of urls) { |
michael@0 | 56 | let url = href + leaf; |
michael@0 | 57 | let label = gUtils.getSourceLabel(url); |
michael@0 | 58 | let dummy = document.createElement("label"); |
michael@0 | 59 | gSources.push([dummy, url], { |
michael@0 | 60 | staged: true, |
michael@0 | 61 | attachment: { |
michael@0 | 62 | label: label |
michael@0 | 63 | } |
michael@0 | 64 | }); |
michael@0 | 65 | } |
michael@0 | 66 | gSources.commit({ sorted: true }); |
michael@0 | 67 | break; |
michael@0 | 68 | |
michael@0 | 69 | case 2: |
michael@0 | 70 | for (let { href, leaf } of urls) { |
michael@0 | 71 | let url = href + leaf; |
michael@0 | 72 | let label = gUtils.getSourceLabel(url); |
michael@0 | 73 | let dummy = document.createElement("label"); |
michael@0 | 74 | gSources.push([dummy, url], { |
michael@0 | 75 | staged: false, |
michael@0 | 76 | attachment: { |
michael@0 | 77 | label: label |
michael@0 | 78 | } |
michael@0 | 79 | }); |
michael@0 | 80 | } |
michael@0 | 81 | break; |
michael@0 | 82 | |
michael@0 | 83 | case 3: |
michael@0 | 84 | let i = 0 |
michael@0 | 85 | for (; i < urls.length / 2; i++) { |
michael@0 | 86 | let { href, leaf } = urls[i]; |
michael@0 | 87 | let url = href + leaf; |
michael@0 | 88 | let label = gUtils.getSourceLabel(url); |
michael@0 | 89 | let dummy = document.createElement("label"); |
michael@0 | 90 | gSources.push([dummy, url], { |
michael@0 | 91 | staged: true, |
michael@0 | 92 | attachment: { |
michael@0 | 93 | label: label |
michael@0 | 94 | } |
michael@0 | 95 | }); |
michael@0 | 96 | } |
michael@0 | 97 | gSources.commit({ sorted: true }); |
michael@0 | 98 | |
michael@0 | 99 | for (; i < urls.length; i++) { |
michael@0 | 100 | let { href, leaf } = urls[i]; |
michael@0 | 101 | let url = href + leaf; |
michael@0 | 102 | let label = gUtils.getSourceLabel(url); |
michael@0 | 103 | let dummy = document.createElement("label"); |
michael@0 | 104 | gSources.push([dummy, url], { |
michael@0 | 105 | staged: false, |
michael@0 | 106 | attachment: { |
michael@0 | 107 | label: label |
michael@0 | 108 | } |
michael@0 | 109 | }); |
michael@0 | 110 | } |
michael@0 | 111 | break; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | checkSourcesOrder(aMethod); |
michael@0 | 115 | aCallback(); |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | function checkSourcesOrder(aMethod) { |
michael@0 | 119 | let attachments = gSources.attachments; |
michael@0 | 120 | |
michael@0 | 121 | for (let i = 0; i < attachments.length - 1; i++) { |
michael@0 | 122 | let first = attachments[i].label; |
michael@0 | 123 | let second = attachments[i + 1].label; |
michael@0 | 124 | ok(first < second, |
michael@0 | 125 | "Using method " + aMethod + ", " + |
michael@0 | 126 | "the sources weren't in the correct order: " + first + " vs. " + second); |
michael@0 | 127 | } |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | registerCleanupFunction(function() { |
michael@0 | 131 | gTab = null; |
michael@0 | 132 | gDebuggee = null; |
michael@0 | 133 | gPanel = null; |
michael@0 | 134 | gDebugger = null; |
michael@0 | 135 | gSources = null; |
michael@0 | 136 | gUtils = null; |
michael@0 | 137 | }); |