viewport-width-test-after-history-navigation.html 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <html>
  2. <head>
  3. <meta name="viewport" content="width=700">
  4. <script>
  5. var originalViewportWidth;
  6. function checkViewportWidthAfterHistoryNavigation() {
  7. if (originalViewportWidth == window.innerWidth)
  8. document.body.innerHTML = "<div style='color:green'>PASS, viewport width is OK after history navigation.</div>";
  9. else
  10. document.body.innerHTML = "<div style='color:red'>FAIL, viewport width is different after history navigation.</div>";
  11. }
  12. function navigateAwayAndBack() {
  13. // Force layout before getting viewport width.
  14. document.body.offsetTop;
  15. originalViewportWidth = window.innerWidth;
  16. // Assigning to window.location does not create a history entry, so instead link click is simulated.
  17. var evt = document.createEvent("MouseEvents");
  18. evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  19. document.getElementById('anchor').dispatchEvent(evt);
  20. // Initiate timer to do final verification as we have navigated back to the cached version of this page.
  21. // This test makes use of the behavior where timers are restored on a cached page.
  22. setTimeout('checkViewportWidthAfterHistoryNavigation()', 1000);
  23. }
  24. </script>
  25. </head>
  26. <body onload='setTimeout("navigateAwayAndBack()", 0 );'>
  27. <a id='anchor' href='data:text/html,
  28. <html>
  29. <head>
  30. <meta name="viewport" content="width=600">
  31. </head>
  32. <body onload="document.body.offsetTop; history.back();"></body>
  33. </html>'>
  34. </a>
  35. </body>
  36. </html>