[PDFHistory] Prevent the history from getting stuck in certain edge cases

This PR fixes another serious issue (the first one was #3338) where the browsing history can get stuck in the current state, preventing the user from going back/forward in the history. Detailed info about the issue in comments: https://github.com/Snuffleupagus/pdf.js/compare/PDFHistory-fix-multiple-identical-states#L0R237. The comments are perhaps a bit too verbose, but since I missed this edge case previously I thought it might be good to properly document it.

__EDIT:__ An example file demonstrating this bug (note how navigation breaks when clicking on the link in the outline): http://www.nordichardware.se/images/labswedish/artiklar/Grafik/Roundup_2013_mainstream/fullimages/Warranty.pdf.

Finally, this PR also fixes a stupid copy-and-paste error (https://github.com/Snuffleupagus/pdf.js/compare/PDFHistory-fix-multiple-identical-states#L0R284) I made in #3449. This is not a particularly serious issue, since the only problem without this change is that when overwriting previous history states the current algorithm will be slightly too greedy in certain circumstances.

/cc @brendandahl