blob: 1cfa04be76f44191f7c9c02e123aadef7b62ac43 [file] [log] [blame]
<!doctype html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script src="resources/test-view.js"></script>
<script>
function test()
{
InspectorTest.redirectRequestAnimationFrame();
let suite = InspectorTest.createAsyncSuite("View.AsynchronousLayout");
suite.addTestCase({
name: "View.automaticLayout",
test(resolve, reject) {
let view = new WI.TestView;
WI.View.rootView().addSubview(view);
InspectorTest.expectThat(view.layoutPending, "View should have a pending layout once it is attached.");
view.evaluateAfterLayout(() => {
InspectorTest.log("Layout complete.");
InspectorTest.expectEqual(view.initialLayoutCount, 1, "View should do an initial layout.");
InspectorTest.expectEqual(view.layoutCount, 1, "View should update its layout.");
InspectorTest.expectFalse(view.layoutPending, "View should not have a pending layout.");
resolve();
});
}
});
suite.addTestCase({
name: "View.automaticLayout.cancelled",
test(resolve, reject) {
let view = new WI.TestView;
WI.View.rootView().addSubview(view);
InspectorTest.expectThat(view.layoutPending, "View should have a pending layout once it is attached.");
WI.View.rootView().removeSubview(view);
InspectorTest.expectFalse(view.layoutPending, "View should not have a pending layout once it is detached.");
resolve();
}
});
suite.addTestCase({
name: "View.needsLayout",
test(resolve, reject) {
let view = new WI.TestView;
WI.View.rootView().addSubview(view);
InspectorTest.log("Flush pending layouts, then schedule an update.");
view.updateLayout();
view.needsLayout();
InspectorTest.expectThat(view.layoutPending, "View should have a pending layout.");
view.evaluateAfterLayout(() => {
InspectorTest.log("Layout complete.");
InspectorTest.expectEqual(view.layoutCount, 2, "View should update its layout.");
InspectorTest.expectFalse(view.layoutPending, "View should not have a pending layout.");
resolve();
});
}
});
suite.addTestCase({
name: "View.needsLayout.propogateToSubview",
test(resolve, reject) {
let parent = new WI.TestView;
let child = new WI.TestView;
WI.View.rootView().addSubview(parent);
parent.addSubview(child);
InspectorTest.log("Schedule parent view update.");
parent.needsLayout();
child.evaluateAfterLayout(() => {
InspectorTest.log("Layout complete.");
InspectorTest.expectEqual(child.initialLayoutCount, 1, "Chlid view should do an initial layout.");
InspectorTest.expectEqual(child.layoutCount, 1, "Child view should update its layout.");
resolve();
});
}
});
suite.addTestCase({
name: "View.cancelLayout",
test(resolve, reject) {
let view = new WI.TestView;
WI.View.rootView().addSubview(view);
InspectorTest.log("Cancel automatic layout.");
view.cancelLayout();
InspectorTest.expectFalse(view.layoutPending, "View should not have a pending layout.");
InspectorTest.log("Cancel scheduled layout.");
view.needsLayout();
view.cancelLayout();
InspectorTest.expectFalse(view.layoutPending, "View should not have a pending layout.");
resolve();
}
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
<p>Testing asynchronous View layout operations: needsLayout, cancelLayout.</p>
</body>
</html>