browser/devtools/debugger/test/browser_dbg_navigation.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 * Check tab attach/navigation.
michael@0 6 */
michael@0 7
michael@0 8 const TAB1_URL = EXAMPLE_URL + "doc_empty-tab-01.html";
michael@0 9 const TAB2_URL = EXAMPLE_URL + "doc_empty-tab-02.html";
michael@0 10
michael@0 11 let gClient;
michael@0 12
michael@0 13 function test() {
michael@0 14 if (!DebuggerServer.initialized) {
michael@0 15 DebuggerServer.init(() => true);
michael@0 16 DebuggerServer.addBrowserActors();
michael@0 17 }
michael@0 18
michael@0 19 let transport = DebuggerServer.connectPipe();
michael@0 20 gClient = new DebuggerClient(transport);
michael@0 21 gClient.connect((aType, aTraits) => {
michael@0 22 is(aType, "browser",
michael@0 23 "Root actor should identify itself as a browser.");
michael@0 24
michael@0 25 addTab(TAB1_URL)
michael@0 26 .then(() => attachTabActorForUrl(gClient, TAB1_URL))
michael@0 27 .then(testNavigate)
michael@0 28 .then(testDetach)
michael@0 29 .then(finish)
michael@0 30 .then(null, aError => {
michael@0 31 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
michael@0 32 });
michael@0 33 });
michael@0 34 }
michael@0 35
michael@0 36 function testNavigate([aGrip, aResponse]) {
michael@0 37 let outstanding = [promise.defer(), promise.defer()];
michael@0 38
michael@0 39 gClient.addListener("tabNavigated", function onTabNavigated(aEvent, aPacket) {
michael@0 40 is(aPacket.url, TAB2_URL,
michael@0 41 "Got a tab navigation notification.");
michael@0 42
michael@0 43 if (aPacket.state == "start") {
michael@0 44 ok(true, "Tab started to navigate.");
michael@0 45 outstanding[0].resolve();
michael@0 46 } else {
michael@0 47 ok(true, "Tab finished navigating.");
michael@0 48 gClient.removeListener("tabNavigated", onTabNavigated);
michael@0 49 outstanding[1].resolve();
michael@0 50 }
michael@0 51 });
michael@0 52
michael@0 53 gBrowser.selectedTab.linkedBrowser.loadURI(TAB2_URL);
michael@0 54 return promise.all(outstanding.map(e => e.promise))
michael@0 55 .then(() => aGrip.actor);
michael@0 56 }
michael@0 57
michael@0 58 function testDetach(aActor) {
michael@0 59 let deferred = promise.defer();
michael@0 60
michael@0 61 gClient.addOneTimeListener("tabDetached", (aType, aPacket) => {
michael@0 62 ok(true, "Got a tab detach notification.");
michael@0 63 is(aPacket.from, aActor, "tab detach message comes from the expected actor");
michael@0 64 gClient.close(deferred.resolve);
michael@0 65 });
michael@0 66
michael@0 67 removeTab(gBrowser.selectedTab);
michael@0 68 return deferred.promise;
michael@0 69 }
michael@0 70
michael@0 71 registerCleanupFunction(function() {
michael@0 72 gClient = null;
michael@0 73 });

mercurial