From 2ff4c3a1bc39151016102aa16599ab52c3e873f7 Mon Sep 17 00:00:00 2001 From: Jordan Santell Date: Mon, 22 Sep 2014 10:28:00 -0400 Subject: [PATCH] Bug 1066450 - Fix regression of web audio tools not reinitializing after navigation. r=vp --- .../devtools/webaudioeditor/test/browser.ini | 1 + .../test/browser_wa_navigate.js | 45 +++++++++++++++++++ browser/devtools/webaudioeditor/test/head.js | 5 +++ toolkit/devtools/server/actors/webaudio.js | 13 ++++++ 4 files changed, 64 insertions(+) create mode 100644 browser/devtools/webaudioeditor/test/browser_wa_navigate.js diff --git a/browser/devtools/webaudioeditor/test/browser.ini b/browser/devtools/webaudioeditor/test/browser.ini index 943d64760556..9545b68393f9 100644 --- a/browser/devtools/webaudioeditor/test/browser.ini +++ b/browser/devtools/webaudioeditor/test/browser.ini @@ -31,6 +31,7 @@ support-files = [browser_wa_reset-02.js] [browser_wa_reset-03.js] [browser_wa_reset-04.js] +[browser_wa_navigate.js] [browser_wa_graph-click.js] [browser_wa_graph-markers.js] diff --git a/browser/devtools/webaudioeditor/test/browser_wa_navigate.js b/browser/devtools/webaudioeditor/test/browser_wa_navigate.js new file mode 100644 index 000000000000..8bacd64eb59f --- /dev/null +++ b/browser/devtools/webaudioeditor/test/browser_wa_navigate.js @@ -0,0 +1,45 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Tests naviating from a page to another will repopulate + * the audio graph if both pages have an AudioContext. + */ + +function spawnTest() { + let [target, debuggee, panel] = yield initWebAudioEditor(SIMPLE_CONTEXT_URL); + let { panelWin } = panel; + let { gFront, $ } = panelWin; + + reload(target); + + var [actors] = yield Promise.all([ + get3(gFront, "create-node"), + waitForGraphRendered(panelWin, 3, 2) + ]); + + var { nodes, edges } = countGraphObjects(panelWin); + ise(nodes, 3, "should only be 3 nodes."); + ise(edges, 2, "should only be 2 edges."); + + navigate(target, SIMPLE_NODES_URL); + + var [actors] = yield Promise.all([ + getN(gFront, "create-node", 14), + waitForGraphRendered(panelWin, 14, 0) + ]); + + is($("#reload-notice").hidden, true, + "The 'reload this page' notice should be hidden after context found after navigation."); + is($("#waiting-notice").hidden, true, + "The 'waiting for an audio context' notice should be hidden after context found after navigation."); + is($("#content").hidden, false, + "The tool's content should reappear without closing and reopening the toolbox."); + + var { nodes, edges } = countGraphObjects(panelWin); + ise(nodes, 14, "after navigation, should have 14 nodes"); + ise(edges, 0, "after navigation, should have 0 edges."); + + yield teardown(panel); + finish(); +} diff --git a/browser/devtools/webaudioeditor/test/head.js b/browser/devtools/webaudioeditor/test/head.js index 0f5d0cbb2264..d088c36a3cf4 100644 --- a/browser/devtools/webaudioeditor/test/head.js +++ b/browser/devtools/webaudioeditor/test/head.js @@ -114,6 +114,11 @@ function reload(aTarget, aWaitForTargetEvent = "navigate") { return once(aTarget, aWaitForTargetEvent); } +function navigate(aTarget, aUrl, aWaitForTargetEvent = "navigate") { + executeSoon(() => aTarget.activeTab.navigateTo(aUrl)); + return once(aTarget, aWaitForTargetEvent); +} + function test () { Task.spawn(spawnTest).then(finish, handleError); } diff --git a/toolkit/devtools/server/actors/webaudio.js b/toolkit/devtools/server/actors/webaudio.js index 41529ae64b4f..1358696f228c 100644 --- a/toolkit/devtools/server/actors/webaudio.js +++ b/toolkit/devtools/server/actors/webaudio.js @@ -284,6 +284,7 @@ let WebAudioActor = exports.WebAudioActor = protocol.ActorClass({ this._onDestroyNode = this._onDestroyNode.bind(this); this._onGlobalDestroyed = this._onGlobalDestroyed.bind(this); + this._onGlobalCreated = this._onGlobalCreated.bind(this); }, destroy: function(conn) { @@ -322,6 +323,9 @@ let WebAudioActor = exports.WebAudioActor = protocol.ActorClass({ holdWeak: true, storeCalls: false }); + // Bind to `window-ready` so we can reenable recording on the + // call watcher + on(this.tabActor, "window-ready", this._onGlobalCreated); // Bind to the `window-destroyed` event so we can unbind events between // the global destruction and the `finalize` cleanup method on the actor. on(this.tabActor, "window-destroyed", this._onGlobalDestroyed); @@ -395,6 +399,7 @@ let WebAudioActor = exports.WebAudioActor = protocol.ActorClass({ this.tabActor = null; this._initialized = false; off(this.tabActor, "window-destroyed", this._onGlobalDestroyed); + off(this.tabActor, "window-ready", this._onGlobalCreated); this._nativeToActorID = null; this._callWatcher.eraseRecording(); this._callWatcher.finalize(); @@ -569,6 +574,14 @@ let WebAudioActor = exports.WebAudioActor = protocol.ActorClass({ } }, + /** + * Ensures that the new global has recording on + * so we can proxy the function calls. + */ + _onGlobalCreated: function () { + this._callWatcher.resumeRecording(); + }, + /** * Called when the underlying ContentObserver fires `global-destroyed` * so we can cleanup some things between the global being destroyed and