Bug 805704 - Update sessionrestore module to not use remote pages and correctly handles dtds. r=dhunt mozilla-aurora
authorHenrik Skupin <hskupin@mozilla.com>
Sat, 27 Oct 2012 14:18:30 -0400
branchmozilla-aurora
changeset 2691 1c140308b898ee3a330c03ef741829df96055d01
parent 2690 05b0c885ab0909c8545f3417228c4d3f682949b8
child 2695 e9bea4e2f8eeabd07702e3e2b2b99b64b031b20e
push id2521
push userhskupin@mozilla.com
push dateSun, 28 Oct 2012 03:24:26 +0000
reviewersdhunt
bugs805704
Bug 805704 - Update sessionrestore module to not use remote pages and correctly handles dtds. r=dhunt
lib/sessionstore.js
lib/tests/testSessionStore.js
--- a/lib/sessionstore.js
+++ b/lib/sessionstore.js
@@ -5,30 +5,28 @@
 /**
  * @fileoverview
  * The SessionStoreAPI adds support for accessing session related elements and features
  *
  * @version 1.0.0
  */
 
 // Include required modules
-var assert = require("assertions");
+var { assert } = require("assertions");
 var prefs = require("prefs");
 var utils = require("utils");
 var widgets = require("widgets");
 
 // Session Store service
 var sessionStoreService = Cc["@mozilla.org/browser/sessionstore;1"]
                              .getService(Ci.nsISessionStore);
 
 // Preference for indicating the amount of restorable tabs
 const SESSIONSTORE_MAXTABS_PREF = 'browser.sessionstore.max_tabs_undo';
 
-const gTimeout = 5000;
-
 /**
  * Constructor
  *
  * @param {MozMillController} controller
  *        MozMill controller of the browser window to operate on.
  */
 function aboutSessionRestore(controller)
 {
@@ -61,18 +59,17 @@ aboutSessionRestore.prototype = {
 
   /**
    * Gets all the needed external DTD urls as an array
    *
    * @returns Array of external DTD urls
    * @type [string]
    */
   getDtds : function aboutSessionRestore_getDtds() {
-    var dtds = ["chrome://browser/locale/browser.dtd",
-                "chrome://browser/locale/aboutSessionRestore.dtd"];
+    var dtds = ["chrome://browser/locale/aboutSessionRestore.dtd"];
     return dtds;
   },
 
   /**
    * Retrieve an UI element based on the given spec
    *
    * @param {object} spec
    *        Information of the UI element which should be retrieved
@@ -221,49 +218,53 @@ function getClosedTabCount(controller)
  * @param {MozMillController} controller
  *        MozMillController of the window to operate on
  * @param {object} event
  *        Specifies the event to use to execute the command
  */
 function undoClosedTab(controller, event)
 {
   var count = sessionStoreService.getClosedTabCount(controller.window);
+  var dtds = ["chrome://browser/locale/browser.dtd"];
 
   switch (event.type) {
     case "menu":
       throw new Error("Menu gets build dynamically and cannot be accessed.");
       break;
     case "shortcut":
-      var cmdKey = utils.getEntity(this.getDtds(), "tabCmd.commandkey");
+      var cmdKey = utils.getEntity(dtds, "tabCmd.commandkey");
       controller.keypress(null, cmdKey, {accelKey: true, shiftKey: true});
       break;
   }
 
-  if (count > 0)
-    assert.ok(sessionStoreService.getClosedTabCount(controller.window) < count, "Closed tab count is lower");
+  if (count > 0) {
+    assert.ok(sessionStoreService.getClosedTabCount(controller.window) < count,
+              "Closed tab count is lower");
+  }
 }
 
 /**
  * Restores the window which has been recently closed
  *
  * @param {MozMillController} controller
  *        MozMillController of the window to operate on
  * @param {object} event
  *        Specifies the event to use to execute the command
  */
 function undoClosedWindow(controller, event)
 {
   var count = sessionStoreService.getClosedWindowCount(controller.window);
+  var dtds = ["chrome://browser/locale/browser.dtd"];
 
   switch (event.type) {
     case "menu":
       throw new Error("Menu gets build dynamically and cannot be accessed.");
       break;
     case "shortcut":
-      var cmdKey = utils.getEntity(this.getDtds(), "newNavigatorCmd.key");
+      var cmdKey = utils.getEntity(dtds, "newNavigatorCmd.key");
       controller.keypress(null, cmdKey, {accelKey: true, shiftKey: true});
       break;
   }
 
   if (count > 0)
     assert.ok(sessionStoreService.getClosedWindowCount(controller.window) < count, "Closed window count is lower");
 }
 
--- a/lib/tests/testSessionStore.js
+++ b/lib/tests/testSessionStore.js
@@ -3,18 +3,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // Include required modules
 var {expect} = require("../assertions");
 var sessionStore = require("../sessionstore");
 var tabs = require("../tabs");
 var utils = require("../utils");
 
-const gDelay = 0;
-const gTimeout = 5000;
+const LOCAL_TEST_FOLDER = collector.addHttpResource('../../data/');
+const LOCAL_TEST_PAGE = LOCAL_TEST_FOLDER + 'layout/mozilla_projects.html';
 
 var setupModule = function(module)
 {
   module.controller = mozmill.getBrowserController();
 
   module.session = new sessionStore.aboutSessionRestore(controller);
   module.tabBrowser = new tabs.tabBrowser(controller);
 }
@@ -38,17 +38,18 @@ var testAboutSessionRestoreErrorPage = f
       if (jj == 0) {
         session.toggleRestoreState(tab);
       }
     }
   }
 
   // Test the buttons
   var button = session.getElement({type: "button_restoreSession"});
-  expect.equal(button.getNode().getAttribute('oncommand'), "restoreSession()", "Restore Session button has the correct action");
+  expect.equal(button.getNode().getAttribute('oncommand'), "restoreSession();",
+               "Restore Session button has the correct action");
 
-  tabBrowser.openTab({type: "shortcut"});
-  controller.open("http://www.google.com");
+  tabBrowser.openTab("shortcut");
+  controller.open(LOCAL_TEST_PAGE);
   controller.waitForPageLoad();
-  tabBrowser.closeTab({type: "shortcut"});
+  tabBrowser.closeTab("shortcut");
 
   sessionStore.undoClosedTab(controller, {type: "shortcut"});
 }