Move logic for calculating relative URL to a separate class
Add a unit test, preparing to fix Bug 410551