function checkMap(contents, expected) {
expected = Array.from(expected);
equal(contents.keys.length, expected.length, "Got correct number of keys");
equal(
contents.values.length,
expected.length, "Got correct number of values"
);
equal(
contents.entries.length,
expected.length, "Got correct number of entries"
);
if (!parentOnly) {
info("Checking out-of-process content map");
let contents = await contentPage.spawn([], getContents);
checkMap(contents, expected);
}
}
async function loadContentPage() {
let page = await XPCShellContentUtils.loadContentPage("data:text/html,", {
remote,
});
registerCleanupFunction(() => page.close()); return page;
}
add_setup(async function () { // Start with one content process so that we can increase the number // later and test the behavior of a fresh content process.
Services.prefs.setIntPref(PROCESS_COUNT_PREF, 1);
contentPage = await loadContentPage();
});
add_task(async function test_sharedMap() {
let { sharedData } = Services.ppmm;
info("Check that parent and child maps are both initially empty");
checkParentMap([]);
await checkContentMaps([]);
let expected = [
["foo-a", { foo: "a" }],
["foo-b", { foo: "b" }],
["bar-c", null],
["bar-d", 42],
];
function setKey(key, val) {
sharedData.set(key, val);
expected = expected.filter(([k]) => k != key);
expected.push([key, val]);
} function deleteKey(key) {
sharedData.delete(key);
expected = expected.filter(([k]) => k != key);
}
for (let [key, val] of expected) {
sharedData.set(key, val);
}
info( "Add some entries, test that they are initially only available in the parent"
);
info( "Add another entry. Check that it is initially only available in the parent"
);
let oldExpected = Array.from(expected);
setKey("baz-a", { meh: "meh" });
// When we do several checks in a row, we can't check the values in // the content process, since the async checks may allow the idle // flush task to run, and update it before we're ready.
// Test that has() rebuilds map after a flush.
sharedData.set("grick", true);
sharedData.flush();
equal(
await contentPage.spawn(["grick"], hasKey), true, "has() should see key after flush"
);
sharedData.set("grack", true);
sharedData.flush();
equal(
await contentPage.spawn(["gruck"], hasKey), false, "has() should return false for nonexistent key"
);
});
add_task(async function test_blobs() {
let { sharedData } = Services.ppmm;
let text = [ "The quick brown fox jumps over the lazy dog", "Lorem ipsum dolor sit amet, consectetur adipiscing elit", "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
];
let blobs = text.map(str => new Blob([str]));
equal(
await readBlob("blob0", sharedData),
text[0], "Expected text for blob0 in parent ppmm"
);
sharedData.flush();
equal(
await readBlob("blob0", sharedData),
text[0], "Expected text for blob0 in parent ppmm"
);
equal(
await readBlob("blob1", sharedData),
text[1], "Expected text for blob1 in parent ppmm"
);
equal(
await readBlob("blob0"),
text[0], "Expected text for blob0 in parent cpmm"
);
equal(
await readBlob("blob1"),
text[1], "Expected text for blob1 in parent cpmm"
);
equal(
await contentPage.spawn(["blob0"], readBlob),
text[0], "Expected text for blob0 in child 1 cpmm"
);
equal(
await contentPage.spawn(["blob1"], readBlob),
text[1], "Expected text for blob1 in child 1 cpmm"
);
// Start a second child process
Services.prefs.setIntPref(PROCESS_COUNT_PREF, 2);
let page2 = await loadContentPage();
equal(
await page2.spawn(["blob0"], readBlob),
text[0], "Expected text for blob0 in child 2 cpmm"
);
equal(
await page2.spawn(["blob1"], readBlob),
text[1], "Expected text for blob1 in child 2 cpmm"
);
sharedData.set("blob0", blobs[2]);
equal(
await readBlob("blob0", sharedData),
text[2], "Expected text for blob0 in parent ppmm"
);
sharedData.flush();
equal(
await readBlob("blob0", sharedData),
text[2], "Expected text for blob0 in parent ppmm"
);
equal(
await readBlob("blob1", sharedData),
text[1], "Expected text for blob1 in parent ppmm"
);
equal(
await readBlob("blob0"),
text[2], "Expected text for blob0 in parent cpmm"
);
equal(
await readBlob("blob1"),
text[1], "Expected text for blob1 in parent cpmm"
);
equal(
await contentPage.spawn(["blob0"], readBlob),
text[2], "Expected text for blob0 in child 1 cpmm"
);
equal(
await contentPage.spawn(["blob1"], readBlob),
text[1], "Expected text for blob1 in child 1 cpmm"
);
equal(
await page2.spawn(["blob0"], readBlob),
text[2], "Expected text for blob0 in child 2 cpmm"
);
equal(
await page2.spawn(["blob1"], readBlob),
text[1], "Expected text for blob1 in child 2 cpmm"
);
deepEqual(
await page2.spawn(["data"], getKey),
data, "Expected data for data key in child 2 cpmm"
);
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.