Bug 1158016 - Skip the test if the page is not loaded from the bf-cache when going back. r=bzbarsky, a=test-only
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 26 May 2015 23:49:18 -0400
changeset 266138 477a0035c253
parent 266137 f2130e4494d3
child 266139 ceac3b53900f
push id4764
push userryanvm@gmail.com
push date2015-05-29 14:57 +0000
treeherdermozilla-beta@ceac3b53900f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky, test-only
bugs1158016
milestone39.0
Bug 1158016 - Skip the test if the page is not loaded from the bf-cache when going back. r=bzbarsky, a=test-only
docshell/test/navigation/test_bug386782.html
--- a/docshell/test/navigation/test_bug386782.html
+++ b/docshell/test/navigation/test_bug386782.html
@@ -12,30 +12,34 @@ https://bugzilla.mozilla.org/show_bug.cg
   <script>
 
     // This tests if we can load a document whose root is in designMode,
     // edit it, navigate to a new page, navigate back, still edit, and still
     // undo/redo. Note that this is different from the case where the
     // designMode document is in a frame inside the window, as this means
     // the editable region is not in the root docshell (a less complicated case).  
 
+    var pageShowChecker = '<scr' + 'ipt>' +
+      'window.addEventListener("pageshow", function(event) {' +
+        'window.opener.postMessage({persisted:event.persisted}, "*");' +
+      '});</scr' + 'ipt>';
   
     var gTests = [
       {
         // <html><body><p>designModeDocument</p></body></html>
-        url: "data:text/html;charset=utf-8,<html><body><p>designModeDocument</p></body></html>",
+        url: "data:text/html;charset=utf-8,<html><head>" + pageShowChecker + "</head><body><p>designModeDocument</p></body></html>",
         name: 'designModeNavigate',
         onload(doc) { doc.designMode = "on"; },
         expectedBodyBeforeEdit: '<p>designModeDocument</p>',
         expectedBodyAfterEdit:  '<p>EDITED designModeDocument</p>',
         expectedBodyAfterSecondEdit: '<p>EDITED TWICE designModeDocument</p>',
       },
       {
         // <html><body contentEditable="true"><p>contentEditable</p></body></html>
-        url: 'data:text/html;charset=utf-8,<html><body contentEditable="true"><p>contentEditable</p></body></html>',
+        url: "data:text/html;charset=utf-8,<html><head>" + pageShowChecker + "</head><body contentEditable=\"true\"><p>contentEditable</p></body></html>",
         name: 'contentEditableNavigate',
         expectedBodyBeforeEdit: '<p>contentEditable</p>',
         expectedBodyAfterEdit:  'EDITED <br><p>contentEditable</p>',
         expectedBodyAfterSecondEdit: 'EDITED TWICE <br><p>contentEditable</p>',
       }
     ];
     
     var gTestNum = -1;
@@ -46,42 +50,51 @@ https://bugzilla.mozilla.org/show_bug.cg
     function goNext() {
       gTestNum++;
       if (gTestNum >= gTests.length) {
         SimpleTest.finish();
         return;
       }
       gTest = gTests[gTestNum];
       gTest.window = window.open(gTest.url, gTest.name, "width=500,height=500");
-      gTest.window.addEventListener("load", function() {
+      window.onmessage = function(e) {
+        is(e.data.persisted, false, "Initial load cannot be persisted");
+        window.onmessage = null;
         if ("onload" in gTest) {
           gTest.onload(gTest.window.document);
         }
         SimpleTest.waitForFocus(beginTest, gTest.window);
-      }, false);
+      };
     }
 
     function beginTest() {
       gTest.window.document.body.focus();
 
       // WARNING: If the following test fails, give the setTimeout() in the onload()
       // a bit longer; the doc hasn't had enough time to setup its editor.
       is(gTest.window.document.body.innerHTML, gTest.expectedBodyBeforeEdit, "Is doc setup yet");
       sendString('EDITED ', gTest.window);
       is(gTest.window.document.body.innerHTML, gTest.expectedBodyAfterEdit, "Editing failed.");
 
       gTest.window.location = 'data:text/html;charset=utf-8,SomeOtherDocument';
       SimpleTest.waitForFocus(goBack, gTest.window);
     }
     
     function goBack() {
+      window.onmessage = function(e) {
+        window.onmessage = null;
+        // Skip the test if the page is not loaded from the bf-cache when going back.
+        if (e.data.persisted) {
+          checkStillEditable();
+        } else {
+          gTest.window.close();
+          goNext();
+        }
+      };
       gTest.window.history.back();
-      setTimeout(function() {
-        SimpleTest.waitForFocus(checkStillEditable, gTest.window);
-      }, 0);
     }
 
     function checkStillEditable() {
 
       // Check that the contents are correct.
       is(gTest.window.document.body.innerHTML, gTest.expectedBodyAfterEdit, "Edited contents still correct?");
       
       // Check that we can undo/redo and the contents are correct.