This is a follow-up for D2628 and D2629.
It appeared that these changes are part of a core PR (PR14738).
This diff backports the remaining parts from the original PR.
Note that the test is renamed in the original PR, this is a change from
core PR12953 that could be backported later.
Partial backport of core PR14738
Depends on D2635