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 | * Make sure the root actor's live tab list implementation works as specified. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | let gTestPage = "data:text/html;charset=utf-8," + encodeURIComponent( |
michael@0 | 9 | "<title>JS Debugger BrowserTabList test page</title><body>Yo.</body>"); |
michael@0 | 10 | |
michael@0 | 11 | // The tablist object whose behavior we observe. |
michael@0 | 12 | let gTabList; |
michael@0 | 13 | let gFirstActor, gActorA; |
michael@0 | 14 | let gTabA, gTabB, gTabC; |
michael@0 | 15 | let gNewWindow; |
michael@0 | 16 | |
michael@0 | 17 | // Stock onListChanged handler. |
michael@0 | 18 | let onListChangedCount = 0; |
michael@0 | 19 | function onListChangedHandler() { |
michael@0 | 20 | onListChangedCount++; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | function test() { |
michael@0 | 24 | if (!DebuggerServer.initialized) { |
michael@0 | 25 | DebuggerServer.init(() => true); |
michael@0 | 26 | DebuggerServer.addBrowserActors(); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | gTabList = new DebuggerServer.BrowserTabList("fake DebuggerServerConnection"); |
michael@0 | 30 | gTabList._testing = true; |
michael@0 | 31 | gTabList.onListChanged = onListChangedHandler; |
michael@0 | 32 | |
michael@0 | 33 | checkSingleTab() |
michael@0 | 34 | .then(addTabA) |
michael@0 | 35 | .then(testTabA) |
michael@0 | 36 | .then(addTabB) |
michael@0 | 37 | .then(testTabB) |
michael@0 | 38 | .then(removeTabA) |
michael@0 | 39 | .then(testTabClosed) |
michael@0 | 40 | .then(addTabC) |
michael@0 | 41 | .then(testTabC) |
michael@0 | 42 | .then(removeTabC) |
michael@0 | 43 | .then(testNewWindow) |
michael@0 | 44 | .then(removeNewWindow) |
michael@0 | 45 | .then(testWindowClosed) |
michael@0 | 46 | .then(removeTabB) |
michael@0 | 47 | .then(checkSingleTab) |
michael@0 | 48 | .then(finishUp); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | function checkSingleTab() { |
michael@0 | 52 | return gTabList.getList().then(aTabActors => { |
michael@0 | 53 | is(aTabActors.length, 1, "initial tab list: contains initial tab"); |
michael@0 | 54 | gFirstActor = aTabActors[0]; |
michael@0 | 55 | is(gFirstActor.url, "about:blank", "initial tab list: initial tab URL is 'about:blank'"); |
michael@0 | 56 | is(gFirstActor.title, "New Tab", "initial tab list: initial tab title is 'New Tab'"); |
michael@0 | 57 | }); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function addTabA() { |
michael@0 | 61 | return addTab(gTestPage).then(aTab => { |
michael@0 | 62 | gTabA = aTab; |
michael@0 | 63 | }); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | function testTabA() { |
michael@0 | 67 | is(onListChangedCount, 1, "onListChanged handler call count"); |
michael@0 | 68 | |
michael@0 | 69 | return gTabList.getList().then(aTabActors => { |
michael@0 | 70 | let tabActors = new Set(aTabActors); |
michael@0 | 71 | is(tabActors.size, 2, "gTabA opened: two tabs in list"); |
michael@0 | 72 | ok(tabActors.has(gFirstActor), "gTabA opened: initial tab present"); |
michael@0 | 73 | |
michael@0 | 74 | info("actors: " + [a.url for (a of tabActors)]); |
michael@0 | 75 | gActorA = [a for (a of tabActors) if (a !== gFirstActor)][0]; |
michael@0 | 76 | ok(gActorA.url.match(/^data:text\/html;/), "gTabA opened: new tab URL"); |
michael@0 | 77 | is(gActorA.title, "JS Debugger BrowserTabList test page", "gTabA opened: new tab title"); |
michael@0 | 78 | }); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | function addTabB() { |
michael@0 | 82 | return addTab(gTestPage).then(aTab => { |
michael@0 | 83 | gTabB = aTab; |
michael@0 | 84 | }); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | function testTabB() { |
michael@0 | 88 | is(onListChangedCount, 2, "onListChanged handler call count"); |
michael@0 | 89 | |
michael@0 | 90 | return gTabList.getList().then(aTabActors => { |
michael@0 | 91 | let tabActors = new Set(aTabActors); |
michael@0 | 92 | is(tabActors.size, 3, "gTabB opened: three tabs in list"); |
michael@0 | 93 | }); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | function removeTabA() { |
michael@0 | 97 | let deferred = promise.defer(); |
michael@0 | 98 | |
michael@0 | 99 | once(gBrowser.tabContainer, "TabClose").then(aEvent => { |
michael@0 | 100 | ok(!aEvent.detail, "This was a normal tab close"); |
michael@0 | 101 | |
michael@0 | 102 | // Let the actor's TabClose handler finish first. |
michael@0 | 103 | executeSoon(deferred.resolve); |
michael@0 | 104 | }, false); |
michael@0 | 105 | |
michael@0 | 106 | removeTab(gTabA); |
michael@0 | 107 | return deferred.promise; |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | function testTabClosed() { |
michael@0 | 111 | is(onListChangedCount, 3, "onListChanged handler call count"); |
michael@0 | 112 | |
michael@0 | 113 | gTabList.getList().then(aTabActors => { |
michael@0 | 114 | let tabActors = new Set(aTabActors); |
michael@0 | 115 | is(tabActors.size, 2, "gTabA closed: two tabs in list"); |
michael@0 | 116 | ok(tabActors.has(gFirstActor), "gTabA closed: initial tab present"); |
michael@0 | 117 | |
michael@0 | 118 | info("actors: " + [a.url for (a of tabActors)]); |
michael@0 | 119 | gActorA = [a for (a of tabActors) if (a !== gFirstActor)][0]; |
michael@0 | 120 | ok(gActorA.url.match(/^data:text\/html;/), "gTabA closed: new tab URL"); |
michael@0 | 121 | is(gActorA.title, "JS Debugger BrowserTabList test page", "gTabA closed: new tab title"); |
michael@0 | 122 | }); |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | function addTabC() { |
michael@0 | 126 | return addTab(gTestPage).then(aTab => { |
michael@0 | 127 | gTabC = aTab; |
michael@0 | 128 | }); |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | function testTabC() { |
michael@0 | 132 | is(onListChangedCount, 4, "onListChanged handler call count"); |
michael@0 | 133 | |
michael@0 | 134 | gTabList.getList().then(aTabActors => { |
michael@0 | 135 | let tabActors = new Set(aTabActors); |
michael@0 | 136 | is(tabActors.size, 3, "gTabC opened: three tabs in list"); |
michael@0 | 137 | }); |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | function removeTabC() { |
michael@0 | 141 | let deferred = promise.defer(); |
michael@0 | 142 | |
michael@0 | 143 | once(gBrowser.tabContainer, "TabClose").then(aEvent => { |
michael@0 | 144 | ok(aEvent.detail, "This was a tab closed by moving"); |
michael@0 | 145 | |
michael@0 | 146 | // Let the actor's TabClose handler finish first. |
michael@0 | 147 | executeSoon(deferred.resolve); |
michael@0 | 148 | }, false); |
michael@0 | 149 | |
michael@0 | 150 | gNewWindow = gBrowser.replaceTabWithWindow(gTabC); |
michael@0 | 151 | return deferred.promise; |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | function testNewWindow() { |
michael@0 | 155 | is(onListChangedCount, 5, "onListChanged handler call count"); |
michael@0 | 156 | |
michael@0 | 157 | return gTabList.getList().then(aTabActors => { |
michael@0 | 158 | let tabActors = new Set(aTabActors); |
michael@0 | 159 | is(tabActors.size, 3, "gTabC closed: three tabs in list"); |
michael@0 | 160 | ok(tabActors.has(gFirstActor), "gTabC closed: initial tab present"); |
michael@0 | 161 | |
michael@0 | 162 | info("actors: " + [a.url for (a of tabActors)]); |
michael@0 | 163 | gActorA = [a for (a of tabActors) if (a !== gFirstActor)][0]; |
michael@0 | 164 | ok(gActorA.url.match(/^data:text\/html;/), "gTabC closed: new tab URL"); |
michael@0 | 165 | is(gActorA.title, "JS Debugger BrowserTabList test page", "gTabC closed: new tab title"); |
michael@0 | 166 | }); |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | function removeNewWindow() { |
michael@0 | 170 | let deferred = promise.defer(); |
michael@0 | 171 | |
michael@0 | 172 | once(gNewWindow, "unload").then(aEvent => { |
michael@0 | 173 | ok(!aEvent.detail, "This was a normal window close"); |
michael@0 | 174 | |
michael@0 | 175 | // Let the actor's TabClose handler finish first. |
michael@0 | 176 | executeSoon(deferred.resolve); |
michael@0 | 177 | }, false); |
michael@0 | 178 | |
michael@0 | 179 | gNewWindow.close(); |
michael@0 | 180 | return deferred.promise; |
michael@0 | 181 | } |
michael@0 | 182 | |
michael@0 | 183 | function testWindowClosed() { |
michael@0 | 184 | is(onListChangedCount, 6, "onListChanged handler call count"); |
michael@0 | 185 | |
michael@0 | 186 | return gTabList.getList().then(aTabActors => { |
michael@0 | 187 | let tabActors = new Set(aTabActors); |
michael@0 | 188 | is(tabActors.size, 2, "gNewWindow closed: two tabs in list"); |
michael@0 | 189 | ok(tabActors.has(gFirstActor), "gNewWindow closed: initial tab present"); |
michael@0 | 190 | |
michael@0 | 191 | info("actors: " + [a.url for (a of tabActors)]); |
michael@0 | 192 | gActorA = [a for (a of tabActors) if (a !== gFirstActor)][0]; |
michael@0 | 193 | ok(gActorA.url.match(/^data:text\/html;/), "gNewWindow closed: new tab URL"); |
michael@0 | 194 | is(gActorA.title, "JS Debugger BrowserTabList test page", "gNewWindow closed: new tab title"); |
michael@0 | 195 | }); |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | function removeTabB() { |
michael@0 | 199 | let deferred = promise.defer(); |
michael@0 | 200 | |
michael@0 | 201 | once(gBrowser.tabContainer, "TabClose").then(aEvent => { |
michael@0 | 202 | ok(!aEvent.detail, "This was a normal tab close"); |
michael@0 | 203 | |
michael@0 | 204 | // Let the actor's TabClose handler finish first. |
michael@0 | 205 | executeSoon(deferred.resolve); |
michael@0 | 206 | }, false); |
michael@0 | 207 | |
michael@0 | 208 | removeTab(gTabB); |
michael@0 | 209 | return deferred.promise; |
michael@0 | 210 | } |
michael@0 | 211 | |
michael@0 | 212 | function finishUp() { |
michael@0 | 213 | gTabList = gFirstActor = gActorA = gTabA = gTabB = gTabC = gNewWindow = null; |
michael@0 | 214 | finish(); |
michael@0 | 215 | } |