Fix OverlayManager#replaceCurrent

Add a test for it (and promise myself not to be lazy and do TDD next
time when I have a gut feeling things might be trickier than they seem).
In the process refactor the code a bit (mostly renaming of some vars to
make their meaning more obvious).

Bug: 62907
Change-Id: I68ca90cb2633634064a5a953f8b72cf141d0e06e
Merge "Fix OverlayManager#replaceCurrent"