layout/tests: Add two width resize tests with the same issue as just fixed
Browse files at this commit36af02ad34efb3be9184d1d0449fc1ab42c432caParent: a9f0f4d1 changed file +185 -0
- src/layout/tests/animations.rs +185 -0
src/layout/tests/animations.rsmodified+185 -0
| @@ -913,3 +913,188 @@ fn height_resize_cancel_with_stationary_second_window() { | ||
| 913 | 913 | 200 × 200 at x: 0 y:100 |
| 914 | 914 | "); |
| 915 | 915 | } |
| 916 | + | |
| 917 | +#[test] | |
| 918 | +fn width_resize_and_cancel() { | |
| 919 | + let ops = [ | |
| 920 | + Op::AddOutput(1), | |
| 921 | + Op::AddWindow { | |
| 922 | + params: TestWindowParams::new(1), | |
| 923 | + }, | |
| 924 | + Op::AddWindow { | |
| 925 | + params: TestWindowParams::new(2), | |
| 926 | + }, | |
| 927 | + Op::FocusColumnLeft, | |
| 928 | + Op::SetForcedSize { | |
| 929 | + id: 1, | |
| 930 | + size: Some(Size::new(100, 100)), | |
| 931 | + }, | |
| 932 | + Op::SetForcedSize { | |
| 933 | + id: 2, | |
| 934 | + size: Some(Size::new(200, 200)), | |
| 935 | + }, | |
| 936 | + Op::Communicate(1), | |
| 937 | + Op::Communicate(2), | |
| 938 | + Op::CompleteAnimations, | |
| 939 | + ]; | |
| 940 | + let mut layout = check_ops_with_options(make_options(), &ops); | |
| 941 | + | |
| 942 | + // The initial state. | |
| 943 | + assert_snapshot!(format_tiles(&layout), @r" | |
| 944 | + 100 × 100 at x: 0 y: 0 | |
| 945 | + 200 × 200 at x:100 y: 0 | |
| 946 | + "); | |
| 947 | + | |
| 948 | + let ops = [ | |
| 949 | + // Issue a resize. | |
| 950 | + Op::SetWindowWidth { | |
| 951 | + id: None, | |
| 952 | + change: SizeChange::SetFixed(200), | |
| 953 | + }, | |
| 954 | + // The left window grows in response. | |
| 955 | + Op::SetForcedSize { | |
| 956 | + id: 1, | |
| 957 | + size: Some(Size::new(200, 100)), | |
| 958 | + }, | |
| 959 | + // This starts the resize animation. | |
| 960 | + Op::Communicate(1), | |
| 961 | + Op::Communicate(2), | |
| 962 | + // Advance the time slightly. | |
| 963 | + Op::AdvanceAnimations { msec_delta: 50 }, | |
| 964 | + ]; | |
| 965 | + check_ops_on_layout(&mut layout, &ops); | |
| 966 | + | |
| 967 | + // Left window is half-resized at 105 px wide, right window is at x=105 matching it. | |
| 968 | + assert_snapshot!(format_tiles(&layout), @r" | |
| 969 | + 105 × 100 at x: 0 y: 0 | |
| 970 | + 200 × 200 at x:105 y: 0 | |
| 971 | + "); | |
| 972 | + | |
| 973 | + let ops = [ | |
| 974 | + // Issue a resize back. | |
| 975 | + Op::SetWindowWidth { | |
| 976 | + id: None, | |
| 977 | + change: SizeChange::SetFixed(100), | |
| 978 | + }, | |
| 979 | + // The top window shrinks in response. | |
| 980 | + Op::SetForcedSize { | |
| 981 | + id: 1, | |
| 982 | + size: Some(Size::new(100, 100)), | |
| 983 | + }, | |
| 984 | + // This cancels the resize animation since the change of 5 px is less than the resize | |
| 985 | + // animation threshold. | |
| 986 | + Op::Communicate(1), | |
| 987 | + Op::Communicate(2), | |
| 988 | + ]; | |
| 989 | + check_ops_on_layout(&mut layout, &ops); | |
| 990 | + | |
| 991 | + // Since the resize animation is cancelled, the width goes to the new value immediately. The X | |
| 992 | + // position doesn't jump, instead the animation is offset to preserve the current position. | |
| 993 | + // | |
| 994 | + // FIXME: this is not currently the case! | |
| 995 | + assert_snapshot!(format_tiles(&layout), @r" | |
| 996 | + 100 × 100 at x: 0 y: 0 | |
| 997 | + 200 × 200 at x: 5 y: 0 | |
| 998 | + "); | |
| 999 | + | |
| 1000 | + // Advance to the end of the move animation. | |
| 1001 | + Op::AdvanceAnimations { msec_delta: 950 }.apply(&mut layout); | |
| 1002 | + | |
| 1003 | + // Final state. | |
| 1004 | + assert_snapshot!(format_tiles(&layout), @r" | |
| 1005 | + 100 × 100 at x: 0 y: 0 | |
| 1006 | + 200 × 200 at x:100 y: 0 | |
| 1007 | + "); | |
| 1008 | +} | |
| 1009 | + | |
| 1010 | +#[test] | |
| 1011 | +fn width_resize_and_cancel_of_column_to_the_left() { | |
| 1012 | + let ops = [ | |
| 1013 | + Op::AddOutput(1), | |
| 1014 | + Op::AddWindow { | |
| 1015 | + params: TestWindowParams::new(1), | |
| 1016 | + }, | |
| 1017 | + Op::AddWindow { | |
| 1018 | + params: TestWindowParams::new(2), | |
| 1019 | + }, | |
| 1020 | + Op::SetForcedSize { | |
| 1021 | + id: 1, | |
| 1022 | + size: Some(Size::new(100, 100)), | |
| 1023 | + }, | |
| 1024 | + Op::SetForcedSize { | |
| 1025 | + id: 2, | |
| 1026 | + size: Some(Size::new(200, 200)), | |
| 1027 | + }, | |
| 1028 | + Op::Communicate(1), | |
| 1029 | + Op::Communicate(2), | |
| 1030 | + Op::CompleteAnimations, | |
| 1031 | + ]; | |
| 1032 | + let mut layout = check_ops_with_options(make_options(), &ops); | |
| 1033 | + | |
| 1034 | + // The initial state. | |
| 1035 | + assert_snapshot!(format_tiles(&layout), @r" | |
| 1036 | + 100 × 100 at x: 0 y: 0 | |
| 1037 | + 200 × 200 at x:100 y: 0 | |
| 1038 | + "); | |
| 1039 | + | |
| 1040 | + let ops = [ | |
| 1041 | + // Issue a resize. | |
| 1042 | + Op::SetWindowWidth { | |
| 1043 | + id: Some(1), | |
| 1044 | + change: SizeChange::SetFixed(200), | |
| 1045 | + }, | |
| 1046 | + // The left window grows in response. | |
| 1047 | + Op::SetForcedSize { | |
| 1048 | + id: 1, | |
| 1049 | + size: Some(Size::new(200, 100)), | |
| 1050 | + }, | |
| 1051 | + // This starts the resize animation. | |
| 1052 | + Op::Communicate(1), | |
| 1053 | + Op::Communicate(2), | |
| 1054 | + // Advance the time slightly. | |
| 1055 | + Op::AdvanceAnimations { msec_delta: 50 }, | |
| 1056 | + ]; | |
| 1057 | + check_ops_on_layout(&mut layout, &ops); | |
| 1058 | + | |
| 1059 | + // Left window is half-resized at 105 px wide, it's at x=-5 matching the right edge position. | |
| 1060 | + assert_snapshot!(format_tiles(&layout), @r" | |
| 1061 | + 105 × 100 at x: -5 y: 0 | |
| 1062 | + 200 × 200 at x:100 y: 0 | |
| 1063 | + "); | |
| 1064 | + | |
| 1065 | + let ops = [ | |
| 1066 | + // Issue a resize back. | |
| 1067 | + Op::SetWindowWidth { | |
| 1068 | + id: Some(1), | |
| 1069 | + change: SizeChange::SetFixed(100), | |
| 1070 | + }, | |
| 1071 | + // The top window shrinks in response. | |
| 1072 | + Op::SetForcedSize { | |
| 1073 | + id: 1, | |
| 1074 | + size: Some(Size::new(100, 100)), | |
| 1075 | + }, | |
| 1076 | + // This cancels the resize animation since the change of 5 px is less than the resize | |
| 1077 | + // animation threshold. | |
| 1078 | + Op::Communicate(1), | |
| 1079 | + Op::Communicate(2), | |
| 1080 | + ]; | |
| 1081 | + check_ops_on_layout(&mut layout, &ops); | |
| 1082 | + | |
| 1083 | + // Since the resize animation is cancelled, the width goes to the new value immediately. The X | |
| 1084 | + // position doesn't jump, instead the animation is offset to preserve the current position. | |
| 1085 | + // | |
| 1086 | + // FIXME: this is not currently the case! | |
| 1087 | + assert_snapshot!(format_tiles(&layout), @r" | |
| 1088 | + 100 × 100 at x: 95 y: 0 | |
| 1089 | + 200 × 200 at x:100 y: 0 | |
| 1090 | + "); | |
| 1091 | + | |
| 1092 | + // Advance to the end of the move animation. | |
| 1093 | + Op::AdvanceAnimations { msec_delta: 950 }.apply(&mut layout); | |
| 1094 | + | |
| 1095 | + // Final state. | |
| 1096 | + assert_snapshot!(format_tiles(&layout), @r" | |
| 1097 | + 100 × 100 at x: 0 y: 0 | |
| 1098 | + 200 × 200 at x:100 y: 0 | |
| 1099 | + "); | |
| 1100 | +} |