Add regression tests for DonwloadManager and fix some bugs in it.