blob: ca8e1407ad5c2775a8f072725e276989d7f4bb9c [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.SyncronousLayoutDuringAsyncronousLayout",
test(resolve, reject) {
let UpdateLayoutTestView = class UpdateLayoutTestView extends WI.TestView {
layout() {
super.layout();
this.subviews[0].updateLayout();
}
}
let rootView = WI.View.rootView();
let parentView = new UpdateLayoutTestView;
let childView = new WI.TestView;
rootView.addSubview(parentView);
parentView.addSubview(childView);
InspectorTest.expectEqual(rootView._dirtyDescendantsCount, 2, "Root view should have 2 dirty descendants.");
InspectorTest.expectEqual(parentView._dirtyDescendantsCount, 1, "Parent view should have 1 dirty descendant.");
InspectorTest.expectEqual(childView._dirtyDescendantsCount, 0, "Child view should have 0 dirty descendants.");
InspectorTest.expectThat(parentView.layoutPending, "View should have a pending layout.");
childView.evaluateAfterLayout(() => {
InspectorTest.log("Child view completed a layout.");
InspectorTest.expectEqual(rootView._dirtyDescendantsCount, 0, "Root view should have 1 dirty descendant.");
InspectorTest.expectEqual(parentView._dirtyDescendantsCount, 0, "Parent view should have 0 dirty descendants.");
InspectorTest.expectEqual(childView._dirtyDescendantsCount, 0, "Child view should have 0 dirty descendants.");
InspectorTest.expectEqual(parentView.layoutCount, 1, "Parent view should have started a layout.");
InspectorTest.expectEqual(childView.layoutCount, 1, "Child view should have completed 1 layout.");
childView.evaluateAfterLayout(() => {
InspectorTest.log("Child view completed a layout.");
InspectorTest.expectEqual(rootView._dirtyDescendantsCount, 0, "Root view should have 0 dirty descendants.");
InspectorTest.expectEqual(parentView._dirtyDescendantsCount, 0, "Parent view should have 0 dirty descendants.");
InspectorTest.expectEqual(childView._dirtyDescendantsCount, 0, "Child view should have 0 dirty descendants.");
InspectorTest.expectEqual(parentView.layoutCount, 1, "Parent view should have started a layout.");
InspectorTest.expectEqual(childView.layoutCount, 2, "Child view should have completed 2 layouts.");
});
});
parentView.evaluateAfterLayout(() => {
InspectorTest.log("Parent view completed a layout.");
InspectorTest.expectEqual(rootView._dirtyDescendantsCount, 0, "Root view should have 0 dirty descendants.");
InspectorTest.expectEqual(parentView._dirtyDescendantsCount, 0, "Root view should have 0 dirty descendants.");
InspectorTest.expectEqual(childView._dirtyDescendantsCount, 0, "Root view should have 0 dirty descendants.");
InspectorTest.expectEqual(parentView.layoutCount, 1, "Parent view should have completed 1 layout.");
InspectorTest.expectFalse(parentView.layoutPending, "Parent 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.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
<p>Testing asynchronous View layout operations: needsLayout, cancelLayout.</p>
</body>
</html>