Files
firefox/devtools/server/tests/unit/test_objectgrips-array-like-object.js
T
Alexandre Poirot f381d2e193 Bug 1508287 - Refactor most debugger server test using run_test_with_server to share more code. r=yulia
There is a lot of code being copy paste in all these tests
and as I'm most likely going to change things around them in the near future
regarding fission, it would be better if we start sharing more code.

After this there is still a couple of copy paste code (but way less!):
* breakpoints: wait a paused event and eval a custom script in a sandbox
* object grips: set the security.allow_eval_with_system_principal pref, eval stopMe and wait for paused
* stepping: use executeOnNextTickAndWaitForPause to eval a custom script and wait for pause while doing this only on next tick

There is most likely more to share, but at least this isn't framework code, but now only code specific to the debugger.

MozReview-Commit-ID: JgD389cas2j

Depends on D12309

Differential Revision: https://phabricator.services.mozilla.com/D12310
2018-11-22 15:23:22 +00:00

58 lines
2.4 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test that objects are labeled as ArrayLike only when they have sequential
// numeric keys, and if they have a length property, that it matches the number
// of numeric keys. (See Bug 1371936)
Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true);
registerCleanupFunction(() => {
Services.prefs.clearUserPref("security.allow_eval_with_system_principal");
});
add_task(threadClientTest(async ({ threadClient, debuggee, client }) => {
debuggee.eval(function stopMe(arg1) {
debugger;
}.toString());
// Currying test function so we don't have to pass the debuggee and clients
const isArrayLike = object => test_object_grip_is_array_like(
debuggee, client, threadClient, object);
equal(await isArrayLike({}), false, "An empty object is not ArrayLike");
equal(await isArrayLike({length: 0}), false,
"An object with only a length property is not ArrayLike");
equal(await isArrayLike({2: "two"}), false,
"Object not starting at 0 is not ArrayLike");
equal(await isArrayLike({0: "zero", 2: "two"}), false,
"Object with non-consecutive numeric keys is not ArrayLike");
equal(await isArrayLike({0: "zero", 2: "two", length: 2}), false,
"Object with non-consecutive numeric keys is not ArrayLike");
equal(await isArrayLike({0: "zero", 1: "one", 2: "two", three: 3}), false,
"Object with a non-numeric property other than `length` is not ArrayLike");
equal(await isArrayLike({0: "zero", 1: "one", 2: "two", three: 3, length: 3}), false,
"Object with a non-numeric property other than `length` is not ArrayLike");
equal(await isArrayLike({0: "zero", 1: "one", 2: "two", length: 30}), false,
"Object with a wrongful `length` property is not ArrayLike");
equal(await isArrayLike({0: "zero"}), true);
equal(await isArrayLike({0: "zero", 1: "two"}), true);
equal(await isArrayLike({0: "zero", 1: "one", 2: "two", length: 3}), true);
}));
async function test_object_grip_is_array_like(debuggee, dbgClient, threadClient, object) {
return new Promise((resolve, reject) => {
threadClient.addOneTimeListener("paused", async function(event, packet) {
const [grip] = packet.frame.arguments;
await threadClient.resume();
resolve(grip.preview.kind === "ArrayLike");
});
debuggee.eval(`
stopMe(${JSON.stringify(object)});
`);
});
}