Bug 451366: Convert chrome tests to browser tests. r=dietrich
--- a/browser/components/sessionstore/test/Makefile.in
+++ b/browser/components/sessionstore/test/Makefile.in
@@ -37,13 +37,13 @@
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
-DIRS += chrome \
+DIRS += browser \
$(NULL)
include $(topsrcdir)/config/rules.mk
--- a/browser/components/sessionstore/test/browser/Makefile.in
+++ b/browser/components/sessionstore/test/browser/Makefile.in
@@ -40,13 +40,15 @@ topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = browser/components/sessionstore/test/browser
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_BROWSER_TEST_FILES = \
+ browser_350525.js \
+ browser_393716.js \
browser_448741.js \
$(NULL)
libs:: $(_BROWSER_TEST_FILES)
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/browser/browser_350525.js
@@ -0,0 +1,100 @@
+function test() {
+ /** Test for Bug 350525 **/
+
+ function test(aLambda) {
+ try {
+ return aLambda() || true;
+ }
+ catch (ex) { }
+ return false;
+ }
+
+ // test setup
+ let tabbrowser = getBrowser();
+ waitForExplicitFinish();
+
+ // component
+ let ssComponent = test(function() Cc["@mozilla.org/browser/sessionstore;1"]);
+ ok(ssComponent, "reference the sessionstore component");
+
+ // service
+ let ss = test(function() ssComponent.getService(Ci.nsISessionStore));
+ ok(ss, "reference the sessionstore service");
+
+ ////////////////////////////
+ // setWindowValue, et al. //
+ ////////////////////////////
+ let key = "Unique name: " + Date.now();
+ let value = "Unique value: " + Math.random();
+
+ // test adding
+ ok(test(function() ss.setWindowValue(window, key, value)), "set a window value");
+
+ // test retrieving
+ is(ss.getWindowValue(window, key), value, "stored window value matches original");
+
+ // test deleting
+ ok(test(function() ss.deleteWindowValue(window, key)), "delete the window value");
+
+ // value should not exist post-delete
+ is(ss.getWindowValue(window, key), "", "window value was deleted");
+
+ /////////////////////////
+ // setTabValue, et al. //
+ /////////////////////////
+ key = "Unique name: " + Math.random();
+ value = "Unique value: " + Date.now();
+ let tab = tabbrowser.addTab();
+
+ // test adding
+ ok(test(function() ss.setTabValue(tab, key, value)), "store a tab value");
+
+ // test retrieving
+ is(ss.getTabValue(tab, key), value, "stored tab value match original");
+
+ // test deleting
+ ok(test(function() ss.deleteTabValue(tab, key)), "delete the tab value");
+ // value should not exist post-delete
+ is(ss.getTabValue(tab, key), "", "tab value was deleted");
+
+ // clean up
+ tabbrowser.removeTab(tab);
+
+ /////////////////////////////////////
+ // getClosedTabCount, undoCloseTab //
+ /////////////////////////////////////
+
+ // get closed tab count
+ let count = ss.getClosedTabCount(window);
+ let max_tabs_undo = gPrefService.getIntPref("browser.sessionstore.max_tabs_undo");
+ ok(0 <= count && count <= max_tabs_undo,
+ "getClosedTabCount returns zero or at most max_tabs_undo");
+
+ // create a new tab
+ let testURL = "about:";
+ tab = tabbrowser.addTab(testURL);
+ tab.linkedBrowser.addEventListener("load", function(aEvent) {
+ // make sure that the next closed tab will increase getClosedTabCount
+ gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo + 1);
+
+ // remove tab
+ tabbrowser.removeTab(tab);
+
+ // getClosedTabCount
+ var newcount = ss.getClosedTabCount(window);
+ ok(newcount > count, "after closing a tab, getClosedTabCount has been incremented");
+
+ // undoCloseTab
+ ok(test(function() ss.undoCloseTab(window, 0)), "undoCloseTab doesn't throw")
+ tab = tabbrowser.selectedTab;
+
+ tab.linkedBrowser.addEventListener("load", function(aEvent) {
+ is(this.currentURI.spec, testURL, "correct tab was reopened");
+
+ // clean up
+ gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo);
+ tabbrowser.removeTab(tab);
+ finish();
+ }, true);
+ }, true);
+}
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/browser/browser_393716.js
@@ -0,0 +1,78 @@
+function test() {
+ /** Test for Bug 393716 **/
+
+ // set up the basics (SessionStore service, tabbrowser)
+ try {
+ var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
+ }
+ catch (ex) { }
+ ok(ss, "SessionStore service is available");
+ let tabbrowser = getBrowser();
+ waitForExplicitFinish();
+
+ /////////////////
+ // getTabState //
+ /////////////////
+ let key = "Unique key: " + Date.now();
+ let value = "Unique value: " + Math.random();
+ let testURL = "about:config";
+
+ // create a new tab
+ let tab = tabbrowser.addTab(testURL);
+ ss.setTabValue(tab, key, value);
+ tab.linkedBrowser.addEventListener("load", function(aEvent) {
+ // get the tab's state
+ let state = ss.getTabState(tab);
+ ok(state, "get the tab's state");
+
+ // verify the tab state's integrity
+ state = eval("(" + state + ")");
+ ok(state instanceof Object && state.entries instanceof Array && state.entries.length > 0,
+ "state object seems valid");
+ ok(state.entries.length == 1 && state.entries[0].url == testURL,
+ "Got the expected state object (test URL)");
+ ok(state.extData && state.extData[key] == value,
+ "Got the expected state object (test manually set tab value)");
+
+ // clean up
+ tabbrowser.removeTab(tab);
+ }, true);
+
+ //////////////////////////////////
+ // setTabState and duplicateTab //
+ //////////////////////////////////
+ let key2 = "key2";
+ let value2 = "Value " + Math.random();
+ let value3 = "Another value: " + Date.now();
+ let state = { entries: [{ url: testURL }], extData: { key2: value2 } };
+
+ // create a new tab
+ let tab2 = tabbrowser.addTab();
+ // set the tab's state
+ ss.setTabState(tab2, state.toSource());
+ tab2.linkedBrowser.addEventListener("load", function(aEvent) {
+ // verify the correctness of the restored tab
+ ok(ss.getTabValue(tab2, key2) == value2 && this.currentURI.spec == testURL,
+ "the tab's state was correctly restored");
+
+ // add text data
+ let textbox = this.contentDocument.getElementById("textbox");
+ textbox.wrappedJSObject.value = value3;
+
+ // duplicate the tab
+ let duplicateTab = ss.duplicateTab(window, tab2);
+ tabbrowser.removeTab(tab2);
+
+ duplicateTab.linkedBrowser.addEventListener("load", function(aEvent) {
+ // verify the correctness of the duplicated tab
+ ok(ss.getTabValue(duplicateTab, key2) == value2 && this.currentURI.spec == testURL,
+ "correctly duplicated the tab's state");
+ let textbox = this.contentDocument.getElementById("textbox");
+ is(textbox.wrappedJSObject.value, value3, "also duplicated text data");
+
+ // clean up
+ tabbrowser.removeTab(duplicateTab);
+ finish();
+ }, true);
+ }, true);
+}
deleted file mode 100644
--- a/browser/components/sessionstore/test/chrome/Makefile.in
+++ /dev/null
@@ -1,52 +0,0 @@
-# ***** BEGIN LICENSE BLOCK *****
-# Version: MPL 1.1/GPL 2.0/LGPL 2.1
-#
-# The contents of this file are subject to the Mozilla Public License Version
-# 1.1 (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-# http://www.mozilla.org/MPL/
-#
-# Software distributed under the License is distributed on an "AS IS" basis,
-# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-# for the specific language governing rights and limitations under the
-# License.
-#
-# The Original Code is mozilla.org code.
-#
-# The Initial Developer of the Original Code is
-# Mozilla Foundation.
-# Portions created by the Initial Developer are Copyright (C) 2007
-# the Initial Developer. All Rights Reserved.
-#
-# Contributor(s):
-#
-# Alternatively, the contents of this file may be used under the terms of
-# either of the GNU General Public License Version 2 or later (the "GPL"),
-# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
-# in which case the provisions of the GPL or the LGPL are applicable instead
-# of those above. If you wish to allow use of your version of this file only
-# under the terms of either the GPL or the LGPL, and not to allow others to
-# use your version of this file under the terms of the MPL, indicate your
-# decision by deleting the provisions above and replace them with the notice
-# and other provisions required by the GPL or the LGPL. If you do not delete
-# the provisions above, a recipient may use your version of this file under
-# the terms of any one of the MPL, the GPL or the LGPL.
-#
-# ***** END LICENSE BLOCK *****
-
-DEPTH = ../../../../..
-topsrcdir = @top_srcdir@
-srcdir = @srcdir@
-VPATH = @srcdir@
-relativesrcdir = browser/components/sessionstore/test/chrome
-
-include $(DEPTH)/config/autoconf.mk
-include $(topsrcdir)/config/rules.mk
-
-_TEST_FILES = \
- test_bug350525.xul \
- test_bug393716.xul \
- $(NULL)
-
-libs:: $(_TEST_FILES)
- $(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
deleted file mode 100644
--- a/browser/components/sessionstore/test/chrome/test_bug350525.xul
+++ /dev/null
@@ -1,132 +0,0 @@
-<?xml version="1.0"?>
-<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
-<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=350525
--->
-<window title="Mozilla Bug 350525"
- xmlns:html="http://www.w3.org/1999/xhtml"
- xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
- xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
-
- <title>Test for Bug 350525</title>
- <script type="application/javascript"
- src="chrome://mochikit/content/MochiKit/packed.js"></script>
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
-<body xmlns="http://www.w3.org/1999/xhtml">
- <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=350525">Mozilla Bug 350525</a>
-
- <p id="display"></p>
-
- <pre id="test">
- <script class="testbody" type="application/javascript">
-
- /** Test for Bug 350525 **/
-
- const Cc = Components.classes;
- const Ci = Components.interfaces;
- const Cr = Components.results;
-
- // component
- try {
- Cc["@mozilla.org/browser/sessionstore;1"];
- ok(1==1, "Able to reference the sessionstore component?");
- } catch(ex) {
- alert(ex);
- ok(1==2, "Able to reference the sessionstore component?");
- }
-
- // service
- try {
- var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
- ok(true, "Able to reference the sessionstore service?");
- } catch(ex) {
- ok(false, "Able to reference the sessionstore service?");
- }
-
- // get current window, tabbrowser
- var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
- var windowEnumerator = wm.getEnumerator("navigator:browser");
- var currentWindow = windowEnumerator.getNext();
- var tabbrowser = currentWindow.getBrowser();
-
- /*****************
- undoCloseTab, getClosedTabCount
- *****************/
-
- // get closed tab count
- var count = ss.getClosedTabCount(currentWindow);
- ok(count > -1, "getClosedTabCount returns zero or more?");
-
- // create a new tab
- var newTab = tabbrowser.addTab("http://www.mozilla.org");
-
- // remove tab
- tabbrowser.removeTab(newTab);
-
- // getClosedTabCount
- var newcount = ss.getClosedTabCount(currentWindow);
- todo(newcount > count, "After closing a tab, getClosedTabCount has been incremented? " + newcount + " > " + count);
-
- // undoCloseTab
- var undid = ss.undoCloseTab(currentWindow, null);
- ok(undid != -1, "undoCloseTab throws?");
-
- // clean up
- tabbrowser.removeAllTabsBut(tabbrowser.selectedTab);
-
- /*****************
- setWindowValue
- *****************/
- var key = "key1";
- var value = "value1";
-
- // create a new tab
- var newTab = tabbrowser.addTab("http://www.mozilla.org");
-
- // test adding
- ok(ss.setWindowValue(currentWindow, key, value) != -1, "Able to set a window value?");
-
- // test retrieving
- var storedValue = ss.getWindowValue(currentWindow, key);
- is(value, storedValue, "Stored window value matches original?");
-
- // test deleting
- ok(ss.deleteWindowValue(currentWindow, key) != -1, "Delete window value?");
-
- // value should not exist post-delete
- is(ss.getWindowValue(currentWindow, key), "", "Fetching deleted window value fails?");
-
- // clean up
- tabbrowser.removeTab(newTab);
-
- /*********************
- tabValues
- *********************/
- key = "key1";
- value = "value1";
-
- // create a new tab
- newTab = tabbrowser.addTab("http://www.mozilla.org");
-
- // test adding
- ok(ss.setTabValue(newTab, key, value) != -1, "Able to store a tab value?");
-
- // test retrieving
- var storedValue = ss.getTabValue(newTab, key);
- ok(value==storedValue, "Stored tab value match original?");
-
- // test deleting
- ok(ss.deleteTabValue(newTab, key) != -1, "Able to delete a tab value?");
- // value should not exist post-delete
- ok(ss.getTabValue(newTab, key) == "", "Unable to retrieve deleted tab value?");
-
- // clean up
- tabbrowser.removeTab(newTab);
-
- </script>
- </pre>
-</body>
-
-</window>
deleted file mode 100644
--- a/browser/components/sessionstore/test/chrome/test_bug393716.xul
+++ /dev/null
@@ -1,101 +0,0 @@
-<?xml version="1.0"?>
-<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
-<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
-<!--
- https://bugzilla.mozilla.org/show_bug.cgi?id=393716
--->
-<window title="Mozilla Bug 393716"
- xmlns:html="http://www.w3.org/1999/xhtml"
- xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
- xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
-
- <title>Test for Bug 393716</title>
- <script type="application/javascript"
- src="chrome://mochikit/content/MochiKit/packed.js"></script>
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
-<body xmlns="http://www.w3.org/1999/xhtml">
- <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=393716">Mozilla Bug 393716</a>
-
- <p id="display"></p>
-
- <pre id="test">
- <script class="testbody" type="application/javascript">
- <![CDATA[
-
- const Cc = Components.classes;
- const Ci = Components.interfaces;
-
- // set up the basics (SessionStore service, tabbrowser)
- try {
- var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
- } catch (ex) {
- ok(false, "SessionStore service available?");
- }
- try {
- var windowEnumerator = Cc["@mozilla.org/appshell/window-mediator;1"].
- getService(Ci.nsIWindowMediator).
- getEnumerator("navigator:browser");
- var currentWindow = windowEnumerator.getNext();
- var tabbrowser = currentWindow.getBrowser();
- } catch (ex) {
- ok(false, "tabbrowser available?");
- }
-
- /**************
- * getTabState
- **************/
- var key = "key1", value = "value1";
-
- // create a new tab
- var newTab = tabbrowser.addTab();
- ss.setTabValue(newTab, key, value);
-
- // get the tab's state
- var state = ss.getTabState(newTab);
- ok(state, "Able to get the tab's state?");
-
- // verify the tab state's integrity
- state = eval("(" + state + ")");
- ok(state instanceof Object && state.entries instanceof Array && state.entries.length > 0,
- "Got a valid state object?");
- ok(state.entries.length == 1 && state.entries[0].url == "about:blank",
- "Got the expected state object (test URL)?");
- ok(state.extData && state.extData[key] == value,
- "Got the expected state object (test manually set tab value)?");
-
- // clean up
- tabbrowser.removeTab(newTab);
-
- /*****************************
- * setTabState / duplicateTab
- *****************************/
- key = "key2";
- value = "value2";
- state = { entries: [{ url: "about:blank" }], extData: { key2: value } };
-
- // create a new tab
- newTab = tabbrowser.addTab();
-
- // set the tab's state
- ss.setTabState(newTab, state.toSource());
-
- // verify the correctness of the restored tab
- ok(ss.getTabValue(newTab, key) == value, "Correctly restored the tab's state?");
-
- // duplicate the tab
- var duplicateTab = ss.duplicateTab(currentWindow, newTab);
-
- // verify the correctness of the duplicated tab
- ok(ss.getTabValue(duplicateTab, key) == value, "Correctly duplicated the tab's state?");
-
- // clean up
- tabbrowser.removeTab(newTab);
- tabbrowser.removeTab(duplicateTab);
-
- ]]>
- </script>
- </pre>
-</body>
-
-</window>