Files
firefox/devtools/client/shared/test/browser_dbg_debugger-statement.js
T
Alexandre Poirot 0205bcb97a Bug 1509315 - Use TargetFactory.forTab for creating targets in tests. r=yulia
There is 4 patterns here:
* Tests using attachThreadActorForUrl like event-listeners ones. I augmented this helper method to call TargetFactory.
* Tests using attachTargetActorForUrl like debugger-statement, dbg-navigation and target-scoped-actor. Uses TargetFactory directly.
* Tests using connectDebuggerClient like navigateEvents and spaw_actor_in_parent. Uses TargetFactory directly.
* All the others, where creating DebuggerClient on their own, and calling listTabs+attachTarget. They now use TargetFactory directly.

A note about webconsole-helpers, only consoleClient attribute was used from tests using this helper.
Also, in various tests I remove the call to client.destroy, that's because shared-head will
close all the tabs/toolboxes and it should lead to target/client destruction.
Finally, debugger-statement now request the thread actor via the client instead of manual request,
it should help the refactoring to a front!

MozReview-Commit-ID: 2ah4UmSjuoi

Depends on D12730

Differential Revision: https://phabricator.services.mozilla.com/D12731
2018-11-27 21:47:59 +00:00

68 lines
2.0 KiB
JavaScript

/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Tests the behavior of the debugger statement.
*/
// Import helpers for the workers
/* import-globals-from helper_workers.js */
Services.scriptloader.loadSubScript(
"chrome://mochitests/content/browser/devtools/client/shared/test/helper_workers.js",
this);
const TAB_URL = TEST_URI_ROOT + "doc_inline-debugger-statement.html";
add_task(async () => {
const tab = await addTab(TAB_URL);
const target = await TargetFactory.forTab(tab);
await target.attach();
const { client } = target;
const targetFront = target.activeTab;
const threadClient = await testEarlyDebuggerStatement(client, tab, targetFront);
await testDebuggerStatement(client, tab, threadClient);
await target.destroy();
});
async function testEarlyDebuggerStatement(client, tab, targetFront) {
const onPaused = function(event, packet) {
ok(false, "Pause shouldn't be called before we've attached!");
};
client.addListener("paused", onPaused);
// This should continue without nesting an event loop and calling
// the onPaused hook, because we haven't attached yet.
callInTab(tab, "runDebuggerStatement");
client.removeListener("paused", onPaused);
// Now attach and resume...
const [, threadClient] = await targetFront.attachThread();
await threadClient.resume();
ok(true, "Pause wasn't called before we've attached.");
return threadClient;
}
async function testDebuggerStatement(client, tab, threadClient) {
const onPaused = new Promise(resolve => {
client.addListener("paused", async (event, packet) => {
await threadClient.resume();
ok(true, "The pause handler was triggered on a debugger statement.");
resolve();
});
});
// Reach around the debugging protocol and execute the debugger statement.
callInTab(tab, "runDebuggerStatement");
return onPaused;
}