1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_listtabs-02.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,215 @@ 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 + * Make sure the root actor's live tab list implementation works as specified. 1.9 + */ 1.10 + 1.11 +let gTestPage = "data:text/html;charset=utf-8," + encodeURIComponent( 1.12 + "<title>JS Debugger BrowserTabList test page</title><body>Yo.</body>"); 1.13 + 1.14 +// The tablist object whose behavior we observe. 1.15 +let gTabList; 1.16 +let gFirstActor, gActorA; 1.17 +let gTabA, gTabB, gTabC; 1.18 +let gNewWindow; 1.19 + 1.20 +// Stock onListChanged handler. 1.21 +let onListChangedCount = 0; 1.22 +function onListChangedHandler() { 1.23 + onListChangedCount++; 1.24 +} 1.25 + 1.26 +function test() { 1.27 + if (!DebuggerServer.initialized) { 1.28 + DebuggerServer.init(() => true); 1.29 + DebuggerServer.addBrowserActors(); 1.30 + } 1.31 + 1.32 + gTabList = new DebuggerServer.BrowserTabList("fake DebuggerServerConnection"); 1.33 + gTabList._testing = true; 1.34 + gTabList.onListChanged = onListChangedHandler; 1.35 + 1.36 + checkSingleTab() 1.37 + .then(addTabA) 1.38 + .then(testTabA) 1.39 + .then(addTabB) 1.40 + .then(testTabB) 1.41 + .then(removeTabA) 1.42 + .then(testTabClosed) 1.43 + .then(addTabC) 1.44 + .then(testTabC) 1.45 + .then(removeTabC) 1.46 + .then(testNewWindow) 1.47 + .then(removeNewWindow) 1.48 + .then(testWindowClosed) 1.49 + .then(removeTabB) 1.50 + .then(checkSingleTab) 1.51 + .then(finishUp); 1.52 +} 1.53 + 1.54 +function checkSingleTab() { 1.55 + return gTabList.getList().then(aTabActors => { 1.56 + is(aTabActors.length, 1, "initial tab list: contains initial tab"); 1.57 + gFirstActor = aTabActors[0]; 1.58 + is(gFirstActor.url, "about:blank", "initial tab list: initial tab URL is 'about:blank'"); 1.59 + is(gFirstActor.title, "New Tab", "initial tab list: initial tab title is 'New Tab'"); 1.60 + }); 1.61 +} 1.62 + 1.63 +function addTabA() { 1.64 + return addTab(gTestPage).then(aTab => { 1.65 + gTabA = aTab; 1.66 + }); 1.67 +} 1.68 + 1.69 +function testTabA() { 1.70 + is(onListChangedCount, 1, "onListChanged handler call count"); 1.71 + 1.72 + return gTabList.getList().then(aTabActors => { 1.73 + let tabActors = new Set(aTabActors); 1.74 + is(tabActors.size, 2, "gTabA opened: two tabs in list"); 1.75 + ok(tabActors.has(gFirstActor), "gTabA opened: initial tab present"); 1.76 + 1.77 + info("actors: " + [a.url for (a of tabActors)]); 1.78 + gActorA = [a for (a of tabActors) if (a !== gFirstActor)][0]; 1.79 + ok(gActorA.url.match(/^data:text\/html;/), "gTabA opened: new tab URL"); 1.80 + is(gActorA.title, "JS Debugger BrowserTabList test page", "gTabA opened: new tab title"); 1.81 + }); 1.82 +} 1.83 + 1.84 +function addTabB() { 1.85 + return addTab(gTestPage).then(aTab => { 1.86 + gTabB = aTab; 1.87 + }); 1.88 +} 1.89 + 1.90 +function testTabB() { 1.91 + is(onListChangedCount, 2, "onListChanged handler call count"); 1.92 + 1.93 + return gTabList.getList().then(aTabActors => { 1.94 + let tabActors = new Set(aTabActors); 1.95 + is(tabActors.size, 3, "gTabB opened: three tabs in list"); 1.96 + }); 1.97 +} 1.98 + 1.99 +function removeTabA() { 1.100 + let deferred = promise.defer(); 1.101 + 1.102 + once(gBrowser.tabContainer, "TabClose").then(aEvent => { 1.103 + ok(!aEvent.detail, "This was a normal tab close"); 1.104 + 1.105 + // Let the actor's TabClose handler finish first. 1.106 + executeSoon(deferred.resolve); 1.107 + }, false); 1.108 + 1.109 + removeTab(gTabA); 1.110 + return deferred.promise; 1.111 +} 1.112 + 1.113 +function testTabClosed() { 1.114 + is(onListChangedCount, 3, "onListChanged handler call count"); 1.115 + 1.116 + gTabList.getList().then(aTabActors => { 1.117 + let tabActors = new Set(aTabActors); 1.118 + is(tabActors.size, 2, "gTabA closed: two tabs in list"); 1.119 + ok(tabActors.has(gFirstActor), "gTabA closed: initial tab present"); 1.120 + 1.121 + info("actors: " + [a.url for (a of tabActors)]); 1.122 + gActorA = [a for (a of tabActors) if (a !== gFirstActor)][0]; 1.123 + ok(gActorA.url.match(/^data:text\/html;/), "gTabA closed: new tab URL"); 1.124 + is(gActorA.title, "JS Debugger BrowserTabList test page", "gTabA closed: new tab title"); 1.125 + }); 1.126 +} 1.127 + 1.128 +function addTabC() { 1.129 + return addTab(gTestPage).then(aTab => { 1.130 + gTabC = aTab; 1.131 + }); 1.132 +} 1.133 + 1.134 +function testTabC() { 1.135 + is(onListChangedCount, 4, "onListChanged handler call count"); 1.136 + 1.137 + gTabList.getList().then(aTabActors => { 1.138 + let tabActors = new Set(aTabActors); 1.139 + is(tabActors.size, 3, "gTabC opened: three tabs in list"); 1.140 + }); 1.141 +} 1.142 + 1.143 +function removeTabC() { 1.144 + let deferred = promise.defer(); 1.145 + 1.146 + once(gBrowser.tabContainer, "TabClose").then(aEvent => { 1.147 + ok(aEvent.detail, "This was a tab closed by moving"); 1.148 + 1.149 + // Let the actor's TabClose handler finish first. 1.150 + executeSoon(deferred.resolve); 1.151 + }, false); 1.152 + 1.153 + gNewWindow = gBrowser.replaceTabWithWindow(gTabC); 1.154 + return deferred.promise; 1.155 +} 1.156 + 1.157 +function testNewWindow() { 1.158 + is(onListChangedCount, 5, "onListChanged handler call count"); 1.159 + 1.160 + return gTabList.getList().then(aTabActors => { 1.161 + let tabActors = new Set(aTabActors); 1.162 + is(tabActors.size, 3, "gTabC closed: three tabs in list"); 1.163 + ok(tabActors.has(gFirstActor), "gTabC closed: initial tab present"); 1.164 + 1.165 + info("actors: " + [a.url for (a of tabActors)]); 1.166 + gActorA = [a for (a of tabActors) if (a !== gFirstActor)][0]; 1.167 + ok(gActorA.url.match(/^data:text\/html;/), "gTabC closed: new tab URL"); 1.168 + is(gActorA.title, "JS Debugger BrowserTabList test page", "gTabC closed: new tab title"); 1.169 + }); 1.170 +} 1.171 + 1.172 +function removeNewWindow() { 1.173 + let deferred = promise.defer(); 1.174 + 1.175 + once(gNewWindow, "unload").then(aEvent => { 1.176 + ok(!aEvent.detail, "This was a normal window close"); 1.177 + 1.178 + // Let the actor's TabClose handler finish first. 1.179 + executeSoon(deferred.resolve); 1.180 + }, false); 1.181 + 1.182 + gNewWindow.close(); 1.183 + return deferred.promise; 1.184 +} 1.185 + 1.186 +function testWindowClosed() { 1.187 + is(onListChangedCount, 6, "onListChanged handler call count"); 1.188 + 1.189 + return gTabList.getList().then(aTabActors => { 1.190 + let tabActors = new Set(aTabActors); 1.191 + is(tabActors.size, 2, "gNewWindow closed: two tabs in list"); 1.192 + ok(tabActors.has(gFirstActor), "gNewWindow closed: initial tab present"); 1.193 + 1.194 + info("actors: " + [a.url for (a of tabActors)]); 1.195 + gActorA = [a for (a of tabActors) if (a !== gFirstActor)][0]; 1.196 + ok(gActorA.url.match(/^data:text\/html;/), "gNewWindow closed: new tab URL"); 1.197 + is(gActorA.title, "JS Debugger BrowserTabList test page", "gNewWindow closed: new tab title"); 1.198 + }); 1.199 +} 1.200 + 1.201 +function removeTabB() { 1.202 + let deferred = promise.defer(); 1.203 + 1.204 + once(gBrowser.tabContainer, "TabClose").then(aEvent => { 1.205 + ok(!aEvent.detail, "This was a normal tab close"); 1.206 + 1.207 + // Let the actor's TabClose handler finish first. 1.208 + executeSoon(deferred.resolve); 1.209 + }, false); 1.210 + 1.211 + removeTab(gTabB); 1.212 + return deferred.promise; 1.213 +} 1.214 + 1.215 +function finishUp() { 1.216 + gTabList = gFirstActor = gActorA = gTabA = gTabB = gTabC = gNewWindow = null; 1.217 + finish(); 1.218 +}