blob: 2d30beab7fab246c8c5c2650d60fad57ece55271 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script>
function test()
{
let suite = InspectorTest.createAsyncSuite("Runtime.getPreview");
// ------ RemoteObject.prototype.updatePreview
suite.addTestCase({
name: "RemoteObject.updatePreview.ObjectWithoutPreview",
description: "Should be able to update the preview of a RemoteObject without a preview.",
test(resolve, reject) {
RuntimeAgent.evaluate.invoke({expression: `({a:1, b:2})`, objectGroup: "test", generatePreview: false}, (error, remoteObjectPayload) => {
InspectorTest.assert(!error, "Should not be a protocol error.");
let remoteObject = WI.RemoteObject.fromPayload(remoteObjectPayload);
InspectorTest.expectThat(!remoteObject.preview, "RemoteObject should not have a preview.");
InspectorTest.expectThat(remoteObject.canLoadPreview(), "RemoteObject should be able to load a preview.");
remoteObject.updatePreview((preview) => {
InspectorTest.expectThat(preview instanceof WI.ObjectPreview, "RemoteObject.updatePreview should produce an ObjectPreview.");
InspectorTest.expectEqual(remoteObject.preview, preview, "RemoteObject.preview should be the same object as the callback.");
InspectorTest.expectEqual(remoteObject.preview.propertyPreviews.length, 2, "Preview should have 2 properties.");
resolve();
});
});
}
});
suite.addTestCase({
name: "RemoteObject.updatePreview.ObjectWithPreview",
description: "Should be able to update the preview of a RemoteObject with a preview.",
test(resolve, reject) {
RuntimeAgent.evaluate.invoke({expression: `window.alpha = ({a:1, b:2, c:3})`, objectGroup: "test", generatePreview: true}, (error, remoteObjectPayload) => {
InspectorTest.assert(!error, "Should not be a protocol error.");
let remoteObject = WI.RemoteObject.fromPayload(remoteObjectPayload);
let originalPreview = remoteObject.preview;
InspectorTest.expectThat(remoteObject.preview, "RemoteObject should have a preview.");
InspectorTest.expectThat(remoteObject.canLoadPreview(), "RemoteObject should be able to load a preview.");
InspectorTest.expectEqual(originalPreview.propertyPreviews.length, 3, "Original preview should have 3 properties.");
InspectorTest.evaluateInPage(`window.alpha.d = 4`, () => {
remoteObject.updatePreview((preview) => {
InspectorTest.expectThat(preview instanceof WI.ObjectPreview, "RemoteObject.updatePreview should produce an ObjectPreview.");
InspectorTest.expectEqual(remoteObject.preview, preview, "RemoteObject.preview should be the same object as the callback.");
InspectorTest.expectEqual(remoteObject.preview.propertyPreviews.length, 4, "Preview should now have 4 properties.");
resolve();
});
});
});
}
});
suite.addTestCase({
name: "RemoteObject.updatePreview.NonObject",
description: "Non-object RemoteObjects should not request a preview.",
test(resolve, reject) {
function testRemoteObject(remoteObject, preferredTypeName) {
InspectorTest.expectThat(!remoteObject.canLoadPreview(), `Should not be able to load a preview for a ${preferredTypeName || remoteObject.type} RemoteObject.`);
remoteObject.updatePreview((preview) => {
InspectorTest.expectNull(preview, `RemoteObject.updatePreview should return null for a ${preferredTypeName || remoteObject.type} RemoteObject.`);
});
}
testRemoteObject(WI.RemoteObject.fromPrimitiveValue(true));
testRemoteObject(WI.RemoteObject.fromPrimitiveValue(100));
testRemoteObject(WI.RemoteObject.fromPrimitiveValue("str"));
testRemoteObject(WI.RemoteObject.createFakeRemoteObject(), "fake object");
InspectorBackend.runAfterPendingDispatches(resolve);
}
});
suite.addTestCase({
name: "RemoteObject.updatePreview.Symbol",
description: "Non-object RemoteObjects should not request a preview.",
test(resolve, reject) {
InspectorTest.evaluateInPage(`Symbol.iterator`, (error, remoteObject) => {
InspectorTest.expectThat(!remoteObject.canLoadPreview(), `Should not be able to load a preview for a ${remoteObject.type} RemoteObject.`);
remoteObject.updatePreview((preview) => {
InspectorTest.expectNull(preview, `RemoteObject.updatePreview should return null for a ${remoteObject.type} RemoteObject.`);
resolve();
});
});
}
});
suite.addTestCase({
name: "RemoteObject.updatePreview.Function",
description: "Non-object RemoteObjects should not request a preview.",
test(resolve, reject) {
InspectorTest.evaluateInPage(`function f() {}; f`, (error, remoteObject) => {
InspectorTest.expectThat(!remoteObject.canLoadPreview(), `Should not be able to load a preview for a ${remoteObject.type} RemoteObject.`);
remoteObject.updatePreview((preview) => {
InspectorTest.expectNull(preview, `RemoteObject.updatePreview should return null for a ${remoteObject.type} RemoteObject.`);
resolve();
});
});
}
});
suite.addTestCase({
name: "RemoteObject.updatePreview.Null",
description: "Non-object RemoteObjects should not request a preview.",
test(resolve, reject) {
InspectorTest.evaluateInPage(`null`, (error, remoteObject) => {
InspectorTest.expectThat(!remoteObject.canLoadPreview(), `Should not be able to load a preview for a ${remoteObject.subtype} RemoteObject.`);
remoteObject.updatePreview((preview) => {
InspectorTest.expectNull(preview, `RemoteObject.updatePreview should return null for a ${remoteObject.subtype} RemoteObject.`);
resolve();
});
}, {remoteObjectOnly: true});
}
});
// ------ Runtime.getPreview
suite.addTestCase({
name: "Runtime.getPreview.Symbol",
description: "Runtime.getPreview should return an empty preview for non-objects.",
test(resolve, reject) {
InspectorTest.evaluateInPage(`Symbol.iterator`, (error, remoteObject) => {
RuntimeAgent.getPreview(remoteObject.objectId, (error, result) => {
InspectorTest.log(JSON.stringify(result));
resolve();
});
});
}
});
suite.addTestCase({
name: "Runtime.getPreview.Function",
description: "Runtime.getPreview should return an empty preview for non-objects.",
test(resolve, reject) {
InspectorTest.evaluateInPage(`function f() {}; f`, (error, remoteObject) => {
RuntimeAgent.getPreview(remoteObject.objectId, (error, result) => {
InspectorTest.log(JSON.stringify(result));
resolve();
});
});
}
});
// ------
suite.addTestCase({
name: "Runtime.getPreview.InvalidObjectId",
description: "Invalid objectId should produce and error.",
test(resolve, reject) {
const objectId = "DOES_NOT_EXIST";
RuntimeAgent.getPreview(objectId, (error) => {
InspectorTest.expectThat(error, "Should produce an error.");
InspectorTest.log("Error: " + error);
resolve();
});
}
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
<p>Tests for the Runtime.getPreview command and associated RemoteObject.prototype.updatePreview.</p>
</body>
</html>