/* Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ */ "use strict"; // Test the ResourceCommand API around ROOT_NODE /** * The original test still asserts some scenarios using several watchRootNode * call sites, which is not something we intend to support at the moment in the * resource command. * * Otherwise this test checks the basic behavior of the resource when reloading * an empty page. */ add_task(async function () { // Open a test tab const tab = await addTab("data:text/html,Root Node tests"); const { client, resourceCommand, targetCommand } = await initResourceCommand( tab ); const browser = gBrowser.selectedBrowser; info("Call watchResources([ROOT_NODE], ...)"); let onAvailableCounter = 0; const onAvailable = resources => (onAvailableCounter += resources.length); await resourceCommand.watchResources([resourceCommand.TYPES.ROOT_NODE], { onAvailable, }); info("Wait until onAvailable has been called"); await waitUntil(() => onAvailableCounter === 1); is(onAvailableCounter, 1, "onAvailable has been called 1 time"); info("Reload the selected browser"); browser.reload(); info( "Wait until the watchResources([ROOT_NODE], ...) callback has been called" ); await waitUntil(() => onAvailableCounter === 2); is(onAvailableCounter, 2, "onAvailable has been called 2 times"); info("Call unwatchResources([ROOT_NODE], ...) for the onAvailable callback"); resourceCommand.unwatchResources([resourceCommand.TYPES.ROOT_NODE], { onAvailable, }); info("Reload the selected browser"); const reloaded = BrowserTestUtils.browserLoaded(browser); browser.reload(); await reloaded; is( onAvailableCounter, 2, "onAvailable was not called after calling unwatchResources" ); // Cleanup targetCommand.destroy(); await client.close(); }); /** * Test that the watchRootNode API provides the expected node fronts. */ add_task(async function testRootNodeFrontIsCorrect() { const tab = await addTab("data:text/html,