bug298622_window.xhtml (5095B)
1 <?xml version="1.0"?> 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> 3 4 <window id="298622Test" 5 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 6 width="600" 7 height="600" 8 onload="setTimeout(runTest, 0);" 9 title="bug 298622 test"> 10 11 <script type="application/javascript" src= "chrome://mochikit/content/chrome-harness.js" /> 12 <script type="application/javascript" src= "docshell_helpers.js" /> 13 <script type="application/javascript"><![CDATA[ 14 // Global variable that holds a reference to the find bar. 15 var gFindBar; 16 17 //// 18 // Test for bug 298622: 19 // Find should work correctly on a page loaded from the 20 // bfcache. 21 // 22 async function runTest() 23 { 24 // Make sure bfcache is on. 25 enableBFCache(true); 26 27 // Load a test page which contains some text to be found. 28 await promisePageNavigation({ 29 uri: "data:text/html,<html><head><title>test1</title></head>" + 30 "<body>find this!</body></html>", 31 }); 32 33 // Load a second, dummy page, verifying that the original 34 // page gets stored in the bfcache. 35 await promisePageNavigation({ 36 uri: getHttpUrl("generic.html"), 37 eventsToListenFor: ["pageshow", "pagehide"], 38 expectedEvents: [ { type: "pagehide", 39 title: "test1", 40 persisted: true }, 41 { type: "pageshow", 42 title: "generic page" } ], 43 }); 44 45 // Make sure we unsuppress painting before continuing 46 await new Promise(resolve => { 47 SimpleTest.executeSoon(resolve); 48 }); 49 50 // Search for some text that's on the second page (but not on 51 // the first page), and verify that it can be found. 52 gFindBar = document.getElementById("FindToolbar"); 53 document.getElementById("cmd_find").doCommand(); 54 ok(!gFindBar.hidden, "failed to open findbar"); 55 gFindBar._findField.value = "A generic page"; 56 gFindBar._find(); 57 await new Promise(resolve => { 58 SimpleTest.executeSoon(resolve); 59 }); 60 61 // Make sure Find bar's internal status is not 'notfound' 62 isnot(gFindBar._findField.getAttribute("status"), "notfound", 63 "Findfield status attribute should not have been 'notfound'" + 64 " after Find"); 65 66 // Make sure the key events above have time to be processed 67 // before continuing 68 await promiseTrue(() => 69 SpecialPowers.spawn(document.getElementById("content"), [], function() { 70 return content.document.getSelection().toString().toLowerCase() == "a generic page"; 71 }), 20 72 ); 73 74 is(gFindBar._findField.value, "A generic page", 75 "expected text not present in find input field"); 76 is(await SpecialPowers.spawn(document.getElementById("content"), [], async function() { 77 return content.document.getSelection().toString().toLowerCase(); 78 }), 79 "a generic page", 80 "find failed on second page loaded"); 81 82 // Go back to the original page and verify it's loaded from the 83 // bfcache. 84 await promisePageNavigation({ 85 back: true, 86 eventsToListenFor: ["pageshow"], 87 expectedEvents: [ { type: "pageshow", 88 title: "test1", 89 persisted: true } ], 90 }); 91 92 // Search for some text that's on the original page (but not 93 // the dummy page loaded above), and verify that it can 94 // be found. 95 gFindBar = document.getElementById("FindToolbar"); 96 document.getElementById("cmd_find").doCommand(); 97 ok(!gFindBar.hidden, "failed to open findbar"); 98 gFindBar._findField.value = "find this"; 99 gFindBar._find(); 100 await new Promise(resolve => { 101 SimpleTest.executeSoon(resolve); 102 }); 103 104 // Make sure Find bar's internal status is not 'notfound' 105 isnot(gFindBar._findField.getAttribute("status"), "notfound", 106 "Findfield status attribute should not have been 'notfound'" + 107 " after Find"); 108 109 // Make sure the key events above have time to be processed 110 // before continuing 111 await promiseTrue(() => 112 SpecialPowers.spawn(document.getElementById("content"), [], function() { 113 return content.document.getSelection().toString().toLowerCase() == "find this"; 114 }), 20 115 ); 116 117 is(await SpecialPowers.spawn(document.getElementById("content"), [], async function() { 118 return content.document.getSelection().toString().toLowerCase(); 119 }), 120 "find this", 121 "find failed on page loaded from bfcache"); 122 123 // Tell the framework the test is finished. 124 finish(); 125 } 126 127 ]]></script> 128 129 <commandset> 130 <command id="cmd_find" 131 oncommand="document.getElementById('FindToolbar').onFindCommand();"/> 132 </commandset> 133 <browser type="content" primary="true" flex="1" id="content" messagemanagergroup="test" remote="true" maychangeremoteness="true" /> 134 <findbar id="FindToolbar" browserid="content"/> 135 </window>