test_computed_style_bfcache_display_none.html (1797B)
1 <!doctype html> 2 <title>Test for getting the computed style on the root node of a display:none subtree in a document in the bfcache</title> 3 <script src="/tests/SimpleTest/SimpleTest.js"></script> 4 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 5 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1377010">Mozilla Bug 1377010</a> 6 <p id="display"></p> 7 <script> 8 SimpleTest.waitForExplicitFinish(); 9 10 let testDiv; 11 let loadedPromiseResolve; 12 13 const TEST_PATH = "http://mochi.test:8888/tests/layout/style/test/"; 14 const TEST_FILE1 = TEST_PATH + "file_computed_style_bfcache_display_none.html"; 15 const TEST_FILE2 = TEST_PATH + "file_computed_style_bfcache_display_none2.html"; 16 17 // Open a new window. 18 const w = window.open(TEST_FILE1); 19 waitForLoadMessage().then(() => { 20 // Take a reference to a node in the new window. 21 testDiv = w.document.getElementById('div'); 22 23 // Open a new document so that the test div now refers to a node in a 24 // document in the bfcache. 25 w.location = TEST_FILE2; 26 return waitForLoadMessage(); 27 }).then(() => { 28 // Compute styles for the node in the bfcache document. 29 is(w.getComputedStyle(testDiv).opacity, '1'); 30 31 // Restore the bfcache document. 32 return goBack(w); 33 }).then(() => { 34 // Fetch the style once again. 35 is(w.getComputedStyle(testDiv).opacity, '1'); 36 37 w.close(); 38 SimpleTest.finish(); 39 }); 40 41 window.addEventListener('message', e => { 42 if (e.data === 'loaded' && loadedPromiseResolve) { 43 loadedPromiseResolve(); 44 loadedPromiseResolve = undefined; 45 } 46 }); 47 48 function waitForLoadMessage() { 49 return new Promise(resolve => { 50 loadedPromiseResolve = resolve; 51 }); 52 } 53 54 function goBack(win) { 55 return new Promise(resolve => { 56 win.onpagehide = e => resolve(win); 57 win.history.back(); 58 }); 59 } 60 </script>