diff options
Diffstat (limited to 'browser/components')
366 files changed, 7 insertions, 25861 deletions
diff --git a/browser/components/certerror/moz.build b/browser/components/certerror/moz.build index 86ec46748..8deb0b138 100644 --- a/browser/components/certerror/moz.build +++ b/browser/components/certerror/moz.build @@ -4,4 +4,4 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -TEST_DIRS += ['test'] + diff --git a/browser/components/certerror/test/Makefile.in b/browser/components/certerror/test/Makefile.in deleted file mode 100644 index 6037dae12..000000000 --- a/browser/components/certerror/test/Makefile.in +++ /dev/null @@ -1,19 +0,0 @@ -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -DEPTH = @DEPTH@ -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ -relativesrcdir = @relativesrcdir@ - -include $(DEPTH)/config/autoconf.mk - -MOCHITEST_BROWSER_FILES := \ - browser_bug431826.js \ - browser_bug633691.js \ - $(NULL) - -include $(topsrcdir)/config/rules.mk diff --git a/browser/components/certerror/test/browser_bug431826.js b/browser/components/certerror/test/browser_bug431826.js deleted file mode 100644 index 5d07b5905..000000000 --- a/browser/components/certerror/test/browser_bug431826.js +++ /dev/null @@ -1,41 +0,0 @@ -function test() { - waitForExplicitFinish(); - - gBrowser.selectedTab = gBrowser.addTab(); - - // Navigate to a site with a broken cert - window.addEventListener("DOMContentLoaded", testBrokenCert, true); - content.location = "https://nocert.example.com/"; -} - -function testBrokenCert() { - window.removeEventListener("DOMContentLoaded", testBrokenCert, true); - - // Confirm that we are displaying the contributed error page, not the default - ok(gBrowser.contentDocument.documentURI.startsWith("about:certerror"), "Broken page should go to about:certerror, not about:neterror"); - - // Confirm that the expert section is collapsed - var expertDiv = gBrowser.contentDocument.getElementById("expertContent"); - ok(expertDiv, "Expert content div should exist"); - ok(expertDiv.hasAttribute("collapsed"), "Expert content should be collapsed by default"); - - // Tweak the expert mode pref - gPrefService.setBoolPref("browser.xul.error_pages.expert_bad_cert", true); - - window.addEventListener("DOMContentLoaded", testExpertPref, true); - gBrowser.reload(); -} - -function testExpertPref() { - window.removeEventListener("DOMContentLoaded", testExpertPref, true); - var expertDiv = gBrowser.contentDocument.getElementById("expertContent"); - var technicalDiv = gBrowser.contentDocument.getElementById("technicalContent"); - ok(!expertDiv.hasAttribute("collapsed"), "Expert content should not be collapsed with the expert mode pref set"); - ok(!technicalDiv.hasAttribute("collapsed"), "Technical content should not be collapsed with the expert mode pref set"); - - // Clean up - gBrowser.removeCurrentTab(); - if (gPrefService.prefHasUserValue("browser.xul.error_pages.expert_bad_cert")) - gPrefService.clearUserPref("browser.xul.error_pages.expert_bad_cert"); - finish(); -} diff --git a/browser/components/certerror/test/browser_bug633691.js b/browser/components/certerror/test/browser_bug633691.js deleted file mode 100644 index 17ce7fcdc..000000000 --- a/browser/components/certerror/test/browser_bug633691.js +++ /dev/null @@ -1,25 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -function test() { - waitForExplicitFinish(); - gBrowser.selectedTab = gBrowser.addTab(); - // Open a html page with about:certerror in an iframe - window.content.addEventListener("load", testIframeCert, true); - content.location = "data:text/html,<iframe width='700' height='700' src='about:certerror'></iframe>"; -} - -function testIframeCert() { - window.content.removeEventListener("load", testIframeCert, true); - // Confirm that the expert section is hidden - var doc = gBrowser.contentDocument.getElementsByTagName('iframe')[0].contentDocument; - var eC = doc.getElementById("expertContent"); - ok(eC, "Expert content should exist") - ok(eC.hasAttribute("hidden"), "Expert content should be hidded by default"); - - // Clean up - gBrowser.removeCurrentTab(); - - finish(); -} diff --git a/browser/components/certerror/test/moz.build b/browser/components/certerror/test/moz.build deleted file mode 100644 index 895d11993..000000000 --- a/browser/components/certerror/test/moz.build +++ /dev/null @@ -1,6 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - diff --git a/browser/components/dirprovider/moz.build b/browser/components/dirprovider/moz.build index 82c902f96..2976a921f 100644 --- a/browser/components/dirprovider/moz.build +++ b/browser/components/dirprovider/moz.build @@ -4,8 +4,6 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -TEST_DIRS += ['tests'] - MODULE = 'browserdir' EXPORTS.mozilla.browser += [ diff --git a/browser/components/dirprovider/tests/moz.build b/browser/components/dirprovider/tests/moz.build deleted file mode 100644 index 3e825b7cd..000000000 --- a/browser/components/dirprovider/tests/moz.build +++ /dev/null @@ -1,9 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -MODULE = 'test_browserdir' - -XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini'] diff --git a/browser/components/dirprovider/tests/unit/head_dirprovider.js b/browser/components/dirprovider/tests/unit/head_dirprovider.js deleted file mode 100644 index 7c3904707..000000000 --- a/browser/components/dirprovider/tests/unit/head_dirprovider.js +++ /dev/null @@ -1,20 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-const Cc = Components.classes;
-const Ci = Components.interfaces;
-
-var gProfD = do_get_profile();
-var gDirSvc = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties);
-var gPrefSvc = Cc["@mozilla.org/preferences-service;1"].
- getService(Ci.nsIPrefBranch);
-
-function writeTestFile(aParent, aName) {
- let file = aParent.clone();
- file.append(aName);
- file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0644);
- return file;
-}
-
diff --git a/browser/components/dirprovider/tests/unit/test_bookmark_pref.js b/browser/components/dirprovider/tests/unit/test_bookmark_pref.js deleted file mode 100644 index 1bacc15af..000000000 --- a/browser/components/dirprovider/tests/unit/test_bookmark_pref.js +++ /dev/null @@ -1,14 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-// We need to run this test separately since DirectoryProvider persists BMarks
-
-function run_test() {
- let dir = gProfD.clone();
- let tfile = writeTestFile(dir, "bookmarkfile.test");
- gPrefSvc.setCharPref("browser.bookmarks.file", tfile.path);
-
- let bmarks = gDirSvc.get("BMarks", Ci.nsIFile);
- do_check_true(tfile.equals(bmarks));
-}
diff --git a/browser/components/dirprovider/tests/unit/test_keys.js b/browser/components/dirprovider/tests/unit/test_keys.js deleted file mode 100644 index 8f0773b27..000000000 --- a/browser/components/dirprovider/tests/unit/test_keys.js +++ /dev/null @@ -1,21 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test_bookmarkhtml() { - let bmarks = gProfD.clone(); - bmarks.append("bookmarks.html"); - - let tbmarks = gDirSvc.get("BMarks", Ci.nsIFile); - do_check_true(bmarks.equals(tbmarks)); -} - -function run_test() { - [test_bookmarkhtml - ].forEach(function(f) { - do_test_pending(); - print("Running test: " + f.name); - f(); - do_test_finished(); - }); -} diff --git a/browser/components/dirprovider/tests/unit/xpcshell.ini b/browser/components/dirprovider/tests/unit/xpcshell.ini deleted file mode 100644 index 27afed650..000000000 --- a/browser/components/dirprovider/tests/unit/xpcshell.ini +++ /dev/null @@ -1,7 +0,0 @@ -[DEFAULT] -head = head_dirprovider.js -tail = -firefox-appdir = browser - -[test_bookmark_pref.js] -[test_keys.js] diff --git a/browser/components/downloads/moz.build b/browser/components/downloads/moz.build index 6f65f014f..009942516 100644 --- a/browser/components/downloads/moz.build +++ b/browser/components/downloads/moz.build @@ -5,4 +5,4 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DIRS += ['src'] -TEST_DIRS += ['test'] + diff --git a/browser/components/downloads/test/browser/Makefile.in b/browser/components/downloads/test/browser/Makefile.in deleted file mode 100644 index 1fc7a4522..000000000 --- a/browser/components/downloads/test/browser/Makefile.in +++ /dev/null @@ -1,19 +0,0 @@ -# Any copyright is dedicated to the Public Domain. -# http://creativecommons.org/publicdomain/zero/1.0/ - -DEPTH = @DEPTH@ -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -relativesrcdir = @relativesrcdir@ - -include $(DEPTH)/config/autoconf.mk - -MOCHITEST_BROWSER_FILES = \ - browser_basic_functionality.js \ - browser_first_download_panel.js \ - head.js \ - $(NULL) - -include $(topsrcdir)/config/rules.mk diff --git a/browser/components/downloads/test/browser/browser_basic_functionality.js b/browser/components/downloads/test/browser/browser_basic_functionality.js deleted file mode 100644 index f235b6f8a..000000000 --- a/browser/components/downloads/test/browser/browser_basic_functionality.js +++ /dev/null @@ -1,62 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=2 et sw=2 tw=80: */ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -/** - * Make sure the downloads panel can display items in the right order and - * contains the expected data. - */ -function gen_test() -{ - // Display one of each download state. - const DownloadData = [ - { endTime: 1180493839859239, state: nsIDM.DOWNLOAD_NOTSTARTED }, - { endTime: 1180493839859238, state: nsIDM.DOWNLOAD_DOWNLOADING }, - { endTime: 1180493839859237, state: nsIDM.DOWNLOAD_PAUSED }, - { endTime: 1180493839859236, state: nsIDM.DOWNLOAD_SCANNING }, - { endTime: 1180493839859235, state: nsIDM.DOWNLOAD_QUEUED }, - { endTime: 1180493839859234, state: nsIDM.DOWNLOAD_FINISHED }, - { endTime: 1180493839859233, state: nsIDM.DOWNLOAD_FAILED }, - { endTime: 1180493839859232, state: nsIDM.DOWNLOAD_CANCELED }, - { endTime: 1180493839859231, state: nsIDM.DOWNLOAD_BLOCKED_PARENTAL }, - { endTime: 1180493839859230, state: nsIDM.DOWNLOAD_DIRTY }, - { endTime: 1180493839859229, state: nsIDM.DOWNLOAD_BLOCKED_POLICY }, - ]; - - // For testing purposes, show all the download items at once. - var originalCountLimit = DownloadsView.kItemCountLimit; - DownloadsView.kItemCountLimit = DownloadData.length; - registerCleanupFunction(function () { - DownloadsView.kItemCountLimit = originalCountLimit; - }); - - try { - // Ensure that state is reset in case previous tests didn't finish. - for (let yy in gen_resetState(DownloadsCommon.getData(window))) yield; - - // Populate the downloads database with the data required by this test. - for (let yy in gen_addDownloadRows(DownloadData)) yield; - - // Open the user interface and wait for data to be fully loaded. - for (let yy in gen_openPanel(DownloadsCommon.getData(window))) yield; - - // Test item data and count. This also tests the ordering of the display. - let richlistbox = document.getElementById("downloadsListBox"); -/* disabled for failing intermittently (bug 767828) - is(richlistbox.children.length, DownloadData.length, - "There is the correct number of richlistitems"); -*/ - for (let i = 0; i < richlistbox.children.length; i++) { - let element = richlistbox.children[i]; - let dataItem = new DownloadsViewItemController(element).dataItem; - is(dataItem.target, DownloadData[i].name, "Download names match up"); - is(dataItem.state, DownloadData[i].state, "Download states match up"); - is(dataItem.file, DownloadData[i].target, "Download targets match up"); - is(dataItem.uri, DownloadData[i].source, "Download sources match up"); - } - } finally { - // Clean up when the test finishes. - for (let yy in gen_resetState(DownloadsCommon.getData(window))) yield; - } -} diff --git a/browser/components/downloads/test/browser/browser_first_download_panel.js b/browser/components/downloads/test/browser/browser_first_download_panel.js deleted file mode 100644 index dc8f0ff43..000000000 --- a/browser/components/downloads/test/browser/browser_first_download_panel.js +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=2 et sw=2 tw=80: */ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -/** - * Make sure the downloads panel only opens automatically on the first - * download it notices. All subsequent downloads, even across sessions, should - * not open the panel automatically. - */ -function gen_test() -{ - try { - // Ensure that state is reset in case previous tests didn't finish. - for (let yy in gen_resetState(DownloadsCommon.getData(window))) yield; - - // With this set to false, we should automatically open the panel - // the first time a download is started. - DownloadsCommon.getData(window).panelHasShownBefore = false; - - prepareForPanelOpen(); - DownloadsCommon.getData(window)._notifyDownloadEvent("start"); - yield; - - // If we got here, that means the panel opened. - DownloadsPanel.hidePanel(); - - ok(DownloadsCommon.getData(window).panelHasShownBefore, - "Should have recorded that the panel was opened on a download.") - - // Next, make sure that if we start another download, we don't open - // the panel automatically. - panelShouldNotOpen(); - DownloadsCommon.getData(window)._notifyDownloadEvent("start"); - yield waitFor(2); - } catch(e) { - ok(false, e); - } finally { - // Clean up when the test finishes. - for (let yy in gen_resetState(DownloadsCommon.getData(window))) yield; - } -} - -/** - * Call this to record a test failure for the next time the downloads panel - * opens. - */ -function panelShouldNotOpen() -{ - // Hook to wait until the test data has been loaded. - let originalOnViewLoadCompleted = DownloadsPanel.onViewLoadCompleted; - DownloadsPanel.onViewLoadCompleted = function () { - DownloadsPanel.onViewLoadCompleted = originalOnViewLoadCompleted; - ok(false, "Should not have opened the downloads panel."); - }; -} diff --git a/browser/components/downloads/test/browser/head.js b/browser/components/downloads/test/browser/head.js deleted file mode 100644 index 6d3d60777..000000000 --- a/browser/components/downloads/test/browser/head.js +++ /dev/null @@ -1,274 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=2 et sw=2 tw=80: */ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -/** - * Provides infrastructure for automated download components tests. - */ - -//////////////////////////////////////////////////////////////////////////////// -//// Globals - -XPCOMUtils.defineLazyModuleGetter(this, "FileUtils", - "resource://gre/modules/FileUtils.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "DownloadsCommon", - "resource:///modules/DownloadsCommon.jsm"); -const nsIDM = Ci.nsIDownloadManager; - -let gTestTargetFile = FileUtils.getFile("TmpD", ["dm-ui-test.file"]); -gTestTargetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); -registerCleanupFunction(function () { - gTestTargetFile.remove(false); -}); - -/** - * This objects contains a property for each column in the downloads table. - */ -let gDownloadRowTemplate = { - name: "test-download.txt", - source: "http://www.example.com/test-download.txt", - target: NetUtil.newURI(gTestTargetFile).spec, - startTime: 1180493839859230, - endTime: 1180493839859234, - state: nsIDM.DOWNLOAD_FINISHED, - currBytes: 0, - maxBytes: -1, - preferredAction: 0, - autoResume: 0 -}; - -//////////////////////////////////////////////////////////////////////////////// -//// Infrastructure - -// All test are run through the test runner. -function test() -{ - testRunner.runTest(this.gen_test); -} - -/** - * Runs a browser-chrome test defined through a generator function. - * - * This object is a singleton, initialized automatically when this script is - * included. Every browser-chrome test file includes a new copy of this object. - */ -var testRunner = { - _testIterator: null, - _lastEventResult: undefined, - _testRunning: false, - _eventRaised: false, - - // --- Main test runner --- - - /** - * Runs the test described by the provided generator function asynchronously. - * - * Calling yield in the generator will cause it to wait until continueTest is - * called. The parameter provided to continueTest will be the return value of - * the yield operator. - * - * @param aGenerator - * Test generator function. The function will be called with no - * arguments to retrieve its iterator. - */ - runTest: function TR_runTest(aGenerator) { - waitForExplicitFinish(); - testRunner._testIterator = aGenerator(); - testRunner.continueTest(); - }, - - /** - * Continues the currently running test. - * - * @param aEventResult - * This will be the return value of the yield operator in the test. - */ - continueTest: function TR_continueTest(aEventResult) { - // Store the last event result, or set it to undefined. - testRunner._lastEventResult = aEventResult; - - // Never reenter the main loop, but notify that the event has been raised. - if (testRunner._testRunning) { - testRunner._eventRaised = true; - return; - } - - // Enter the main iteration loop. - testRunner._testRunning = true; - try { - do { - // Call the iterator, but don't leave the loop if the expected event is - // raised during the execution of the generator. - testRunner._eventRaised = false; - testRunner._testIterator.send(testRunner._lastEventResult); - } while (testRunner._eventRaised); - } - catch (e) { - // This block catches exceptions raised by the generator, including the - // normal StopIteration exception. Unexpected exceptions are reported as - // test failures. - if (!(e instanceof StopIteration)) - ok(false, e); - // In any case, stop the tests in this file. - finish(); - } - - // Wait for the next event or finish. - testRunner._testRunning = false; - } -}; - -//////////////////////////////////////////////////////////////////////////////// -//// Asynchronous generator-based support subroutines - -// -// The following functions are all generators that can be used inside the main -// test generator to perform specific tasks asynchronously. To invoke these -// subroutines correctly, an iteration syntax should be used: -// -// for (let yy in gen_example("Parameter")) yield; -// - -function gen_resetState(aData) -{ - let statement = Services.downloads.DBConnection.createAsyncStatement( - "DELETE FROM moz_downloads"); - try { - statement.executeAsync({ - handleResult: function(aResultSet) { }, - handleError: function(aError) - { - Cu.reportError(aError); - }, - handleCompletion: function(aReason) - { - testRunner.continueTest(); - } - }); - yield; - } finally { - statement.finalize(); - } - - // Reset any prefs that might have been changed. - Services.prefs.clearUserPref("browser.download.panel.shown"); - - // Ensure that the panel is closed and data is unloaded. - aData.clear(); - aData._loadState = aData.kLoadNone; - DownloadsPanel.hidePanel(); - - // Wait for focus on the main window. - waitForFocus(testRunner.continueTest); - yield; -} - -function gen_addDownloadRows(aDataRows) -{ - let columnNames = Object.keys(gDownloadRowTemplate).join(", "); - let parameterNames = Object.keys(gDownloadRowTemplate) - .map(function(n) ":" + n) - .join(", "); - let statement = Services.downloads.DBConnection.createAsyncStatement( - "INSERT INTO moz_downloads (" + columnNames + - ", guid) VALUES(" + parameterNames + ", GENERATE_GUID())"); - try { - // Execute the statement for each of the provided downloads in reverse. - for (let i = aDataRows.length - 1; i >= 0; i--) { - let dataRow = aDataRows[i]; - - // Populate insert parameters from the provided data. - for (let columnName in gDownloadRowTemplate) { - if (!(columnName in dataRow)) { - // Update the provided row object with data from the global template, - // for columns whose value is not provided explicitly. - dataRow[columnName] = gDownloadRowTemplate[columnName]; - } - statement.params[columnName] = dataRow[columnName]; - } - - // Run the statement asynchronously and wait. - statement.executeAsync({ - handleResult: function(aResultSet) { }, - handleError: function(aError) - { - Cu.reportError(aError.message + " (Result = " + aError.result + ")"); - }, - handleCompletion: function(aReason) - { - testRunner.continueTest(); - } - }); - yield; - - // At each iteration, ensure that the start and end time in the global - // template is distinct, as these column are used to sort each download - // in its category. - gDownloadRowTemplate.startTime++; - gDownloadRowTemplate.endTime++; - } - } finally { - statement.finalize(); - } -} - -function gen_openPanel(aData) -{ - // Hook to wait until the test data has been loaded. - let originalOnViewLoadCompleted = DownloadsPanel.onViewLoadCompleted; - DownloadsPanel.onViewLoadCompleted = function () { - DownloadsPanel.onViewLoadCompleted = originalOnViewLoadCompleted; - originalOnViewLoadCompleted.apply(this); - testRunner.continueTest(); - }; - - // Start loading all the downloads from the database asynchronously. - aData.ensurePersistentDataLoaded(false); - - // Wait for focus on the main window. - waitForFocus(testRunner.continueTest); - yield; - - // Open the downloads panel, waiting until loading is completed. - DownloadsPanel.showPanel(); - yield; -} - -/** - * Spin the event loop for aSeconds seconds, and then signal the test to - * continue. - * - * @param aSeconds the number of seconds to wait. - * @note This helper should _only_ be used when there's no valid event to - * listen to and one can't be made. - */ -function waitFor(aSeconds) -{ - setTimeout(function() { - testRunner.continueTest(); - }, aSeconds * 1000); -} - -/** - * Make it so that the next time the downloads panel opens, we signal to - * continue the test. This function needs to be called each time you want - * to wait for the panel to open. - * - * Example usage: - * - * prepareForPanelOpen(); - * // Do something to open the panel - * yield; - * // We can assume the panel is open now. - */ -function prepareForPanelOpen() -{ - // Hook to wait until the test data has been loaded. - let originalOnPopupShown = DownloadsPanel.onPopupShown; - DownloadsPanel.onPopupShown = function (aEvent) { - DownloadsPanel.onPopupShown = originalOnPopupShown; - DownloadsPanel.onPopupShown.apply(this, [aEvent]); - testRunner.continueTest(); - }; -} diff --git a/browser/components/downloads/test/browser/moz.build b/browser/components/downloads/test/browser/moz.build deleted file mode 100644 index 895d11993..000000000 --- a/browser/components/downloads/test/browser/moz.build +++ /dev/null @@ -1,6 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - diff --git a/browser/components/downloads/test/moz.build b/browser/components/downloads/test/moz.build deleted file mode 100644 index 30780a141..000000000 --- a/browser/components/downloads/test/moz.build +++ /dev/null @@ -1,9 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -DIRS += ['browser'] - -XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini'] diff --git a/browser/components/downloads/test/unit/head.js b/browser/components/downloads/test/unit/head.js deleted file mode 100644 index fb75c12c8..000000000 --- a/browser/components/downloads/test/unit/head.js +++ /dev/null @@ -1,18 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=2 et sw=2 tw=80: */ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -/** - * Provides infrastructure for automated download components tests. - */ - -//////////////////////////////////////////////////////////////////////////////// -//// Globals - -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cu = Components.utils; -const Cr = Components.results; - -Cu.import("resource:///modules/DownloadsCommon.jsm"); diff --git a/browser/components/downloads/test/unit/test_DownloadsCommon.js b/browser/components/downloads/test/unit/test_DownloadsCommon.js deleted file mode 100644 index f065907cc..000000000 --- a/browser/components/downloads/test/unit/test_DownloadsCommon.js +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=2 et sw=2 tw=80: */ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -/** - * Tests for the functions located directly in the "DownloadsCommon" object. - */ - -function testFormatTimeLeft(aSeconds, aExpectedValue, aExpectedUnitString) -{ - let expected = ""; - if (aExpectedValue) { - // Format the expected result based on the current language. - expected = DownloadsCommon.strings[aExpectedUnitString](aExpectedValue); - } - do_check_eq(DownloadsCommon.formatTimeLeft(aSeconds), expected); -} - -function run_test() -{ - testFormatTimeLeft( 0, "", ""); - testFormatTimeLeft( 1, "1", "shortTimeLeftSeconds"); - testFormatTimeLeft( 29, "29", "shortTimeLeftSeconds"); - testFormatTimeLeft( 30, "30", "shortTimeLeftSeconds"); - testFormatTimeLeft( 31, "1", "shortTimeLeftMinutes"); - testFormatTimeLeft( 60, "1", "shortTimeLeftMinutes"); - testFormatTimeLeft( 89, "1", "shortTimeLeftMinutes"); - testFormatTimeLeft( 90, "2", "shortTimeLeftMinutes"); - testFormatTimeLeft( 91, "2", "shortTimeLeftMinutes"); - testFormatTimeLeft( 3600, "1", "shortTimeLeftHours"); - testFormatTimeLeft( 86400, "24", "shortTimeLeftHours"); - testFormatTimeLeft( 169200, "47", "shortTimeLeftHours"); - testFormatTimeLeft( 172800, "2", "shortTimeLeftDays"); - testFormatTimeLeft(8553600, "99", "shortTimeLeftDays"); - testFormatTimeLeft(8640000, "99", "shortTimeLeftDays"); -} diff --git a/browser/components/downloads/test/unit/xpcshell.ini b/browser/components/downloads/test/unit/xpcshell.ini deleted file mode 100644 index 924123c74..000000000 --- a/browser/components/downloads/test/unit/xpcshell.ini +++ /dev/null @@ -1,6 +0,0 @@ -[DEFAULT] -head = head.js -tail = -firefox-appdir = browser - -[test_DownloadsCommon.js] diff --git a/browser/components/feeds/moz.build b/browser/components/feeds/moz.build index 92950f537..76218104c 100644 --- a/browser/components/feeds/moz.build +++ b/browser/components/feeds/moz.build @@ -5,4 +5,4 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DIRS += ['public', 'src'] -TEST_DIRS += ['test'] + diff --git a/browser/components/feeds/test/Makefile.in b/browser/components/feeds/test/Makefile.in deleted file mode 100644 index bfc6e9869..000000000 --- a/browser/components/feeds/test/Makefile.in +++ /dev/null @@ -1,27 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -DEPTH = @DEPTH@ -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ -relativesrcdir = @relativesrcdir@ - -include $(DEPTH)/config/autoconf.mk - -MOCHITEST_FILES = \ - bug408328-data.xml \ - bug368464-data.xml \ - test_bug494328.html \ - bug494328-data.xml \ - test_bug589543.html \ - bug589543-data.xml \ - test_bug436801.html \ - bug436801-data.xml \ - test_registerHandler.html \ - valid-feed.xml \ - valid-unsniffable-feed.xml \ - $(NULL) - -include $(topsrcdir)/config/rules.mk diff --git a/browser/components/feeds/test/bug368464-data.xml b/browser/components/feeds/test/bug368464-data.xml deleted file mode 100644 index 2745b061d..000000000 --- a/browser/components/feeds/test/bug368464-data.xml +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0"?> - <rdf:RDF - xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" - xmlns="http://my.netscape.com/rdf/simple/0.9/"> - <channel> - <title>Tinderbox - Firefox</title> - <description>Build bustages for Firefox</description> - <link>http://tinderbox.mozilla.org/showbuilds.cgi?tree=Firefox</link> - </channel> - <image> - <title>Bad</title> - <url>http://tinderbox.mozilla.org/channelflames.gif</url> - <link>http://tinderbox.mozilla.org/showbuilds.cgi?tree=Firefox</link> - </image> - <item><title>The tree is currently closed</title><link>http://tinderbox.mozilla.org/showbuilds.cgi?tree=Firefox</link></item> - -<item><title>MacOSX Darwin 8.8.4 qm-xserve01 dep unit test is in flames</title><link>http://tinderbox.mozilla.org/showbuilds.cgi?tree=Firefox</link></item> -</rdf:RDF> diff --git a/browser/components/feeds/test/bug408328-data.xml b/browser/components/feeds/test/bug408328-data.xml deleted file mode 100644 index e9385e5ab..000000000 --- a/browser/components/feeds/test/bug408328-data.xml +++ /dev/null @@ -1,63 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<feed xmlns="http://www.w3.org/2005/Atom"> - - <title>Example Feed</title> - <link href="http://example.org/"/> - <updated>2003-12-13T18:30:02Z</updated> - - <author> - <name>John Doe</name> - </author> - <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id> - - <entry> - - <title>Good item</title> - <link href="http://example.org/first"/> - <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id> - <updated>2003-12-13T18:30:02Z</updated> - - <summary>Some text.</summary> - </entry> - - <entry> - - <title>data: link</title> - <link href="data:text/plain,Hi"/> - <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6b</id> - <updated>2003-12-13T18:30:03Z</updated> - - <summary>Some text.</summary> - </entry> - - <entry> - - <title>javascript: link</title> - <link href="javascript:alert('Hi')"/> - <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6c</id> - <updated>2003-12-13T18:30:04Z</updated> - - <summary>Some text.</summary> - </entry> - - <entry> - - <title>file: link</title> - <link href="file:///var/"/> - <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6d</id> - <updated>2003-12-13T18:30:05Z</updated> - - <summary>Some text.</summary> - </entry> - - <entry> - - <title>chrome: link</title> - <link href="chrome://browser/content/browser.js"/> - <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6e</id> - <updated>2003-12-13T18:30:06Z</updated> - - <summary>Some text.</summary> - </entry> - -</feed> diff --git a/browser/components/feeds/test/bug436801-data.xml b/browser/components/feeds/test/bug436801-data.xml deleted file mode 100644 index 0e45c7ed8..000000000 --- a/browser/components/feeds/test/bug436801-data.xml +++ /dev/null @@ -1,44 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<feed xmlns="http://www.w3.org/2005/Atom" xml:base="http://www.example.com/"> - - <title type="xhtml" xml:base="/foo/bar/"> - <div xmlns="http://www.w3.org/1999/xhtml">Example of a <em>special</em> feed (<img height="20px" src="baz.png" alt="base test sprite"/>)</div> - </title> - - <subtitle type="html" xml:base="/foo/bar/"> - <![CDATA[ - With a <em>special</em> subtitle (<img height="20px" src="baz.png" alt="base test sprite"/>) - ]]> - </subtitle> - - <link href="http://example.org/"/> - - <updated>2010-09-02T18:30:02Z</updated> - - <author> - <name>John Doe</name> - </author> - - <id>urn:uuid:22906062-ecbd-46e2-b6a7-3039506a398f</id> - - <entry> - <title type="xhtml" xml:base="/foo/bar/"> - <div xmlns="http://www.w3.org/1999/xhtml">Some <abbr title="Extensible Hyper-text Mark-up Language">XHTML</abbr> examples (<img height="20px" src="baz.png" alt="base test sprite"/>)</div> - </title> - <id>urn:uuid:b48083a7-71a7-4c9c-8515-b7c0d22955e7</id> - <updated>2010-09-02T18:30:02Z</updated> - <summary>Some text.</summary> - </entry> - - <entry> - <title type="html" xml:base="/foo/bar/"> - <![CDATA[ - Some <abbr title="Hyper-text Mark-up Language">HTML</abbr> examples (<img height="20px" src="baz.png" alt="base test sprite"/>) - ]]> - </title> - <id>urn:uuid:1424967a-280a-414d-b0ab-8b11c4ac1bb7</id> - <updated>2010-09-02T18:30:02Z</updated> - <summary>Some text.</summary> - </entry> - -</feed> diff --git a/browser/components/feeds/test/bug494328-data.xml b/browser/components/feeds/test/bug494328-data.xml deleted file mode 100644 index 58342bafc..000000000 --- a/browser/components/feeds/test/bug494328-data.xml +++ /dev/null @@ -1,24 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?>
-<rss version="2.0">
- <channel>
- <title>Channel title</title>
- <description>Channel description</description>
- <link>Channel link</link>
- <item>
- <title>Episode 1</title>
- <enclosure url="http://www.example.com/podcasts/Episode%201" length="0" type="audio/x-m4a" />
- </item>
- <item>
- <title>Episode 2</title>
- <enclosure url="http://www.example.com/podcasts/Episode%20%232" length="0" type="audio/x-m4a" />
- </item>
- <item>
- <title>Episode 3</title>
- <enclosure url="http://www.example.com/podcasts/Episode%20%233/" length="0" type="audio/x-m4a" />
- </item>
- <item>
- <title>Episode 4</title>
- <enclosure url="http://www.example.com/podcasts/Is%20This%20Episode%20%234%3F" length="0" type="audio/x-m4a" />
- </item>
- </channel>
-</rss>
diff --git a/browser/components/feeds/test/bug589543-data.xml b/browser/components/feeds/test/bug589543-data.xml deleted file mode 100644 index 0e700b6d8..000000000 --- a/browser/components/feeds/test/bug589543-data.xml +++ /dev/null @@ -1,23 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<feed xmlns="http://www.w3.org/2005/Atom"> - - <title>Example Feed</title> - <link href="http://example.org/"/> - <updated>2010-08-22T18:30:02Z</updated> - - <author> - <name>John Doe</name> - </author> - <id>urn:uuid:e2df8375-99be-4848-b05e-b9d407555267</id> - - <entry> - - <title>Item</title> - <link href="http://example.org/first"/> - <id>urn:uuid:9e0f4bed-33d3-4a9d-97ab-ecaa31b3f14a</id> - <updated>2010-08-22T18:30:02Z</updated> - - <summary>Some text.</summary> - </entry> - -</feed> diff --git a/browser/components/feeds/test/chrome/Makefile.in b/browser/components/feeds/test/chrome/Makefile.in deleted file mode 100644 index 020e4b652..000000000 --- a/browser/components/feeds/test/chrome/Makefile.in +++ /dev/null @@ -1,27 +0,0 @@ -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -DEPTH = @DEPTH@ -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ -relativesrcdir = @relativesrcdir@ - -include $(DEPTH)/config/autoconf.mk - -# sample_feed.atom was copied from toolkit/components/places/tests/chrome -MOCHITEST_FILES = \ - sample_feed.atom \ - $(NULL) - -MOCHITEST_CHROME_FILES = \ - test_423060.xul \ - test_bug368464.html \ - test_bug408328.html \ - test_maxSniffing.html \ - $(NULL) - -include $(topsrcdir)/config/rules.mk - diff --git a/browser/components/feeds/test/chrome/moz.build b/browser/components/feeds/test/chrome/moz.build deleted file mode 100644 index 895d11993..000000000 --- a/browser/components/feeds/test/chrome/moz.build +++ /dev/null @@ -1,6 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - diff --git a/browser/components/feeds/test/chrome/sample_feed.atom b/browser/components/feeds/test/chrome/sample_feed.atom deleted file mode 100644 index add75efb4..000000000 --- a/browser/components/feeds/test/chrome/sample_feed.atom +++ /dev/null @@ -1,23 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<feed xmlns="http://www.w3.org/2005/Atom"> - - <title>Example Feed</title> - <link href="http://example.org/"/> - <updated>2003-12-13T18:30:02Z</updated> - - <author> - <name>John Doe</name> - </author> - <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id> - - <entry> - - <title>Atom-Powered Robots Run Amok</title> - <link href="http://example.org/2003/12/13/atom03"/> - <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id> - <updated>2003-12-13T18:30:02Z</updated> - - <summary>Some text.</summary> - </entry> - -</feed> diff --git a/browser/components/feeds/test/chrome/test_423060.xul b/browser/components/feeds/test/chrome/test_423060.xul deleted file mode 100644 index 465cf2dd2..000000000 --- a/browser/components/feeds/test/chrome/test_423060.xul +++ /dev/null @@ -1,56 +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"?> -<window title="Make sure feed preview works when a default reader is selected" - xmlns:html="http://www.w3.org/1999/xhtml" - xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> - <script type="application/javascript" - src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> - - <body xmlns="http://www.w3.org/1999/xhtml" /> - - <script type="application/javascript"> - SimpleTest.waitForExplicitFinish(); - - const Cc = Components.classes; - const Ci = Components.interfaces; - - var wccrID = "@mozilla.org/embeddor.implemented/web-content-handler-registrar;1"; - /* abort the test if web feed handlers are not available */ - if (!Cc[wccrID]) - SimpleTest.finish() - - /* Turn off the first run UI */ - var prefBranch = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); - prefBranch.setBoolPref("browser.feeds.showFirstRunUI", false); - - /* register a handler for the feed type */ - const MAYBE_FEED = "application/vnd.mozilla.maybe.feed"; - var handlerPage = "http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/demohandler.html?feedurl=%s"; - var wccr = Cc[wccrID].getService(Ci.nsIWebContentConverterService); - wccr.registerContentHandler(MAYBE_FEED, handlerPage, "Demo handler", null); - var demoHandler = wccr.getWebContentHandlerByURI(MAYBE_FEED, handlerPage); - wccr.setAutoHandler(MAYBE_FEED, demoHandler); - - /* Don't show the preview page */ - prefBranch.setCharPref("browser.feeds.handler", "reader"); - - function finishUp() { - var theframe = document.getElementById('theframe'); - var previewURL = "http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/demohandler.html?feedurl=http%3A%2F%2Fmochi.test%3A8888%2Ftests%2Ftoolkit%2Fcomponents%2Fplaces%2Ftests%2Fchrome%2Fsample_feed.atom"; - is(theframe.contentDocument.URL, previewURL); - - /* remove our demoHandler */ - wccr.setAutoHandler(MAYBE_FEED, null); - wccr.removeContentHandler(MAYBE_FEED, handlerPage); - prefBranch.setCharPref("browser.feeds.handler", "ask"); - prefBranch.setBoolPref("browser.feeds.showFirstRunUI", true); - - SimpleTest.finish(); - } - </script> - <html:iframe src="http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/sample_feed.atom" height="400px" - id="theframe" onload="finishUp();"> - </html:iframe> -</window> diff --git a/browser/components/feeds/test/chrome/test_bug368464.html b/browser/components/feeds/test/chrome/test_bug368464.html deleted file mode 100644 index dd7486f66..000000000 --- a/browser/components/feeds/test/chrome/test_bug368464.html +++ /dev/null @@ -1,32 +0,0 @@ -<!DOCTYPE HTML> -<html> -<!-- -https://bugzilla.mozilla.org/show_bug.cgi?id=368464 ---> -<head> - <title>Test that RSS 0.90 isn't sniffed</title> - <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> - <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> -</head> -<body> -<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=368464">Mozilla Bug 368464</a> -<p id="display"><iframe id="testFrame" src="http://mochi.test:8888/tests/browser/components/feeds/test/bug368464-data.xml"></iframe></p> -<div id="content" style="display: none"> - -</div> -<pre id="test"> -<script class="testbody" type="text/javascript"> - -/** Test for Bug 368464 **/ -SimpleTest.waitForExplicitFinish(); - -addLoadEvent(function() { - ok($("testFrame").contentDocument.documentElement.id != "feedHandler", - "RSS 0.90 shouldn't be sniffed as a feed"); -}); -addLoadEvent(SimpleTest.finish); - -</script> -</pre> -</body> -</html> diff --git a/browser/components/feeds/test/chrome/test_bug408328.html b/browser/components/feeds/test/chrome/test_bug408328.html deleted file mode 100644 index e4901320a..000000000 --- a/browser/components/feeds/test/chrome/test_bug408328.html +++ /dev/null @@ -1,37 +0,0 @@ -<!DOCTYPE HTML> -<html> -<!-- -https://bugzilla.mozilla.org/show_bug.cgi?id=408328 ---> -<head> - <title>Test feed preview safe-linkification</title> - <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> - <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> -</head> -<body> -<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=408328">Mozilla Bug 408328</a> -<p id="display"><iframe id="testFrame" src="http://mochi.test:8888/tests/browser/components/feeds/test/bug408328-data.xml"></iframe></p> -<div id="content" style="display: none"> - -</div> -<pre id="test"> -<script class="testbody" type="text/javascript"> - -/** Test for Bug 408328 **/ -SimpleTest.waitForExplicitFinish(); - -addLoadEvent(function() { - var links = $("testFrame").contentDocument.getElementById("feedContent").getElementsByTagName("a"); - is(links.length, 5, "wrong number of linked items in feed preview"); - for (var i = 0; i < links.length; i++) { - if (links[i].href) - is(links[i].href, "http://example.org/first", "bad linkified item"); - } -}); -addLoadEvent(SimpleTest.finish); - -</script> -</pre> -</body> -</html> - diff --git a/browser/components/feeds/test/chrome/test_maxSniffing.html b/browser/components/feeds/test/chrome/test_maxSniffing.html deleted file mode 100644 index 7a2044687..000000000 --- a/browser/components/feeds/test/chrome/test_maxSniffing.html +++ /dev/null @@ -1,37 +0,0 @@ -<!DOCTYPE HTML> -<html> -<!-- -https://bugzilla.mozilla.org/show_bug.cgi?id=739040 ---> -<head> - <title>Test that we only sniff 512 bytes</title> - <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> - <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> -</head> -<body> -<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=739040">Mozilla Bug 739040</a> -<p id="display"> - <iframe id="validTestFrame" src="http://mochi.test:8888/tests/browser/components/feeds/test/valid-feed.xml"></iframe> - <iframe id="unsniffableTestFrame" src="http://mochi.test:8888/tests/browser/components/feeds/test/valid-unsniffable-feed.xml"></iframe> -</p> -<div id="content" style="display: none"> - -</div> -<pre id="test"> -<script class="testbody" type="text/javascript"> - -/** Test for Bug 739040 **/ -SimpleTest.waitForExplicitFinish(); - -addLoadEvent(function() { - is($("validTestFrame").contentDocument.documentElement.id, "feedHandler", - "valid feed should be sniffed"); - isnot($("unsniffableTestFrame").contentDocument.documentElement.id, "feedHandler", - "unsniffable feed should not be sniffed"); -}); -addLoadEvent(SimpleTest.finish); - -</script> -</pre> -</body> -</html> diff --git a/browser/components/feeds/test/moz.build b/browser/components/feeds/test/moz.build deleted file mode 100644 index 51e55b106..000000000 --- a/browser/components/feeds/test/moz.build +++ /dev/null @@ -1,11 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -DIRS += ['chrome'] - -MODULE = 'test_browser_feeds' - -XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini'] diff --git a/browser/components/feeds/test/test_bug436801.html b/browser/components/feeds/test/test_bug436801.html deleted file mode 100644 index a72d2c11a..000000000 --- a/browser/components/feeds/test/test_bug436801.html +++ /dev/null @@ -1,118 +0,0 @@ -<!DOCTYPE HTML> -<html> -<!-- -https://bugzilla.mozilla.org/show_bug.cgi?id=436801 ---> -<head> - <title>Test feed preview subscribe UI</title> - <script type="text/javascript" src="/MochiKit/packed.js"></script> - <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> - <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> -</head> -<body> -<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=436801">Mozilla Bug 436801</a> -<p id="display"><iframe id="testFrame" src="bug436801-data.xml"></iframe></p> -<div id="content" style="display: none"> -</div> -<pre id="test"> -<script class="testbody" type="text/javascript"> - -SimpleTest.waitForExplicitFinish(); - -addLoadEvent(function () { - var doc = SpecialPowers.wrap($("testFrame")).contentDocument; - - checkNode(doc.getElementById("feedTitleText"), [ - "ELEMENT", "h1", { "xml:base": "http://www.example.com/foo/bar/" }, [ - ["TEXT", "Example of a "], - ["ELEMENT", "em", [ - ["TEXT", "special"], - ]], - ["TEXT", " feed ("], - ["ELEMENT", "img", { "src": "baz.png" }], - ["TEXT", ")"], - ] - ]); - - checkNode(doc.getElementById("feedSubtitleText"), [ - "ELEMENT", "h2", { "xml:base": "http://www.example.com/foo/bar/" }, [ - ["TEXT", "With a "], - ["ELEMENT", "em", [ - ["TEXT", "special"], - ]], - ["TEXT", " subtitle ("], - ["ELEMENT", "img", { "src": "baz.png" }], - ["TEXT", ")"], - ] - ]); - - checkNode(doc.querySelector(".entry").firstChild.firstChild.firstChild, [ - "ELEMENT", "span", { "xml:base": "http://www.example.com/foo/bar/" }, [ - ["TEXT", "Some "], - ["ELEMENT", "abbr", { title: "Extensible Hyper-text Mark-up Language" }, [ - ["TEXT", "XHTML"], - ]], - ["TEXT", " examples ("], - ["ELEMENT", "img", { "src": "baz.png" }], - ["TEXT", ")"], - ] - ]); - - checkNode(doc.querySelectorAll(".entry")[1].firstChild.firstChild.firstChild, [ - "ELEMENT", "span", { "xml:base": "http://www.example.com/foo/bar/" }, [ - ["TEXT", "Some "], - ["ELEMENT", "abbr", { title: "Hyper-text Mark-up Language" }, [ - ["TEXT", "HTML"], - ]], - ["TEXT", " examples ("], - ["ELEMENT", "img", { "src": "baz.png" }], - ["TEXT", ")"], - ] - ]); -}); - -addLoadEvent(SimpleTest.finish); - -function checkNode(node, schema) { - var typeName = schema.shift() + "_NODE"; - var type = Node[typeName]; - is(node.nodeType, type, "Node should be expected type " + typeName); - if (type == Node.TEXT_NODE) { - var text = schema.shift(); - is(node.data, text, "Text should match"); - return; - } - // type == Node.ELEMENT_NODE - var tag = schema.shift(); - is(node.localName, tag, "Element should have expected tag"); - while (schema.length) { - var val = schema.shift(); - if (Array.isArray(val)) - var childSchema = val; - else - var attrSchema = val; - } - if (attrSchema) { - var nsTable = { - xml: "http://www.w3.org/XML/1998/namespace", - }; - for (var name in attrSchema) { - var [ns, nsName] = name.split(":"); - var val = nsName ? node.getAttributeNS(nsTable[ns], nsName) : - node.getAttribute(name); - is(val, attrSchema[name], "Attribute " + name + " should match"); - } - } - if (childSchema) { - var numChildren = node.childNodes.length; - is(childSchema.length, numChildren, - "Element should have expected number of children"); - for (var i = 0; i < numChildren; i++) - checkNode(node.childNodes[i], childSchema[i]); - } -} - -</script> -</pre> -</body> -</html> diff --git a/browser/components/feeds/test/test_bug494328.html b/browser/components/feeds/test/test_bug494328.html deleted file mode 100644 index 054f62c1d..000000000 --- a/browser/components/feeds/test/test_bug494328.html +++ /dev/null @@ -1,36 +0,0 @@ -<!DOCTYPE HTML> -<html> -<!-- -https://bugzilla.mozilla.org/show_bug.cgi?id=494328 ---> -<head> - <title>Test for bug 494328</title> - <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> - <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> -</head> -<body> -<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=494328">Mozilla Bug 494328</a> -<p id="display"><iframe id="testFrame" src="bug494328-data.xml"></iframe></p> -<div id="content" style="display: none"> - -</div> -<pre id="test"> -<script class="testbody" type="text/javascript"> - -/** Test for Bug 494328 **/ -SimpleTest.waitForExplicitFinish(); - -addLoadEvent(function() { - var links = SpecialPowers.wrap($("testFrame")).contentDocument.getElementById("feedContent").querySelectorAll("div.enclosure > a"); - is(links[0].textContent, "Episode 1", "filename decoded incorrectly"); - is(links[1].textContent, "Episode #2", "filename decoded incorrectly"); - is(links[2].textContent, "http://www.example.com/podcasts/Episode #3/", "filename decoded incorrectly"); - is(links[3].textContent, "Is This Episode #4?", "filename decoded incorrectly"); -}); -addLoadEvent(SimpleTest.finish); - -</script> -</pre> -</body> -</html> - diff --git a/browser/components/feeds/test/test_bug589543.html b/browser/components/feeds/test/test_bug589543.html deleted file mode 100644 index a6dd0b283..000000000 --- a/browser/components/feeds/test/test_bug589543.html +++ /dev/null @@ -1,33 +0,0 @@ -<!DOCTYPE HTML> -<html> -<!-- -https://bugzilla.mozilla.org/show_bug.cgi?id=589543 ---> -<head> - <title>Test feed preview subscribe UI</title> - <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> - <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> -</head> -<body> -<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=589543">Mozilla Bug 589543</a> -<p id="display"><iframe id="testFrame" src="bug589543-data.xml"></iframe></p> -<div id="content" style="display: none"> -</div> -<pre id="test"> -<script class="testbody" type="text/javascript"> - -/** Test for Bug 589543 **/ -SimpleTest.waitForExplicitFinish(); - -addLoadEvent(function() { - var doc = SpecialPowers.wrap($("testFrame")).contentDocument; - var daddy = doc.getElementById("feedSubscribeLine"); - var popup = doc.getAnonymousElementByAttribute(daddy, "anonid", "handlersMenuPopup"); - isnot(popup, null, "Feed preview should have a handlers popup"); -}); -addLoadEvent(SimpleTest.finish); - -</script> -</pre> -</body> -</html> diff --git a/browser/components/feeds/test/test_registerHandler.html b/browser/components/feeds/test/test_registerHandler.html deleted file mode 100644 index 4df5f326d..000000000 --- a/browser/components/feeds/test/test_registerHandler.html +++ /dev/null @@ -1,85 +0,0 @@ -<!DOCTYPE HTML> -<html> -<!-- -https://bugzilla.mozilla.org/show_bug.cgi?id=402788 ---> -<head> - <title>Test for Bug 402788</title> - <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> - <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> -</head> -<body> -<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=402788">Mozilla Bug 402788</a> -<p id="display"></p> -<div id="content" style="display: none"> - -</div> -<pre id="test"> -<script class="testbody" type="text/javascript"> - -/** Test for Bug 402788 **/ - - // return false if an exception has been catched, true otherwise - function testRegisterHandler(aIsProtocol, aTxt, aUri, aTitle) - { - try { - if (aIsProtocol) - navigator.registerProtocolHandler(aTxt, aUri, aTitle); - else - navigator.registerContentHandler(aTxt, aUri, aTitle); - } - catch(e) { - return false; - } - - return true; - } - - ok(navigator.registerProtocolHandler, "navigator.registerProtocolHandler should be defined"); - ok(navigator.registerContentHandler, "navigator.registerContentHandler should be defined"); - - // testing a generic case - is(true, testRegisterHandler(true, "foo", "http://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler should work"); - is(true, testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler should work"); - - // testing with wrong uris - is(false, testRegisterHandler(true, "foo", "http://mochi.test:8888/", "Foo handler"), "a protocol handler uri should contain %s"); - is(false, testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/", "Foo handler"), "a content handler uri should contain %s"); - - // the spec says we should not throw here, but it probably needs to be changed - is(false, testRegisterHandler(true, "foo", "foo/%s", "Foo handler"), "a protocol handler uri should be valid"); - is(false, testRegisterHandler(false, "application/rss+xml", "foo/%s", "Foo handler"), "a content handler uri should be valid"); - - // we should only accept to register when the handler has the same host as the current page (bug 402287) - is(false, testRegisterHandler(true, "foo", "http://remotehost:8888/%s", "Foo handler"), "registering a foo protocol handler with a different host should not work"); - is(false, testRegisterHandler(false, "application/rss+xml", "http://remotehost:8888/%s", "Foo handler"), "registering a foo content handler with a different host should not work"); - - // restriction to http(s) for the uri of the handler (bug 401343) - // https should work (http already tested in the generic case) - is(true, testRegisterHandler(true, "foo", "https://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler with https scheme should work"); - is(true, testRegisterHandler(false, "application/rss+xml", "https://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler with https scheme should work"); - // ftp should not work - is(false, testRegisterHandler(true, "foo", "ftp://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler with ftp scheme should not work"); - is(false, testRegisterHandler(false, "application/rss+xml", "ftp://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler with ftp scheme should not work"); - // chrome should not work - is(false, testRegisterHandler(true, "foo", "chrome://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler with chrome scheme should not work"); - is(false, testRegisterHandler(false, "application/rss+xml", "chrome://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler with chrome scheme should not work"); - // foo should not work - is(false, testRegisterHandler(true, "foo", "foo://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler with foo scheme should not work"); - is(false, testRegisterHandler(false, "application/rss+xml", "foo://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler with foo scheme should not work"); - - // for security reasons, protocol handlers should never be registered for some schemes (chrome, vbscript, ...) (bug 402788) - is(false, testRegisterHandler(true, "chrome", "http://mochi.test:8888/%s", "chrome handler"), "registering a chrome protocol handler should not work"); - is(false, testRegisterHandler(true, "vbscript", "http://mochi.test:8888/%s", "vbscript handler"), "registering a vbscript protocol handler should not work"); - is(false, testRegisterHandler(true, "javascript", "http://mochi.test:8888/%s", "javascript handler"), "registering a javascript protocol handler should not work"); - is(false, testRegisterHandler(true, "moz-icon", "http://mochi.test:8888/%s", "moz-icon handler"), "registering a moz-icon protocol handler should not work"); - - // for security reasons, content handlers should never be registered for some types (html, ...) - is(true, testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/%s", "Foo handler"), "registering rss content handlers should work"); - is(true, testRegisterHandler(false, "application/atom+xml", "http://mochi.test:8888/%s", "Foo handler"), "registering atom content handlers should work"); - todo(false, testRegisterHandler(false, "text/html", "http://mochi.test:8888/%s", "Foo handler"), "registering html content handlers should not work"); // bug 403798 - -</script> -</pre> -</body> -</html> diff --git a/browser/components/feeds/test/unit/head_feeds.js b/browser/components/feeds/test/unit/head_feeds.js deleted file mode 100644 index 841f68157..000000000 --- a/browser/components/feeds/test/unit/head_feeds.js +++ /dev/null @@ -1,5 +0,0 @@ -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cr = Components.results; - -var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); diff --git a/browser/components/feeds/test/unit/test_355473.js b/browser/components/feeds/test/unit/test_355473.js deleted file mode 100644 index 54900a5a7..000000000 --- a/browser/components/feeds/test/unit/test_355473.js +++ /dev/null @@ -1,27 +0,0 @@ -function run_test() { - var feedFeedURI = ios.newURI("feed://example.com/feed.xml", null, null); - var httpFeedURI = ios.newURI("feed:http://example.com/feed.xml", null, null); - var httpURI = ios.newURI("http://example.com/feed.xml", null, null); - - var httpsFeedURI = - ios.newURI("feed:https://example.com/feed.xml", null, null); - var httpsURI = ios.newURI("https://example.com/feed.xml", null, null); - - var feedChannel = ios.newChannelFromURI(feedFeedURI, null); - var httpChannel = ios.newChannelFromURI(httpFeedURI, null); - var httpsChannel = ios.newChannelFromURI(httpsFeedURI, null); - - // not setting .originalURI to the original URI is naughty - do_check_true(feedFeedURI.equals(feedChannel.originalURI)); - do_check_true(httpFeedURI.equals(httpChannel.originalURI)); - do_check_true(httpsFeedURI.equals(httpsChannel.originalURI)); - - // actually using the horrible mess that's a feed: URI is suicidal - do_check_true(httpURI.equals(feedChannel.URI)); - do_check_true(httpURI.equals(httpChannel.URI)); - do_check_true(httpsURI.equals(httpsChannel.URI)); - - // check that we don't throw creating feed: URIs from file and ftp - var ftpFeedURI = ios.newURI("feed:ftp://example.com/feed.xml", null, null); - var fileFeedURI = ios.newURI("feed:file:///var/feed.xml", null, null); -} diff --git a/browser/components/feeds/test/unit/test_758990.js b/browser/components/feeds/test/unit/test_758990.js deleted file mode 100644 index 3a1dde770..000000000 --- a/browser/components/feeds/test/unit/test_758990.js +++ /dev/null @@ -1,42 +0,0 @@ -function run_test() { - var success = false; - try { - var newURI = ios.newURI("feed:javascript:alert('hi');", null, null); - } - catch (e) { - success = e.result == Cr.NS_ERROR_MALFORMED_URI; - } - if (!success) - do_throw("We didn't throw NS_ERROR_MALFORMED_URI creating a feed:javascript: URI"); - - success = false; - try { - newURI = ios.newURI("feed:data:text/html,hi", null, null); - } - catch (e) { - success = e.result == Cr.NS_ERROR_MALFORMED_URI; - } - if (!success) - do_throw("We didn't throw NS_ERROR_MALFORMED_URI creating a feed:data: URI"); - - success = false; - try { - newURI = ios.newURI("pcast:javascript:alert('hi');", null, null); - } - catch (e) { - success = e.result == Cr.NS_ERROR_MALFORMED_URI; - } - if (!success) - do_throw("We didn't throw NS_ERROR_MALFORMED_URI creating a pcast:javascript: URI"); - - success = false; - try { - newURI = ios.newURI("pcast:data:text/html,hi", null, null); - } - catch (e) { - success = e.result == Cr.NS_ERROR_MALFORMED_URI; - } - if (!success) - do_throw("We didn't throw NS_ERROR_MALFORMED_URI creating a pcast:data: URI"); - -} diff --git a/browser/components/feeds/test/unit/xpcshell.ini b/browser/components/feeds/test/unit/xpcshell.ini deleted file mode 100644 index abe786897..000000000 --- a/browser/components/feeds/test/unit/xpcshell.ini +++ /dev/null @@ -1,7 +0,0 @@ -[DEFAULT] -head = head_feeds.js -tail = -firefox-appdir = browser - -[test_355473.js] -[test_758990.js] diff --git a/browser/components/feeds/test/valid-feed.xml b/browser/components/feeds/test/valid-feed.xml deleted file mode 100644 index 0e700b6d8..000000000 --- a/browser/components/feeds/test/valid-feed.xml +++ /dev/null @@ -1,23 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<feed xmlns="http://www.w3.org/2005/Atom"> - - <title>Example Feed</title> - <link href="http://example.org/"/> - <updated>2010-08-22T18:30:02Z</updated> - - <author> - <name>John Doe</name> - </author> - <id>urn:uuid:e2df8375-99be-4848-b05e-b9d407555267</id> - - <entry> - - <title>Item</title> - <link href="http://example.org/first"/> - <id>urn:uuid:9e0f4bed-33d3-4a9d-97ab-ecaa31b3f14a</id> - <updated>2010-08-22T18:30:02Z</updated> - - <summary>Some text.</summary> - </entry> - -</feed> diff --git a/browser/components/feeds/test/valid-unsniffable-feed.xml b/browser/components/feeds/test/valid-unsniffable-feed.xml deleted file mode 100644 index e75315739..000000000 --- a/browser/components/feeds/test/valid-unsniffable-feed.xml +++ /dev/null @@ -1,32 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- 512 bytes! -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - --> -<feed xmlns="http://www.w3.org/2005/Atom"> - - <title>Example Feed</title> - <link href="http://example.org/"/> - <updated>2010-08-22T18:30:02Z</updated> - - <author> - <name>John Doe</name> - </author> - <id>urn:uuid:e2df8375-99be-4848-b05e-b9d407555267</id> - - <entry> - - <title>Item</title> - <link href="http://example.org/first"/> - <id>urn:uuid:9e0f4bed-33d3-4a9d-97ab-ecaa31b3f14a</id> - <updated>2010-08-22T18:30:02Z</updated> - - <summary>Some text.</summary> - </entry> - -</feed> diff --git a/browser/components/migration/moz.build b/browser/components/migration/moz.build index 7f633c4e9..76218104c 100644 --- a/browser/components/migration/moz.build +++ b/browser/components/migration/moz.build @@ -5,4 +5,4 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DIRS += ['public', 'src'] -TEST_DIRS += ['tests'] + diff --git a/browser/components/migration/tests/moz.build b/browser/components/migration/tests/moz.build deleted file mode 100644 index 191c90f0b..000000000 --- a/browser/components/migration/tests/moz.build +++ /dev/null @@ -1,7 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini'] diff --git a/browser/components/migration/tests/unit/head_migration.js b/browser/components/migration/tests/unit/head_migration.js deleted file mode 100644 index 2f84eac2b..000000000 --- a/browser/components/migration/tests/unit/head_migration.js +++ /dev/null @@ -1,64 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cu = Components.utils; -const Cr = Components.results; - -Cu.import("resource://gre/modules/XPCOMUtils.jsm"); -Cu.import("resource://gre/modules/Services.jsm"); - -XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils", - "resource://gre/modules/PlacesUtils.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "FileUtils", - "resource://gre/modules/FileUtils.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "MigrationUtils", - "resource:///modules/MigrationUtils.jsm"); -// Initialize profile. -let gProfD = do_get_profile(); - -// Create a fake XULAppInfo to satisfy the eventual needs of the migrators. -let (XULAppInfo = { - // nsIXUlAppInfo - get vendor() "Mozilla", - get name() "XPCShell", - get ID() "xpcshell@tests.mozilla.org", - get version() "1", - get appBuildID() "2007010101", - get platformVersion() "1.0", - get platformBuildID() "2007010101", - - // nsIXUlRuntime (partial) - get inSafeMode() false, - logConsoleErrors: true, - get OS() "XPCShell", - get XPCOMABI() "noarch-spidermonkey", - invalidateCachesOnRestart: function () {}, - - // nsIWinAppHelper - get userCanElevate() false, - - QueryInterface: function (aIID) { - let interfaces = [Ci.nsIXULAppInfo, Ci.nsIXULRuntime]; - if ("nsIWinAppHelper" in Ci) - interfaces.push(Ci.nsIWinAppHelper); - if (!interfaces.some(function (v) aIID.equals(v))) - throw Cr.NS_ERROR_NO_INTERFACE; - return this; - } -}) { - const CONTRACT_ID = "@mozilla.org/xre/app-info;1"; - const CID = Components.ID("7685dac8-3637-4660-a544-928c5ec0e714}"); - - let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); - registrar.registerFactory(CID, "XULAppInfo", CONTRACT_ID, { - createInstance: function (aOuter, aIID) { - if (aOuter != null) - throw Cr.NS_ERROR_NO_AGGREGATION; - return XULAppInfo.QueryInterface(aIID); - }, - QueryInterface: XPCOMUtils.generateQI(Ci.nsIFactory) - }); -} diff --git a/browser/components/migration/tests/unit/test_IE_bookmarks.js b/browser/components/migration/tests/unit/test_IE_bookmarks.js deleted file mode 100644 index abead5736..000000000 --- a/browser/components/migration/tests/unit/test_IE_bookmarks.js +++ /dev/null @@ -1,56 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function run_test() { - do_test_pending(); - - let migrator = MigrationUtils.getMigrator("ie"); - - // Sanity check for the source. - do_check_true(migrator.sourceExists); - - // Ensure bookmarks migration is available. - let availableSources = migrator.getMigrateData("FieldOfFlowers", false); - do_check_true((availableSources & MigrationUtils.resourceTypes.BOOKMARKS) > 0); - - // Wait for the imported bookmarks. Check that "From Internet Explorer" - // folders are created in the menu and on the toolbar. - let source = MigrationUtils.getLocalizedString("sourceNameIE"); - let label = MigrationUtils.getLocalizedString("importedBookmarksFolder", [source]); - - let expectedParents = [ PlacesUtils.bookmarksMenuFolderId, - PlacesUtils.toolbarFolderId ]; - - PlacesUtils.bookmarks.addObserver({ - onItemAdded: function onItemAdded(aItemId, aParentId, aIndex, aItemType, - aURI, aTitle) { - if (aTitle == label) { - let index = expectedParents.indexOf(aParentId); - do_check_neq(index, -1); - expectedParents.splice(index, 1); - if (expectedParents.length == 0) - PlacesUtils.bookmarks.removeObserver(this); - } - }, - onBeginUpdateBatch: function () {}, - onEndUpdateBatch: function () {}, - onItemRemoved: function () {}, - onItemChanged: function () {}, - onItemVisited: function () {}, - onItemMoved: function () {}, - }, false); - - // Wait for migration. - Services.obs.addObserver(function onMigrationEnded() { - Services.obs.removeObserver(onMigrationEnded, "Migration:Ended"); - - // Check the bookmarks have been imported to all the expected parents. - do_check_eq(expectedParents.length, 0); - - do_test_finished(); - }, "Migration:Ended", false); - - migrator.migrate(MigrationUtils.resourceTypes.BOOKMARKS, null, - "FieldOfFlowers"); -} diff --git a/browser/components/migration/tests/unit/xpcshell.ini b/browser/components/migration/tests/unit/xpcshell.ini deleted file mode 100644 index c08c2533f..000000000 --- a/browser/components/migration/tests/unit/xpcshell.ini +++ /dev/null @@ -1,7 +0,0 @@ -[DEFAULT] -head = head_migration.js -tail = -firefox-appdir = browser - -[test_IE_bookmarks.js] -skip-if = os != "win" diff --git a/browser/components/moz.build b/browser/components/moz.build index f17553cbc..9a842528b 100644 --- a/browser/components/moz.build +++ b/browser/components/moz.build @@ -23,7 +23,6 @@ PARALLEL_DIRS += [ if CONFIG['MOZ_SAFE_BROWSING']: PARALLEL_DIRS += ['safebrowsing'] -TEST_DIRS += ['test'] DIRS += ['build'] XPIDL_SOURCES += [ diff --git a/browser/components/places/moz.build b/browser/components/places/moz.build index 003d9ed15..52d271a42 100644 --- a/browser/components/places/moz.build +++ b/browser/components/places/moz.build @@ -5,7 +5,6 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DIRS += ['src'] -TEST_DIRS += ['tests'] XPIDL_FLAGS += [ '-I$(topsrcdir)/browser/components/', diff --git a/browser/components/places/tests/browser/Makefile.in b/browser/components/places/tests/browser/Makefile.in deleted file mode 100644 index 177fa0fc9..000000000 --- a/browser/components/places/tests/browser/Makefile.in +++ /dev/null @@ -1,47 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -DEPTH = @DEPTH@ -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ -relativesrcdir = @relativesrcdir@ - -include $(DEPTH)/config/autoconf.mk - -MOCHITEST_BROWSER_FILES = \ - head.js \ - browser_0_library_left_pane_migration.js \ - browser_library_left_pane_fixnames.js \ - browser_425884.js \ - browser_475045.js \ - browser_423515.js \ - browser_410196_paste_into_tags.js \ - browser_sort_in_library.js \ - browser_library_open_leak.js \ - browser_library_panel_leak.js \ - browser_library_search.js \ - browser_history_sidebar_search.js \ - browser_bookmarksProperties.js \ - $(filter disabled-for-very-frequent-oranges--bug-551540, browser_forgetthissite_single.js) \ - browser_library_left_pane_commands.js \ - browser_drag_bookmarks_on_toolbar.js \ - browser_library_middleclick.js \ - browser_library_views_liveupdate.js \ - browser_views_liveupdate.js \ - $(filter temporarily-disabled-for-breaking-the-treeview--bug-658744, browser_sidebarpanels_click.js) \ - sidebarpanels_click_test_page.html \ - browser_library_infoBox.js \ - browser_markPageAsFollowedLink.js \ - framedPage.html \ - frameLeft.html \ - frameRight.html \ - browser_toolbar_migration.js \ - browser_library_batch_delete.js \ - browser_555547.js \ - browser_416459_cut.js \ - browser_library_downloads.js \ - $(NULL) - -include $(topsrcdir)/config/rules.mk diff --git a/browser/components/places/tests/browser/browser_0_library_left_pane_migration.js b/browser/components/places/tests/browser/browser_0_library_left_pane_migration.js deleted file mode 100644 index b0be0ee12..000000000 --- a/browser/components/places/tests/browser/browser_0_library_left_pane_migration.js +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Test we correctly migrate Library left pane to the latest version. - * Note: this test MUST be the first between browser chrome tests, or results - * of next tests could be unexpected due to PlacesUIUtils getters. - */ - -const TEST_URI = "http://www.mozilla.org/"; - -function onLibraryReady(organizer) { - // Check left pane. - ok(PlacesUIUtils.leftPaneFolderId > 0, - "Left pane folder correctly created"); - var leftPaneItems = - PlacesUtils.annotations - .getItemsWithAnnotation(PlacesUIUtils.ORGANIZER_FOLDER_ANNO); - is(leftPaneItems.length, 1, - "We correctly have only 1 left pane folder"); - var leftPaneRoot = leftPaneItems[0]; - is(leftPaneRoot, PlacesUIUtils.leftPaneFolderId, - "leftPaneFolderId getter has correct value"); - // Check version has been upgraded. - var version = - PlacesUtils.annotations.getItemAnnotation(leftPaneRoot, - PlacesUIUtils.ORGANIZER_FOLDER_ANNO); - is(version, PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION, - "Left pane version has been correctly upgraded"); - - // Check left pane is populated. - organizer.PlacesOrganizer.selectLeftPaneQuery('History'); - is(organizer.PlacesOrganizer._places.selectedNode.itemId, - PlacesUIUtils.leftPaneQueries["History"], - "Library left pane is populated and working"); - - // Close Library window. - organizer.close(); - // No need to cleanup anything, we have a correct left pane now. - finish(); -} - -function test() { - waitForExplicitFinish(); - // Sanity checks. - ok(PlacesUtils, "PlacesUtils is running in chrome context"); - ok(PlacesUIUtils, "PlacesUIUtils is running in chrome context"); - ok(PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION > 0, - "Left pane version in chrome context, current version is: " + PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION ); - - // Check if we have any left pane folder already set, remove it eventually. - var leftPaneItems = PlacesUtils.annotations - .getItemsWithAnnotation(PlacesUIUtils.ORGANIZER_FOLDER_ANNO); - if (leftPaneItems.length > 0) { - // The left pane has already been created, touching it now would cause - // next tests to rely on wrong values (and possibly crash) - is(leftPaneItems.length, 1, "We correctly have only 1 left pane folder"); - // Check version. - var version = PlacesUtils.annotations.getItemAnnotation(leftPaneItems[0], - PlacesUIUtils.ORGANIZER_FOLDER_ANNO); - is(version, PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION, "Left pane version is actual"); - ok(true, "left pane has already been created, skipping test"); - finish(); - return; - } - - // Create a fake left pane folder with an old version (current version - 1). - var fakeLeftPaneRoot = - PlacesUtils.bookmarks.createFolder(PlacesUtils.placesRootId, "", - PlacesUtils.bookmarks.DEFAULT_INDEX); - PlacesUtils.annotations.setItemAnnotation(fakeLeftPaneRoot, - PlacesUIUtils.ORGANIZER_FOLDER_ANNO, - PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION - 1, - 0, - PlacesUtils.annotations.EXPIRE_NEVER); - - // Check fake left pane root has been correctly created. - var leftPaneItems = - PlacesUtils.annotations.getItemsWithAnnotation(PlacesUIUtils.ORGANIZER_FOLDER_ANNO); - is(leftPaneItems.length, 1, "We correctly have only 1 left pane folder"); - is(leftPaneItems[0], fakeLeftPaneRoot, "left pane root itemId is correct"); - - // Check version. - var version = PlacesUtils.annotations.getItemAnnotation(fakeLeftPaneRoot, - PlacesUIUtils.ORGANIZER_FOLDER_ANNO); - is(version, PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION - 1, "Left pane version correctly set"); - - // Open Library, this will upgrade our left pane version. - openLibrary(onLibraryReady); -} diff --git a/browser/components/places/tests/browser/browser_410196_paste_into_tags.js b/browser/components/places/tests/browser/browser_410196_paste_into_tags.js deleted file mode 100644 index 8688a938f..000000000 --- a/browser/components/places/tests/browser/browser_410196_paste_into_tags.js +++ /dev/null @@ -1,141 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -function add_bookmark(aURI) { - return PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, - aURI, PlacesUtils.bookmarks.DEFAULT_INDEX, - "bookmark/" + aURI.spec); -} - -Components.utils.import("resource://gre/modules/NetUtil.jsm"); - -const TEST_URL = "http://example.com/"; -const MOZURISPEC = "http://mozilla.com/"; - -let gLibrary; -let PlacesOrganizer; -let ContentTree; - -function test() { - waitForExplicitFinish(); - gLibrary = openLibrary(onLibraryReady); -} - -function onLibraryReady() { - ok(PlacesUtils, "PlacesUtils in scope"); - ok(PlacesUIUtils, "PlacesUIUtils in scope"); - - PlacesOrganizer = gLibrary.PlacesOrganizer; - ok(PlacesOrganizer, "Places organizer in scope"); - - ContentTree = gLibrary.ContentTree; - ok(ContentTree, "ContentTree is in scope"); - - tests.makeHistVisit(function() { - tests.makeTag(); - tests.focusTag(); - waitForClipboard(function(aData) !!aData, - tests.copyHistNode, - onClipboardReady, - PlacesUtils.TYPE_X_MOZ_PLACE); - }); -} - -function onClipboardReady() { - tests.focusTag(); - PlacesOrganizer._places.controller.paste(); - tests.historyNode(); - tests.checkForBookmarkInUI(); - - gLibrary.close(); - - // Remove new Places data we created. - PlacesUtils.tagging.untagURI(NetUtil.newURI(MOZURISPEC), ["foo"]); - PlacesUtils.tagging.untagURI(NetUtil.newURI(TEST_URL), ["foo"]); - let tags = PlacesUtils.tagging.getTagsForURI(NetUtil.newURI(TEST_URL)); - is(tags.length, 0, "tags are gone"); - PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId); - - waitForClearHistory(finish); -} - -let tests = { - - makeHistVisit: function(aCallback) { - // need to add a history object - let testURI1 = NetUtil.newURI(MOZURISPEC); - isnot(testURI1, null, "testURI is not null"); - addVisits( - {uri: testURI1, transition: PlacesUtils.history.TRANSITION_TYPED}, - window, - aCallback); - }, - - makeTag: function() { - // create an initial tag to work with - let bmId = add_bookmark(NetUtil.newURI(TEST_URL)); - ok(bmId > 0, "A bookmark was added"); - PlacesUtils.tagging.tagURI(NetUtil.newURI(TEST_URL), ["foo"]); - let tags = PlacesUtils.tagging.getTagsForURI(NetUtil.newURI(TEST_URL)); - is(tags[0], 'foo', "tag is foo"); - }, - - focusTag: function (){ - // focus the new tag - PlacesOrganizer.selectLeftPaneQuery("Tags"); - let tags = PlacesOrganizer._places.selectedNode; - tags.containerOpen = true; - let fooTag = tags.getChild(0); - let tagNode = fooTag; - PlacesOrganizer._places.selectNode(fooTag); - is(tagNode.title, 'foo', "tagNode title is foo"); - let ip = PlacesOrganizer._places.insertionPoint; - ok(ip.isTag, "IP is a tag"); - }, - - copyHistNode: function (){ - // focus the history object - PlacesOrganizer.selectLeftPaneQuery("History"); - let histContainer = PlacesOrganizer._places.selectedNode; - PlacesUtils.asContainer(histContainer); - histContainer.containerOpen = true; - PlacesOrganizer._places.selectNode(histContainer.getChild(0)); - let histNode = ContentTree.view.view.nodeForTreeIndex(0); - ContentTree.view.selectNode(histNode); - is(histNode.uri, MOZURISPEC, - "historyNode exists: " + histNode.uri); - // copy the history node - ContentTree.view.controller.copy(); - }, - - historyNode: function (){ - // re-focus the history again - PlacesOrganizer.selectLeftPaneQuery("History"); - let histContainer = PlacesOrganizer._places.selectedNode; - PlacesUtils.asContainer(histContainer); - histContainer.containerOpen = true; - PlacesOrganizer._places.selectNode(histContainer.getChild(0)); - let histNode = ContentTree.view.view.nodeForTreeIndex(0); - ok(histNode, "histNode exists: " + histNode.title); - // check to see if the history node is tagged! - let tags = PlacesUtils.tagging.getTagsForURI(NetUtil.newURI(MOZURISPEC)); - ok(tags.length == 1, "history node is tagged: " + tags.length); - // check if a bookmark was created - let isBookmarked = PlacesUtils.bookmarks.isBookmarked(NetUtil.newURI(MOZURISPEC)); - is(isBookmarked, true, MOZURISPEC + " is bookmarked"); - let bookmarkIds = PlacesUtils.bookmarks.getBookmarkIdsForURI( - NetUtil.newURI(histNode.uri)); - ok(bookmarkIds.length > 0, "bookmark exists for the tagged history item: " + bookmarkIds); - }, - - checkForBookmarkInUI: function(){ - // is the bookmark visible in the UI? - // get the Unsorted Bookmarks node - PlacesOrganizer.selectLeftPaneQuery("UnfiledBookmarks"); - // now we can see what is in the ContentTree tree - let unsortedNode = ContentTree.view.view.nodeForTreeIndex(1); - ok(unsortedNode, "unsortedNode is not null: " + unsortedNode.uri); - is(unsortedNode.uri, MOZURISPEC, "node uri's are the same"); - }, -}; diff --git a/browser/components/places/tests/browser/browser_416459_cut.js b/browser/components/places/tests/browser/browser_416459_cut.js deleted file mode 100644 index ec78df1b7..000000000 --- a/browser/components/places/tests/browser/browser_416459_cut.js +++ /dev/null @@ -1,72 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -const TEST_URL = "http://example.com/"; - -let gLibrary; -let gItemId; -let PlacesOrganizer; -let ContentTree; - -function test() { - waitForExplicitFinish(); - gLibrary = openLibrary(onLibraryReady); -} - -function onLibraryReady() { - PlacesOrganizer = gLibrary.PlacesOrganizer; - ContentTree = gLibrary.ContentTree; - - // Sanity checks. - ok(PlacesUtils, "PlacesUtils in scope"); - ok(PlacesUIUtils, "PlacesUIUtils in scope"); - ok(PlacesOrganizer, "PlacesOrganizer in scope"); - ok(ContentTree, "ContentTree is in scope"); - - gItemId = PlacesUtils.bookmarks.insertBookmark( - PlacesUtils.toolbarFolderId, NetUtil.newURI(TEST_URL), - PlacesUtils.bookmarks.DEFAULT_INDEX, "test" - ); - - selectBookmarkIn("BookmarksToolbar"); - - waitForClipboard(function(aData) !!aData, - cutSelection, - onClipboardReady, - PlacesUtils.TYPE_X_MOZ_PLACE); -} - -function selectBookmarkIn(aLeftPaneQuery) { - info("Selecting " + aLeftPaneQuery + " in the left pane"); - PlacesOrganizer.selectLeftPaneQuery(aLeftPaneQuery); - let rootId = PlacesUtils.getConcreteItemId(PlacesOrganizer._places.selectedNode); - is(PlacesUtils.bookmarks.getFolderIdForItem(gItemId), rootId, - "Bookmark has the right parent"); - info("Selecting the bookmark in the right pane"); - ContentTree.view.selectItems([gItemId]); - let bookmarkNode = ContentTree.view.selectedNode; - is(bookmarkNode.uri, TEST_URL, "Found the expected bookmark"); -} - -function cutSelection() { - info("Cutting selection"); - ContentTree.view.controller.cut(); -} - -function pasteClipboard(aLeftPaneQuery) { - info("Selecting " + aLeftPaneQuery + " in the left pane"); - PlacesOrganizer.selectLeftPaneQuery(aLeftPaneQuery); - info("Pasting clipboard"); - ContentTree.view.controller.paste(); -} - -function onClipboardReady() { - pasteClipboard("UnfiledBookmarks"); - selectBookmarkIn("UnfiledBookmarks"); - - // Cleanup. - gLibrary.close(); - PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId); - finish(); -} diff --git a/browser/components/places/tests/browser/browser_423515.js b/browser/components/places/tests/browser/browser_423515.js deleted file mode 100644 index 6be928881..000000000 --- a/browser/components/places/tests/browser/browser_423515.js +++ /dev/null @@ -1,220 +0,0 @@ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - // sanity check - ok(PlacesUtils, "checking PlacesUtils, running in chrome context?"); - ok(PlacesUIUtils, "checking PlacesUIUtils, running in chrome context?"); - ok(PlacesControllerDragHelper, "checking PlacesControllerDragHelper, running in chrome context?"); - - const IDX = PlacesUtils.bookmarks.DEFAULT_INDEX; - - // setup - var rootId = PlacesUtils.bookmarks.createFolder(PlacesUtils.toolbarFolderId, "", IDX); - var rootNode = PlacesUtils.getFolderContents(rootId, false, true).root; - is(rootNode.childCount, 0, "confirm test root is empty"); - - var tests = []; - - // add a regular folder, should be moveable - tests.push({ - populate: function() { - this.id = - PlacesUtils.bookmarks.createFolder(rootId, "", IDX); - }, - validate: function() { - is(rootNode.childCount, 1, - "populate added data to the test root"); - is(PlacesControllerDragHelper.canMoveContainer(this.id), - true, "can move regular folder id"); - is(PlacesControllerDragHelper.canMoveNode(rootNode.getChild(0)), - true, "can move regular folder node"); - } - }); - - // add a regular folder shortcut, should be moveable - tests.push({ - populate: function() { - this.folderId = - PlacesUtils.bookmarks.createFolder(rootId, "foo", IDX); - this.shortcutId = - PlacesUtils.bookmarks.insertBookmark(rootId, makeURI("place:folder="+this.folderId), IDX, "bar"); - }, - validate: function() { - is(rootNode.childCount, 2, - "populated data to the test root"); - - var folderNode = rootNode.getChild(0); - is(folderNode.type, 6, "node is folder"); - is(this.folderId, folderNode.itemId, "folder id and folder node item id match"); - - var shortcutNode = rootNode.getChild(1); - is(shortcutNode.type, 9, "node is folder shortcut"); - is(this.shortcutId, shortcutNode.itemId, "shortcut id and shortcut node item id match"); - - var concreteId = PlacesUtils.getConcreteItemId(shortcutNode); - is(concreteId, folderNode.itemId, "shortcut node id and concrete id match"); - - is(PlacesControllerDragHelper.canMoveContainer(this.shortcutId), - true, "can move folder shortcut id"); - - is(PlacesControllerDragHelper.canMoveNode(shortcutNode), - true, "can move folder shortcut node"); - } - }); - - // add a regular query, should be moveable - tests.push({ - populate: function() { - this.bookmarkId = - PlacesUtils.bookmarks.insertBookmark(rootId, makeURI("http://foo.com"), IDX, "foo"); - this.queryId = - PlacesUtils.bookmarks.insertBookmark(rootId, makeURI("place:terms=foo"), IDX, "bar"); - }, - validate: function() { - is(rootNode.childCount, 2, - "populated data to the test root"); - - var bmNode = rootNode.getChild(0); - is(bmNode.itemId, this.bookmarkId, "bookmark id and bookmark node item id match"); - - var queryNode = rootNode.getChild(1); - is(queryNode.itemId, this.queryId, "query id and query node item id match"); - - is(PlacesControllerDragHelper.canMoveContainer(this.queryId), - true, "can move query id"); - - is(PlacesControllerDragHelper.canMoveNode(queryNode), - true, "can move query node"); - } - }); - - // test that special folders cannot be moved - // test that special folders shortcuts can be moved - tests.push({ - folders: [PlacesUtils.bookmarksMenuFolderId, - PlacesUtils.tagsFolderId, PlacesUtils.unfiledBookmarksFolderId, - PlacesUtils.toolbarFolderId], - shortcuts: {}, - populate: function() { - for (var i = 0; i < this.folders.length; i++) { - var id = this.folders[i]; - this.shortcuts[id] = - PlacesUtils.bookmarks.insertBookmark(rootId, makeURI("place:folder=" + id), IDX, ""); - } - }, - validate: function() { - // test toolbar shortcut node - is(rootNode.childCount, this.folders.length, - "populated data to the test root"); - - function getRootChildNode(aId) { - var node = PlacesUtils.getFolderContents(PlacesUtils.placesRootId, false, true).root; - for (var i = 0; i < node.childCount; i++) { - var child = node.getChild(i); - if (child.itemId == aId) { - node.containerOpen = false; - return child; - } - } - node.containerOpen = false; - ok(false, "Unable to find child node"); - return null; - } - - for (var i = 0; i < this.folders.length; i++) { - var id = this.folders[i]; - - is(PlacesControllerDragHelper.canMoveContainer(id), - false, "shouldn't be able to move special folder id"); - - var node = getRootChildNode(id); - isnot(node, null, "Node found"); - is(PlacesControllerDragHelper.canMoveNode(node), - false, "shouldn't be able to move special folder node"); - - var shortcutId = this.shortcuts[id]; - var shortcutNode = rootNode.getChild(i); - - is(shortcutNode.itemId, shortcutId, "shortcut id and shortcut node item id match"); - - dump("can move shortcut id?\n"); - is(PlacesControllerDragHelper.canMoveContainer(shortcutId), - true, "should be able to move special folder shortcut id"); - - dump("can move shortcut node?\n"); - is(PlacesControllerDragHelper.canMoveNode(shortcutNode), - true, "should be able to move special folder shortcut node"); - } - } - }); - - // test that a tag container cannot be moved - tests.push({ - populate: function() { - // tag a uri - this.uri = makeURI("http://foo.com"); - PlacesUtils.tagging.tagURI(this.uri, ["bar"]); - }, - validate: function() { - // get tag root - var query = PlacesUtils.history.getNewQuery(); - var options = PlacesUtils.history.getNewQueryOptions(); - options.resultType = Ci.nsINavHistoryQueryOptions.RESULTS_AS_TAG_QUERY; - var tagsNode = PlacesUtils.history.executeQuery(query, options).root; - - tagsNode.containerOpen = true; - is(tagsNode.childCount, 1, "has new tag"); - - var tagNode = tagsNode.getChild(0); - - is(PlacesControllerDragHelper.canMoveNode(tagNode), - false, "should not be able to move tag container node"); - - tagsNode.containerOpen = false; - } - }); - - // test that any child of a read-only node cannot be moved - tests.push({ - populate: function() { - this.id = - PlacesUtils.bookmarks.createFolder(rootId, "foo", IDX); - PlacesUtils.bookmarks.createFolder(this.id, "bar", IDX); - PlacesUtils.bookmarks.setFolderReadonly(this.id, true); - }, - validate: function() { - is(rootNode.childCount, 1, - "populate added data to the test root"); - var readOnlyFolder = rootNode.getChild(0); - - // test that we can move the read-only folder - is(PlacesControllerDragHelper.canMoveContainer(this.id), - true, "can move read-only folder id"); - is(PlacesControllerDragHelper.canMoveNode(readOnlyFolder), - true, "can move read-only folder node"); - - // test that we cannot move the child of a read-only folder - readOnlyFolder.QueryInterface(Ci.nsINavHistoryContainerResultNode); - readOnlyFolder.containerOpen = true; - var childFolder = readOnlyFolder.getChild(0); - - is(PlacesControllerDragHelper.canMoveContainer(childFolder.itemId), - false, "cannot move a child of a read-only folder"); - is(PlacesControllerDragHelper.canMoveNode(childFolder), - false, "cannot move a child node of a read-only folder node"); - readOnlyFolder.containerOpen = false; - } - }); - - tests.forEach(function(aTest) { - PlacesUtils.bookmarks.removeFolderChildren(rootId); - aTest.populate(); - aTest.validate(); - }); - - rootNode.containerOpen = false; - PlacesUtils.bookmarks.removeItem(rootId); -} diff --git a/browser/components/places/tests/browser/browser_425884.js b/browser/components/places/tests/browser/browser_425884.js deleted file mode 100644 index 4140ac023..000000000 --- a/browser/components/places/tests/browser/browser_425884.js +++ /dev/null @@ -1,103 +0,0 @@ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - // sanity check - ok(PlacesUtils, "checking PlacesUtils, running in chrome context?"); - ok(PlacesUIUtils, "checking PlacesUIUtils, running in chrome context?"); - - /* - Deep copy of bookmark data, using the front-end codepath: - - - create test folder A - - add a subfolder to folder A, and add items to it - - validate folder A (sanity check) - - copy folder A, creating new folder B, using the front-end path - - validate folder B - - undo copy transaction - - validate folder B (empty) - - redo copy transaction - - validate folder B's contents - - */ - - var toolbarId = PlacesUtils.toolbarFolderId; - var toolbarNode = PlacesUtils.getFolderContents(toolbarId).root; - - var oldCount = toolbarNode.childCount; - var testRootId = PlacesUtils.bookmarks.createFolder(toolbarId, "test root", -1); - is(toolbarNode.childCount, oldCount+1, "confirm test root node is a container, and is empty"); - var testRootNode = toolbarNode.getChild(toolbarNode.childCount-1); - testRootNode.QueryInterface(Ci.nsINavHistoryContainerResultNode); - testRootNode.containerOpen = true; - is(testRootNode.childCount, 0, "confirm test root node is a container, and is empty"); - - // create folder A, fill it, validate its contents - var folderAId = PlacesUtils.bookmarks.createFolder(testRootId, "A", -1); - populate(folderAId); - var folderANode = PlacesUtils.getFolderContents(folderAId).root; - validate(folderANode); - is(testRootNode.childCount, 1, "create test folder"); - - // copy it, using the front-end helper functions - var serializedNode = PlacesUtils.wrapNode(folderANode, PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER); - var rawNode = PlacesUtils.unwrapNodes(serializedNode, PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER).shift(); - // confirm serialization - ok(rawNode.type, "confirm json node"); - folderANode.containerOpen = false; - - var transaction = PlacesUIUtils.makeTransaction(rawNode, - PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER, - testRootId, - -1, - true); - ok(transaction, "create transaction"); - PlacesUtils.transactionManager.doTransaction(transaction); - // confirm copy - is(testRootNode.childCount, 2, "create test folder via copy"); - - // validate the copy - var folderBNode = testRootNode.getChild(1); - validate(folderBNode); - - // undo the transaction, confirm the removal - PlacesUtils.transactionManager.undoTransaction(); - is(testRootNode.childCount, 1, "confirm undo removed the copied folder"); - - // redo the transaction - PlacesUtils.transactionManager.redoTransaction(); - is(testRootNode.childCount, 2, "confirm redo re-copied the folder"); - folderBNode = testRootNode.getChild(1); - validate(folderBNode); - - // Close containers, cleaning up their observers. - testRootNode.containerOpen = false; - toolbarNode.containerOpen = false; - - // clean up - PlacesUtils.transactionManager.undoTransaction(); - PlacesUtils.bookmarks.removeItem(folderAId); -} - -function populate(aFolderId) { - var folderId = PlacesUtils.bookmarks.createFolder(aFolderId, "test folder", -1); - PlacesUtils.bookmarks.insertBookmark(folderId, PlacesUtils._uri("http://foo"), -1, "test bookmark"); - PlacesUtils.bookmarks.insertSeparator(folderId, -1); -} - -function validate(aNode) { - PlacesUtils.asContainer(aNode); - aNode.containerOpen = true; - is(aNode.childCount, 1, "confirm child count match"); - var folderNode = aNode.getChild(0); - is(folderNode.title, "test folder", "confirm folder title"); - PlacesUtils.asContainer(folderNode); - folderNode.containerOpen = true; - is(folderNode.childCount, 2, "confirm child count match"); - var bookmarkNode = folderNode.getChild(0); - var separatorNode = folderNode.getChild(1); - folderNode.containerOpen = false; - aNode.containerOpen = false; -} diff --git a/browser/components/places/tests/browser/browser_475045.js b/browser/components/places/tests/browser/browser_475045.js deleted file mode 100644 index e8ca50278..000000000 --- a/browser/components/places/tests/browser/browser_475045.js +++ /dev/null @@ -1,65 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ -// Instead of loading ChromeUtils.js into the test scope in browser-test.js for all tests, -// we only need ChromeUtils.js for a few files which is why we are using loadSubScript. -var ChromeUtils = {}; -this._scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"]. - getService(Ci.mozIJSSubScriptLoader); -this._scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js", ChromeUtils); - -function test() { - // Make sure the bookmarks bar is visible and restore its state on cleanup. - let toolbar = document.getElementById("PersonalToolbar"); - ok(toolbar, "PersonalToolbar should not be null"); - - if (toolbar.collapsed) { - setToolbarVisibility(toolbar, true); - registerCleanupFunction(function() { - setToolbarVisibility(toolbar, false); - }); - } - - // Setup the node we will use to be dropped. The actual node used does not - // matter because we will set its data, effect, and mimeType manually. - let placesItems = document.getElementById("PlacesToolbarItems"); - ok(placesItems, "PlacesToolbarItems should not be null"); - ok(placesItems.localName == "scrollbox", "PlacesToolbarItems should not be null"); - ok(placesItems.childNodes[0], "PlacesToolbarItems must have at least one child"); - - /** - * Simulates a drop of a URI onto the bookmarks bar. - * - * @param aEffect - * The effect to use for the drop operation: move, copy, or link. - * @param aMimeType - * The mime type to use for the drop operation. - */ - let simulateDragDrop = function(aEffect, aMimeType) { - const uriSpec = "http://www.mozilla.org/D1995729-A152-4e30-8329-469B01F30AA7"; - let uri = makeURI(uriSpec); - ChromeUtils.synthesizeDrop(placesItems.childNodes[0], - placesItems, - [[{type: aMimeType, - data: uriSpec}]], - aEffect, window); - - // Verify that the drop produces exactly one bookmark. - let bookmarkIds = PlacesUtils.bookmarks - .getBookmarkIdsForURI(uri); - ok(bookmarkIds.length == 1, "There should be exactly one bookmark"); - - PlacesUtils.bookmarks.removeItem(bookmarkIds[0]); - - // Verify that we removed the bookmark successfully. - ok(!PlacesUtils.bookmarks.isBookmarked(uri), "URI should be removed"); - } - - // Simulate a bookmark drop for all of the mime types and effects. - let mimeTypes = ["text/plain", "text/unicode", "text/x-moz-url"]; - let effects = ["move", "copy", "link"]; - effects.forEach(function (effect) { - mimeTypes.forEach(function (mimeType) { - simulateDragDrop(effect, mimeType); - }); - }); -} diff --git a/browser/components/places/tests/browser/browser_555547.js b/browser/components/places/tests/browser/browser_555547.js deleted file mode 100644 index 42deecbb7..000000000 --- a/browser/components/places/tests/browser/browser_555547.js +++ /dev/null @@ -1,59 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -function test() { - waitForExplicitFinish(); - - let sidebarBox = document.getElementById("sidebar-box"); - is(sidebarBox.hidden, true, "The sidebar should be hidden"); - - // Uncollapse the personal toolbar if needed. - let toolbar = document.getElementById("PersonalToolbar"); - let wasCollapsed = toolbar.collapsed; - if (wasCollapsed) - setToolbarVisibility(toolbar, true); - - let sidebar = document.getElementById("sidebar"); - sidebar.addEventListener("load", function() { - sidebar.removeEventListener("load", arguments.callee, true); - let tree = sidebar.contentDocument.getElementById("bookmarks-view"); - - // The Places view is build on load, so we enqueue our test. - executeSoon(function() { - // Focus the tree and check if its controller is returned. - tree.focus(); - - let controller = doGetPlacesControllerForCommand("placesCmd_copy"); - let treeController = tree.controllers - .getControllerForCommand("placesCmd_copy"); - ok(controller == treeController, "tree controller was returned"); - - // Open the context menu for a toolbar item, and check if the toolbar's - // controller is returned. - let toolbarItems = document.getElementById("PlacesToolbarItems"); - EventUtils.synthesizeMouse(toolbarItems.childNodes[0], - 4, 4, { type: "contextmenu", button: 2 }, - window); - controller = doGetPlacesControllerForCommand("placesCmd_copy"); - let toolbarController = document.getElementById("PlacesToolbar") - .controllers - .getControllerForCommand("placesCmd_copy"); - ok(controller == toolbarController, "the toolbar controller was returned"); - - document.getElementById("placesContext").hidePopup(); - - // Now that the context menu is closed, try to get the tree controller again. - tree.focus(); - controller = doGetPlacesControllerForCommand("placesCmd_copy"); - ok(controller == treeController, "tree controller was returned"); - - toggleSidebar(); - if (wasCollapsed) - setToolbarVisibility(toolbar, false); - - finish(); - }); - }, true); - toggleSidebar("viewBookmarksSidebar", true); -} diff --git a/browser/components/places/tests/browser/browser_bookmarksProperties.js b/browser/components/places/tests/browser/browser_bookmarksProperties.js deleted file mode 100644 index 46bf5272f..000000000 --- a/browser/components/places/tests/browser/browser_bookmarksProperties.js +++ /dev/null @@ -1,601 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Tests the bookmarks Properties dialog. - */ - -// DOM ids of Places sidebar trees. -const SIDEBAR_HISTORY_TREE_ID = "historyTree"; -const SIDEBAR_BOOKMARKS_TREE_ID = "bookmarks-view"; - -const SIDEBAR_HISTORY_ID = "viewHistorySidebar"; -const SIDEBAR_BOOKMARKS_ID = "viewBookmarksSidebar"; - -// For history sidebar. -const SIDEBAR_HISTORY_BYLASTVISITED_VIEW = "bylastvisited"; -const SIDEBAR_HISTORY_BYMOSTVISITED_VIEW = "byvisited"; -const SIDEBAR_HISTORY_BYDATE_VIEW = "byday"; -const SIDEBAR_HISTORY_BYSITE_VIEW = "bysite"; -const SIDEBAR_HISTORY_BYDATEANDSITE_VIEW = "bydateandsite"; - -// Action to execute on the current node. -const ACTION_EDIT = 0; -const ACTION_ADD = 1; - -// If action is ACTION_ADD, set type to one of those, to define what do you -// want to create. -const TYPE_FOLDER = 0; -const TYPE_BOOKMARK = 1; - -const TEST_URL = "http://www.example.com/"; - -const DIALOG_URL = "chrome://browser/content/places/bookmarkProperties.xul"; -const DIALOG_URL_MINIMAL_UI = "chrome://browser/content/places/bookmarkProperties2.xul"; - -var wm = Cc["@mozilla.org/appshell/window-mediator;1"]. - getService(Ci.nsIWindowMediator); -var win = wm.getMostRecentWindow("navigator:browser"); -var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"]. - getService(Ci.nsIWindowWatcher); - -function add_bookmark(aURI) { - var bId = PlacesUtils.bookmarks - .insertBookmark(PlacesUtils.unfiledBookmarksFolderId, - aURI, - PlacesUtils.bookmarks.DEFAULT_INDEX, - "bookmark/" + aURI.spec); - return bId; -} - -// Each test is an obj w/ a desc property and run method. -var gTests = []; -var gCurrentTest = null; - -//------------------------------------------------------------------------------ -// TEST SKELETON: use this template to add new tests. -/* -gTests.push({ - desc: "Bug Description", - sidebar: SIDEBAR_BOOKMARKS_ID, // See SIDEBAR_ constants above. - action: ACTION_EDIT, // See ACTION_ constants above. - itemType: null, // See TYPE_ constants above, required for ACTION_ADD, only for Bookmarks sidebar. - historyView: SIDEBAR_HISTORY_BYLASTVISITED_VIEW, // See constants above, only for History sidebar. - window: null, // Will contain handle of dialog window - - setup: function(aCallback) { - // Setup everything needed for this test, runs before everything else. - aCallback(); - }, - - selectNode: function(tree) { - // Select the node to edit or to add to, runs when sidebar tree is visible. - }, - - run: function() { - // Actual test, runs when dialog is open. - }, - - finish: function() { - // Close window, toggle sidebar and goto next test. - this.window.document.documentElement.cancelDialog(); - toggleSidebar(this.sidebar, false); - runNextTest(); - }, - - cleanup: function() { - // Undo everything added during setup, runs after dialog has been closed. - } -}); -*/ - -//------------------------------------------------------------------------------ -// Bug 479348 - Properties on a root should be read-only - -gTests.push({ - desc: "Bug 479348 - Properties on a root should be read-only", - sidebar: SIDEBAR_BOOKMARKS_ID, - action: ACTION_EDIT, - itemType: null, - window: null, - - setup: function(aCallback) { - // Nothing to do. - aCallback(); - }, - - selectNode: function(tree) { - // Select Unfiled Bookmarks root. - var itemId = PlacesUIUtils.leftPaneQueries["UnfiledBookmarks"]; - tree.selectItems([itemId]); - this.selectedNode = tree.selectedNode; - }, - - run: function() { - // Check that the dialog is read-only. - ok(this.window.BookmarkPropertiesPanel._readOnly, "Dialog is read-only"); - - // Check that accept button is disabled - var acceptButton = this.window.document.documentElement.getButton("accept"); - ok(acceptButton.disabled, "Accept button is disabled"); - - // Check that name picker is read only - var namepicker = this.window.document.getElementById("editBMPanel_namePicker"); - ok(namepicker.readOnly, "Name field is disabled"); - is(namepicker.value, - PlacesUtils.bookmarks.getItemTitle(PlacesUtils.unfiledBookmarksFolderId), - "Node title is correct"); - // Blur the field and ensure root's name has not been changed. - this.window.gEditItemOverlay.onNamePickerChange(); - is(namepicker.value, - PlacesUtils.bookmarks.getItemTitle(PlacesUtils.unfiledBookmarksFolderId), - "Root title is correct"); - // Check the shortcut's title. - is(PlacesUtils.bookmarks.getItemTitle(this.selectedNode.itemId), null, - "Shortcut title is null"); - this.finish(); - }, - - finish: function() { - this.window.document.documentElement.cancelDialog(); - toggleSidebar(this.sidebar, false); - runNextTest(); - }, - - cleanup: function() { - // Nothing to do. - } -}); - -//------------------------------------------------------------------------------ -// Bug 462662 - Pressing Enter to select tag from autocomplete closes bookmarks properties dialog - -gTests.push({ - desc: "Bug 462662 - Pressing Enter to select tag from autocomplete closes bookmarks properties dialog", - sidebar: SIDEBAR_BOOKMARKS_ID, - action: ACTION_EDIT, - itemType: null, - window: null, - _itemId: null, - _cleanShutdown: false, - - setup: function(aCallback) { - // Add a bookmark in unsorted bookmarks folder. - this._itemId = add_bookmark(PlacesUtils._uri(TEST_URL)); - ok(this._itemId > 0, "Correctly added a bookmark"); - // Add a tag to this bookmark. - PlacesUtils.tagging.tagURI(PlacesUtils._uri(TEST_URL), - ["testTag"]); - var tags = PlacesUtils.tagging.getTagsForURI(PlacesUtils._uri(TEST_URL)); - is(tags[0], "testTag", "Correctly added a tag"); - aCallback(); - }, - - selectNode: function(tree) { - tree.selectItems([this._itemId]); - is(tree.selectedNode.itemId, this._itemId, "Bookmark has been selected"); - }, - - run: function() { - // open tags autocomplete and press enter - var tagsField = this.window.document.getElementById("editBMPanel_tagsField"); - var self = this; - - this.window.addEventListener("unload", function(event) { - self.window.removeEventListener("unload", arguments.callee, true); - tagsField.popup.removeEventListener("popuphidden", popupListener, true); - ok(self._cleanShutdown, "Dialog window should not be closed by pressing Enter on the autocomplete popup"); - executeSoon(function () { - self.finish(); - }); - }, true); - - var popupListener = { - handleEvent: function(aEvent) { - switch (aEvent.type) { - case "popuphidden": - // Everything worked fine, we can stop observing the window. - self._cleanShutdown = true; - self.window.document.documentElement.cancelDialog(); - break; - case "popupshown": - tagsField.popup.removeEventListener("popupshown", this, true); - // In case this test fails the window will close, the test will fail - // since we didn't set _cleanShutdown. - var tree = tagsField.popup.tree; - // Focus and select first result. - isnot(tree, null, "Autocomplete results tree exists"); - is(tree.view.rowCount, 1, "We have 1 autocomplete result"); - tagsField.popup.selectedIndex = 0; - is(tree.view.selection.count, 1, - "We have selected a tag from the autocomplete popup"); - info("About to focus the autocomplete results tree"); - tree.focus(); - EventUtils.synthesizeKey("VK_RETURN", {}, self.window); - break; - default: - ok(false, "unknown event: " + aEvent.type); - return; - } - } - }; - tagsField.popup.addEventListener("popupshown", popupListener, true); - tagsField.popup.addEventListener("popuphidden", popupListener, true); - - // Open tags autocomplete popup. - info("About to focus the tagsField"); - tagsField.focus(); - tagsField.value = ""; - EventUtils.synthesizeKey("t", {}, this.window); - }, - - finish: function() { - toggleSidebar(this.sidebar, false); - runNextTest(); - }, - - cleanup: function() { - // Check tags have not changed. - var tags = PlacesUtils.tagging.getTagsForURI(PlacesUtils._uri(TEST_URL)); - is(tags[0], "testTag", "Tag on node has not changed"); - - // Cleanup. - PlacesUtils.tagging.untagURI(PlacesUtils._uri(TEST_URL), ["testTag"]); - PlacesUtils.bookmarks.removeItem(this._itemId); - } -}); - -//------------------------------------------------------------------------------ -// Bug 475529 - Add button in new folder dialog not default anymore - -gTests.push({ - desc: "Bug 475529 - Add button in new folder dialog not default anymore", - sidebar: SIDEBAR_BOOKMARKS_ID, - action: ACTION_ADD, - itemType: TYPE_FOLDER, - window: null, - _itemId: null, - - setup: function(aCallback) { - // Nothing to do. - aCallback(); - }, - - selectNode: function(tree) { - // Select Unfiled Bookmarks root. - var itemId = PlacesUIUtils.leftPaneQueries["UnfiledBookmarks"]; - tree.selectItems([itemId]); - this.selectedNode = tree.selectedNode; - }, - - run: function() { - this._itemId = this.window.gEditItemOverlay._itemId; - // Change folder name - var namePicker = this.window.document.getElementById("editBMPanel_namePicker"); - var self = this; - - this.window.addEventListener("unload", function(event) { - self.window.removeEventListener("unload", arguments.callee, false); - executeSoon(function () { - self.finish(); - }); - }, false); - - namePicker.value = "n"; - info("About to focus the namePicker field"); - namePicker.focus(); - EventUtils.synthesizeKey("VK_RETURN", {}, this.window); - }, - - finish: function() { - // Window is already closed. - toggleSidebar(this.sidebar, false); - runNextTest(); - }, - - cleanup: function() { - // Check that folder name has been changed. - is(PlacesUtils.bookmarks.getItemTitle(this._itemId), "n", - "Folder name has been edited"); - - // Cleanup. - PlacesUtils.bookmarks.removeItem(this._itemId); - } -}); - -//------------------------------------------------------------------------------ -// Bug 476020 - Pressing Esc while having the tag autocomplete open closes the bookmarks panel - -gTests.push({ - desc: "Bug 476020 - Pressing Esc while having the tag autocomplete open closes the bookmarks panel", - sidebar: SIDEBAR_BOOKMARKS_ID, - action: ACTION_EDIT, - itemType: null, - window: null, - _itemId: null, - _cleanShutdown: false, - - setup: function(aCallback) { - // Add a bookmark in unsorted bookmarks folder. - this._itemId = add_bookmark(PlacesUtils._uri(TEST_URL)); - ok(this._itemId > 0, "Correctly added a bookmark"); - // Add a tag to this bookmark. - PlacesUtils.tagging.tagURI(PlacesUtils._uri(TEST_URL), - ["testTag"]); - var tags = PlacesUtils.tagging.getTagsForURI(PlacesUtils._uri(TEST_URL)); - is(tags[0], "testTag", "Correctly added a tag"); - aCallback(); - }, - - selectNode: function(tree) { - tree.selectItems([this._itemId]); - is(tree.selectedNode.itemId, this._itemId, "Bookmark has been selected"); - }, - - run: function() { - // open tags autocomplete and press enter - var tagsField = this.window.document.getElementById("editBMPanel_tagsField"); - var self = this; - - this.window.addEventListener("unload", function(event) { - self.window.removeEventListener("unload", arguments.callee, true); - tagsField.popup.removeEventListener("popuphidden", popupListener, true); - ok(self._cleanShutdown, "Dialog window should not be closed by pressing Escape on the autocomplete popup"); - executeSoon(function () { - self.finish(); - }); - }, true); - - var popupListener = { - handleEvent: function(aEvent) { - switch (aEvent.type) { - case "popuphidden": - // Everything worked fine. - self._cleanShutdown = true; - self.window.document.documentElement.cancelDialog(); - break; - case "popupshown": - tagsField.popup.removeEventListener("popupshown", this, true); - // In case this test fails the window will close, the test will fail - // since we didn't set _cleanShutdown. - var tree = tagsField.popup.tree; - // Focus and select first result. - isnot(tree, null, "Autocomplete results tree exists"); - is(tree.view.rowCount, 1, "We have 1 autocomplete result"); - tagsField.popup.selectedIndex = 0; - is(tree.view.selection.count, 1, - "We have selected a tag from the autocomplete popup"); - info("About to focus the autocomplete results tree"); - tree.focus(); - EventUtils.synthesizeKey("VK_ESCAPE", {}, self.window); - break; - default: - ok(false, "unknown event: " + aEvent.type); - return; - } - } - }; - tagsField.popup.addEventListener("popupshown", popupListener, true); - tagsField.popup.addEventListener("popuphidden", popupListener, true); - - // Open tags autocomplete popup. - info("About to focus the tagsField"); - tagsField.focus(); - tagsField.value = ""; - EventUtils.synthesizeKey("t", {}, this.window); - }, - - finish: function() { - toggleSidebar(this.sidebar, false); - runNextTest(); - }, - - cleanup: function() { - // Check tags have not changed. - var tags = PlacesUtils.tagging.getTagsForURI(PlacesUtils._uri(TEST_URL)); - is(tags[0], "testTag", "Tag on node has not changed"); - - // Cleanup. - PlacesUtils.tagging.untagURI(PlacesUtils._uri(TEST_URL), - ["testTag"]); - PlacesUtils.bookmarks.removeItem(this._itemId); - } -}); - -//------------------------------------------------------------------------------ -// Bug 491269 - Test that editing folder name in bookmarks properties dialog does not accept the dialog - -gTests.push({ - desc: " Bug 491269 - Test that editing folder name in bookmarks properties dialog does not accept the dialog", - sidebar: SIDEBAR_HISTORY_ID, - action: ACTION_ADD, - historyView: SIDEBAR_HISTORY_BYLASTVISITED_VIEW, - window: null, - - setup: function(aCallback) { - // Add a visit. - addVisits( - {uri: PlacesUtils._uri(TEST_URL), - transition: PlacesUtils.history.TRANSITION_TYPED}, - window, - aCallback); - }, - - selectNode: function(tree) { - var visitNode = tree.view.nodeForTreeIndex(0); - tree.selectNode(visitNode); - is(tree.selectedNode.uri, TEST_URL, "The correct visit has been selected"); - is(tree.selectedNode.itemId, -1, "The selected node is not bookmarked"); - }, - - run: function() { - // Open folder selector. - var foldersExpander = this.window.document.getElementById("editBMPanel_foldersExpander"); - var folderTree = this.window.document.getElementById("editBMPanel_folderTree"); - var self = this; - - this.window.addEventListener("unload", function(event) { - self.window.removeEventListener("unload", arguments.callee, true); - ok(self._cleanShutdown, "Dialog window should not be closed by pressing ESC in folder name textbox"); - executeSoon(function () { - self.finish(); - }); - }, true); - - folderTree.addEventListener("DOMAttrModified", function onDOMAttrModified(event) { - if (event.attrName != "place") - return; - folderTree.removeEventListener("DOMAttrModified", arguments.callee, false); - executeSoon(function () { - // Create a new folder. - var newFolderButton = self.window.document.getElementById("editBMPanel_newFolderButton"); - newFolderButton.doCommand(); - ok(folderTree.hasAttribute("editing"), - "We are editing new folder name in folder tree"); - - // Press Escape to discard editing new folder name. - EventUtils.synthesizeKey("VK_ESCAPE", {}, self.window); - ok(!folderTree.hasAttribute("editing"), - "We have finished editing folder name in folder tree"); - self._cleanShutdown = true; - self.window.document.documentElement.cancelDialog(); - }); - }, false); - foldersExpander.doCommand(); - }, - - finish: function() { - toggleSidebar(this.sidebar, false); - runNextTest(); - }, - - cleanup: function() { - var bh = PlacesUtils.history.QueryInterface(Ci.nsIBrowserHistory); - bh.removeAllPages(); - } -}); - -//------------------------------------------------------------------------------ - -function test() { - waitForExplicitFinish(); - // This test can take some time, if we timeout too early it could run - // in the middle of other tests, or hang them. - requestLongerTimeout(2); - - // Sanity checks. - ok(PlacesUtils, "PlacesUtils in context"); - ok(PlacesUIUtils, "PlacesUIUtils in context"); - - // kick off tests - runNextTest(); -} - -function runNextTest() { - // Cleanup from previous test. - if (gCurrentTest) { - gCurrentTest.cleanup(); - info("End of test: " + gCurrentTest.desc); - gCurrentTest = null; - waitForAsyncUpdates(runNextTest); - return; - } - - if (gTests.length > 0) { - // Goto next tests. - gCurrentTest = gTests.shift(); - info("Start of test: " + gCurrentTest.desc); - gCurrentTest.setup(function() { - execute_test_in_sidebar(); - }); - } - else { - // Finished all tests. - finish(); - } -} - -/** - * Global functions to run a test in Properties dialog context. - */ - -function execute_test_in_sidebar() { - var sidebar = document.getElementById("sidebar"); - sidebar.addEventListener("load", function() { - sidebar.removeEventListener("load", arguments.callee, true); - // Need to executeSoon since the tree is initialized on sidebar load. - executeSoon(open_properties_dialog); - }, true); - toggleSidebar(gCurrentTest.sidebar, true); -} - -function open_properties_dialog() { - var sidebar = document.getElementById("sidebar"); - - // If this is history sidebar, set the required view. - if (gCurrentTest.sidebar == SIDEBAR_HISTORY_ID) - sidebar.contentDocument.getElementById(gCurrentTest.historyView).doCommand(); - - // Get sidebar's Places tree. - var sidebarTreeID = gCurrentTest.sidebar == SIDEBAR_BOOKMARKS_ID ? - SIDEBAR_BOOKMARKS_TREE_ID : - SIDEBAR_HISTORY_TREE_ID; - var tree = sidebar.contentDocument.getElementById(sidebarTreeID); - ok(tree, "Sidebar tree has been loaded"); - - // Ask current test to select the node to edit. - gCurrentTest.selectNode(tree); - ok(tree.selectedNode, - "We have a places node selected: " + tree.selectedNode.title); - - // Wait for the Properties dialog. - function windowObserver(aSubject, aTopic, aData) { - if (aTopic != "domwindowopened") - return; - ww.unregisterNotification(windowObserver); - var win = aSubject.QueryInterface(Ci.nsIDOMWindow); - win.addEventListener("focus", function (event) { - win.removeEventListener("focus", arguments.callee, false); - // Windows has been loaded, execute our test now. - executeSoon(function () { - // Ensure overlay is loaded - ok(win.gEditItemOverlay._initialized, "EditItemOverlay is initialized"); - gCurrentTest.window = win; - try { - gCurrentTest.run(); - } catch (ex) { - ok(false, "An error occured during test run: " + ex.message); - } - }); - }, false); - } - ww.registerNotification(windowObserver); - - var command = null; - switch (gCurrentTest.action) { - case ACTION_EDIT: - command = "placesCmd_show:info"; - break; - case ACTION_ADD: - if (gCurrentTest.sidebar == SIDEBAR_BOOKMARKS_ID) { - if (gCurrentTest.itemType == TYPE_FOLDER) - command = "placesCmd_new:folder"; - else if (gCurrentTest.itemType == TYPE_BOOKMARK) - command = "placesCmd_new:bookmark"; - else - ok(false, "You didn't set a valid itemType for adding an item"); - } - else - command = "placesCmd_createBookmark"; - break; - default: - ok(false, "You didn't set a valid action for this test"); - } - // Ensure command is enabled for this node. - ok(tree.controller.isCommandEnabled(command), - " command '" + command + "' on current selected node is enabled"); - - // This will open the dialog. - tree.controller.doCommand(command); -} diff --git a/browser/components/places/tests/browser/browser_drag_bookmarks_on_toolbar.js b/browser/components/places/tests/browser/browser_drag_bookmarks_on_toolbar.js deleted file mode 100644 index 699c99127..000000000 --- a/browser/components/places/tests/browser/browser_drag_bookmarks_on_toolbar.js +++ /dev/null @@ -1,255 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const TEST_URL = "http://www.mozilla.org"; -const TEST_TITLE = "example_title"; - -var gBookmarksToolbar = window.document.getElementById("PlacesToolbar"); -var dragDirections = { LEFT: 0, UP: 1, RIGHT: 2, DOWN: 3 }; - -/** - * Tests dragging on toolbar. - * - * We must test these 2 cases: - * - Dragging toward left, top, right should start a drag. - * - Dragging toward down should should open the container if the item is a - * container, drag the item otherwise. - * - * @param aElement - * DOM node element we will drag - * @param aExpectedDragData - * Array of flavors and values in the form: - * [ ["text/plain: sometext", "text/html: <b>sometext</b>"], [...] ] - * Pass an empty array to check that drag even has been canceled. - * @param aDirection - * Direction for the dragging gesture, see dragDirections helper object. - */ -function synthesizeDragWithDirection(aElement, aExpectedDragData, aDirection, aCallback) { - // Dragstart listener function. - gBookmarksToolbar.addEventListener("dragstart", function(event) - { - info("A dragstart event has been trapped."); - var dataTransfer = event.dataTransfer; - is(dataTransfer.mozItemCount, aExpectedDragData.length, - "Number of dragged items should be the same."); - - for (var t = 0; t < dataTransfer.mozItemCount; t++) { - var types = dataTransfer.mozTypesAt(t); - var expecteditem = aExpectedDragData[t]; - is(types.length, expecteditem.length, - "Number of flavors for item " + t + " should be the same."); - - for (var f = 0; f < types.length; f++) { - is(types[f], expecteditem[f].substring(0, types[f].length), - "Flavor " + types[f] + " for item " + t + " should be the same."); - is(dataTransfer.mozGetDataAt(types[f], t), - expecteditem[f].substring(types[f].length + 2), - "Contents for item " + t + " with flavor " + types[f] + " should be the same."); - } - } - - if (!aExpectedDragData.length) - ok(event.defaultPrevented, "Drag has been canceled."); - - event.preventDefault(); - event.stopPropagation(); - - gBookmarksToolbar.removeEventListener("dragstart", arguments.callee, false); - - // This is likely to cause a click event, and, in case we are dragging a - // bookmark, an unwanted page visit. Prevent the click event. - aElement.addEventListener("click", prevent, false); - EventUtils.synthesizeMouse(aElement, - startingPoint.x + xIncrement * 9, - startingPoint.y + yIncrement * 9, - { type: "mouseup" }); - aElement.removeEventListener("click", prevent, false); - - // Cleanup eventually opened menus. - if (aElement.localName == "menu" && aElement.open) - aElement.open = false; - aCallback() - }, false); - - var prevent = function(aEvent) {aEvent.preventDefault();} - - var xIncrement = 0; - var yIncrement = 0; - - switch (aDirection) { - case dragDirections.LEFT: - xIncrement = -1; - break; - case dragDirections.RIGHT: - xIncrement = +1; - break; - case dragDirections.UP: - yIncrement = -1; - break; - case dragDirections.DOWN: - yIncrement = +1; - break; - } - - var rect = aElement.getBoundingClientRect(); - var startingPoint = { x: (rect.right - rect.left)/2, - y: (rect.bottom - rect.top)/2 }; - - EventUtils.synthesizeMouse(aElement, - startingPoint.x, - startingPoint.y, - { type: "mousedown" }); - EventUtils.synthesizeMouse(aElement, - startingPoint.x + xIncrement * 1, - startingPoint.y + yIncrement * 1, - { type: "mousemove" }); - EventUtils.synthesizeMouse(aElement, - startingPoint.x + xIncrement * 9, - startingPoint.y + yIncrement * 9, - { type: "mousemove" }); -} - -function getToolbarNodeForItemId(aItemId) { - var children = document.getElementById("PlacesToolbarItems").childNodes; - var node = null; - for (var i = 0; i < children.length; i++) { - if (aItemId == children[i]._placesNode.itemId) { - node = children[i]; - break; - } - } - return node; -} - -function getExpectedDataForPlacesNode(aNode) { - var wrappedNode = []; - var flavors = ["text/x-moz-place", - "text/x-moz-url", - "text/plain", - "text/html"]; - - flavors.forEach(function(aFlavor) { - var wrappedFlavor = aFlavor + ": " + - PlacesUtils.wrapNode(aNode, aFlavor); - wrappedNode.push(wrappedFlavor); - }); - - return [wrappedNode]; -} - -var gTests = [ - -//------------------------------------------------------------------------------ - - { - desc: "Drag a folder on toolbar", - run: function() { - // Create a test folder to be dragged. - var folderId = PlacesUtils.bookmarks - .createFolder(PlacesUtils.toolbarFolderId, - TEST_TITLE, - PlacesUtils.bookmarks.DEFAULT_INDEX); - var element = getToolbarNodeForItemId(folderId); - isnot(element, null, "Found node on toolbar"); - - isnot(element._placesNode, null, "Toolbar node has an associated Places node."); - var expectedData = getExpectedDataForPlacesNode(element._placesNode); - - info("Dragging left"); - synthesizeDragWithDirection(element, expectedData, dragDirections.LEFT, - function () - { - info("Dragging right"); - synthesizeDragWithDirection(element, expectedData, dragDirections.RIGHT, - function () - { - info("Dragging up"); - synthesizeDragWithDirection(element, expectedData, dragDirections.UP, - function () - { - info("Dragging down"); - synthesizeDragWithDirection(element, new Array(), dragDirections.DOWN, - function () { - // Cleanup. - PlacesUtils.bookmarks.removeItem(folderId); - nextTest(); - }); - }); - }); - }); - } - }, - -//------------------------------------------------------------------------------ - - { - desc: "Drag a bookmark on toolbar", - run: function() { - // Create a test bookmark to be dragged. - var itemId = PlacesUtils.bookmarks - .insertBookmark(PlacesUtils.toolbarFolderId, - PlacesUtils._uri(TEST_URL), - PlacesUtils.bookmarks.DEFAULT_INDEX, - TEST_TITLE); - var element = getToolbarNodeForItemId(itemId); - isnot(element, null, "Found node on toolbar"); - - isnot(element._placesNode, null, "Toolbar node has an associated Places node."); - var expectedData = getExpectedDataForPlacesNode(element._placesNode); - - info("Dragging left"); - synthesizeDragWithDirection(element, expectedData, dragDirections.LEFT, - function () - { - info("Dragging right"); - synthesizeDragWithDirection(element, expectedData, dragDirections.RIGHT, - function () - { - info("Dragging up"); - synthesizeDragWithDirection(element, expectedData, dragDirections.UP, - function () - { - info("Dragging down"); - synthesizeDragWithDirection(element, expectedData, dragDirections.DOWN, - function () { - // Cleanup. - PlacesUtils.bookmarks.removeItem(itemId); - nextTest(); - }); - }); - }); - }); - } - }, -]; - -function nextTest() { - if (gTests.length) { - var test = gTests.shift(); - waitForFocus(function() { - info("Start of test: " + test.desc); - test.run(); - }); - } - else { - // Collapse the personal toolbar if needed. - if (wasCollapsed) - setToolbarVisibility(toolbar, false); - finish(); - } -} - -let toolbar = document.getElementById("PersonalToolbar"); -let wasCollapsed = toolbar.collapsed; - -function test() { - waitForExplicitFinish(); - - // Uncollapse the personal toolbar if needed. - if (wasCollapsed) - setToolbarVisibility(toolbar, true); - - nextTest(); -} - diff --git a/browser/components/places/tests/browser/browser_forgetthissite_single.js b/browser/components/places/tests/browser/browser_forgetthissite_single.js deleted file mode 100644 index 57451ccc8..000000000 --- a/browser/components/places/tests/browser/browser_forgetthissite_single.js +++ /dev/null @@ -1,73 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test makes sure that the Forget This Site command is hidden for multiple -// selections. -function test() { - // initialization - waitForExplicitFinish(); - - // Add a history entry. - let TEST_URIs = ["http://www.mozilla.org/test1", "http://www.mozilla.org/test2"]; - ok(PlacesUtils, "checking PlacesUtils, running in chrome context?"); - let places = []; - TEST_URIs.forEach(function(TEST_URI) { - places.push({uri: PlacesUtils._uri(TEST_URI), - transition: PlacesUtils.history.TRANSITION_TYPED}); - }); - addVisits(places, window, function() { - testForgetThisSiteVisibility(1, function() { - testForgetThisSiteVisibility(2, function() { - // Cleanup - waitForClearHistory(finish); - }); - }); - }); - - function testForgetThisSiteVisibility(selectionCount, funcNext) { - openLibrary(function (organizer) { - // Select History in the left pane. - organizer.PlacesOrganizer.selectLeftPaneQuery('History'); - let PO = organizer.PlacesOrganizer; - let histContainer = PO._places.selectedNode.QueryInterface(Ci.nsINavHistoryContainerResultNode); - histContainer.containerOpen = true; - PO._places.selectNode(histContainer.getChild(0)); - // Select the first history entry. - let doc = organizer.document; - let tree = PO._content; - let selection = tree.view.selection; - selection.clearSelection(); - selection.rangedSelect(0, selectionCount - 1, true); - is(selection.count, selectionCount, - "The selected range is as big as expected"); - // Open the context menu - let contextmenu = doc.getElementById("placesContext"); - contextmenu.addEventListener("popupshown", function() { - contextmenu.removeEventListener("popupshown", arguments.callee, true); - let forgetThisSite = doc.getElementById("placesContext_deleteHost"); - let hideForgetThisSite = (selectionCount != 1); - is(forgetThisSite.hidden, hideForgetThisSite, - "The Forget this site menu item should " + (hideForgetThisSite ? "" : "not ") + - "be hidden with " + selectionCount + " items selected"); - // Close the context menu - contextmenu.hidePopup(); - // Wait for the Organizer window to actually be closed - organizer.addEventListener("unload", function () { - organizer.removeEventListener("unload", arguments.callee, false); - // Proceed - funcNext(); - }, false); - // Close Library window. - organizer.close(); - }, true); - // Get cell coordinates - var x = {}, y = {}, width = {}, height = {}; - tree.treeBoxObject.getCoordsForCellItem(0, tree.columns[0], "text", - x, y, width, height); - // Initiate a context menu for the selected cell - EventUtils.synthesizeMouse(tree.body, x.value + width.value / 2, y.value + height.value / 2, {type: "contextmenu"}, organizer); - }); - } -} - diff --git a/browser/components/places/tests/browser/browser_history_sidebar_search.js b/browser/components/places/tests/browser/browser_history_sidebar_search.js deleted file mode 100644 index 93e5305bb..000000000 --- a/browser/components/places/tests/browser/browser_history_sidebar_search.js +++ /dev/null @@ -1,89 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Bug 392497 - search in history sidebar loses sort - */ - -var hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); -var bh = hs.QueryInterface(Ci.nsIBrowserHistory); -var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); -function uri(spec) { - return ios.newURI(spec, null, null); -} - -var sidebar = document.getElementById("sidebar"); - -// Visited pages listed by descending visit date. -var pages = [ - "http://sidebar.mozilla.org/a", - "http://sidebar.mozilla.org/b", - "http://sidebar.mozilla.org/c", - "http://www.mozilla.org/d", -]; -// Number of pages that will be filtered out by the search. -const FILTERED_COUNT = 1; - -function test() { - waitForExplicitFinish(); - - // Cleanup. - waitForClearHistory(continue_test); -} - -function continue_test() { - // Add some visited page. - var time = Date.now(); - var pagesLength = pages.length; - var places = []; - for (var i = 0; i < pagesLength; i++) { - places.push({uri: uri(pages[i]), visitDate: (time - i) * 1000, - transition: hs.TRANSITION_TYPED}); - } - addVisits(places, window, function() { - toggleSidebar("viewHistorySidebar", true); - }); - - sidebar.addEventListener("load", function() { - sidebar.removeEventListener("load", arguments.callee, true); - executeSoon(function() { - // Set "by last visited" in the sidebar (sort by visit date descendind). - sidebar.contentDocument.getElementById("bylastvisited").doCommand(); - check_sidebar_tree_order(pages.length); - var searchBox = sidebar.contentDocument.getElementById("search-box"); - ok(searchBox, "search box is in context"); - searchBox.value = "sidebar.mozilla"; - searchBox.doCommand(); - check_sidebar_tree_order(pages.length - FILTERED_COUNT); - searchBox.value = ""; - searchBox.doCommand(); - check_sidebar_tree_order(pages.length); - - // Cleanup. - toggleSidebar("viewHistorySidebar", false); - waitForClearHistory(finish); - }); - }, true); -} - -function check_sidebar_tree_order(aExpectedRows) { - var tree = sidebar.contentDocument.getElementById("historyTree"); - var treeView = tree.view; - var rc = treeView.rowCount; - var columns = tree.columns; - is(columns.count, 1, "There should be only 1 column in the sidebar"); - var found = 0; - for (var r = 0; r < rc; r++) { - var node = treeView.nodeForTreeIndex(r); - // We could inherit visits from previous tests, skip them since they are - // not interesting for us. - if (pages.indexOf(node.uri) == -1) - continue; - is(node.uri, pages[r], "Node is in correct position based on its visit date"); - found++; - } - ok(found, aExpectedRows, "Found all expected results"); -} diff --git a/browser/components/places/tests/browser/browser_library_batch_delete.js b/browser/components/places/tests/browser/browser_library_batch_delete.js deleted file mode 100644 index 2a65b6b90..000000000 --- a/browser/components/places/tests/browser/browser_library_batch_delete.js +++ /dev/null @@ -1,114 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -/** - * Tests that Library handles correctly batch deletes. - */ - -const TEST_URL = "http://www.batch.delete.me/"; - -var gTests = []; -var gLibrary; - -//------------------------------------------------------------------------------ - -gTests.push({ - desc: "Create and batch remove bookmarks", - run: function() { - let testURI = makeURI(TEST_URL); - PlacesUtils.history.runInBatchMode({ - runBatched: function (aUserData) { - // Create a folder in unserted and populate it with bookmarks. - let folder = PlacesUtils.bookmarks.createFolder( - PlacesUtils.unfiledBookmarksFolderId, "deleteme", - PlacesUtils.bookmarks.DEFAULT_INDEX - ); - PlacesUtils.bookmarks.createFolder( - PlacesUtils.unfiledBookmarksFolderId, "keepme", - PlacesUtils.bookmarks.DEFAULT_INDEX - ); - for (let i = 0; i < 10; i++) { - PlacesUtils.bookmarks.insertBookmark(folder, - testURI, - PlacesUtils.bookmarks.DEFAULT_INDEX, - "bm" + i); - } - } - }, null); - - // Select and open the left pane "History" query. - let PO = gLibrary.PlacesOrganizer; - PO.selectLeftPaneQuery("UnfiledBookmarks"); - isnot(PO._places.selectedNode, null, "Selected unsorted bookmarks"); - - let unsortedNode = PlacesUtils.asContainer(PO._places.selectedNode); - unsortedNode.containerOpen = true; - is(unsortedNode.childCount, 2, "Unsorted node has 2 children"); - let folderNode = unsortedNode.getChild(0); - is(folderNode.title, "deleteme", "Folder found in unsorted bookmarks"); - // Check delete command is available. - PO._places.selectNode(folderNode); - is(PO._places.selectedNode.title, "deleteme", "Folder node selected"); - ok(PO._places.controller.isCommandEnabled("cmd_delete"), - "Delete command is enabled"); - // Execute the delete command and check bookmark has been removed. - PO._places.controller.doCommand("cmd_delete"); - ok(!PlacesUtils.bookmarks.isBookmarked(testURI), - "Bookmark has been correctly removed"); - // Test live update. - is(unsortedNode.childCount, 1, "Unsorted node has 1 child"); - is(PO._places.selectedNode.title, "keepme", "Folder node selected"); - unsortedNode.containerOpen = false; - nextTest(); - } -}); - -//------------------------------------------------------------------------------ - -gTests.push({ - desc: "Ensure correct selection and functionality in Library", - run: function() { - let PO = gLibrary.PlacesOrganizer; - let ContentTree = gLibrary.ContentTree; - // Move selection forth and back. - PO.selectLeftPaneQuery("History"); - PO.selectLeftPaneQuery("UnfiledBookmarks"); - // Now select the "keepme" folder in the right pane and delete it. - ContentTree.view.selectNode(ContentTree.view.result.root.getChild(0)); - is(ContentTree.view.selectedNode.title, "keepme", - "Found folder in content pane"); - // Test live update. - PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, - makeURI(TEST_URL), - PlacesUtils.bookmarks.DEFAULT_INDEX, - "bm"); - is(ContentTree.view.result.root.childCount, 2, - "Right pane was correctly updated"); - nextTest(); - } -}); - -//------------------------------------------------------------------------------ - -function test() { - waitForExplicitFinish(); - registerCleanupFunction(function () { - PlacesUtils.bookmarks - .removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId); - }); - - gLibrary = openLibrary(nextTest); -} - -function nextTest() { - if (gTests.length) { - var test = gTests.shift(); - info("Start of test: " + test.desc); - test.run(); - } - else { - // Close Library window. - gLibrary.close(); - finish(); - } -} diff --git a/browser/components/places/tests/browser/browser_library_downloads.js b/browser/components/places/tests/browser/browser_library_downloads.js deleted file mode 100644 index c761fa15c..000000000 --- a/browser/components/places/tests/browser/browser_library_downloads.js +++ /dev/null @@ -1,70 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/* - * Tests bug 564900: Add folder specifically for downloads to Library left pane. - * https://bugzilla.mozilla.org/show_bug.cgi?id=564900 - * This test visits various pages then opens the Library and ensures - * that both the Downloads folder shows up and that the correct visits - * are shown in it. - */ - -let now = Date.now(); - -function test() { - waitForExplicitFinish(); - - let onLibraryReady = function(win) { - // Add visits to compare contents with. - let places = [ - { uri: NetUtil.newURI("http://mozilla.com"), - visits: [ new VisitInfo(PlacesUtils.history.TRANSITION_TYPED) ] - }, - { uri: NetUtil.newURI("http://google.com"), - visits: [ new VisitInfo(PlacesUtils.history.TRANSITION_DOWNLOAD) ] - }, - { uri: NetUtil.newURI("http://en.wikipedia.org"), - visits: [ new VisitInfo(PlacesUtils.history.TRANSITION_TYPED) ] - }, - { uri: NetUtil.newURI("http://ubuntu.org"), - visits: [ new VisitInfo(PlacesUtils.history.TRANSITION_DOWNLOAD) ] - }, - ] - PlacesUtils.asyncHistory.updatePlaces(places, { - handleResult: function () {}, - handleError: function () { - ok(false, "gHistory.updatePlaces() failed"); - }, - handleCompletion: function () { - // Make sure Downloads is present. - isnot(win.PlacesOrganizer._places.selectedNode, null, - "Downloads is present and selected"); - - - // Check results. - let contentRoot = win.ContentArea.currentView.result.root; - let len = contentRoot.childCount; - const TEST_URIS = ["http://ubuntu.org/", "http://google.com/"]; - for (let i = 0; i < len; i++) { - is(contentRoot.getChild(i).uri, TEST_URIS[i], - "Comparing downloads shown at index " + i); - } - - win.close(); - waitForClearHistory(finish); - } - }) - } - - openLibrary(onLibraryReady, "Downloads"); -} - -function VisitInfo(aTransitionType) -{ - this.transitionType = - aTransitionType === undefined ? - PlacesUtils.history.TRANSITION_LINK : aTransitionType; - this.visitDate = now++ * 1000; -} -VisitInfo.prototype = {} diff --git a/browser/components/places/tests/browser/browser_library_infoBox.js b/browser/components/places/tests/browser/browser_library_infoBox.js deleted file mode 100644 index 87561607f..000000000 --- a/browser/components/places/tests/browser/browser_library_infoBox.js +++ /dev/null @@ -1,199 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Test appropriate visibility of infoBoxExpanderWrapper and - * additionalInfoFields in infoBox section of library - */ - -const TEST_URI = "http://www.mozilla.org/"; - -var gTests = []; -var gLibrary; - -//------------------------------------------------------------------------------ - -gTests.push({ - desc: "Bug 430148 - Remove or hide the more/less button in details pane...", - run: function() { - var PO = gLibrary.PlacesOrganizer; - let ContentTree = gLibrary.ContentTree; - var infoBoxExpanderWrapper = getAndCheckElmtById("infoBoxExpanderWrapper"); - - function addVisitsCallback() { - // open all bookmarks node - PO.selectLeftPaneQuery("AllBookmarks"); - isnot(PO._places.selectedNode, null, - "Correctly selected all bookmarks node."); - checkInfoBoxSelected(PO); - ok(infoBoxExpanderWrapper.hidden, - "Expander button is hidden for all bookmarks node."); - checkAddInfoFieldsCollapsed(PO); - - // open history node - PO.selectLeftPaneQuery("History"); - isnot(PO._places.selectedNode, null, "Correctly selected history node."); - checkInfoBoxSelected(PO); - ok(infoBoxExpanderWrapper.hidden, - "Expander button is hidden for history node."); - checkAddInfoFieldsCollapsed(PO); - - // open history child node - var historyNode = PO._places.selectedNode. - QueryInterface(Ci.nsINavHistoryContainerResultNode); - historyNode.containerOpen = true; - var childNode = historyNode.getChild(0); - isnot(childNode, null, "History node first child is not null."); - PO._places.selectNode(childNode); - checkInfoBoxSelected(PO); - ok(infoBoxExpanderWrapper.hidden, - "Expander button is hidden for history child node."); - checkAddInfoFieldsCollapsed(PO); - - // open history item - var view = ContentTree.view.treeBoxObject.view; - ok(view.rowCount > 0, "History item exists."); - view.selection.select(0); - ok(infoBoxExpanderWrapper.hidden, - "Expander button is hidden for history item."); - checkAddInfoFieldsCollapsed(PO); - - historyNode.containerOpen = false; - - // open bookmarks menu node - PO.selectLeftPaneQuery("BookmarksMenu"); - isnot(PO._places.selectedNode, null, - "Correctly selected bookmarks menu node."); - checkInfoBoxSelected(PO); - ok(infoBoxExpanderWrapper.hidden, - "Expander button is hidden for bookmarks menu node."); - checkAddInfoFieldsCollapsed(PO); - - // open recently bookmarked node - var menuNode = PO._places.selectedNode. - QueryInterface(Ci.nsINavHistoryContainerResultNode); - menuNode.containerOpen = true; - childNode = menuNode.getChild(0); - isnot(childNode, null, "Bookmarks menu child node exists."); - var recentlyBookmarkedTitle = PlacesUIUtils. - getString("recentlyBookmarkedTitle"); - isnot(recentlyBookmarkedTitle, null, - "Correctly got the recently bookmarked title locale string."); - is(childNode.title, recentlyBookmarkedTitle, - "Correctly selected recently bookmarked node."); - PO._places.selectNode(childNode); - checkInfoBoxSelected(PO); - ok(!infoBoxExpanderWrapper.hidden, - "Expander button is not hidden for recently bookmarked node."); - checkAddInfoFieldsNotCollapsed(PO); - - // open first bookmark - var view = ContentTree.view.treeBoxObject.view; - ok(view.rowCount > 0, "Bookmark item exists."); - view.selection.select(0); - checkInfoBoxSelected(PO); - ok(!infoBoxExpanderWrapper.hidden, - "Expander button is not hidden for bookmark item."); - checkAddInfoFieldsNotCollapsed(PO); - checkAddInfoFields(PO, "bookmark item"); - - // make sure additional fields are still hidden in second bookmark item - ok(view.rowCount > 1, "Second bookmark item exists."); - view.selection.select(1); - checkInfoBoxSelected(PO); - ok(!infoBoxExpanderWrapper.hidden, - "Expander button is not hidden for second bookmark item."); - checkAddInfoFieldsNotCollapsed(PO); - checkAddInfoFields(PO, "second bookmark item"); - - menuNode.containerOpen = false; - - waitForClearHistory(nextTest); - } - // add a visit to browser history - addVisits( - { uri: PlacesUtils._uri(TEST_URI), visitDate: Date.now() * 1000, - transition: PlacesUtils.history.TRANSITION_TYPED }, - window, - addVisitsCallback); - } -}); - -function checkInfoBoxSelected(PO) { - is(getAndCheckElmtById("detailsDeck").selectedIndex, 1, - "Selected element in detailsDeck is infoBox."); -} - -function checkAddInfoFieldsCollapsed(PO) { - PO._additionalInfoFields.forEach(function (id) { - ok(getAndCheckElmtById(id).collapsed, - "Additional info field correctly collapsed: #" + id); - }); -} - -function checkAddInfoFieldsNotCollapsed(PO) { - ok(PO._additionalInfoFields.some(function (id) { - return !getAndCheckElmtById(id).collapsed; - }), "Some additional info field correctly not collapsed"); -} - -function checkAddInfoFields(PO, nodeName) { - ok(true, "Checking additional info fields visibiity for node: " + nodeName); - var expanderButton = getAndCheckElmtById("infoBoxExpander"); - - // make sure additional fields are hidden by default - PO._additionalInfoFields.forEach(function (id) { - ok(getAndCheckElmtById(id).hidden, - "Additional info field correctly hidden by default: #" + id); - }); - - // toggle fields and make sure they are hidden/unhidden as expected - expanderButton.click(); - PO._additionalInfoFields.forEach(function (id) { - ok(!getAndCheckElmtById(id).hidden, - "Additional info field correctly unhidden after toggle: #" + id); - }); - expanderButton.click(); - PO._additionalInfoFields.forEach(function (id) { - ok(getAndCheckElmtById(id).hidden, - "Additional info field correctly hidden after toggle: #" + id); - }); -} - -function getAndCheckElmtById(id) { - var elmt = gLibrary.document.getElementById(id); - isnot(elmt, null, "Correctly got element: #" + id); - return elmt; -} - -//------------------------------------------------------------------------------ - -function nextTest() { - if (gTests.length) { - var test = gTests.shift(); - ok(true, "TEST: " + test.desc); - dump("TEST: " + test.desc + "\n"); - test.run(); - } - else { - // Close Library window. - gLibrary.close(); - // No need to cleanup anything, we have a correct left pane now. - finish(); - } -} - -function test() { - waitForExplicitFinish(); - // Sanity checks. - ok(PlacesUtils, "PlacesUtils is running in chrome context"); - ok(PlacesUIUtils, "PlacesUIUtils is running in chrome context"); - - // Open Library. - openLibrary(function (library) { - gLibrary = library; - gLibrary.PlacesOrganizer._places.focus(); - nextTest(gLibrary); - }); -} diff --git a/browser/components/places/tests/browser/browser_library_left_pane_commands.js b/browser/components/places/tests/browser/browser_library_left_pane_commands.js deleted file mode 100644 index b8ef7ecef..000000000 --- a/browser/components/places/tests/browser/browser_library_left_pane_commands.js +++ /dev/null @@ -1,156 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Test enabled commands in the left pane folder of the Library. - */ - -const TEST_URI = "http://www.mozilla.org/"; - -var gTests = []; -var gLibrary; - -//------------------------------------------------------------------------------ - -gTests.push({ - desc: "Bug 489351 - Date containers under History in Library cannot be deleted/cut", - run: function() { - function addVisitsCallback() { - // Select and open the left pane "History" query. - var PO = gLibrary.PlacesOrganizer; - PO.selectLeftPaneQuery('History'); - isnot(PO._places.selectedNode, null, "We correctly selected History"); - - // Check that both delete and cut commands are disabled. - ok(!PO._places.controller.isCommandEnabled("cmd_cut"), - "Cut command is disabled"); - ok(!PO._places.controller.isCommandEnabled("cmd_delete"), - "Delete command is disabled"); - var historyNode = PO._places.selectedNode - .QueryInterface(Ci.nsINavHistoryContainerResultNode); - historyNode.containerOpen = true; - - // Check that we have a child container. It is "Today" container. - is(historyNode.childCount, 1, "History node has one child"); - var todayNode = historyNode.getChild(0); - var todayNodeExpectedTitle = PlacesUtils.getString("finduri-AgeInDays-is-0"); - is(todayNode.title, todayNodeExpectedTitle, - "History child is the expected container"); - - // Select "Today" container. - PO._places.selectNode(todayNode); - is(PO._places.selectedNode, todayNode, - "We correctly selected Today container"); - // Check that delete command is enabled but cut command is disabled. - ok(!PO._places.controller.isCommandEnabled("cmd_cut"), - "Cut command is disabled"); - ok(PO._places.controller.isCommandEnabled("cmd_delete"), - "Delete command is enabled"); - - // Execute the delete command and check visit has been removed. - PO._places.controller.doCommand("cmd_delete"); - - // Test live update of "History" query. - is(historyNode.childCount, 0, "History node has no more children"); - - historyNode.containerOpen = false; - - let testURI = NetUtil.newURI(TEST_URI); - PlacesUtils.asyncHistory.isURIVisited(testURI, function(aURI, aIsVisited) { - ok(!aIsVisited, "Visit has been removed"); - nextTest(); - }); - } - addVisits( - {uri: NetUtil.newURI(TEST_URI), visitDate: Date.now() * 1000, - transition: PlacesUtils.history.TRANSITION_TYPED}, - window, - addVisitsCallback); - } -}); - -//------------------------------------------------------------------------------ - -gTests.push({ - desc: "Bug 490156 - Can't delete smart bookmark containers", - run: function() { - // Select and open the left pane "Bookmarks Toolbar" folder. - var PO = gLibrary.PlacesOrganizer; - PO.selectLeftPaneQuery('BookmarksToolbar'); - isnot(PO._places.selectedNode, null, "We have a valid selection"); - is(PlacesUtils.getConcreteItemId(PO._places.selectedNode), - PlacesUtils.toolbarFolderId, - "We have correctly selected bookmarks toolbar node."); - - // Check that both cut and delete commands are disabled. - ok(!PO._places.controller.isCommandEnabled("cmd_cut"), - "Cut command is disabled"); - ok(!PO._places.controller.isCommandEnabled("cmd_delete"), - "Delete command is disabled"); - - var toolbarNode = PO._places.selectedNode - .QueryInterface(Ci.nsINavHistoryContainerResultNode); - toolbarNode.containerOpen = true; - - // Add an History query to the toolbar. - PlacesUtils.bookmarks.insertBookmark(PlacesUtils.toolbarFolderId, - NetUtil.newURI("place:sort=4"), - 0, // Insert at start. - "special_query"); - // Get first child and check it is the "Most Visited" smart bookmark. - ok(toolbarNode.childCount > 0, "Toolbar node has children"); - var queryNode = toolbarNode.getChild(0); - is(queryNode.title, "special_query", "Query node is correctly selected"); - - // Select query node. - PO._places.selectNode(queryNode); - is(PO._places.selectedNode, queryNode, "We correctly selected query node"); - - // Check that both cut and delete commands are enabled. - ok(PO._places.controller.isCommandEnabled("cmd_cut"), - "Cut command is enabled"); - ok(PO._places.controller.isCommandEnabled("cmd_delete"), - "Delete command is enabled"); - - // Execute the delete command and check bookmark has been removed. - PO._places.controller.doCommand("cmd_delete"); - try { - PlacesUtils.bookmarks.getFolderIdForItem(queryNode.itemId); - ok(false, "Unable to remove query node bookmark"); - } catch(ex) { - ok(true, "Query node bookmark has been correctly removed"); - } - - toolbarNode.containerOpen = false; - nextTest(); - } -}); - -//------------------------------------------------------------------------------ - -function nextTest() { - if (gTests.length) { - var test = gTests.shift(); - info("Start of test: " + test.desc); - test.run(); - } - else { - // Close Library window. - gLibrary.close(); - // No need to cleanup anything, we have a correct left pane now. - finish(); - } -} - -function test() { - waitForExplicitFinish(); - // Sanity checks. - ok(PlacesUtils, "PlacesUtils is running in chrome context"); - ok(PlacesUIUtils, "PlacesUIUtils is running in chrome context"); - - // Open Library. - gLibrary = openLibrary(nextTest); -} diff --git a/browser/components/places/tests/browser/browser_library_left_pane_fixnames.js b/browser/components/places/tests/browser/browser_library_left_pane_fixnames.js deleted file mode 100644 index d7a6bae50..000000000 --- a/browser/components/places/tests/browser/browser_library_left_pane_fixnames.js +++ /dev/null @@ -1,94 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Test we correctly fix broken Library left pane queries names. - */ - -// Array of left pane queries objects, each one has the following properties: -// name: query's identifier got from annotations, -// itemId: query's itemId, -// correctTitle: original and correct query's title. -var leftPaneQueries = []; - -function onLibraryReady(organizer) { - // Check titles have been fixed. - for (var i = 0; i < leftPaneQueries.length; i++) { - var query = leftPaneQueries[i]; - is(PlacesUtils.bookmarks.getItemTitle(query.itemId), - query.correctTitle, "Title is correct for query " + query.name); - if ("concreteId" in query) { - is(PlacesUtils.bookmarks.getItemTitle(query.concreteId), - query.concreteTitle, "Concrete title is correct for query " + query.name); - } - } - - // Close Library window. - organizer.close(); - // No need to cleanup anything, we have a correct left pane now. - finish(); -} - -function test() { - waitForExplicitFinish(); - // Sanity checks. - ok(PlacesUtils, "PlacesUtils is running in chrome context"); - ok(PlacesUIUtils, "PlacesUIUtils is running in chrome context"); - ok(PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION > 0, - "Left pane version in chrome context, current version is: " + PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION ); - - // Ensure left pane is initialized. - ok(PlacesUIUtils.leftPaneFolderId > 0, "left pane folder is initialized"); - - // Get the left pane folder. - var leftPaneItems = PlacesUtils.annotations - .getItemsWithAnnotation(PlacesUIUtils.ORGANIZER_FOLDER_ANNO); - - is(leftPaneItems.length, 1, "We correctly have only 1 left pane folder"); - // Check version. - var version = PlacesUtils.annotations - .getItemAnnotation(leftPaneItems[0], - PlacesUIUtils.ORGANIZER_FOLDER_ANNO); - is(version, PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION, "Left pane version is actual"); - - // Get all left pane queries. - var items = PlacesUtils.annotations - .getItemsWithAnnotation(PlacesUIUtils.ORGANIZER_QUERY_ANNO); - // Get current queries names. - for (var i = 0; i < items.length; i++) { - var itemId = items[i]; - var queryName = PlacesUtils.annotations - .getItemAnnotation(items[i], - PlacesUIUtils.ORGANIZER_QUERY_ANNO); - var query = { name: queryName, - itemId: itemId, - correctTitle: PlacesUtils.bookmarks.getItemTitle(itemId) } - switch (queryName) { - case "BookmarksToolbar": - query.concreteId = PlacesUtils.toolbarFolderId; - query.concreteTitle = PlacesUtils.bookmarks.getItemTitle(query.concreteId); - break; - case "BookmarksMenu": - query.concreteId = PlacesUtils.bookmarksMenuFolderId; - query.concreteTitle = PlacesUtils.bookmarks.getItemTitle(query.concreteId); - break; - case "UnfiledBookmarks": - query.concreteId = PlacesUtils.unfiledBookmarksFolderId; - query.concreteTitle = PlacesUtils.bookmarks.getItemTitle(query.concreteId); - break; - } - leftPaneQueries.push(query); - // Rename to a bad title. - PlacesUtils.bookmarks.setItemTitle(query.itemId, "badName"); - if ("concreteId" in query) - PlacesUtils.bookmarks.setItemTitle(query.concreteId, "badName"); - } - - PlacesUIUtils.__defineGetter__("leftPaneFolderId", cachedLeftPaneFolderIdGetter); - - // Open Library, this will kick-off left pane code. - openLibrary(onLibraryReady); -} diff --git a/browser/components/places/tests/browser/browser_library_middleclick.js b/browser/components/places/tests/browser/browser_library_middleclick.js deleted file mode 100644 index 13a62da30..000000000 --- a/browser/components/places/tests/browser/browser_library_middleclick.js +++ /dev/null @@ -1,281 +0,0 @@ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - - /** - * Tests middle-clicking items in the Library. - */ - -const ENABLE_HISTORY_PREF = "places.history.enabled"; - -var gLibrary = null; -var gTests = []; -var gCurrentTest = null; - -// Listener for TabOpen and tabs progress. -var gTabsListener = { - _loadedURIs: [], - _openTabsCount: 0, - - handleEvent: function(aEvent) { - if (aEvent.type != "TabOpen") - return; - - if (++this._openTabsCount == gCurrentTest.URIs.length) { - is(gBrowser.tabs.length, gCurrentTest.URIs.length + 1, - "We have opened " + gCurrentTest.URIs.length + " new tab(s)"); - } - - var tab = aEvent.target; - is(tab.ownerDocument.defaultView, window, - "Tab has been opened in current browser window"); - }, - - onLocationChange: function(aBrowser, aWebProgress, aRequest, aLocationURI, - aFlags) { - var spec = aLocationURI.spec; - ok(true, spec); - // When a new tab is opened, location is first set to "about:blank", so - // we can ignore those calls. - // Ignore multiple notifications for the same URI too. - if (spec == "about:blank" || this._loadedURIs.indexOf(spec) != -1) - return; - - ok(gCurrentTest.URIs.indexOf(spec) != -1, - "Opened URI found in list: " + spec); - - if (gCurrentTest.URIs.indexOf(spec) != -1 ) - this._loadedURIs.push(spec); - - if (this._loadedURIs.length == gCurrentTest.URIs.length) { - // We have correctly opened all URIs. - - // Reset arrays. - this._loadedURIs.length = 0; - - this._openTabsCount = 0; - - executeSoon(function () { - // Close all tabs. - while (gBrowser.tabs.length > 1) - gBrowser.removeCurrentTab(); - - // Test finished. This will move to the next one. - waitForFocus(gCurrentTest.finish, gBrowser.ownerDocument.defaultView); - }); - } - } -} - -//------------------------------------------------------------------------------ -// Open bookmark in a new tab. - -gTests.push({ - desc: "Open bookmark in a new tab.", - URIs: ["about:buildconfig"], - _itemId: -1, - - setup: function() { - var bs = PlacesUtils.bookmarks; - // Add a new unsorted bookmark. - this._itemId = bs.insertBookmark(bs.unfiledBookmarksFolder, - PlacesUtils._uri(this.URIs[0]), - bs.DEFAULT_INDEX, - "Title"); - // Select unsorted bookmarks root in the left pane. - gLibrary.PlacesOrganizer.selectLeftPaneQuery("UnfiledBookmarks"); - isnot(gLibrary.PlacesOrganizer._places.selectedNode, null, - "We correctly have selection in the Library left pane"); - // Get our bookmark in the right pane. - var bookmarkNode = gLibrary.ContentTree.view.view.nodeForTreeIndex(0); - is(bookmarkNode.uri, this.URIs[0], "Found bookmark in the right pane"); - }, - - finish: function() { - setTimeout(runNextTest, 0); - }, - - cleanup: function() { - PlacesUtils.bookmarks.removeItem(this._itemId); - } -}); - -//------------------------------------------------------------------------------ -// Open a folder in tabs. - -gTests.push({ - desc: "Open a folder in tabs.", - URIs: ["about:buildconfig", "about:"], - _folderId: -1, - - setup: function() { - var bs = PlacesUtils.bookmarks; - // Create a new folder. - var folderId = bs.createFolder(bs.unfiledBookmarksFolder, - "Folder", - bs.DEFAULT_INDEX); - this._folderId = folderId; - - // Add bookmarks in folder. - this.URIs.forEach(function(aURI) { - bs.insertBookmark(folderId, - PlacesUtils._uri(aURI), - bs.DEFAULT_INDEX, - "Title"); - }); - - // Select unsorted bookmarks root in the left pane. - gLibrary.PlacesOrganizer.selectLeftPaneQuery("UnfiledBookmarks"); - isnot(gLibrary.PlacesOrganizer._places.selectedNode, null, - "We correctly have selection in the Library left pane"); - // Get our bookmark in the right pane. - var folderNode = gLibrary.ContentTree.view.view.nodeForTreeIndex(0); - is(folderNode.title, "Folder", "Found folder in the right pane"); - }, - - finish: function() { - setTimeout(runNextTest, 0); - }, - - cleanup: function() { - PlacesUtils.bookmarks.removeItem(this._folderId); - } -}); - -//------------------------------------------------------------------------------ -// Open a query in tabs. - -gTests.push({ - desc: "Open a query in tabs.", - URIs: ["about:buildconfig", "about:"], - _folderId: -1, - _queryId: -1, - - setup: function() { - var bs = PlacesUtils.bookmarks; - // Create a new folder. - var folderId = bs.createFolder(bs.unfiledBookmarksFolder, - "Folder", - bs.DEFAULT_INDEX); - this._folderId = folderId; - - // Add bookmarks in folder. - this.URIs.forEach(function(aURI) { - bs.insertBookmark(folderId, - PlacesUtils._uri(aURI), - bs.DEFAULT_INDEX, - "Title"); - }); - - // Create a bookmarks query containing our bookmarks. - var hs = PlacesUtils.history; - var options = hs.getNewQueryOptions(); - options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS; - var query = hs.getNewQuery(); - // The colon included in the terms selects only about: URIs. If not included - // we also may get pages like about.html included in the query result. - query.searchTerms = "about:"; - var queryString = hs.queriesToQueryString([query], 1, options); - this._queryId = bs.insertBookmark(bs.unfiledBookmarksFolder, - PlacesUtils._uri(queryString), - 0, // It must be the first. - "Query"); - - // Select unsorted bookmarks root in the left pane. - gLibrary.PlacesOrganizer.selectLeftPaneQuery("UnfiledBookmarks"); - isnot(gLibrary.PlacesOrganizer._places.selectedNode, null, - "We correctly have selection in the Library left pane"); - // Get our bookmark in the right pane. - var folderNode = gLibrary.ContentTree.view.view.nodeForTreeIndex(0); - is(folderNode.title, "Query", "Found query in the right pane"); - }, - - finish: function() { - setTimeout(runNextTest, 0); - }, - - cleanup: function() { - PlacesUtils.bookmarks.removeItem(this._folderId); - PlacesUtils.bookmarks.removeItem(this._queryId); - } -}); - -//------------------------------------------------------------------------------ - -function test() { - waitForExplicitFinish(); - // Increase timeout, this test can be quite slow due to waitForFocus calls. - requestLongerTimeout(2); - - // Sanity checks. - ok(PlacesUtils, "PlacesUtils in context"); - ok(PlacesUIUtils, "PlacesUIUtils in context"); - - // Add tabs listeners. - gBrowser.tabContainer.addEventListener("TabOpen", gTabsListener, false); - gBrowser.addTabsProgressListener(gTabsListener); - - // Temporary disable history, so we won't record pages navigation. - gPrefService.setBoolPref(ENABLE_HISTORY_PREF, false); - - // Open Library window. - openLibrary(function (library) { - gLibrary = library; - // Kick off tests. - runNextTest(); - }); -} - -function runNextTest() { - // Cleanup from previous test. - if (gCurrentTest) - gCurrentTest.cleanup(); - - if (gTests.length > 0) { - // Goto next test. - gCurrentTest = gTests.shift(); - info("Start of test: " + gCurrentTest.desc); - // Test setup will set Library so that the bookmark to be opened is the - // first node in the content (right pane) tree. - gCurrentTest.setup(); - - // Middle click on first node in the content tree of the Library. - gLibrary.focus(); - waitForFocus(function() { - mouseEventOnCell(gLibrary.ContentTree.view, 0, 0, { button: 1 }); - }, gLibrary); - } - else { - // No more tests. - - // Close Library window. - gLibrary.close(); - - // Remove tabs listeners. - gBrowser.tabContainer.removeEventListener("TabOpen", gTabsListener, false); - gBrowser.removeTabsProgressListener(gTabsListener); - - // Restore history. - try { - gPrefService.clearUserPref(ENABLE_HISTORY_PREF); - } catch(ex) {} - - finish(); - } -} - -function mouseEventOnCell(aTree, aRowIndex, aColumnIndex, aEventDetails) { - var selection = aTree.view.selection; - selection.select(aRowIndex); - aTree.treeBoxObject.ensureRowIsVisible(aRowIndex); - var column = aTree.columns[aColumnIndex]; - - // get cell coordinates - var x = {}, y = {}, width = {}, height = {}; - aTree.treeBoxObject.getCoordsForCellItem(aRowIndex, column, "text", - x, y, width, height); - - EventUtils.synthesizeMouse(aTree.body, x.value, y.value, - aEventDetails, gLibrary); -} diff --git a/browser/components/places/tests/browser/browser_library_open_leak.js b/browser/components/places/tests/browser/browser_library_open_leak.js deleted file mode 100644 index 03aa3408f..000000000 --- a/browser/components/places/tests/browser/browser_library_open_leak.js +++ /dev/null @@ -1,23 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Bug 474831 - * https://bugzilla.mozilla.org/show_bug.cgi?id=474831 - * - * Tests for leaks caused by simply opening and closing the Places Library - * window. Opens the Places Library window, waits for it to load, closes it, - * and finishes. - */ - -function test() { - waitForExplicitFinish(); - openLibrary(function (win) { - ok(true, "Library has been correctly opened"); - win.close(); - finish(); - }); -} diff --git a/browser/components/places/tests/browser/browser_library_panel_leak.js b/browser/components/places/tests/browser/browser_library_panel_leak.js deleted file mode 100644 index 56519d9da..000000000 --- a/browser/components/places/tests/browser/browser_library_panel_leak.js +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Bug 433231 - Places Library leaks the nsGlobalWindow when closed with a - * history entry selected. - * https://bugzilla.mozilla.org/show_bug.cgi?id=433231 - * - * STRs: Open Library, select an history entry in History, close Library. - * ISSUE: We were adding a bookmarks observer when editing a bookmark, when - * selecting an history entry the panel was not un-initialized, and - * since an histroy entry does not have an itemId, the observer was - * never removed. - */ - -const TEST_URI = "http://www.mozilla.org/"; - -function test() { - function onLibraryReady(organizer) { - let contentTree = organizer.document.getElementById("placeContent"); - isnot(contentTree, null, "Sanity check: placeContent tree should exist"); - isnot(organizer.PlacesOrganizer, null, "Sanity check: PlacesOrganizer should exist"); - isnot(organizer.gEditItemOverlay, null, "Sanity check: gEditItemOverlay should exist"); - - ok(organizer.gEditItemOverlay._initialized, "gEditItemOverlay is initialized"); - isnot(organizer.gEditItemOverlay.itemId, -1, "Editing a bookmark"); - - // Select History in the left pane. - organizer.PlacesOrganizer.selectLeftPaneQuery('History'); - // Select the first history entry. - let selection = contentTree.view.selection; - selection.clearSelection(); - selection.rangedSelect(0, 0, true); - // Check the panel is editing the history entry. - is(organizer.gEditItemOverlay.itemId, -1, "Editing an history entry"); - // Close Library window. - organizer.close(); - // Clean up history. - waitForClearHistory(finish); - } - - waitForExplicitFinish(); - // Add an history entry. - ok(PlacesUtils, "checking PlacesUtils, running in chrome context?"); - addVisits( - {uri: PlacesUtils._uri(TEST_URI), visitDate: Date.now() * 1000, - transition: PlacesUtils.history.TRANSITION_TYPED}, - window, - function() { - openLibrary(onLibraryReady); - }); -} diff --git a/browser/components/places/tests/browser/browser_library_search.js b/browser/components/places/tests/browser/browser_library_search.js deleted file mode 100644 index 8e51fdf76..000000000 --- a/browser/components/places/tests/browser/browser_library_search.js +++ /dev/null @@ -1,187 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Bug 451151 - * https://bugzilla.mozilla.org/show_bug.cgi?id=451151 - * - * Summary: - * Tests frontend Places Library searching -- search, search reset, search scope - * consistency. - * - * Details: - * Each test below - * 1. selects a folder in the left pane and ensures that the content tree is - * appropriately updated, - * 2. performs a search and ensures that the content tree is correct for the - * folder and search and that the search UI is visible and appropriate to - * folder, - * 5. resets the search and ensures that the content tree is correct and that - * the search UI is hidden, and - * 6. if folder scope was clicked, searches again and ensures folder scope - * remains selected. - */ - -const TEST_URL = "http://dummy.mozilla.org/"; -const TEST_DOWNLOAD_URL = "http://dummy.mozilla.org/dummy.pdf"; - -let gLibrary; - -let testCases = [ - function allBookmarksScope() { - let defScope = getDefaultScope(PlacesUIUtils.allBookmarksFolderId); - search(PlacesUIUtils.allBookmarksFolderId, "dummy", defScope); - }, - - function historyScope() { - let defScope = getDefaultScope(PlacesUIUtils.leftPaneQueries["History"]); - search(PlacesUIUtils.leftPaneQueries["History"], "dummy", defScope); - }, - - function downloadsScope() { - let defScope = getDefaultScope(PlacesUIUtils.leftPaneQueries["Downloads"]); - search(PlacesUIUtils.leftPaneQueries["Downloads"], "dummy", defScope); - }, -]; - -/////////////////////////////////////////////////////////////////////////////// - -/** - * Returns the default search scope for a given folder. - * - * @param aFolderId - * the item ID of a node in the left pane's tree - * @return the default scope when the folder is newly selected - */ -function getDefaultScope(aFolderId) { - switch (aFolderId) { - case PlacesUIUtils.leftPaneQueries["History"]: - return "scopeBarHistory" - case PlacesUIUtils.leftPaneQueries["Downloads"]: - return "scopeBarDownloads"; - default: - return "scopeBarAll"; - } -} - -/** - * Returns the single nsINavHistoryQuery represented by a given place URI. - * - * @param aPlaceURI - * a URI that represents a single query - * @return an nsINavHistoryQuery object - */ -function queryStringToQuery(aPlaceURI) { - let queries = {}; - PlacesUtils.history.queryStringToQueries(aPlaceURI, queries, {}, {}); - return queries.value[0]; -} - -/** - * Resets the search by clearing the search box's text and ensures that the - * search scope remains as expected. - * - * @param aExpectedScopeButtonId - * this button should be selected after the reset - */ -function resetSearch(aExpectedScopeButtonId) { - search(null, "", aExpectedScopeButtonId); -} - -/** - * Performs a search for a given folder and search string and ensures that the - * URI of the right pane's content tree is as expected for the folder and search - * string. Also ensures that the search scope button is as expected after the - * search. - * - * @param aFolderId - * the item ID of a node in the left pane's tree - * @param aSearchStr - * the search text; may be empty to reset the search - * @param aExpectedScopeButtonId - * after searching the selected scope button should be this - */ -function search(aFolderId, aSearchStr, aExpectedScopeButtonId) { - let doc = gLibrary.document; - let folderTree = doc.getElementById("placesList"); - let contentTree = doc.getElementById("placeContent"); - - // First, ensure that selecting the folder in the left pane updates the - // content tree properly. - if (aFolderId) { - folderTree.selectItems([aFolderId]); - isnot(folderTree.selectedNode, null, - "Sanity check: left pane tree should have selection after selecting!"); - - // getFolders() on a History query returns an empty array, so no use - // comparing against aFolderId in that case. - if (aFolderId !== PlacesUIUtils.leftPaneQueries["History"] && - aFolderId !== PlacesUIUtils.leftPaneQueries["Downloads"]) { - // contentTree.place should be equal to contentTree.result.root.uri, - // but it's not until bug 476952 is fixed. - let query = queryStringToQuery(contentTree.result.root.uri); - is(query.getFolders()[0], aFolderId, - "Content tree's folder should be what was selected in the left pane"); - } - } - - // Second, ensure that searching updates the content tree and search UI - // properly. - let searchBox = doc.getElementById("searchFilter"); - searchBox.value = aSearchStr; - gLibrary.PlacesSearchBox.search(searchBox.value); - let query = queryStringToQuery(contentTree.result.root.uri); - if (aSearchStr) { - is(query.searchTerms, aSearchStr, - "Content tree's searchTerms should be text in search box"); - } - else { - is(query.hasSearchTerms, false, - "Content tree's searchTerms should not exist after search reset"); - } -} - -/** - * test() contains window-launching boilerplate that calls this to really kick - * things off. Add functions to the testCases array, and this will call them. - */ -function onLibraryAvailable() { - testCases.forEach(function (aTest) aTest()); - - gLibrary.close(); - gLibrary = null; - - // Cleanup. - PlacesUtils.tagging.untagURI(PlacesUtils._uri(TEST_URL), ["dummyTag"]); - PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId); - waitForClearHistory(finish); -} - -/////////////////////////////////////////////////////////////////////////////// - -function test() { - waitForExplicitFinish(); - - // Sanity: - ok(PlacesUtils, "PlacesUtils in context"); - - // Add visits, a bookmark and a tag. - addVisits( - [{ uri: PlacesUtils._uri(TEST_URL), visitDate: Date.now() * 1000, - transition: PlacesUtils.history.TRANSITION_TYPED }, - { uri: PlacesUtils._uri(TEST_DOWNLOAD_URL), visitDate: Date.now() * 1000, - transition: PlacesUtils.history.TRANSITION_DOWNLOAD }], - window, - function() { - PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, - PlacesUtils._uri(TEST_URL), - PlacesUtils.bookmarks.DEFAULT_INDEX, - "dummy"); - PlacesUtils.tagging.tagURI(PlacesUtils._uri(TEST_URL), ["dummyTag"]); - - gLibrary = openLibrary(onLibraryAvailable); - }); -} diff --git a/browser/components/places/tests/browser/browser_library_views_liveupdate.js b/browser/components/places/tests/browser/browser_library_views_liveupdate.js deleted file mode 100644 index d339fd447..000000000 --- a/browser/components/places/tests/browser/browser_library_views_liveupdate.js +++ /dev/null @@ -1,301 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Tests Library Left pane view for liveupdate. - */ - -var gLibrary = null; - -function test() { - waitForExplicitFinish(); - // This test takes quite some time, and timeouts frequently, so we require - // more time to run. - // See Bug 525610. - requestLongerTimeout(2); - - // Sanity checks. - ok(PlacesUtils, "PlacesUtils in context"); - ok(PlacesUIUtils, "PlacesUIUtils in context"); - - // Open Library, we will check the left pane. - openLibrary(function (library) { - gLibrary = library; - startTest(); - }); -} - -/** - * Adds bookmarks observer, and executes a bunch of bookmarks operations. - */ -function startTest() { - var bs = PlacesUtils.bookmarks; - // Add observers. - bs.addObserver(bookmarksObserver, false); - PlacesUtils.annotations.addObserver(bookmarksObserver, false); - var addedBookmarks = []; - - // MENU - ok(true, "*** Acting on menu bookmarks"); - var id = bs.insertBookmark(bs.bookmarksMenuFolder, - PlacesUtils._uri("http://bm1.mozilla.org/"), - bs.DEFAULT_INDEX, - "bm1"); - addedBookmarks.push(id); - id = bs.insertBookmark(bs.bookmarksMenuFolder, - PlacesUtils._uri("place:"), - bs.DEFAULT_INDEX, - "bm2"); - bs.setItemTitle(id, "bm2_edited"); - addedBookmarks.push(id); - id = bs.insertSeparator(bs.bookmarksMenuFolder, bs.DEFAULT_INDEX); - addedBookmarks.push(id); - id = bs.createFolder(bs.bookmarksMenuFolder, - "bmf", - bs.DEFAULT_INDEX); - bs.setItemTitle(id, "bmf_edited"); - addedBookmarks.push(id); - id = bs.insertBookmark(id, - PlacesUtils._uri("http://bmf1.mozilla.org/"), - bs.DEFAULT_INDEX, - "bmf1"); - addedBookmarks.push(id); - bs.moveItem(id, bs.bookmarksMenuFolder, 0); - - // TOOLBAR - ok(true, "*** Acting on toolbar bookmarks"); - bs.insertBookmark(bs.toolbarFolder, - PlacesUtils._uri("http://tb1.mozilla.org/"), - bs.DEFAULT_INDEX, - "tb1"); - bs.setItemTitle(id, "tb1_edited"); - addedBookmarks.push(id); - id = bs.insertBookmark(bs.toolbarFolder, - PlacesUtils._uri("place:"), - bs.DEFAULT_INDEX, - "tb2"); - bs.setItemTitle(id, "tb2_edited"); - addedBookmarks.push(id); - id = bs.insertSeparator(bs.toolbarFolder, bs.DEFAULT_INDEX); - addedBookmarks.push(id); - id = bs.createFolder(bs.toolbarFolder, - "tbf", - bs.DEFAULT_INDEX); - bs.setItemTitle(id, "tbf_edited"); - addedBookmarks.push(id); - id = bs.insertBookmark(id, - PlacesUtils._uri("http://tbf1.mozilla.org/"), - bs.DEFAULT_INDEX, - "bmf1"); - addedBookmarks.push(id); - bs.moveItem(id, bs.toolbarFolder, 0); - - // UNSORTED - ok(true, "*** Acting on unsorted bookmarks"); - id = bs.insertBookmark(bs.unfiledBookmarksFolder, - PlacesUtils._uri("http://ub1.mozilla.org/"), - bs.DEFAULT_INDEX, - "ub1"); - bs.setItemTitle(id, "ub1_edited"); - addedBookmarks.push(id); - id = bs.insertBookmark(bs.unfiledBookmarksFolder, - PlacesUtils._uri("place:"), - bs.DEFAULT_INDEX, - "ub2"); - bs.setItemTitle(id, "ub2_edited"); - addedBookmarks.push(id); - id = bs.insertSeparator(bs.unfiledBookmarksFolder, bs.DEFAULT_INDEX); - addedBookmarks.push(id); - id = bs.createFolder(bs.unfiledBookmarksFolder, - "ubf", - bs.DEFAULT_INDEX); - bs.setItemTitle(id, "ubf_edited"); - addedBookmarks.push(id); - id = bs.insertBookmark(id, - PlacesUtils._uri("http://ubf1.mozilla.org/"), - bs.DEFAULT_INDEX, - "ubf1"); - addedBookmarks.push(id); - bs.moveItem(id, bs.unfiledBookmarksFolder, 0); - - // Remove all added bookmarks. - addedBookmarks.forEach(function (aItem) { - // If we remove an item after its containing folder has been removed, - // this will throw, but we can ignore that. - try { - bs.removeItem(aItem); - } catch (ex) {} - }); - - // Remove observers. - bs.removeObserver(bookmarksObserver); - PlacesUtils.annotations.removeObserver(bookmarksObserver); - finishTest(); -} - -/** - * Restores browser state and calls finish. - */ -function finishTest() { - // Close Library window. - gLibrary.close(); - finish(); -} - -/** - * The observer is where magic happens, for every change we do it will look for - * nodes positions in the affected views. - */ -var bookmarksObserver = { - QueryInterface: XPCOMUtils.generateQI([ - Ci.nsINavBookmarkObserver - , Ci.nsIAnnotationObserver - ]), - - // nsIAnnotationObserver - onItemAnnotationSet: function() {}, - onItemAnnotationRemoved: function() {}, - onPageAnnotationSet: function() {}, - onPageAnnotationRemoved: function() {}, - - // nsINavBookmarkObserver - onItemAdded: function PSB_onItemAdded(aItemId, aFolderId, aIndex, aItemType, - aURI) { - var node = null; - var index = null; - [node, index] = getNodeForTreeItem(aItemId, gLibrary.PlacesOrganizer._places); - // Left pane should not be updated for normal bookmarks or separators. - switch (aItemType) { - case PlacesUtils.bookmarks.TYPE_BOOKMARK: - var uriString = aURI.spec; - var isQuery = uriString.substr(0, 6) == "place:"; - if (isQuery) { - isnot(node, null, "Found new Places node in left pane"); - ok(index >= 0, "Node is at index " + index); - break; - } - // Fallback to separator case if this is not a query. - case PlacesUtils.bookmarks.TYPE_SEPARATOR: - is(node, null, "New Places node not added in left pane"); - break; - default: - isnot(node, null, "Found new Places node in left pane"); - ok(index >= 0, "Node is at index " + index); - } - }, - - onItemRemoved: function PSB_onItemRemoved(aItemId, aFolder, aIndex) { - var node = null; - var index = null; - [node, index] = getNodeForTreeItem(aItemId, gLibrary.PlacesOrganizer._places); - is(node, null, "Places node not found in left pane"); - }, - - onItemMoved: function(aItemId, - aOldFolderId, aOldIndex, - aNewFolderId, aNewIndex, aItemType) { - var node = null; - var index = null; - [node, index] = getNodeForTreeItem(aItemId, gLibrary.PlacesOrganizer._places); - // Left pane should not be updated for normal bookmarks or separators. - switch (aItemType) { - case PlacesUtils.bookmarks.TYPE_BOOKMARK: - var uriString = PlacesUtils.bookmarks.getBookmarkURI(aItemId).spec; - var isQuery = uriString.substr(0, 6) == "place:"; - if (isQuery) { - isnot(node, null, "Found new Places node in left pane"); - ok(index >= 0, "Node is at index " + index); - break; - } - // Fallback to separator case if this is not a query. - case PlacesUtils.bookmarks.TYPE_SEPARATOR: - is(node, null, "New Places node not added in left pane"); - break; - default: - isnot(node, null, "Found new Places node in left pane"); - ok(index >= 0, "Node is at index " + index); - } - }, - - onBeginUpdateBatch: function PSB_onBeginUpdateBatch() {}, - onEndUpdateBatch: function PSB_onEndUpdateBatch() {}, - onItemVisited: function() {}, - onItemChanged: function PSB_onItemChanged(aItemId, aProperty, - aIsAnnotationProperty, aNewValue) { - if (aProperty == "title") { - let validator = function(aTreeRowIndex) { - let tree = gLibrary.PlacesOrganizer._places; - let cellText = tree.view.getCellText(aTreeRowIndex, - tree.columns.getColumnAt(0)); - return cellText == aNewValue; - } - let [node, index, valid] = getNodeForTreeItem(aItemId, gLibrary.PlacesOrganizer._places, validator); - if (node) // Only visible nodes. - ok(valid, "Title cell value has been correctly updated"); - } - } -}; - - -/** - * Get places node and index for an itemId in a tree view. - * - * @param aItemId - * item id of the item to search. - * @param aTree - * Tree to search in. - * @param aValidator [optional] - * function to check row validity if found. Defaults to {return true;}. - * @returns [node, index, valid] or [null, null, false] if not found. - */ -function getNodeForTreeItem(aItemId, aTree, aValidator) { - - function findNode(aContainerIndex) { - if (aTree.view.isContainerEmpty(aContainerIndex)) - return [null, null, false]; - - // The rowCount limit is just for sanity, but we will end looping when - // we have checked the last child of this container or we have found node. - for (var i = aContainerIndex + 1; i < aTree.view.rowCount; i++) { - var node = aTree.view.nodeForTreeIndex(i); - - if (node.itemId == aItemId) { - // Minus one because we want relative index inside the container. - let valid = aValidator ? aValidator(i) : true; - return [node, i - aTree.view.getParentIndex(i) - 1, valid]; - } - - if (PlacesUtils.nodeIsFolder(node)) { - // Open container. - aTree.view.toggleOpenState(i); - // Search inside it. - var foundNode = findNode(i); - // Close container. - aTree.view.toggleOpenState(i); - // Return node if found. - if (foundNode[0] != null) - return foundNode; - } - - // We have finished walking this container. - if (!aTree.view.hasNextSibling(aContainerIndex + 1, i)) - break; - } - return [null, null, false] - } - - // Root node is hidden, so we need to manually walk the first level. - for (var i = 0; i < aTree.view.rowCount; i++) { - // Open container. - aTree.view.toggleOpenState(i); - // Search inside it. - var foundNode = findNode(i); - // Close container. - aTree.view.toggleOpenState(i); - // Return node if found. - if (foundNode[0] != null) - return foundNode; - } - return [null, null, false]; -} diff --git a/browser/components/places/tests/browser/browser_markPageAsFollowedLink.js b/browser/components/places/tests/browser/browser_markPageAsFollowedLink.js deleted file mode 100644 index 035fe75a3..000000000 --- a/browser/components/places/tests/browser/browser_markPageAsFollowedLink.js +++ /dev/null @@ -1,86 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/** - * Tests that visits across frames are correctly represented in the database. - */ - -const BASE_URL = "http://mochi.test:8888/browser/browser/components/places/tests/browser"; -const PAGE_URL = BASE_URL + "/framedPage.html"; -const LEFT_URL = BASE_URL + "/frameLeft.html"; -const RIGHT_URL = BASE_URL + "/frameRight.html"; - -let gTabLoaded = false; -let gLeftFrameVisited = false; - -let observer = { - observe: function(aSubject, aTopic, aData) - { - let url = aSubject.QueryInterface(Ci.nsIURI).spec; - if (url == LEFT_URL ) { - is(getTransitionForUrl(url), null, - "Embed visits should not get a database entry."); - gLeftFrameVisited = true; - maybeClickLink(); - } - else if (url == RIGHT_URL ) { - is(getTransitionForUrl(url), PlacesUtils.history.TRANSITION_FRAMED_LINK, - "User activated visits should get a FRAMED_LINK transition."); - finish(); - } - }, - QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]) -}; -Services.obs.addObserver(observer, "uri-visit-saved", false); - -function test() -{ - waitForExplicitFinish(); - gBrowser.selectedTab = gBrowser.addTab(PAGE_URL); - let frameCount = 0; - gBrowser.selectedTab.linkedBrowser.addEventListener("DOMContentLoaded", - function (event) - { - // Wait for all the frames. - if (frameCount++ < 2) - return; - gBrowser.selectedTab.linkedBrowser.removeEventListener("DOMContentLoaded", arguments.callee, false) - gTabLoaded = true; - maybeClickLink(); - }, false - ); -} - -function maybeClickLink() { - if (gTabLoaded && gLeftFrameVisited) { - // Click on the link in the left frame to cause a page load in the - // right frame. - EventUtils.sendMouseEvent({type: "click"}, "clickme", content.frames[0]); - } -} - -function getTransitionForUrl(aUrl) -{ - let dbConn = PlacesUtils.history - .QueryInterface(Ci.nsPIPlacesDatabase).DBConnection; - let stmt = dbConn.createStatement( - "SELECT visit_type FROM moz_historyvisits WHERE place_id = " + - "(SELECT id FROM moz_places WHERE url = :page_url)"); - stmt.params.page_url = aUrl; - try { - if (!stmt.executeStep()) { - return null; - } - return stmt.row.visit_type; - } - finally { - stmt.finalize(); - } -} - -registerCleanupFunction(function () -{ - gBrowser.removeTab(gBrowser.selectedTab); - Services.obs.removeObserver(observer, "uri-visit-saved"); -}) diff --git a/browser/components/places/tests/browser/browser_sidebarpanels_click.js b/browser/components/places/tests/browser/browser_sidebarpanels_click.js deleted file mode 100644 index e5eb685cb..000000000 --- a/browser/components/places/tests/browser/browser_sidebarpanels_click.js +++ /dev/null @@ -1,179 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test makes sure that the items in the bookmarks and history sidebar -// panels are clickable in both LTR and RTL modes. - -function test() { - waitForExplicitFinish(); - ignoreAllUncaughtExceptions(); - - const BOOKMARKS_SIDEBAR_ID = "viewBookmarksSidebar"; - const BOOKMARKS_SIDEBAR_TREE_ID = "bookmarks-view"; - const HISTORY_SIDEBAR_ID = "viewHistorySidebar"; - const HISTORY_SIDEBAR_TREE_ID = "historyTree"; - const TEST_URL = "http://mochi.test:8888/browser/browser/components/places/tests/browser/sidebarpanels_click_test_page.html"; - - // If a sidebar is already open, close it. - if (!document.getElementById("sidebar-box").hidden) { - info("Unexpected sidebar found - a previous test failed to cleanup correctly"); - toggleSidebar(); - } - - let sidebar = document.getElementById("sidebar"); - let tests = []; - let currentTest; - - tests.push({ - _itemID: null, - init: function(aCallback) { - // Add a bookmark to the Unfiled Bookmarks folder. - this._itemID = PlacesUtils.bookmarks.insertBookmark( - PlacesUtils.unfiledBookmarksFolderId, PlacesUtils._uri(TEST_URL), - PlacesUtils.bookmarks.DEFAULT_INDEX, "test" - ); - aCallback(); - }, - prepare: function() { - }, - selectNode: function(tree) { - tree.selectItems([this._itemID]); - }, - cleanup: function(aCallback) { - PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId); - executeSoon(aCallback); - }, - sidebarName: BOOKMARKS_SIDEBAR_ID, - treeName: BOOKMARKS_SIDEBAR_TREE_ID, - desc: "Bookmarks sidebar test" - }); - - tests.push({ - init: function(aCallback) { - // Add a history entry. - let uri = PlacesUtils._uri(TEST_URL); - addVisits( - { uri: uri, visitDate: Date.now() * 1000, - transition: PlacesUtils.history.TRANSITION_TYPED }, - window, - aCallback); - }, - prepare: function() { - sidebar.contentDocument.getElementById("byvisited").doCommand(); - }, - selectNode: function(tree) { - tree.selectNode(tree.view.nodeForTreeIndex(0)); - is(tree.selectedNode.uri, TEST_URL, "The correct visit has been selected"); - is(tree.selectedNode.itemId, -1, "The selected node is not bookmarked"); - }, - cleanup: function(aCallback) { - waitForClearHistory(aCallback); - }, - sidebarName: HISTORY_SIDEBAR_ID, - treeName: HISTORY_SIDEBAR_TREE_ID, - desc: "History sidebar test" - }); - - function testPlacesPanel(preFunc, postFunc) { - currentTest.init(function() { - toggleSidebar(currentTest.sidebarName); - }); - - sidebar.addEventListener("load", function() { - sidebar.removeEventListener("load", arguments.callee, true); - executeSoon(function() { - currentTest.prepare(); - - if (preFunc) - preFunc(); - - function observer(aSubject, aTopic, aData) { - info("alert dialog observed as expected"); - Services.obs.removeObserver(observer, "common-dialog-loaded"); - Services.obs.removeObserver(observer, "tabmodal-dialog-loaded"); - - aSubject.Dialog.ui.button0.click(); - - executeSoon(function () { - toggleSidebar(currentTest.sidebarName); - currentTest.cleanup(postFunc); - }); - } - Services.obs.addObserver(observer, "common-dialog-loaded", false); - Services.obs.addObserver(observer, "tabmodal-dialog-loaded", false); - - let tree = sidebar.contentDocument.getElementById(currentTest.treeName); - - // Select the inserted places item. - currentTest.selectNode(tree); - - synthesizeClickOnSelectedTreeCell(tree); - // Now, wait for the observer to catch the alert dialog. - // If something goes wrong, the test will time out at this stage. - // Note that for the history sidebar, the URL itself is not opened, - // and Places will show the load-js-data-url-error prompt as an alert - // box, which means that the click actually worked, so it's good enough - // for the purpose of this test. - }); - }, true); - } - - function synthesizeClickOnSelectedTreeCell(aTree) { - let tbo = aTree.treeBoxObject; - is(tbo.view.selection.count, 1, - "The test node should be successfully selected"); - // Get selection rowID. - let min = {}, max = {}; - tbo.view.selection.getRangeAt(0, min, max); - let rowID = min.value; - tbo.ensureRowIsVisible(rowID); - - // Calculate the click coordinates. - let x = {}, y = {}, width = {}, height = {}; - tbo.getCoordsForCellItem(rowID, aTree.columns[0], "text", - x, y, width, height); - x = x.value + width.value / 2; - y = y.value + height.value / 2; - // Simulate the click. - EventUtils.synthesizeMouse(aTree.body, x, y, {}, - aTree.ownerDocument.defaultView); - } - - function changeSidebarDirection(aDirection) { - sidebar.contentDocument.documentElement.style.direction = aDirection; - } - - function runNextTest() { - // Remove eventual tabs created by previous sub-tests. - while (gBrowser.tabs.length > 1) { - gBrowser.removeTab(gBrowser.tabContainer.lastChild); - } - - if (tests.length == 0) { - finish(); - } - else { - // Create a new tab and run the test. - gBrowser.selectedTab = gBrowser.addTab(); - currentTest = tests.shift(); - testPlacesPanel(function() { - changeSidebarDirection("ltr"); - info("Running " + currentTest.desc + " in LTR mode"); - }, - function() { - testPlacesPanel(function() { - // Run the test in RTL mode. - changeSidebarDirection("rtl"); - info("Running " + currentTest.desc + " in RTL mode"); - }, - function() { - runNextTest(); - }); - }); - } - } - - // Ensure history is clean before starting the test. - waitForClearHistory(runNextTest); -} diff --git a/browser/components/places/tests/browser/browser_sort_in_library.js b/browser/components/places/tests/browser/browser_sort_in_library.js deleted file mode 100644 index e59abb2be..000000000 --- a/browser/components/places/tests/browser/browser_sort_in_library.js +++ /dev/null @@ -1,254 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Tests the following bugs: - * - * Bug 443745 - View>Sort>of "alpha" sort items is default to Z>A instead of A>Z - * https://bugzilla.mozilla.org/show_bug.cgi?id=443745 - * - * Bug 444179 - Library>Views>Sort>Sort by Tags does nothing - * https://bugzilla.mozilla.org/show_bug.cgi?id=444179 - * - * Basically, fully tests sorting the placeContent tree in the Places Library - * window. Sorting is verified by comparing the nsINavHistoryResult returned by - * placeContent.result to the expected sort values. - */ - -// Two properties of nsINavHistoryResult control the sort of the tree: -// sortingMode and sortingAnnotation. sortingMode's value is one of the -// nsINavHistoryQueryOptions.SORT_BY_* constants. sortingAnnotation is the -// annotation used to sort for SORT_BY_ANNOTATION_* mode. -// -// This lookup table maps the possible values of anonid's of the treecols to -// objects that represent the treecols' correct state after the user sorts the -// previously unsorted tree by selecting a column from the Views > Sort menu. -// sortingMode is constructed from the key and dir properties (i.e., -// SORT_BY_<key>_<dir>) and sortingAnnotation is checked against anno. anno -// may be undefined if key is not "ANNOTATION". -const SORT_LOOKUP_TABLE = { - title: { key: "TITLE", dir: "ASCENDING" }, - tags: { key: "TAGS", dir: "ASCENDING" }, - url: { key: "URI", dir: "ASCENDING" }, - date: { key: "DATE", dir: "DESCENDING" }, - visitCount: { key: "VISITCOUNT", dir: "DESCENDING" }, - keyword: { key: "KEYWORD", dir: "ASCENDING" }, - dateAdded: { key: "DATEADDED", dir: "DESCENDING" }, - lastModified: { key: "LASTMODIFIED", dir: "DESCENDING" }, - description: { key: "ANNOTATION", - dir: "ASCENDING", - anno: "bookmarkProperties/description" } -}; - -// This is the column that's sorted if one is not specified and the tree is -// currently unsorted. Set it to a key substring in the name of one of the -// nsINavHistoryQueryOptions.SORT_BY_* constants, e.g., "TITLE", "URI". -// Method ViewMenu.setSortColumn in browser/components/places/content/places.js -// determines this value. -const DEFAULT_SORT_KEY = "TITLE"; - -// Part of the test is checking that sorts stick, so each time we sort we need -// to remember it. -let prevSortDir = null; -let prevSortKey = null; - -/////////////////////////////////////////////////////////////////////////////// - -/** - * Ensures that the sort of aTree is aSortingMode and aSortingAnno. - * - * @param aTree - * the tree to check - * @param aSortingMode - * one of the Ci.nsINavHistoryQueryOptions.SORT_BY_* constants - * @param aSortingAnno - * checked only if sorting mode is one of the - * Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_* constants - */ -function checkSort(aTree, aSortingMode, aSortingAnno) { - // The placeContent tree's sort is determined by the nsINavHistoryResult it - // stores. Get it and check that the sort is what the caller expects. - let res = aTree.result; - isnot(res, null, - "sanity check: placeContent.result should not return null"); - - // Check sortingMode. - is(res.sortingMode, aSortingMode, - "column should now have sortingMode " + aSortingMode); - - // Check sortingAnnotation, but only if sortingMode is ANNOTATION. - if ([Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_ASCENDING, - Ci.nsINavHistoryQueryOptions.SORT_BY_ANNOTATION_DESCENDING]. - indexOf(aSortingMode) >= 0) { - is(res.sortingAnnotation, aSortingAnno, - "column should now have sorting annotation " + aSortingAnno); - } -} - -/** - * Sets the sort of aTree. - * - * @param aOrganizerWin - * the Places window - * @param aTree - * the tree to sort - * @param aUnsortFirst - * true if the sort should be set to SORT_BY_NONE before sorting by aCol - * and aDir - * @param aShouldFail - * true if setSortColumn should fail on aCol or aDir - * @param aCol - * the column of aTree by which to sort - * @param aDir - * either "ascending" or "descending" - */ -function setSort(aOrganizerWin, aTree, aUnsortFirst, aShouldFail, aCol, aDir) { - if (aUnsortFirst) { - aOrganizerWin.ViewMenu.setSortColumn(); - checkSort(aTree, Ci.nsINavHistoryQueryOptions.SORT_BY_NONE, ""); - - // Remember the sort key and direction. - prevSortKey = null; - prevSortDir = null; - } - - let failed = false; - try { - aOrganizerWin.ViewMenu.setSortColumn(aCol, aDir); - - // Remember the sort key and direction. - if (!aCol && !aDir) { - prevSortKey = null; - prevSortDir = null; - } - else { - if (aCol) - prevSortKey = SORT_LOOKUP_TABLE[aCol.getAttribute("anonid")].key; - else if (prevSortKey === null) - prevSortKey = DEFAULT_SORT_KEY; - - if (aDir) - prevSortDir = aDir.toUpperCase(); - else if (prevSortDir === null) - prevSortDir = SORT_LOOKUP_TABLE[aCol.getAttribute("anonid")].dir; - } - } catch (exc) { - failed = true; - } - - is(failed, !!aShouldFail, - "setSortColumn on column " + - (aCol ? aCol.getAttribute("anonid") : "(no column)") + - " with direction " + (aDir || "(no direction)") + - " and table previously " + (aUnsortFirst ? "unsorted" : "sorted") + - " should " + (aShouldFail ? "" : "not ") + "fail"); -} - -/** - * Tries sorting by an invalid column and sort direction. - * - * @param aOrganizerWin - * the Places window - * @param aPlaceContentTree - * the placeContent tree in aOrganizerWin - */ -function testInvalid(aOrganizerWin, aPlaceContentTree) { - // Invalid column should fail by throwing an exception. - let bogusCol = document.createElement("treecol"); - bogusCol.setAttribute("anonid", "bogusColumn"); - setSort(aOrganizerWin, aPlaceContentTree, true, true, bogusCol, "ascending"); - - // Invalid direction reverts to SORT_BY_NONE. - setSort(aOrganizerWin, aPlaceContentTree, false, false, null, "bogus dir"); - checkSort(aPlaceContentTree, Ci.nsINavHistoryQueryOptions.SORT_BY_NONE, ""); -} - -/** - * Tests sorting aPlaceContentTree by column only and then by both column - * and direction. - * - * @param aOrganizerWin - * the Places window - * @param aPlaceContentTree - * the placeContent tree in aOrganizerWin - * @param aUnsortFirst - * true if, before each sort we try, we should sort to SORT_BY_NONE - */ -function testSortByColAndDir(aOrganizerWin, aPlaceContentTree, aUnsortFirst) { - let cols = aPlaceContentTree.getElementsByTagName("treecol"); - ok(cols.length > 0, "sanity check: placeContent should contain columns"); - - for (let i = 0; i < cols.length; i++) { - let col = cols.item(i); - ok(col.hasAttribute("anonid"), - "sanity check: column " + col.id + " should have anonid"); - - let colId = col.getAttribute("anonid"); - ok(colId in SORT_LOOKUP_TABLE, - "sanity check: unexpected placeContent column anonid"); - - let sortConst = - "SORT_BY_" + SORT_LOOKUP_TABLE[colId].key + "_" + - (aUnsortFirst ? SORT_LOOKUP_TABLE[colId].dir : prevSortDir); - let expectedSortMode = Ci.nsINavHistoryQueryOptions[sortConst]; - let expectedAnno = SORT_LOOKUP_TABLE[colId].anno || ""; - - // Test sorting by only a column. - setSort(aOrganizerWin, aPlaceContentTree, aUnsortFirst, false, col); - checkSort(aPlaceContentTree, expectedSortMode, expectedAnno); - - // Test sorting by both a column and a direction. - ["ascending", "descending"].forEach(function (dir) { - let sortConst = - "SORT_BY_" + SORT_LOOKUP_TABLE[colId].key + "_" + dir.toUpperCase(); - let expectedSortMode = Ci.nsINavHistoryQueryOptions[sortConst]; - setSort(aOrganizerWin, aPlaceContentTree, aUnsortFirst, false, col, dir); - checkSort(aPlaceContentTree, expectedSortMode, expectedAnno); - }); - } -} - -/** - * Tests sorting aPlaceContentTree by direction only. - * - * @param aOrganizerWin - * the Places window - * @param aPlaceContentTree - * the placeContent tree in aOrganizerWin - * @param aUnsortFirst - * true if, before each sort we try, we should sort to SORT_BY_NONE - */ -function testSortByDir(aOrganizerWin, aPlaceContentTree, aUnsortFirst) { - ["ascending", "descending"].forEach(function (dir) { - let key = (aUnsortFirst ? DEFAULT_SORT_KEY : prevSortKey); - let sortConst = "SORT_BY_" + key + "_" + dir.toUpperCase(); - let expectedSortMode = Ci.nsINavHistoryQueryOptions[sortConst]; - setSort(aOrganizerWin, aPlaceContentTree, aUnsortFirst, false, null, dir); - checkSort(aPlaceContentTree, expectedSortMode, ""); - }); -} - -/////////////////////////////////////////////////////////////////////////////// - -function test() { - waitForExplicitFinish(); - - openLibrary(function (win) { - let tree = win.document.getElementById("placeContent"); - isnot(tree, null, "sanity check: placeContent tree should exist"); - // Run the tests. - testSortByColAndDir(win, tree, true); - testSortByColAndDir(win, tree, false); - testSortByDir(win, tree, true); - testSortByDir(win, tree, false); - testInvalid(win, tree); - // Reset the sort to SORT_BY_NONE. - setSort(win, tree, false, false); - // Close the window and finish. - win.close(); - finish(); - }); -} diff --git a/browser/components/places/tests/browser/browser_toolbar_migration.js b/browser/components/places/tests/browser/browser_toolbar_migration.js deleted file mode 100644 index c344aa1c1..000000000 --- a/browser/components/places/tests/browser/browser_toolbar_migration.js +++ /dev/null @@ -1,135 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/** - * Tests PersonalToolbar migration path. - */ - -let bg = Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIObserver); -let gOriginalMigrationVersion; -const BROWSER_URL = getBrowserURL(); - -let localStore = { - get RDF() Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService), - get store() this.RDF.GetDataSource("rdf:local-store"), - - get toolbar() - { - delete this.toolbar; - let toolbar = this.RDF.GetResource(BROWSER_URL + "#PersonalToolbar"); - // Add the entry to the persisted set for this document if it's not there. - // See XULDocument::Persist. - let doc = this.RDF.GetResource(BROWSER_URL); - let persist = this.RDF.GetResource("http://home.netscape.com/NC-rdf#persist"); - if (!this.store.HasAssertion(doc, persist, toolbar, true)) { - this.store.Assert(doc, persist, toolbar, true); - } - return this.toolbar = toolbar; - }, - - getPersist: function getPersist(aProperty) - { - let property = this.RDF.GetResource(aProperty); - let target = this.store.GetTarget(this.toolbar, property, true); - if (target instanceof Ci.nsIRDFLiteral) - return target.Value; - return null; - }, - - setPersist: function setPersist(aProperty, aValue) - { - let property = this.RDF.GetResource(aProperty); - let value = aValue ? this.RDF.GetLiteral(aValue) : null; - - try { - let oldTarget = this.store.GetTarget(this.toolbar, property, true); - if (oldTarget && value) { - this.store.Change(this.toolbar, property, oldTarget, value); - } - else if (value) { - this.store.Assert(this.toolbar, property, value, true); - } - else if (oldTarget) { - this.store.Unassert(this.toolbar, property, oldTarget); - } - else { - return; - } - } - catch(ex) { - return; - } - this.store.QueryInterface(Ci.nsIRDFRemoteDataSource).Flush(); - } -}; - -let gTests = [ - -function test_explicitly_collapsed_toolbar() -{ - info("An explicitly collapsed toolbar should not be uncollapsed."); - localStore.setPersist("collapsed", "true"); - bg.observe(null, "browser-glue-test", "force-ui-migration"); - is(localStore.getPersist("collapsed"), "true", "Toolbar is collapsed"); -}, - -function test_customized_toolbar() -{ - info("A customized toolbar should be uncollapsed."); - localStore.setPersist("currentset", "splitter"); - bg.observe(null, "browser-glue-test", "force-ui-migration"); - is(localStore.getPersist("collapsed"), "false", "Toolbar has been uncollapsed"); -}, - -function test_many_bookmarks_toolbar() -{ - info("A toolbar with added bookmarks should be uncollapsed."); - let ids = []; - ids.push( - PlacesUtils.bookmarks.insertSeparator(PlacesUtils.toolbarFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX) - ); - ids.push( - PlacesUtils.bookmarks.insertSeparator(PlacesUtils.toolbarFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX) - ); - ids.push( - PlacesUtils.bookmarks.insertSeparator(PlacesUtils.toolbarFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX) - ); - bg.observe(null, "browser-glue-test", "force-ui-migration"); - is(localStore.getPersist("collapsed"), "false", "Toolbar has been uncollapsed"); -}, - -]; - -function test() -{ - gOriginalMigrationVersion = Services.prefs.getIntPref("browser.migration.version"); - registerCleanupFunction(clean); - - if (localStore.getPersist("currentset") !== null) { - info("Toolbar currentset was persisted by a previous test, fixing it."); - localStore.setPersist("currentset", null); - } - - if (localStore.getPersist("collapsed") !== null) { - info("Toolbar collapsed status was persisted by a previous test, fixing it."); - localStore.setPersist("collapsed", null); - } - - while (gTests.length) { - clean(); - Services.prefs.setIntPref("browser.migration.version", 4); - gTests.shift().call(); - } -} - -function clean() -{ - Services.prefs.setIntPref("browser.migration.version", gOriginalMigrationVersion); - localStore.setPersist("currentset", null); - localStore.setPersist("collapsed", null); -} - diff --git a/browser/components/places/tests/browser/browser_views_liveupdate.js b/browser/components/places/tests/browser/browser_views_liveupdate.js deleted file mode 100644 index 506f3d091..000000000 --- a/browser/components/places/tests/browser/browser_views_liveupdate.js +++ /dev/null @@ -1,474 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Tests Places views (menu, toolbar, tree) for liveupdate. - */ - -let toolbar = document.getElementById("PersonalToolbar"); -let wasCollapsed = toolbar.collapsed; - -function test() { - // Uncollapse the personal toolbar if needed. - if (wasCollapsed) - setToolbarVisibility(toolbar, true); - - waitForExplicitFinish(); - - // Sanity checks. - ok(PlacesUtils, "PlacesUtils in context"); - ok(PlacesUIUtils, "PlacesUIUtils in context"); - - // Open bookmarks menu. - var popup = document.getElementById("bookmarksMenuPopup"); - ok(popup, "Menu popup element exists"); - fakeOpenPopup(popup); - - // Open bookmarks sidebar. - var sidebar = document.getElementById("sidebar"); - sidebar.addEventListener("load", function() { - sidebar.removeEventListener("load", arguments.callee, true); - // Need to executeSoon since the tree is initialized on sidebar load. - executeSoon(startTest); - }, true); - toggleSidebar("viewBookmarksSidebar", true); -} - -/** - * Simulates popup opening causing it to populate. - * We cannot just use menu.open, since it would not work on Mac due to native menubar. - */ -function fakeOpenPopup(aPopup) { - var popupEvent = document.createEvent("MouseEvent"); - popupEvent.initMouseEvent("popupshowing", true, true, window, 0, - 0, 0, 0, 0, false, false, false, false, - 0, null); - aPopup.dispatchEvent(popupEvent); -} - -/** - * Adds bookmarks observer, and executes a bunch of bookmarks operations. - */ -function startTest() { - var bs = PlacesUtils.bookmarks; - // Add observers. - bs.addObserver(bookmarksObserver, false); - PlacesUtils.annotations.addObserver(bookmarksObserver, false); - var addedBookmarks = []; - - // MENU - info("*** Acting on menu bookmarks"); - var id = bs.insertBookmark(bs.bookmarksMenuFolder, - PlacesUtils._uri("http://bm1.mozilla.org/"), - bs.DEFAULT_INDEX, - "bm1"); - bs.setItemTitle(id, "bm1_edited"); - addedBookmarks.push(id); - id = bs.insertBookmark(bs.bookmarksMenuFolder, - PlacesUtils._uri("place:"), - bs.DEFAULT_INDEX, - "bm2"); - bs.setItemTitle(id, ""); - addedBookmarks.push(id); - id = bs.insertSeparator(bs.bookmarksMenuFolder, bs.DEFAULT_INDEX); - addedBookmarks.push(id); - id = bs.createFolder(bs.bookmarksMenuFolder, - "bmf", - bs.DEFAULT_INDEX); - bs.setItemTitle(id, "bmf_edited"); - addedBookmarks.push(id); - id = bs.insertBookmark(id, - PlacesUtils._uri("http://bmf1.mozilla.org/"), - bs.DEFAULT_INDEX, - "bmf1"); - bs.setItemTitle(id, "bmf1_edited"); - addedBookmarks.push(id); - bs.moveItem(id, bs.bookmarksMenuFolder, 0); - - // TOOLBAR - info("*** Acting on toolbar bookmarks"); - id = bs.insertBookmark(bs.toolbarFolder, - PlacesUtils._uri("http://tb1.mozilla.org/"), - bs.DEFAULT_INDEX, - "tb1"); - bs.setItemTitle(id, "tb1_edited"); - addedBookmarks.push(id); - // Test live update of title. - bs.setItemTitle(id, "tb1_edited"); - id = bs.insertBookmark(bs.toolbarFolder, - PlacesUtils._uri("place:"), - bs.DEFAULT_INDEX, - "tb2"); - bs.setItemTitle(id, ""); - addedBookmarks.push(id); - id = bs.insertSeparator(bs.toolbarFolder, bs.DEFAULT_INDEX); - addedBookmarks.push(id); - id = bs.createFolder(bs.toolbarFolder, - "tbf", - bs.DEFAULT_INDEX); - bs.setItemTitle(id, "tbf_edited"); - addedBookmarks.push(id); - id = bs.insertBookmark(id, - PlacesUtils._uri("http://tbf1.mozilla.org/"), - bs.DEFAULT_INDEX, - "tbf1"); - bs.setItemTitle(id, "tbf1_edited"); - addedBookmarks.push(id); - bs.moveItem(id, bs.toolbarFolder, 0); - - // UNSORTED - info("*** Acting on unsorted bookmarks"); - id = bs.insertBookmark(bs.unfiledBookmarksFolder, - PlacesUtils._uri("http://ub1.mozilla.org/"), - bs.DEFAULT_INDEX, - "ub1"); - bs.setItemTitle(id, "ub1_edited"); - addedBookmarks.push(id); - id = bs.insertBookmark(bs.unfiledBookmarksFolder, - PlacesUtils._uri("place:"), - bs.DEFAULT_INDEX, - "ub2"); - bs.setItemTitle(id, "ub2_edited"); - addedBookmarks.push(id); - id = bs.insertSeparator(bs.unfiledBookmarksFolder, bs.DEFAULT_INDEX); - addedBookmarks.push(id); - id = bs.createFolder(bs.unfiledBookmarksFolder, - "ubf", - bs.DEFAULT_INDEX); - bs.setItemTitle(id, "ubf_edited"); - addedBookmarks.push(id); - id = bs.insertBookmark(id, - PlacesUtils._uri("http://ubf1.mozilla.org/"), - bs.DEFAULT_INDEX, - "bubf1"); - bs.setItemTitle(id, "bubf1_edited"); - addedBookmarks.push(id); - bs.moveItem(id, bs.unfiledBookmarksFolder, 0); - - // Remove all added bookmarks. - addedBookmarks.forEach(function (aItem) { - // If we remove an item after its containing folder has been removed, - // this will throw, but we can ignore that. - try { - bs.removeItem(aItem); - } catch (ex) {} - }); - - // Remove observers. - bs.removeObserver(bookmarksObserver); - PlacesUtils.annotations.removeObserver(bookmarksObserver); - finishTest(); -} - -/** - * Restores browser state and calls finish. - */ -function finishTest() { - // Close bookmarks sidebar. - toggleSidebar("viewBookmarksSidebar", false); - - // Collapse the personal toolbar if needed. - if (wasCollapsed) - setToolbarVisibility(toolbar, false); - - finish(); -} - -/** - * The observer is where magic happens, for every change we do it will look for - * nodes positions in the affected views. - */ -var bookmarksObserver = { - QueryInterface: XPCOMUtils.generateQI([ - Ci.nsINavBookmarkObserver - , Ci.nsIAnnotationObserver - ]), - - // nsIAnnotationObserver - onItemAnnotationSet: function() {}, - onItemAnnotationRemoved: function() {}, - onPageAnnotationSet: function() {}, - onPageAnnotationRemoved: function() {}, - - // nsINavBookmarkObserver - onItemAdded: function PSB_onItemAdded(aItemId, aFolderId, aIndex, - aItemType, aURI) { - var views = getViewsForFolder(aFolderId); - ok(views.length > 0, "Found affected views (" + views.length + "): " + views); - - // Check that item has been added in the correct position. - for (var i = 0; i < views.length; i++) { - var [node, index] = searchItemInView(aItemId, views[i]); - isnot(node, null, "Found new Places node in " + views[i]); - is(index, aIndex, "Node is at index " + index); - } - }, - - onItemRemoved: function PSB_onItemRemoved(aItemId, aFolder, aIndex, - aItemType) { - var views = getViewsForFolder(aFolderId); - ok(views.length > 0, "Found affected views (" + views.length + "): " + views); - // Check that item has been removed. - for (var i = 0; i < views.length; i++) { - var node = null; - var index = null; - [node, index] = searchItemInView(aItemId, views[i]); - is(node, null, "Places node not found in " + views[i]); - } - }, - - onItemMoved: function(aItemId, - aOldFolderId, aOldIndex, - aNewFolderId, aNewIndex, - aItemType) { - var views = getViewsForFolder(aNewFolderId); - ok(views.length > 0, "Found affected views: " + views); - - // Check that item has been moved in the correct position. - for (var i = 0; i < views.length; i++) { - var node = null; - var index = null; - [node, index] = searchItemInView(aItemId, views[i]); - isnot(node, null, "Found new Places node in " + views[i]); - is(index, aNewIndex, "Node is at index " + index); - } - }, - - onBeginUpdateBatch: function PSB_onBeginUpdateBatch() {}, - onEndUpdateBatch: function PSB_onEndUpdateBatch() {}, - onItemVisited: function() {}, - - onItemChanged: function PSB_onItemChanged(aItemId, aProperty, - aIsAnnotationProperty, aNewValue, - aLastModified, aItemType, - aParentId) { - if (aProperty !== "title") - return; - - var views = getViewsForFolder(aParentId); - ok(views.length > 0, "Found affected views (" + views.length + "): " + views); - - // Check that item has been moved in the correct position. - let validator = function(aElementOrTreeIndex) { - if (typeof(aElementOrTreeIndex) == "number") { - var sidebar = document.getElementById("sidebar"); - var tree = sidebar.contentDocument.getElementById("bookmarks-view"); - let cellText = tree.view.getCellText(aElementOrTreeIndex, - tree.columns.getColumnAt(0)); - if (!aNewValue) - return cellText == PlacesUIUtils.getBestTitle(tree.view.nodeForTreeIndex(aElementOrTreeIndex), true); - return cellText == aNewValue; - } - else { - if (!aNewValue && aElementOrTreeIndex.localName != "toolbarbutton") - return aElementOrTreeIndex.getAttribute("label") == PlacesUIUtils.getBestTitle(aElementOrTreeIndex._placesNode); - return aElementOrTreeIndex.getAttribute("label") == aNewValue; - } - }; - - for (var i = 0; i < views.length; i++) { - var [node, index, valid] = searchItemInView(aItemId, views[i], validator); - isnot(node, null, "Found changed Places node in " + views[i]); - is(node.title, aNewValue, "Node has correct title: " + aNewValue); - ok(valid, "Node element has correct label: " + aNewValue); - } - } -}; - -/** - * Search an item id in a view. - * - * @param aItemId - * item id of the item to search. - * @param aView - * either "toolbar", "menu" or "sidebar" - * @param aValidator - * function to check validity of the found node element. - * @returns [node, index, valid] or [null, null, false] if not found. - */ -function searchItemInView(aItemId, aView, aValidator) { - switch (aView) { - case "toolbar": - return getNodeForToolbarItem(aItemId, aValidator); - case "menu": - return getNodeForMenuItem(aItemId, aValidator); - case "sidebar": - return getNodeForSidebarItem(aItemId, aValidator); - } - - return [null, null, false]; -} - -/** - * Get places node and index for an itemId in bookmarks toolbar view. - * - * @param aItemId - * item id of the item to search. - * @returns [node, index] or [null, null] if not found. - */ -function getNodeForToolbarItem(aItemId, aValidator) { - var toolbar = document.getElementById("PlacesToolbarItems"); - - function findNode(aContainer) { - var children = aContainer.childNodes; - for (var i = 0, staticNodes = 0; i < children.length; i++) { - var child = children[i]; - - // Is this a Places node? - if (!child._placesNode) { - staticNodes++; - continue; - } - - if (child._placesNode.itemId == aItemId) { - let valid = aValidator ? aValidator(child) : true; - return [child._placesNode, i - staticNodes, valid]; - } - - // Don't search in queries, they could contain our item in a - // different position. Search only folders - if (PlacesUtils.nodeIsFolder(child._placesNode)) { - var popup = child.lastChild; - popup.showPopup(popup); - var foundNode = findNode(popup); - popup.hidePopup(); - if (foundNode[0] != null) - return foundNode; - } - } - return [null, null]; - } - - return findNode(toolbar); -} - -/** - * Get places node and index for an itemId in bookmarks menu view. - * - * @param aItemId - * item id of the item to search. - * @returns [node, index] or [null, null] if not found. - */ -function getNodeForMenuItem(aItemId, aValidator) { - var menu = document.getElementById("bookmarksMenu"); - - function findNode(aContainer) { - var children = aContainer.childNodes; - for (var i = 0, staticNodes = 0; i < children.length; i++) { - var child = children[i]; - - // Is this a Places node? - if (!child._placesNode) { - staticNodes++; - continue; - } - - if (child._placesNode.itemId == aItemId) { - let valid = aValidator ? aValidator(child) : true; - return [child._placesNode, i - staticNodes, valid]; - } - - // Don't search in queries, they could contain our item in a - // different position. Search only folders - if (PlacesUtils.nodeIsFolder(child._placesNode)) { - var popup = child.lastChild; - fakeOpenPopup(popup); - var foundNode = findNode(popup); - - child.open = false; - if (foundNode[0] != null) - return foundNode; - } - } - return [null, null, false]; - } - - return findNode(menu.lastChild); -} - -/** - * Get places node and index for an itemId in sidebar tree view. - * - * @param aItemId - * item id of the item to search. - * @returns [node, index] or [null, null] if not found. - */ -function getNodeForSidebarItem(aItemId, aValidator) { - var sidebar = document.getElementById("sidebar"); - var tree = sidebar.contentDocument.getElementById("bookmarks-view"); - - function findNode(aContainerIndex) { - if (tree.view.isContainerEmpty(aContainerIndex)) - return [null, null, false]; - - // The rowCount limit is just for sanity, but we will end looping when - // we have checked the last child of this container or we have found node. - for (var i = aContainerIndex + 1; i < tree.view.rowCount; i++) { - var node = tree.view.nodeForTreeIndex(i); - - if (node.itemId == aItemId) { - // Minus one because we want relative index inside the container. - let valid = aValidator ? aValidator(i) : true; - return [node, i - tree.view.getParentIndex(i) - 1, valid]; - } - - if (PlacesUtils.nodeIsFolder(node)) { - // Open container. - tree.view.toggleOpenState(i); - // Search inside it. - var foundNode = findNode(i); - // Close container. - tree.view.toggleOpenState(i); - // Return node if found. - if (foundNode[0] != null) - return foundNode; - } - - // We have finished walking this container. - if (!tree.view.hasNextSibling(aContainerIndex + 1, i)) - break; - } - return [null, null, false] - } - - // Root node is hidden, so we need to manually walk the first level. - for (var i = 0; i < tree.view.rowCount; i++) { - // Open container. - tree.view.toggleOpenState(i); - // Search inside it. - var foundNode = findNode(i); - // Close container. - tree.view.toggleOpenState(i); - // Return node if found. - if (foundNode[0] != null) - return foundNode; - } - return [null, null, false]; -} - -/** - * Get views affected by changes to a folder. - * - * @param aFolderId: - * item id of the folder we have changed. - * @returns a subset of views: ["toolbar", "menu", "sidebar"] - */ -function getViewsForFolder(aFolderId) { - var rootId = aFolderId; - while (!PlacesUtils.isRootItem(rootId)) - rootId = PlacesUtils.bookmarks.getFolderIdForItem(rootId); - - switch (rootId) { - case PlacesUtils.toolbarFolderId: - return ["toolbar", "sidebar"] - break; - case PlacesUtils.bookmarksMenuFolderId: - return ["menu", "sidebar"] - break; - case PlacesUtils.unfiledBookmarksFolderId: - return ["sidebar"] - break; - } - return new Array(); -} diff --git a/browser/components/places/tests/browser/frameLeft.html b/browser/components/places/tests/browser/frameLeft.html deleted file mode 100644 index 5a54fe353..000000000 --- a/browser/components/places/tests/browser/frameLeft.html +++ /dev/null @@ -1,8 +0,0 @@ -<html> - <head> - <title>Left frame</title> - </head> - <body> - <a id="clickme" href="frameRight.html" target="right">Open page in the right frame.</a> - </body> -</html> diff --git a/browser/components/places/tests/browser/frameRight.html b/browser/components/places/tests/browser/frameRight.html deleted file mode 100644 index 226accc34..000000000 --- a/browser/components/places/tests/browser/frameRight.html +++ /dev/null @@ -1,8 +0,0 @@ -<html> - <head> - <title>Right Frame</title> - </head> - <body> - This is the right frame. - </body> -</html> diff --git a/browser/components/places/tests/browser/framedPage.html b/browser/components/places/tests/browser/framedPage.html deleted file mode 100644 index d388562e6..000000000 --- a/browser/components/places/tests/browser/framedPage.html +++ /dev/null @@ -1,9 +0,0 @@ -<html> - <head> - <title>Framed page</title> - </head> - <frameset cols="*,*"> - <frame name="left" src="frameLeft.html"> - <frame name="right" src="about:mozilla"> - </frameset> -</html> diff --git a/browser/components/places/tests/browser/head.js b/browser/components/places/tests/browser/head.js deleted file mode 100644 index 8020052a6..000000000 --- a/browser/components/places/tests/browser/head.js +++ /dev/null @@ -1,147 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -Components.utils.import("resource://gre/modules/NetUtil.jsm"); - -// We need to cache this before test runs... -let cachedLeftPaneFolderIdGetter; -let (getter = PlacesUIUtils.__lookupGetter__("leftPaneFolderId")) { - if (!cachedLeftPaneFolderIdGetter && typeof(getter) == "function") - cachedLeftPaneFolderIdGetter = getter; -} -// ...And restore it when test ends. -registerCleanupFunction(function(){ - let (getter = PlacesUIUtils.__lookupGetter__("leftPaneFolderId")) { - if (cachedLeftPaneFolderIdGetter && typeof(getter) != "function") - PlacesUIUtils.__defineGetter__("leftPaneFolderId", - cachedLeftPaneFolderIdGetter); - } -}); - -function openLibrary(callback, aLeftPaneRoot) { - let library = window.openDialog("chrome://browser/content/places/places.xul", - "", "chrome,toolbar=yes,dialog=no,resizable", - aLeftPaneRoot); - waitForFocus(function () { - callback(library); - }, library); - - return library; -} - -/** - * Waits for completion of a clear history operation, before - * proceeding with aCallback. - * - * @param aCallback - * Function to be called when done. - */ -function waitForClearHistory(aCallback) { - Services.obs.addObserver(function observeCH(aSubject, aTopic, aData) { - Services.obs.removeObserver(observeCH, PlacesUtils.TOPIC_EXPIRATION_FINISHED); - aCallback(); - }, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false); - PlacesUtils.bhistory.removeAllPages(); -} - -/** - * Waits for all pending async statements on the default connection, before - * proceeding with aCallback. - * - * @param aCallback - * Function to be called when done. - * @param aScope - * Scope for the callback. - * @param aArguments - * Arguments array for the callback. - * - * @note The result is achieved by asynchronously executing a query requiring - * a write lock. Since all statements on the same connection are - * serialized, the end of this write operation means that all writes are - * complete. Note that WAL makes so that writers don't block readers, but - * this is a problem only across different connections. - */ -function waitForAsyncUpdates(aCallback, aScope, aArguments) -{ - let scope = aScope || this; - let args = aArguments || []; - let db = PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase) - .DBConnection; - let begin = db.createAsyncStatement("BEGIN EXCLUSIVE"); - begin.executeAsync(); - begin.finalize(); - - let commit = db.createAsyncStatement("COMMIT"); - commit.executeAsync({ - handleResult: function() {}, - handleError: function() {}, - handleCompletion: function(aReason) - { - aCallback.apply(scope, args); - } - }); - commit.finalize(); -} - -/** - * Asynchronously adds visits to a page, invoking a callback function when done. - * - * @param aPlaceInfo - * Can be an nsIURI, in such a case a single LINK visit will be added. - * Otherwise can be an object describing the visit to add, or an array - * of these objects: - * { uri: nsIURI of the page, - * transition: one of the TRANSITION_* from nsINavHistoryService, - * [optional] title: title of the page, - * [optional] visitDate: visit date in microseconds from the epoch - * [optional] referrer: nsIURI of the referrer for this visit - * } - * @param [optional] aCallback - * Function to be invoked on completion. - * @param [optional] aStack - * The stack frame used to report errors. - */ -function addVisits(aPlaceInfo, aWindow, aCallback, aStack) { - let stack = aStack || Components.stack.caller; - let places = []; - if (aPlaceInfo instanceof Ci.nsIURI) { - places.push({ uri: aPlaceInfo }); - } - else if (Array.isArray(aPlaceInfo)) { - places = places.concat(aPlaceInfo); - } else { - places.push(aPlaceInfo) - } - - // Create mozIVisitInfo for each entry. - let now = Date.now(); - for (let i = 0; i < places.length; i++) { - if (!places[i].title) { - places[i].title = "test visit for " + places[i].uri.spec; - } - places[i].visits = [{ - transitionType: places[i].transition === undefined ? Ci.nsINavHistoryService.TRANSITION_LINK - : places[i].transition, - visitDate: places[i].visitDate || (now++) * 1000, - referrerURI: places[i].referrer - }]; - } - - aWindow.PlacesUtils.asyncHistory.updatePlaces( - places, - { - handleError: function AAV_handleError() { - throw("Unexpected error in adding visit."); - }, - handleResult: function () {}, - handleCompletion: function UP_handleCompletion() { - if (aCallback) - aCallback(); - } - } - ); -} - -XPCOMUtils.defineLazyModuleGetter(this, "Promise", - "resource://gre/modules/commonjs/sdk/core/promise.js"); - diff --git a/browser/components/places/tests/browser/moz.build b/browser/components/places/tests/browser/moz.build deleted file mode 100644 index 895d11993..000000000 --- a/browser/components/places/tests/browser/moz.build +++ /dev/null @@ -1,6 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - diff --git a/browser/components/places/tests/browser/sidebarpanels_click_test_page.html b/browser/components/places/tests/browser/sidebarpanels_click_test_page.html deleted file mode 100644 index c73eaa540..000000000 --- a/browser/components/places/tests/browser/sidebarpanels_click_test_page.html +++ /dev/null @@ -1,7 +0,0 @@ -<html> -<head> - <title>browser_sidebarpanels_click.js test page</title> -</head> -<body onload="alert('test');"> -</body> -</html> diff --git a/browser/components/places/tests/chrome/Makefile.in b/browser/components/places/tests/chrome/Makefile.in deleted file mode 100644 index 06fc35cef..000000000 --- a/browser/components/places/tests/chrome/Makefile.in +++ /dev/null @@ -1,26 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -DEPTH = @DEPTH@ -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ -relativesrcdir = @relativesrcdir@ - -include $(DEPTH)/config/autoconf.mk - -MOCHITEST_CHROME_FILES = \ - head.js \ - test_treeview_date.xul \ - test_bug485100-change-case-loses-tag.xul \ - test_bug427633_no_newfolder_if_noip.xul \ - test_0_multiple_left_pane.xul \ - test_0_bug510634.xul \ - test_bug549192.xul \ - test_bug549491.xul \ - test_editBookmarkOverlay_tags_liveUpdate.xul \ - test_bug631374_tags_selector_scroll.xul \ - $(NULL) - -include $(topsrcdir)/config/rules.mk diff --git a/browser/components/places/tests/chrome/head.js b/browser/components/places/tests/chrome/head.js deleted file mode 100644 index 878c28c92..000000000 --- a/browser/components/places/tests/chrome/head.js +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Asynchronously adds visits to a page, invoking a callback function when done. - * - * @param aPlaceInfo - * Can be an nsIURI, in such a case a single LINK visit will be added. - * Otherwise can be an object describing the visit to add, or an array - * of these objects: - * { uri: nsIURI of the page, - * transition: one of the TRANSITION_* from nsINavHistoryService, - * [optional] title: title of the page, - * [optional] visitDate: visit date in microseconds from the epoch - * [optional] referrer: nsIURI of the referrer for this visit - * } - * @param [optional] aCallback - * Function to be invoked on completion. - */ -function addVisits(aPlaceInfo, aCallback) { - let places = []; - if (aPlaceInfo instanceof Ci.nsIURI) { - places.push({ uri: aPlaceInfo }); - } - else if (Array.isArray(aPlaceInfo)) { - places = places.concat(aPlaceInfo); - } else { - places.push(aPlaceInfo) - } - - // Create mozIVisitInfo for each entry. - let now = Date.now(); - for (let i = 0; i < places.length; i++) { - if (!places[i].title) { - places[i].title = "test visit for " + places[i].uri.spec; - } - places[i].visits = [{ - transitionType: places[i].transition === undefined ? PlacesUtils.history.TRANSITION_LINK - : places[i].transition, - visitDate: places[i].visitDate || (now++) * 1000, - referrerURI: places[i].referrer - }]; - } - - PlacesUtils.asyncHistory.updatePlaces( - places, - { - handleError: function AAV_handleError() { - throw("Unexpected error in adding visit."); - }, - handleResult: function () {}, - handleCompletion: function UP_handleCompletion() { - if (aCallback) - aCallback(); - } - } - ); -} - -/** - * Clears history invoking callback when done. - */ -function waitForClearHistory(aCallback) { - const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished"; - Services.obs.addObserver(function observer(aSubject, aTopic, aData) { - Services.obs.removeObserver(observer, TOPIC_EXPIRATION_FINISHED); - aCallback(); - }, TOPIC_EXPIRATION_FINISHED, false); - Cc["@mozilla.org/browser/nav-history-service;1"] - .getService(Ci.nsINavHistoryService) - .QueryInterface(Ci.nsIBrowserHistory).removeAllPages(); -} diff --git a/browser/components/places/tests/chrome/moz.build b/browser/components/places/tests/chrome/moz.build deleted file mode 100644 index 895d11993..000000000 --- a/browser/components/places/tests/chrome/moz.build +++ /dev/null @@ -1,6 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - diff --git a/browser/components/places/tests/chrome/test_0_bug510634.xul b/browser/components/places/tests/chrome/test_0_bug510634.xul deleted file mode 100644 index 1ff1c960b..000000000 --- a/browser/components/places/tests/chrome/test_0_bug510634.xul +++ /dev/null @@ -1,100 +0,0 @@ -<?xml version="1.0"?> - -<!-- This Source Code Form is subject to the terms of the Mozilla Public - - License, v. 2.0. If a copy of the MPL was not distributed with this - - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> - -<?xml-stylesheet href="chrome://global/skin" type="text/css"?> -<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" - type="text/css"?> - -<?xml-stylesheet href="chrome://browser/content/places/places.css"?> -<?xml-stylesheet href="chrome://browser/skin/places/places.css"?> -<?xul-overlay href="chrome://browser/content/places/placesOverlay.xul"?> - -<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" - title="510634: Wrong icons on bookmarks sidebar" - onload="runTest();"> - - <script type="application/javascript" - src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> - - <body xmlns="http://www.w3.org/1999/xhtml" /> - - <tree id="tree" - type="places" - flex="1"> - <treecols> - <treecol label="Title" id="title" anonid="title" primary="true" ordinal="1" flex="1"/> - </treecols> - <treechildren flex="1"/> - </tree> - - <script type="application/javascript"> - <![CDATA[ - - /** - * Bug 510634 - Wrong icons on bookmarks sidebar - * https://bugzilla.mozilla.org/show_bug.cgi?id=510634 - * - * Ensures that properties for special queries are set on their tree nodes, - * even if PlacesUIUtils.leftPaneFolderId was not initialized. - */ - - SimpleTest.waitForExplicitFinish(); - - // converts nsISupportsArray of atoms to a simple JS-strings array - function runTest() { - // We need to cache and restore this getter in order to simulate - // Bug 510634 - let cachedLeftPaneFolderIdGetter = - PlacesUIUtils.__lookupGetter__("leftPaneFolderId"); - // Must also cache and restore this getter as it is affected by - // leftPaneFolderId, from bug 564900. - let cachedAllBookmarksFolderIdGetter = - PlacesUIUtils.__lookupGetter__("allBookmarksFolderId"); - - let leftPaneFolderId = PlacesUIUtils.leftPaneFolderId; - - // restore the getter - PlacesUIUtils.__defineGetter__("leftPaneFolderId", cachedLeftPaneFolderIdGetter); - - // Setup the places tree contents. - let tree = document.getElementById("tree"); - tree.place = "place:queryType=1&folder=" + leftPaneFolderId; - - // The query-property is set on the title column for each row. - let titleColumn = tree.treeBoxObject.columns.getColumnAt(0); - - // Open All Bookmarks - tree.selectItems([PlacesUIUtils.leftPaneQueries["AllBookmarks"]]); - PlacesUtils.asContainer(tree.selectedNode).containerOpen = true; - is(PlacesUIUtils.allBookmarksFolderId, tree.selectedNode.itemId, - "Opened All Bookmarks"); - - ["History", "Downloads", "Tags", "AllBookmarks", "BookmarksToolbar", - "BookmarksMenu", "UnfiledBookmarks"].forEach( - function(aQueryName, aRow) { - let found = false; - for (let i = 0; i < tree.view.rowCount && !found; i++) { - rowProperties = tree.view.getCellProperties(i, titleColumn).split(" "); - found = rowProperties.indexOf("OrganizerQuery_" + aQueryName) != -1; - } - ok(found, "OrganizerQuery_" + aQueryName + " is set"); - } - ); - - // Close the root node - tree.result.root.containerOpen = false; - - // Restore the getters for the next test. - PlacesUIUtils.__defineGetter__("leftPaneFolderId", cachedLeftPaneFolderIdGetter); - PlacesUIUtils.__defineGetter__("allBookmarksFolderId", - cachedAllBookmarksFolderIdGetter); - - SimpleTest.finish(); - } - - ]]> - </script> -</window> diff --git a/browser/components/places/tests/chrome/test_0_multiple_left_pane.xul b/browser/components/places/tests/chrome/test_0_multiple_left_pane.xul deleted file mode 100644 index 39dddcba7..000000000 --- a/browser/components/places/tests/chrome/test_0_multiple_left_pane.xul +++ /dev/null @@ -1,82 +0,0 @@ -<?xml version="1.0"?> - -<!-- This Source Code Form is subject to the terms of the Mozilla Public - - License, v. 2.0. If a copy of the MPL was not distributed with this - - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> - -<!-- Bug 466422: - - Check that we replace the left pane with a correct one if it gets corrupted - - and we end up having more than one. --> - -<?xml-stylesheet href="chrome://global/skin" type="text/css"?> -<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" - type="text/css"?> - -<?xml-stylesheet href="chrome://browser/content/places/places.css"?> -<?xml-stylesheet href="chrome://browser/skin/places/places.css"?> - -<?xul-overlay href="chrome://browser/content/places/placesOverlay.xul"?> - -<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" - title="Test handling of multiple left pane folders" - onload="runTest();"> - - <script type="application/javascript" - src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> - - <body xmlns="http://www.w3.org/1999/xhtml"> - <p id="display"></p> - <div id="content" style="display: none"></div> - <pre id="test"></pre> - </body> - - <script type="application/javascript"> - <![CDATA[ - - function runTest() { - // Sanity checks. - ok(PlacesUtils, "PlacesUtils is running in chrome context"); - ok(PlacesUIUtils, "PlacesUIUtils is running in chrome context"); - ok(PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION > 0, - "Left pane version in chrome context, " + - "current version is: " + PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION ); - - var fakeLeftPanes = []; - var as = PlacesUtils.annotations; - var bs = PlacesUtils.bookmarks; - - // We need 2 left pane folders to simulate a corrupt profile. - do { - let leftPaneItems = as.getItemsWithAnnotation(PlacesUIUtils.ORGANIZER_FOLDER_ANNO); - // Create a fake left pane folder. - let fakeLeftPaneRoot = bs.createFolder(PlacesUtils.placesRootId, "", - bs.DEFAULT_INDEX); - as.setItemAnnotation(fakeLeftPaneRoot, PlacesUIUtils.ORGANIZER_FOLDER_ANNO, - PlacesUIUtils.ORGANIZER_LEFTPANE_VERSION, 0, - as.EXPIRE_NEVER); - fakeLeftPanes.push(fakeLeftPaneRoot); - } while (fakeLeftPanes.length < 2); - - // Initialize the left pane queries. - PlacesUIUtils.leftPaneFolderId; - - // Check left pane. - ok(PlacesUIUtils.leftPaneFolderId > 0, - "Left pane folder correctly created"); - var leftPaneItems = as.getItemsWithAnnotation(PlacesUIUtils.ORGANIZER_FOLDER_ANNO); - is(leftPaneItems.length, 1, - "We correctly have only 1 left pane folder"); - - // Check that all old left pane items have been removed. - fakeLeftPanes.forEach(function(aItemId) { - try { - bs.getItemTitle(aItemId); - throw("This folder should have been removed"); - } catch (ex) {} - }); - - } - ]]> - </script> - -</window> diff --git a/browser/components/places/tests/chrome/test_bug427633_no_newfolder_if_noip.xul b/browser/components/places/tests/chrome/test_bug427633_no_newfolder_if_noip.xul deleted file mode 100644 index c58f380bf..000000000 --- a/browser/components/places/tests/chrome/test_bug427633_no_newfolder_if_noip.xul +++ /dev/null @@ -1,86 +0,0 @@ -<?xml version="1.0"?> - -<!-- This Source Code Form is subject to the terms of the Mozilla Public - - License, v. 2.0. If a copy of the MPL was not distributed with this - - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> - -<?xml-stylesheet href="chrome://global/skin" type="text/css"?> -<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" - type="text/css"?> - -<?xml-stylesheet href="chrome://browser/skin/places/editBookmarkOverlay.css"?> -<?xml-stylesheet href="chrome://browser/content/places/places.css"?> -<?xml-stylesheet href="chrome://browser/skin/places/places.css"?> - -<?xul-overlay href="chrome://browser/content/places/placesOverlay.xul"?> -<?xul-overlay href="chrome://browser/content/places/editBookmarkOverlay.xul"?> - -<!DOCTYPE window [ - <!ENTITY % editBookmarkOverlayDTD SYSTEM "chrome://browser/locale/places/editBookmarkOverlay.dtd"> - %editBookmarkOverlayDTD; -]> - -<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" - title="Bug 427633 - Disable creating a New Folder in the bookmarks dialogs if insertionPoint is invalid" - onload="runTest();"> - - <script type="application/javascript" - src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> - <script type="application/javascript" - src="chrome://browser/content/places/editBookmarkOverlay.js"/> - - <body xmlns="http://www.w3.org/1999/xhtml" /> - - <vbox id="editBookmarkPanelContent"/> - - <script type="application/javascript"> - <![CDATA[ - - /** - * Bug 427633 - Disable creating a New Folder in the bookmarks dialogs if - * insertionPoint is invalid. - */ - - function runTest() { - var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. - getService(Ci.nsINavBookmarksService); - var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - function uri(spec) { - return ios.newURI(spec, null, null); - } - - // Add a bookmark. - var itemId = bs.insertBookmark(PlacesUtils.toolbarFolderId, - uri("http://www.example.com/"), - bs.DEFAULT_INDEX, - "mozilla"); - - // Init panel. - ok(gEditItemOverlay, "gEditItemOverlay is in context"); - gEditItemOverlay.initPanel(itemId); - ok(gEditItemOverlay._initialized, "gEditItemOverlay is initialized"); - // We must be sure tree is initialized, so we wait for place to be set. - SimpleTest.waitForExplicitFinish(); - var tree = gEditItemOverlay._element("folderTree"); - tree.addEventListener("DOMAttrModified", function(event) { - if (event.attrName != "place") - return; - tree.removeEventListener("DOMAttrModified", arguments.callee, false); - SimpleTest.executeSoon(function() { - tree.view.selection.clearSelection(); - ok(document.getElementById("editBMPanel_newFolderButton").disabled, - "New folder button is disabled if there's no selection"); - - // Cleanup. - bs.removeItem(itemId); - SimpleTest.finish(); - }); - }, false); - // Open the folder tree. - document.getElementById("editBMPanel_foldersExpander").doCommand(); - } - ]]> - </script> - -</window> diff --git a/browser/components/places/tests/chrome/test_bug485100-change-case-loses-tag.xul b/browser/components/places/tests/chrome/test_bug485100-change-case-loses-tag.xul deleted file mode 100644 index 7b7f3669d..000000000 --- a/browser/components/places/tests/chrome/test_bug485100-change-case-loses-tag.xul +++ /dev/null @@ -1,85 +0,0 @@ -<?xml version="1.0"?> - -<!-- This Source Code Form is subject to the terms of the Mozilla Public - - License, v. 2.0. If a copy of the MPL was not distributed with this - - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> - -<?xml-stylesheet href="chrome://global/skin" type="text/css"?> -<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" - type="text/css"?> - -<?xml-stylesheet href="chrome://browser/skin/places/editBookmarkOverlay.css"?> -<?xml-stylesheet href="chrome://browser/content/places/places.css"?> -<?xml-stylesheet href="chrome://browser/skin/places/places.css"?> - -<?xul-overlay href="chrome://browser/content/places/placesOverlay.xul"?> -<?xul-overlay href="chrome://browser/content/places/editBookmarkOverlay.xul"?> - -<!DOCTYPE window [ - <!ENTITY % editBookmarkOverlayDTD SYSTEM "chrome://browser/locale/places/editBookmarkOverlay.dtd"> - %editBookmarkOverlayDTD; -]> - -<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" - title="485100: Exchanging a letter of a tag name with its big/small equivalent removes tag from bookmark" - onload="runTest();"> - - <script type="application/javascript" - src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> - <script type="application/javascript" - src="chrome://browser/content/places/editBookmarkOverlay.js"/> - - <body xmlns="http://www.w3.org/1999/xhtml" /> - - <vbox id="editBookmarkPanelContent"/> - - <script type="application/javascript"> - <![CDATA[ - - function runTest() { - var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. - getService(Ci.nsINavBookmarksService); - var ts = Cc["@mozilla.org/browser/tagging-service;1"]. - getService(Ci.nsITaggingService); - var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - function uri(spec) { - return ios.newURI(spec, null, null); - } - - var testURI = uri("http://www.example.com/"); - var testTag = "foo"; - var testTagUpper = "Foo"; - - // Add a bookmark - var itemId = bs.insertBookmark(bs.toolbarFolder, - testURI, - bs.DEFAULT_INDEX, - "mozilla"); - - // Init panel - ok(gEditItemOverlay, "gEditItemOverlay is in context"); - gEditItemOverlay.initPanel(itemId); - - // add a tag - document.getElementById("editBMPanel_tagsField").value = testTag; - gEditItemOverlay.onTagsFieldBlur(); - - // test that the tag has been added in the backend - is(ts.getTagsForURI(testURI)[0], testTag, "tags match"); - - // change the tag - document.getElementById("editBMPanel_tagsField").value = testTagUpper; - gEditItemOverlay.onTagsFieldBlur(); - - // test that the tag has been added in the backend - is(ts.getTagsForURI(testURI)[0], testTagUpper, "tags match"); - - // Cleanup. - ts.untagURI(testURI, [testTag]); - bs.removeItem(itemId); - } - ]]> - </script> - -</window> diff --git a/browser/components/places/tests/chrome/test_bug549192.xul b/browser/components/places/tests/chrome/test_bug549192.xul deleted file mode 100644 index d4c443516..000000000 --- a/browser/components/places/tests/chrome/test_bug549192.xul +++ /dev/null @@ -1,115 +0,0 @@ -<?xml version="1.0"?> - -<!-- - Any copyright is dedicated to the Public Domain. - http://creativecommons.org/licenses/publicdomain/ - --> - -<?xml-stylesheet href="chrome://global/skin" type="text/css"?> -<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" - type="text/css"?> - -<?xml-stylesheet href="chrome://browser/content/places/places.css"?> -<?xml-stylesheet href="chrome://browser/skin/places/places.css"?> -<?xul-overlay href="chrome://browser/content/places/placesOverlay.xul"?> - -<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" - title="549192: History view not updated after deleting entry" - onload="runTest();"> - - <script type="application/javascript" - src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> - <script type="application/javascript" src="head.js" /> - - <body xmlns="http://www.w3.org/1999/xhtml" /> - - <tree id="tree" - type="places" - flatList="true" - flex="1"> - <treecols> - <treecol label="Title" id="title" anonid="title" primary="true" ordinal="1" flex="1"/> - </treecols> - <treechildren flex="1"/> - </tree> - - <script type="application/javascript"><![CDATA[ - /** - * Bug 874407 - * Ensures that history views are updated properly after visits. - * Bug 549192 - * Ensures that history views are updated after deleting entries. - */ - - SimpleTest.waitForExplicitFinish(); - - function runTest() { - // The mochitest page is added to history. - waitForClearHistory(continue_test); - } - - function continue_test() { - // Add some visits. - let vtime = Date.now() * 1000; - const ttype = PlacesUtils.history.TRANSITION_TYPED; - let places = - [{ uri: Services.io.newURI("http://example.tld/", null, null), - visitDate: ++vtime, transition: ttype }, - { uri: Services.io.newURI("http://example2.tld/", null, null), - visitDate: ++vtime, transition: ttype }, - { uri: Services.io.newURI("http://example3.tld/", null, null), - visitDate: ++vtime, transition: ttype }]; - - addVisits(places, function() { - // Make a history query. - let query = PlacesUtils.history.getNewQuery(); - let opts = PlacesUtils.history.getNewQueryOptions(); - opts.sortingMode = opts.SORT_BY_DATE_DESCENDING; - let queryURI = PlacesUtils.history.queriesToQueryString([query], 1, opts); - - // Setup the places tree contents. - var tree = document.getElementById("tree"); - tree.place = queryURI; - - // loop through the rows and check them. - let treeView = tree.view; - let selection = treeView.selection; - let rc = treeView.rowCount; - - for (let i = 0; i < rc; i++) { - selection.select(i); - let node = tree.selectedNode; - is(node.uri, places[rc - i - 1].uri.spec, - "Found expected node at position " + i + "."); - } - - is(rc, 3, "Found expected number of rows."); - - // First check live-update of the view when adding visits. - places.forEach(place => place.visitDate = ++vtime); - addVisits(places, function() { - for (let i = 0; i < rc; i++) { - selection.select(i); - let node = tree.selectedNode; - is(node.uri, places[rc - i - 1].uri.spec, - "Found expected node at position " + i + "."); - } - - // Now remove the pages and verify live-update again. - for (let i = 0; i < rc; i++) { - selection.select(0); - let node = tree.selectedNode; - tree.controller.remove("Removing page"); - ok(treeView.treeIndexForNode(node) == Ci.nsINavHistoryResultTreeViewer.INDEX_INVISIBLE, - node.uri + " removed."); - ok(treeView.rowCount == rc - i - 1, "Rows count decreased"); - } - - // Cleanup. - waitForClearHistory(SimpleTest.finish); - }); - }); - } - - ]]></script> -</window> diff --git a/browser/components/places/tests/chrome/test_bug549491.xul b/browser/components/places/tests/chrome/test_bug549491.xul deleted file mode 100644 index fdc499245..000000000 --- a/browser/components/places/tests/chrome/test_bug549491.xul +++ /dev/null @@ -1,97 +0,0 @@ -<?xml version="1.0"?> - -<!-- - Any copyright is dedicated to the Public Domain. - http://creativecommons.org/licenses/publicdomain/ - --> - -<?xml-stylesheet href="chrome://global/skin" type="text/css"?> -<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" - type="text/css"?> - -<?xml-stylesheet href="chrome://browser/content/places/places.css"?> -<?xml-stylesheet href="chrome://browser/skin/places/places.css"?> -<?xul-overlay href="chrome://browser/content/places/placesOverlay.xul"?> - -<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" - title="549491: 'The root node is never visible' exception when details of the root node are modified " - onload="runTest();"> - - <script type="application/javascript" - src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> - <script type="application/javascript" src="head.js" /> - - <body xmlns="http://www.w3.org/1999/xhtml" /> - - <tree id="tree" - type="places" - flatList="true" - flex="1"> - <treecols> - <treecol label="Title" id="title" anonid="title" primary="true" ordinal="1" flex="1"/> - <splitter class="tree-splitter"/> - <treecol label="Date" anonid="date" flex="1"/> - </treecols> - <treechildren flex="1"/> - </tree> - - <script type="application/javascript"><![CDATA[ - /** - * Bug 549491 - * https://bugzilla.mozilla.org/show_bug.cgi?id=549491 - * - * Ensures that changing the details of places tree's root-node doesn't - * throw. - */ - - SimpleTest.waitForExplicitFinish(); - - function runTest() { - // The mochitest page is added to history. - waitForClearHistory(continue_test); - } - - function continue_test() { - addVisits( - {uri: Services.io.newURI("http://example.tld/", null, null), - transition: PlacesUtils.history.TRANSITION_TYPED}, - function() { - // Make a history query. - let query = PlacesUtils.history.getNewQuery(); - let opts = PlacesUtils.history.getNewQueryOptions(); - let queryURI = PlacesUtils.history.queriesToQueryString([query], 1, opts); - - // Setup the places tree contents. - let tree = document.getElementById("tree"); - tree.place = queryURI; - - let rootNode = tree.result.root; - let obs = tree.view.QueryInterface(Ci.nsINavHistoryResultObserver); - obs.nodeHistoryDetailsChanged(rootNode, rootNode.time, rootNode.accessCount); - obs.nodeTitleChanged(rootNode, rootNode.title); - ok(true, "No exceptions thrown"); - - // Cleanup. - waitForClearHistory(SimpleTest.finish); - }); - } - - /** - * Clears history invoking callback when done. - */ - function waitForClearHistory(aCallback) { - const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished"; - let observer = { - observe: function(aSubject, aTopic, aData) { - Services.obs.removeObserver(this, TOPIC_EXPIRATION_FINISHED); - aCallback(); - } - }; - Services.obs.addObserver(observer, TOPIC_EXPIRATION_FINISHED, false); - let hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); - hs.QueryInterface(Ci.nsIBrowserHistory).removeAllPages(); - } - - ]]></script> -</window> diff --git a/browser/components/places/tests/chrome/test_bug631374_tags_selector_scroll.xul b/browser/components/places/tests/chrome/test_bug631374_tags_selector_scroll.xul deleted file mode 100644 index ffec971b4..000000000 --- a/browser/components/places/tests/chrome/test_bug631374_tags_selector_scroll.xul +++ /dev/null @@ -1,154 +0,0 @@ -<?xml version="1.0"?> - -<!-- Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ --> - -<?xml-stylesheet href="chrome://global/skin" type="text/css"?> -<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" - type="text/css"?> - -<?xml-stylesheet href="chrome://browser/skin/places/editBookmarkOverlay.css"?> -<?xml-stylesheet href="chrome://browser/content/places/places.css"?> -<?xml-stylesheet href="chrome://browser/skin/places/places.css"?> - -<?xul-overlay href="chrome://browser/content/places/placesOverlay.xul"?> -<?xul-overlay href="chrome://browser/content/places/editBookmarkOverlay.xul"?> - -<!DOCTYPE window [ - <!ENTITY % editBookmarkOverlayDTD SYSTEM "chrome://browser/locale/places/editBookmarkOverlay.dtd"> - %editBookmarkOverlayDTD; -]> - -<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" - title="Bug 631374 - Editing tags in the selector scrolls up the listbox" - onload="runTest();"> - - <script type="application/javascript" - src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> - <script type="application/javascript" - src="chrome://browser/content/places/editBookmarkOverlay.js"/> - - <body xmlns="http://www.w3.org/1999/xhtml" /> - - <vbox id="editBookmarkPanelContent"/> - - <script type="application/javascript"> - <![CDATA[ - - /** - * This test checks that editing tags doesn't scroll the tags selector - * listbox to wrong positions. - */ - - function runTest() { - SimpleTest.waitForExplicitFinish(); - - Components.utils.import("resource://gre/modules/NetUtil.jsm"); - - let tags = ["a", "b", "c", "d", "e", "f", "g", - "h", "i", "l", "m", "n", "o", "p"]; - - // Add a bookmark and tag it. - let uri1 = NetUtil.newURI("http://www1.mozilla.org/"); - let id1 = PlacesUtils.bookmarks.insertBookmark( - PlacesUtils.toolbarFolderId, uri1, - PlacesUtils.bookmarks.DEFAULT_INDEX, "mozilla" - ); - PlacesUtils.tagging.tagURI(uri1, tags); - - // Add a second bookmark so that tags won't disappear when unchecked. - let uri2 = NetUtil.newURI("http://www2.mozilla.org/"); - let id2 = PlacesUtils.bookmarks.insertBookmark( - PlacesUtils.toolbarFolderId, uri2, - PlacesUtils.bookmarks.DEFAULT_INDEX, "mozilla" - ); - PlacesUtils.tagging.tagURI(uri2, tags); - - // Init panel. - ok(gEditItemOverlay, "gEditItemOverlay is in context"); - gEditItemOverlay.initPanel(id1); - ok(gEditItemOverlay._initialized, "gEditItemOverlay is initialized"); - - // Wait for the tags selector to be open. - let tagsSelectorRow = document.getElementById("editBMPanel_tagsSelectorRow"); - tagsSelectorRow.addEventListener("DOMAttrModified", function (event) { - tagsSelectorRow.removeEventListener("DOMAttrModified", arguments.callee, false); - SimpleTest.executeSoon(function () { - let tagsSelector = document.getElementById("editBMPanel_tagsSelector"); - - // Go by two so there is some untouched tag in the middle. - for (let i = 8; i < tags.length; i += 2) { - tagsSelector.selectedIndex = i; - let listItem = tagsSelector.selectedItem; - SimpleTest.isnot(listItem, null, "Valid listItem found"); - - tagsSelector.ensureElementIsVisible(listItem); - let visibleIndex = tagsSelector.getIndexOfFirstVisibleRow(); - - SimpleTest.ok(listItem.checked, "Item is checked " + i); - let selectedTag = listItem.label; - - // Uncheck the tag. - listItem.checked = false; - SimpleTest.is(visibleIndex, - tagsSelector.getIndexOfFirstVisibleRow(), - "Scroll position did not change"); - - // The listbox is rebuilt, so we have to get the new element. - let newItem = tagsSelector.selectedItem; - SimpleTest.isnot(newItem, null, "Valid new listItem found"); - SimpleTest.ok(!newItem.checked, "New listItem is unchecked " + i); - SimpleTest.is(newItem.label, selectedTag, - "Correct tag is still selected"); - - // Check the tag. - newItem.checked = true; - SimpleTest.is(visibleIndex, - tagsSelector.getIndexOfFirstVisibleRow(), - "Scroll position did not change"); - } - - // Remove the second bookmark, then nuke some of the tags. - PlacesUtils.bookmarks.removeItem(id2); - - // Doing this backwords tests more interesting paths. - for (let i = tags.length - 1; i >= 0 ; i -= 2) { - tagsSelector.selectedIndex = i; - let listItem = tagsSelector.selectedItem; - SimpleTest.isnot(listItem, null, "Valid listItem found"); - - tagsSelector.ensureElementIsVisible(listItem); - let visibleIndex = tagsSelector.getIndexOfFirstVisibleRow(); - - SimpleTest.ok(listItem.checked, "Item is checked " + i); - let selectedTag = listItem.label; - - // Uncheck the tag. - listItem.checked = false; - SimpleTest.is(tagsSelector.getIndexOfFirstVisibleRow(), - Math.max(visibleIndex -1, 0), - "Scroll position is correct"); - - // The listbox is rebuilt, so we have to get the new element. - let newItem = tagsSelector.selectedItem; - SimpleTest.isnot(newItem, null, "Valid new listItem found"); - SimpleTest.ok(newItem.checked, "New listItem is checked " + i); - SimpleTest.is(tagsSelector.selectedItem.label, - tags[Math.min(i + 1, tags.length - 2)], - "The next tag is now selected"); - } - - // Cleanup. - PlacesUtils.bookmarks.removeItem(id1); - - SimpleTest.finish(); - }); - }, false); - - // Open the tags selector. - document.getElementById("editBMPanel_tagsSelectorExpander").doCommand(); - } - ]]> - </script> - -</window> diff --git a/browser/components/places/tests/chrome/test_editBookmarkOverlay_tags_liveUpdate.xul b/browser/components/places/tests/chrome/test_editBookmarkOverlay_tags_liveUpdate.xul deleted file mode 100644 index df4f6e2e4..000000000 --- a/browser/components/places/tests/chrome/test_editBookmarkOverlay_tags_liveUpdate.xul +++ /dev/null @@ -1,198 +0,0 @@ -<?xml version="1.0"?> - -<!-- Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ --> - -<?xml-stylesheet href="chrome://global/skin" type="text/css"?> -<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" - type="text/css"?> - -<?xml-stylesheet href="chrome://browser/skin/places/editBookmarkOverlay.css"?> -<?xml-stylesheet href="chrome://browser/content/places/places.css"?> -<?xml-stylesheet href="chrome://browser/skin/places/places.css"?> - -<?xul-overlay href="chrome://browser/content/places/placesOverlay.xul"?> -<?xul-overlay href="chrome://browser/content/places/editBookmarkOverlay.xul"?> - -<!DOCTYPE window [ - <!ENTITY % editBookmarkOverlayDTD SYSTEM "chrome://browser/locale/places/editBookmarkOverlay.dtd"> - %editBookmarkOverlayDTD; -]> - -<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" - title="485100: Exchanging a letter of a tag name with its big/small equivalent removes tag from bookmark" - onload="runTest();"> - - <script type="application/javascript" - src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> - <script type="application/javascript" - src="chrome://browser/content/places/editBookmarkOverlay.js"/> - - <body xmlns="http://www.w3.org/1999/xhtml" /> - - <vbox id="editBookmarkPanelContent"/> - - <script type="application/javascript"> - <![CDATA[ - function runTest() - { - Components.utils.import("resource://gre/modules/NetUtil.jsm"); - - const TEST_URI = NetUtil.newURI("http://www.test.me/"); - const TEST_URI2 = NetUtil.newURI("http://www.test.again.me/"); - const TEST_TAG = "test-tag"; - - ok(gEditItemOverlay, "Sanity check: gEditItemOverlay is in context"); - - // Open the tags selector. - document.getElementById("editBMPanel_tagsSelectorRow").collapsed = false; - - function checkTagsSelector(aAvailableTags, aCheckedTags) - { - is(PlacesUtils.tagging.allTags.length, aAvailableTags.length, - "tagging service is in sync."); - let tagsSelector = document.getElementById("editBMPanel_tagsSelector"); - let children = tagsSelector.childNodes; - is(children.length, aAvailableTags.length, - "Found expected number of tags in the tags selector"); - Array.forEach(children, function (aChild) { - let tag = aChild.getAttribute("label"); - ok(true, "Found tag '" + tag + "' in the selector"); - ok(aAvailableTags.indexOf(tag) != -1, "Found expected tag"); - let checked = aChild.getAttribute("checked") == "true"; - is(checked, aCheckedTags.indexOf(tag) != -1, - "Tag is correctly marked"); - }); - } - - // Add a bookmark. - let itemId = PlacesUtils.bookmarks.insertBookmark( - PlacesUtils.unfiledBookmarksFolderId, TEST_URI, - PlacesUtils.bookmarks.DEFAULT_INDEX, "test.me" - ); - - // Init panel. - gEditItemOverlay.initPanel(itemId); - - // Add a tag. - PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]); - - is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG, - "Correctly added tag to a single bookmark"); - is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG, - "Editing a single bookmark shows the added tag"); - checkTagsSelector([TEST_TAG], [TEST_TAG]); - - // Remove tag. - PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]); - is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined, - "The tag has been removed"); - is(document.getElementById("editBMPanel_tagsField").value, "", - "Editing a single bookmark should not show any tag"); - checkTagsSelector([], []); - - // Add a second bookmark. - let itemId2 = PlacesUtils.bookmarks.insertBookmark( - PlacesUtils.unfiledBookmarksFolderId, TEST_URI2, - PlacesUtils.bookmarks.DEFAULT_INDEX, "test.again.me" - ); - - // Init panel with multiple bookmarks. - gEditItemOverlay.initPanel([itemId, itemId2]); - - // Add a tag to the first bookmark. - PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]); - is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG, - "Correctly added a tag to the first bookmark."); - is(document.getElementById("editBMPanel_tagsField").value, "", - "Editing multiple bookmarks without matching tags should not show any tag."); - checkTagsSelector([TEST_TAG], []); - - // Add a tag to the second bookmark. - PlacesUtils.tagging.tagURI(TEST_URI2, [TEST_TAG]); - is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], TEST_TAG, - "Correctly added a tag to the second bookmark."); - is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG, - "Editing multiple bookmarks should show matching tags."); - checkTagsSelector([TEST_TAG], [TEST_TAG]); - - // Remove tag from the first bookmark. - PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]); - is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined, - "Correctly removed tag from the first bookmark."); - is(document.getElementById("editBMPanel_tagsField").value, "", - "Editing multiple bookmarks without matching tags should not show any tag."); - checkTagsSelector([TEST_TAG], []); - - // Remove tag from the second bookmark. - PlacesUtils.tagging.untagURI(TEST_URI2, [TEST_TAG]); - is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], undefined, - "Correctly removed tag from the second bookmark."); - is(document.getElementById("editBMPanel_tagsField").value, "", - "Editing multiple bookmarks without matching tags should not show any tag."); - checkTagsSelector([], []); - - // Init panel with a nsIURI entry. - gEditItemOverlay.initPanel(TEST_URI); - - // Add a tag. - PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]); - is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG, - "Correctly added tag to the first entry."); - is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG, - "Editing a single nsIURI entry shows the added tag"); - checkTagsSelector([TEST_TAG], [TEST_TAG]); - - // Remove tag. - PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]); - is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined, - "Correctly removed tag from the nsIURI entry."); - is(document.getElementById("editBMPanel_tagsField").value, "", - "Editing a single nsIURI entry should not show any tag"); - checkTagsSelector([], []); - - // Init panel with multiple nsIURI entries. - gEditItemOverlay.initPanel([TEST_URI, TEST_URI2]); - - // Add a tag to the first entry. - PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]); - is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], TEST_TAG, - "Tag correctly added."); - is(document.getElementById("editBMPanel_tagsField").value, "", - "Editing multiple nsIURIs without matching tags should not show any tag."); - checkTagsSelector([TEST_TAG], []); - - // Add a tag to the second entry. - PlacesUtils.tagging.tagURI(TEST_URI2, [TEST_TAG]); - is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], TEST_TAG, - "Tag correctly added."); - is(document.getElementById("editBMPanel_tagsField").value, TEST_TAG, - "Editing multiple nsIURIs should show matching tags"); - checkTagsSelector([TEST_TAG], [TEST_TAG]); - - // Remove tag from the first entry. - PlacesUtils.tagging.untagURI(TEST_URI, [TEST_TAG]); - is(PlacesUtils.tagging.getTagsForURI(TEST_URI)[0], undefined, - "Correctly removed tag from the first entry."); - is(document.getElementById("editBMPanel_tagsField").value, "", - "Editing multiple nsIURIs without matching tags should not show any tag."); - checkTagsSelector([TEST_TAG], []); - - // Remove tag from the second entry. - PlacesUtils.tagging.untagURI(TEST_URI2, [TEST_TAG]); - is(PlacesUtils.tagging.getTagsForURI(TEST_URI2)[0], undefined, - "Correctly removed tag from the second entry."); - is(document.getElementById("editBMPanel_tagsField").value, "", - "Editing multiple nsIURIs without matching tags should not show any tag."); - checkTagsSelector([], []); - - // Cleanup. - PlacesUtils.bookmarks.removeFolderChildren( - PlacesUtils.unfiledBookmarksFolderId - ); - - } - ]]> - </script> - -</window> diff --git a/browser/components/places/tests/chrome/test_treeview_date.xul b/browser/components/places/tests/chrome/test_treeview_date.xul deleted file mode 100644 index ba8aa2cc6..000000000 --- a/browser/components/places/tests/chrome/test_treeview_date.xul +++ /dev/null @@ -1,188 +0,0 @@ -<?xml version="1.0"?> - -<!-- This Source Code Form is subject to the terms of the Mozilla Public - - License, v. 2.0. If a copy of the MPL was not distributed with this - - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> - -<?xml-stylesheet href="chrome://global/skin" type="text/css"?> -<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" - type="text/css"?> - -<?xml-stylesheet href="chrome://browser/content/places/places.css"?> -<?xml-stylesheet href="chrome://browser/skin/places/places.css"?> -<?xul-overlay href="chrome://browser/content/places/placesOverlay.xul"?> - -<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" - title="435322: Places tree view's formatting" - onload="runTest();"> - - <script type="application/javascript" - src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> - <script type="application/javascript" src="head.js" /> - - <body xmlns="http://www.w3.org/1999/xhtml" /> - - <tree id="tree" - type="places" - flatList="true" - flex="1"> - <treecols> - <treecol label="Title" id="title" anonid="title" primary="true" ordinal="1" flex="1"/> - <splitter class="tree-splitter"/> - <treecol label="Tags" id="tags" anonid="tags" flex="1"/> - <splitter class="tree-splitter"/> - <treecol label="Url" id="url" anonid="url" flex="1"/> - <splitter class="tree-splitter"/> - <treecol label="Visit Date" id="date" anonid="date" flex="1"/> - <splitter class="tree-splitter"/> - <treecol label="Visit Count" id="visitCount" anonid="visitCount" flex="1"/> - </treecols> - <treechildren flex="1"/> - </tree> - - <script type="application/javascript"> - <![CDATA[ - - /** - * Bug 435322 - * https://bugzilla.mozilla.org/show_bug.cgi?id=435322 - * - * Ensures that date in places treeviews is correctly formatted. - */ - - SimpleTest.waitForExplicitFinish(); - - function runTest() { - // The mochitest page is added to history. - waitForClearHistory(continue_test); - } - - function continue_test() { - var hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); - var bh = hs.QueryInterface(Ci.nsIBrowserHistory); - var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. - getService(Ci.nsINavBookmarksService); - var ds = Cc["@mozilla.org/intl/scriptabledateformat;1"]. - getService(Ci.nsIScriptableDateFormat); - - var iosvc = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService); - function uri(spec) { - return iosvc.newURI(spec, null, null); - } - - var midnight = new Date(); - midnight.setHours(0); - midnight.setMinutes(0); - midnight.setSeconds(0); - midnight.setMilliseconds(0); - - function addVisitsCallback() { - // add a bookmark to the midnight visit - var itemId = bs.insertBookmark(bs.toolbarFolder, - uri("http://at.midnight.com/"), - bs.DEFAULT_INDEX, - "A bookmark at midnight"); - - // Make a history query. - var query = hs.getNewQuery(); - var opts = hs.getNewQueryOptions(); - var queryURI = hs.queriesToQueryString([query], 1, opts); - - // Setup the places tree contents. - var tree = document.getElementById("tree"); - tree.place = queryURI; - - // loop through the rows and check formatting - var treeView = tree.view; - var rc = treeView.rowCount; - ok(rc >= 3, "Rows found"); - var columns = tree.columns; - ok(columns.count > 0, "Columns found"); - for (var r = 0; r < rc; r++) { - var node = treeView.nodeForTreeIndex(r); - ok(node, "Places node found"); - for (var ci = 0; ci < columns.count; ci++) { - var c = columns.getColumnAt(ci); - var text = treeView.getCellText(r, c); - switch (c.element.getAttribute("anonid")) { - case "title": - // The title can differ, we did not set any title so we would - // expect null, but in such a case the view will generate a title - // through PlacesUIUtils.getBestTitle. - if (node.title) - is(text, node.title, "Title is correct"); - break; - case "url": - is(text, node.uri, "Uri is correct"); - break; - case "date": - var timeObj = new Date(node.time / 1000); - // Default is short date format. - var dateFormat = Ci.nsIScriptableDateFormat.dateFormatShort; - // For today's visits we don't show date portion. - if (node.uri == "http://at.midnight.com/" || - node.uri == "http://after.midnight.com/") - dateFormat = Ci.nsIScriptableDateFormat.dateFormatNone; - else if (node.uri == "http://before.midnight.com/") - dateFormat = Ci.nsIScriptableDateFormat.dateFormatShort; - else { - // Avoid to test spurious uris, due to how the test works - // a redirecting uri could be put in the tree while we test. - break; - } - var timeStr = ds.FormatDateTime("", dateFormat, - Ci.nsIScriptableDateFormat.timeFormatNoSeconds, - timeObj.getFullYear(), timeObj.getMonth() + 1, - timeObj.getDate(), timeObj.getHours(), - timeObj.getMinutes(), timeObj.getSeconds()) - - is(text, timeStr, "Date format is correct"); - break; - case "visitCount": - is(text, 1, "Visit count is correct"); - break; - } - } - } - // Cleanup. - bs.removeItem(itemId); - waitForClearHistory(SimpleTest.finish); - } - - // Add a visit 1ms before midnight, a visit at midnight, and - // a visit 1ms after midnight. - addVisits( - [{uri: uri("http://before.midnight.com/"), - visitDate: (midnight.getTime() - 1) * 1000, - transition: hs.TRANSITION_TYPED}, - {uri: uri("http://at.midnight.com/"), - visitDate: (midnight.getTime()) * 1000, - transition: hs.TRANSITION_TYPED}, - {uri: uri("http://after.midnight.com/"), - visitDate: (midnight.getTime() + 1) * 1000, - transition: hs.TRANSITION_TYPED}], - addVisitsCallback); - } - - /** - * Clears history invoking callback when done. - */ - function waitForClearHistory(aCallback) { - const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished"; - let observer = { - observe: function(aSubject, aTopic, aData) { - Services.obs.removeObserver(this, TOPIC_EXPIRATION_FINISHED); - aCallback(); - } - }; - Services.obs.addObserver(observer, TOPIC_EXPIRATION_FINISHED, false); - let hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); - hs.QueryInterface(Ci.nsIBrowserHistory).removeAllPages(); - } - - ]]> - </script> -</window> diff --git a/browser/components/places/tests/moz.build b/browser/components/places/tests/moz.build deleted file mode 100644 index a91509a3f..000000000 --- a/browser/components/places/tests/moz.build +++ /dev/null @@ -1,11 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -DIRS += ['browser', 'chrome'] - -MODULE = 'test_browser_places' - -XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini'] diff --git a/browser/components/places/tests/unit/bookmarks.glue.html b/browser/components/places/tests/unit/bookmarks.glue.html deleted file mode 100644 index 07b22e9b3..000000000 --- a/browser/components/places/tests/unit/bookmarks.glue.html +++ /dev/null @@ -1,16 +0,0 @@ -<!DOCTYPE NETSCAPE-Bookmark-file-1> -<!-- This is an automatically generated file. - It will be read and overwritten. - DO NOT EDIT! --> -<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> -<TITLE>Bookmarks</TITLE> -<H1>Bookmarks Menu</H1> - -<DL><p> - <DT><A HREF="http://example.com/" ADD_DATE="1233157972" LAST_MODIFIED="1233157984">example</A> - <DT><H3 ADD_DATE="1233157910" LAST_MODIFIED="1233157972" PERSONAL_TOOLBAR_FOLDER="true">Bookmarks Toolbar</H3> -<DD>Add bookmarks to this folder to see them displayed on the Bookmarks Toolbar - <DL><p> - <DT><A HREF="http://example.com/" ADD_DATE="1233157972" LAST_MODIFIED="1233157984">example</A> - </DL><p> -</DL><p> diff --git a/browser/components/places/tests/unit/bookmarks.glue.json b/browser/components/places/tests/unit/bookmarks.glue.json deleted file mode 100644 index 7f639e462..000000000 --- a/browser/components/places/tests/unit/bookmarks.glue.json +++ /dev/null @@ -1 +0,0 @@ -{"title":"","id":1,"dateAdded":1233157910552624,"lastModified":1233157955206833,"type":"text/x-moz-place-container","root":"placesRoot","children":[{"title":"Bookmarks Menu","id":2,"parent":1,"dateAdded":1233157910552624,"lastModified":1233157993171424,"type":"text/x-moz-place-container","root":"bookmarksMenuFolder","children":[{"title":"examplejson","id":27,"parent":2,"dateAdded":1233157972101126,"lastModified":1233157984999673,"type":"text/x-moz-place","uri":"http://example.com/"}]},{"index":1,"title":"Bookmarks Toolbar","id":3,"parent":1,"dateAdded":1233157910552624,"lastModified":1233157972101126,"annos":[{"name":"bookmarkProperties/description","flags":0,"expires":4,"mimeType":null,"type":3,"value":"Add bookmarks to this folder to see them displayed on the Bookmarks Toolbar"}],"type":"text/x-moz-place-container","root":"toolbarFolder","children":[{"title":"examplejson","id":26,"parent":3,"dateAdded":1233157972101126,"lastModified":1233157984999673,"type":"text/x-moz-place","uri":"http://example.com/"}]},{"index":2,"title":"Tags","id":4,"parent":1,"dateAdded":1233157910552624,"lastModified":1233157910582667,"type":"text/x-moz-place-container","root":"tagsFolder","children":[]},{"index":3,"title":"Unsorted Bookmarks","id":5,"parent":1,"dateAdded":1233157910552624,"lastModified":1233157911033315,"type":"text/x-moz-place-container","root":"unfiledBookmarksFolder","children":[]}]} diff --git a/browser/components/places/tests/unit/corruptDB.sqlite b/browser/components/places/tests/unit/corruptDB.sqlite Binary files differdeleted file mode 100644 index b234246ca..000000000 --- a/browser/components/places/tests/unit/corruptDB.sqlite +++ /dev/null diff --git a/browser/components/places/tests/unit/distribution.ini b/browser/components/places/tests/unit/distribution.ini deleted file mode 100644 index f94a1be3c..000000000 --- a/browser/components/places/tests/unit/distribution.ini +++ /dev/null @@ -1,21 +0,0 @@ -# Distribution Configuration File -# Bug 516444 demo - -[Global] -id=516444 -version=1.0 -about=Test distribution file - -[BookmarksToolbar] -item.1.title=Toolbar Link Before -item.1.link=http://mozilla.com/ -item.2.type=default -item.3.title=Toolbar Link After -item.3.link=http://mozilla.com/ - -[BookmarksMenu] -item.1.title=Menu Link Before -item.1.link=http://mozilla.com/ -item.2.type=default -item.3.title=Menu Link After -item.3.link=http://mozilla.com/
\ No newline at end of file diff --git a/browser/components/places/tests/unit/head_bookmarks.js b/browser/components/places/tests/unit/head_bookmarks.js deleted file mode 100644 index cbe5aa775..000000000 --- a/browser/components/places/tests/unit/head_bookmarks.js +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const Ci = Components.interfaces; -const Cc = Components.classes; -const Cr = Components.results; -const Cu = Components.utils; - -Cu.import("resource://gre/modules/Services.jsm"); - -// Import common head. -let (commonFile = do_get_file("../../../../../toolkit/components/places/tests/head_common.js", false)) { - let uri = Services.io.newFileURI(commonFile); - Services.scriptloader.loadSubScript(uri.spec, this); -} - -// Put any other stuff relative to this test folder below. - - -XPCOMUtils.defineLazyGetter(this, "PlacesUIUtils", function() { - Cu.import("resource:///modules/PlacesUIUtils.jsm"); - return PlacesUIUtils; -}); - - -const ORGANIZER_FOLDER_ANNO = "PlacesOrganizer/OrganizerFolder"; -const ORGANIZER_QUERY_ANNO = "PlacesOrganizer/OrganizerQuery"; - - -// Needed by some test that relies on having an app registered. -let (XULAppInfo = { - vendor: "Mozilla", - name: "PlacesTest", - ID: "{230de50e-4cd1-11dc-8314-0800200c9a66}", - version: "1", - appBuildID: "2007010101", - platformVersion: "", - platformBuildID: "2007010101", - inSafeMode: false, - logConsoleErrors: true, - OS: "XPCShell", - XPCOMABI: "noarch-spidermonkey", - - QueryInterface: XPCOMUtils.generateQI([ - Ci.nsIXULAppInfo, - Ci.nsIXULRuntime, - ]) -}) { - let XULAppInfoFactory = { - createInstance: function (outer, iid) { - if (outer != null) - throw Cr.NS_ERROR_NO_AGGREGATION; - return XULAppInfo.QueryInterface(iid); - } - }; - let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); - registrar.registerFactory(Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}"), - "XULAppInfo", "@mozilla.org/xre/app-info;1", - XULAppInfoFactory); -} - -// Smart bookmarks constants. -const SMART_BOOKMARKS_VERSION = 4; -const SMART_BOOKMARKS_ON_TOOLBAR = 1; -const SMART_BOOKMARKS_ON_MENU = 3; // Takes in count the additional separator. - -// Default bookmarks constants. -const DEFAULT_BOOKMARKS_ON_TOOLBAR = 1; -const DEFAULT_BOOKMARKS_ON_MENU = 1; diff --git a/browser/components/places/tests/unit/test_421483.js b/browser/components/places/tests/unit/test_421483.js deleted file mode 100644 index 46eb5dc55..000000000 --- a/browser/components/places/tests/unit/test_421483.js +++ /dev/null @@ -1,94 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// Get bookmarks service -try { - var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. - getService(Ci.nsINavBookmarksService); -} catch(ex) { - do_throw("Could not get Bookmarks service\n"); -} - -// Get annotation service -try { - var annosvc = Cc["@mozilla.org/browser/annotation-service;1"]. - getService(Ci.nsIAnnotationService); -} catch(ex) { - do_throw("Could not get Annotation service\n"); -} - -// Get browser glue -try { - var gluesvc = Cc["@mozilla.org/browser/browserglue;1"]. - getService(Ci.nsIBrowserGlue). - QueryInterface(Ci.nsIObserver); - // Avoid default bookmarks import. - gluesvc.observe(null, "initial-migration-will-import-default-bookmarks", ""); -// gluesvc.observe(null, "initial-migration-did-import-default-bookmarks", ""); -} catch(ex) { - do_throw("Could not get BrowserGlue service\n"); -} - -// Get pref service -try { - var pref = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefBranch); -} catch(ex) { - do_throw("Could not get Preferences service\n"); -} - -const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark"; -const SMART_BOOKMARKS_PREF = "browser.places.smartBookmarksVersion"; - -// main -function run_test() { - // TEST 1: smart bookmarks disabled - pref.setIntPref("browser.places.smartBookmarksVersion", -1); - gluesvc.ensurePlacesDefaultQueriesInitialized(); - var smartBookmarkItemIds = annosvc.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); - do_check_eq(smartBookmarkItemIds.length, 0); - // check that pref has not been bumped up - do_check_eq(pref.getIntPref("browser.places.smartBookmarksVersion"), -1); - - // TEST 2: create smart bookmarks - pref.setIntPref("browser.places.smartBookmarksVersion", 0); - gluesvc.ensurePlacesDefaultQueriesInitialized(); - smartBookmarkItemIds = annosvc.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); - do_check_neq(smartBookmarkItemIds.length, 0); - // check that pref has been bumped up - do_check_true(pref.getIntPref("browser.places.smartBookmarksVersion") > 0); - - var smartBookmarksCount = smartBookmarkItemIds.length; - - // TEST 3: smart bookmarks restore - // remove one smart bookmark and restore - bmsvc.removeItem(smartBookmarkItemIds[0]); - pref.setIntPref("browser.places.smartBookmarksVersion", 0); - gluesvc.ensurePlacesDefaultQueriesInitialized(); - smartBookmarkItemIds = annosvc.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); - do_check_eq(smartBookmarkItemIds.length, smartBookmarksCount); - // check that pref has been bumped up - do_check_true(pref.getIntPref("browser.places.smartBookmarksVersion") > 0); - - // TEST 4: move a smart bookmark, change its title, then restore - // smart bookmark should be restored in place - var parent = bmsvc.getFolderIdForItem(smartBookmarkItemIds[0]); - var oldTitle = bmsvc.getItemTitle(smartBookmarkItemIds[0]); - // create a subfolder and move inside it - var newParent = bmsvc.createFolder(parent, "test", bmsvc.DEFAULT_INDEX); - bmsvc.moveItem(smartBookmarkItemIds[0], newParent, bmsvc.DEFAULT_INDEX); - // change title - bmsvc.setItemTitle(smartBookmarkItemIds[0], "new title"); - // restore - pref.setIntPref("browser.places.smartBookmarksVersion", 0); - gluesvc.ensurePlacesDefaultQueriesInitialized(); - smartBookmarkItemIds = annosvc.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); - do_check_eq(smartBookmarkItemIds.length, smartBookmarksCount); - do_check_eq(bmsvc.getFolderIdForItem(smartBookmarkItemIds[0]), newParent); - do_check_eq(bmsvc.getItemTitle(smartBookmarkItemIds[0]), oldTitle); - // check that pref has been bumped up - do_check_true(pref.getIntPref("browser.places.smartBookmarksVersion") > 0); -} diff --git a/browser/components/places/tests/unit/test_PUIU_makeTransaction.js b/browser/components/places/tests/unit/test_PUIU_makeTransaction.js deleted file mode 100644 index 0a2533e1a..000000000 --- a/browser/components/places/tests/unit/test_PUIU_makeTransaction.js +++ /dev/null @@ -1,351 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -function waitForBookmarkNotification(aNotification, aCallback, aProperty) -{ - PlacesUtils.bookmarks.addObserver({ - validate: function (aMethodName, aData) - { - if (aMethodName == aNotification && - (!aProperty || aProperty == aData.property)) { - PlacesUtils.bookmarks.removeObserver(this); - aCallback(aData); - } - }, - - // nsINavBookmarkObserver - QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]), - onBeginUpdateBatch: function onBeginUpdateBatch() - this.validate(arguments.callee.name, arguments), - onEndUpdateBatch: function onEndUpdateBatch() - this.validate(arguments.callee.name, arguments), - onItemAdded: function onItemAdded(aItemId, aParentId, aIndex, aItemType, - aURI, aTitle) - { - return this.validate(arguments.callee.name, { id: aItemId, - index: aIndex, - type: aItemType, - url: aURI ? aURI.spec : null, - title: aTitle }); - }, - onItemRemoved: function onItemRemoved() - this.validate(arguments.callee.name, arguments), - onItemChanged: function onItemChanged(aItemId, aProperty, aIsAnno, - aNewValue, aLastModified, aItemType) - { - return this.validate(arguments.callee.name, - { id: aItemId, - get index() PlacesUtils.bookmarks.getItemIndex(this.id), - type: aItemType, - property: aProperty, - get url() aItemType == PlacesUtils.bookmarks.TYPE_BOOKMARK ? - PlacesUtils.bookmarks.getBookmarkURI(this.id).spec : - null, - get title() PlacesUtils.bookmarks.getItemTitle(this.id), - }); - }, - onItemVisited: function onItemVisited() - this.validate(arguments.callee.name, arguments), - onItemMoved: function onItemMoved(aItemId, aOldParentId, aOldIndex, - aNewParentId, aNewIndex, aItemType) - { - this.validate(arguments.callee.name, { id: aItemId, - index: aNewIndex, - type: aItemType }); - } - }, false); -} - -function wrapNodeByIdAndParent(aItemId, aParentId) -{ - let wrappedNode; - let root = PlacesUtils.getFolderContents(aParentId, false, false).root; - for (let i = 0; i < root.childCount; ++i) { - let node = root.getChild(i); - if (node.itemId == aItemId) { - let type; - if (PlacesUtils.nodeIsContainer(node)) { - type = PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER; - } - else if (PlacesUtils.nodeIsURI(node)) { - type = PlacesUtils.TYPE_X_MOZ_PLACE; - } - else if (PlacesUtils.nodeIsSeparator(node)) { - type = PlacesUtils.TYPE_X_MOZ_PLACE_SEPARATOR; - } - else { - do_throw("Unknown node type"); - } - wrappedNode = PlacesUtils.wrapNode(node, type); - } - } - root.containerOpen = false; - return JSON.parse(wrappedNode); -} - -add_test(function test_text_paste() -{ - const TEST_URL = "http://places.moz.org/" - const TEST_TITLE = "Places bookmark" - - waitForBookmarkNotification("onItemAdded", function(aData) - { - do_check_eq(aData.title, TEST_TITLE); - do_check_eq(aData.url, TEST_URL); - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_BOOKMARK); - do_check_eq(aData.index, 0); - run_next_test(); - }); - - let txn = PlacesUIUtils.makeTransaction( - { title: TEST_TITLE, uri: TEST_URL }, - PlacesUtils.TYPE_X_MOZ_URL, - PlacesUtils.unfiledBookmarksFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX, - true // Unused for text. - ); - PlacesUtils.transactionManager.doTransaction(txn); -}); - -add_test(function test_container() -{ - const TEST_TITLE = "Places folder" - - waitForBookmarkNotification("onItemChanged", function(aData) - { - do_check_eq(aData.title, TEST_TITLE); - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_FOLDER); - do_check_eq(aData.index, 1); - - waitForBookmarkNotification("onItemAdded", function(aData) - { - do_check_eq(aData.title, TEST_TITLE); - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_FOLDER); - do_check_eq(aData.index, 2); - let id = aData.id; - - waitForBookmarkNotification("onItemMoved", function(aData) - { - do_check_eq(aData.id, id); - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_FOLDER); - do_check_eq(aData.index, 1); - - run_next_test(); - }); - - let txn = PlacesUIUtils.makeTransaction( - wrapNodeByIdAndParent(aData.id, PlacesUtils.unfiledBookmarksFolderId), - 0, // Unused for real nodes. - PlacesUtils.unfiledBookmarksFolderId, - 1, // Move to position 1. - false - ); - PlacesUtils.transactionManager.doTransaction(txn); - }); - - try { - let txn = PlacesUIUtils.makeTransaction( - wrapNodeByIdAndParent(aData.id, PlacesUtils.unfiledBookmarksFolderId), - 0, // Unused for real nodes. - PlacesUtils.unfiledBookmarksFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX, - true - ); - PlacesUtils.transactionManager.doTransaction(txn); - } catch(ex) { - do_throw(ex); - } - }, "random-anno"); - - let id = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId, - TEST_TITLE, - PlacesUtils.bookmarks.DEFAULT_INDEX); - PlacesUtils.annotations.setItemAnnotation(id, PlacesUIUtils.DESCRIPTION_ANNO, - "description", 0, - PlacesUtils.annotations.EXPIRE_NEVER); - PlacesUtils.annotations.setItemAnnotation(id, "random-anno", - "random-value", 0, - PlacesUtils.annotations.EXPIRE_NEVER); -}); - - -add_test(function test_separator() -{ - waitForBookmarkNotification("onItemChanged", function(aData) - { - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_SEPARATOR); - do_check_eq(aData.index, 3); - - waitForBookmarkNotification("onItemAdded", function(aData) - { - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_SEPARATOR); - do_check_eq(aData.index, 4); - let id = aData.id; - - waitForBookmarkNotification("onItemMoved", function(aData) - { - do_check_eq(aData.id, id); - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_SEPARATOR); - do_check_eq(aData.index, 1); - - run_next_test(); - }); - - let txn = PlacesUIUtils.makeTransaction( - wrapNodeByIdAndParent(aData.id, PlacesUtils.unfiledBookmarksFolderId), - 0, // Unused for real nodes. - PlacesUtils.unfiledBookmarksFolderId, - 1, // Move to position 1. - false - ); - PlacesUtils.transactionManager.doTransaction(txn); - }); - - try { - let txn = PlacesUIUtils.makeTransaction( - wrapNodeByIdAndParent(aData.id, PlacesUtils.unfiledBookmarksFolderId), - 0, // Unused for real nodes. - PlacesUtils.unfiledBookmarksFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX, - true - ); - PlacesUtils.transactionManager.doTransaction(txn); - } catch(ex) { - do_throw(ex); - } - }, "random-anno"); - - let id = PlacesUtils.bookmarks.insertSeparator(PlacesUtils.unfiledBookmarksFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX); - PlacesUtils.annotations.setItemAnnotation(id, "random-anno", - "random-value", 0, - PlacesUtils.annotations.EXPIRE_NEVER); -}); - -add_test(function test_bookmark() -{ - const TEST_URL = "http://places.moz.org/" - const TEST_TITLE = "Places bookmark" - - waitForBookmarkNotification("onItemChanged", function(aData) - { - do_check_eq(aData.title, TEST_TITLE); - do_check_eq(aData.url, TEST_URL); - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_BOOKMARK); - do_check_eq(aData.index, 5); - - waitForBookmarkNotification("onItemAdded", function(aData) - { - do_check_eq(aData.title, TEST_TITLE); - do_check_eq(aData.url, TEST_URL); - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_BOOKMARK); - do_check_eq(aData.index, 6); - let id = aData.id; - - waitForBookmarkNotification("onItemMoved", function(aData) - { - do_check_eq(aData.id, id); - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_BOOKMARK); - do_check_eq(aData.index, 1); - - run_next_test(); - }); - - let txn = PlacesUIUtils.makeTransaction( - wrapNodeByIdAndParent(aData.id, PlacesUtils.unfiledBookmarksFolderId), - 0, // Unused for real nodes. - PlacesUtils.unfiledBookmarksFolderId, - 1, // Move to position 1. - false - ); - PlacesUtils.transactionManager.doTransaction(txn); - }); - - try { - let txn = PlacesUIUtils.makeTransaction( - wrapNodeByIdAndParent(aData.id, PlacesUtils.unfiledBookmarksFolderId), - 0, // Unused for real nodes. - PlacesUtils.unfiledBookmarksFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX, - true - ); - PlacesUtils.transactionManager.doTransaction(txn); - } catch(ex) { - do_throw(ex); - } - }, "random-anno"); - - let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, - NetUtil.newURI(TEST_URL), - PlacesUtils.bookmarks.DEFAULT_INDEX, - TEST_TITLE); - PlacesUtils.annotations.setItemAnnotation(id, PlacesUIUtils.DESCRIPTION_ANNO, - "description", 0, - PlacesUtils.annotations.EXPIRE_NEVER); - PlacesUtils.annotations.setItemAnnotation(id, "random-anno", - "random-value", 0, - PlacesUtils.annotations.EXPIRE_NEVER); -}); - -add_test(function test_visit() -{ - const TEST_URL = "http://places.moz.org/" - const TEST_TITLE = "Places bookmark" - - waitForBookmarkNotification("onItemAdded", function(aData) - { - do_check_eq(aData.title, TEST_TITLE); - do_check_eq(aData.url, TEST_URL); - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_BOOKMARK); - do_check_eq(aData.index, 7); - - waitForBookmarkNotification("onItemAdded", function(aData) - { - do_check_eq(aData.title, TEST_TITLE); - do_check_eq(aData.url, TEST_URL); - do_check_eq(aData.type, PlacesUtils.bookmarks.TYPE_BOOKMARK); - do_check_eq(aData.index, 8); - run_next_test(); - }); - - try { - let node = wrapNodeByIdAndParent(aData.id, PlacesUtils.unfiledBookmarksFolderId); - // Simulate a not-bookmarked node, will copy it to a new bookmark. - node.id = -1; - let txn = PlacesUIUtils.makeTransaction( - node, - 0, // Unused for real nodes. - PlacesUtils.unfiledBookmarksFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX, - true - ); - PlacesUtils.transactionManager.doTransaction(txn); - } catch(ex) { - do_throw(ex); - } - }); - - PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, - NetUtil.newURI(TEST_URL), - PlacesUtils.bookmarks.DEFAULT_INDEX, - TEST_TITLE); -}); - -add_test(function check_annotations() { - // As last step check how many items for each annotation exist. - - // Copies should retain the description annotation. - let descriptions = - PlacesUtils.annotations.getItemsWithAnnotation(PlacesUIUtils.DESCRIPTION_ANNO, {}); - do_check_eq(descriptions.length, 4); - - // Only the original bookmarks should have this annotation. - let others = PlacesUtils.annotations.getItemsWithAnnotation("random-anno", {}); - do_check_eq(others.length, 3); - run_next_test(); -}); - -function run_test() -{ - run_next_test(); -} diff --git a/browser/components/places/tests/unit/test_browserGlue_corrupt.js b/browser/components/places/tests/unit/test_browserGlue_corrupt.js deleted file mode 100644 index 55c57add4..000000000 --- a/browser/components/places/tests/unit/test_browserGlue_corrupt.js +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Tests that nsBrowserGlue correctly restores bookmarks from a JSON backup if - * database is corrupt and one backup is available. - */ - -Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); - -XPCOMUtils.defineLazyServiceGetter(this, "bs", - "@mozilla.org/browser/nav-bookmarks-service;1", - "nsINavBookmarksService"); -XPCOMUtils.defineLazyServiceGetter(this, "anno", - "@mozilla.org/browser/annotation-service;1", - "nsIAnnotationService"); - -let bookmarksObserver = { - onBeginUpdateBatch: function() {}, - onEndUpdateBatch: function() { - let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0); - do_check_neq(itemId, -1); - if (anno.itemHasAnnotation(itemId, "Places/SmartBookmark")) - continue_test(); - }, - onItemAdded: function() {}, - onItemRemoved: function(id, folder, index, itemType) {}, - onItemChanged: function() {}, - onItemVisited: function(id, visitID, time) {}, - onItemMoved: function() {}, - QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]) -}; - -function run_test() { - do_test_pending(); - - // Create our bookmarks.html copying bookmarks.glue.html to the profile - // folder. It should be ignored. - create_bookmarks_html("bookmarks.glue.html"); - - // Create our JSON backup copying bookmarks.glue.json to the profile folder. - create_JSON_backup("bookmarks.glue.json"); - - // Remove current database file. - let db = gProfD.clone(); - db.append("places.sqlite"); - if (db.exists()) { - db.remove(false); - do_check_false(db.exists()); - } - // Create a corrupt database. - let corruptDB = gTestDir.clone(); - corruptDB.append("corruptDB.sqlite"); - corruptDB.copyTo(gProfD, "places.sqlite"); - do_check_true(db.exists()); - - // Initialize nsBrowserGlue before Places. - Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue); - - // Initialize Places through the History Service. - let hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); - // Check the database was corrupt. - // nsBrowserGlue uses databaseStatus to manage initialization. - do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CORRUPT); - - // The test will continue once restore has finished and smart bookmarks - // have been created. - bs.addObserver(bookmarksObserver, false); -} - -function continue_test() { - // Check that JSON backup has been restored. - // Notice restore from JSON notification is fired before smart bookmarks creation. - let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR); - do_check_eq(bs.getItemTitle(itemId), "examplejson"); - - remove_bookmarks_html(); - remove_all_JSON_backups(); - - do_test_finished(); -} diff --git a/browser/components/places/tests/unit/test_browserGlue_corrupt_nobackup.js b/browser/components/places/tests/unit/test_browserGlue_corrupt_nobackup.js deleted file mode 100644 index e3701f97d..000000000 --- a/browser/components/places/tests/unit/test_browserGlue_corrupt_nobackup.js +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Tests that nsBrowserGlue correctly imports from bookmarks.html if database - * is corrupt but a JSON backup is not available. - */ - -Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); - -XPCOMUtils.defineLazyServiceGetter(this, "bs", - "@mozilla.org/browser/nav-bookmarks-service;1", - "nsINavBookmarksService"); -XPCOMUtils.defineLazyServiceGetter(this, "anno", - "@mozilla.org/browser/annotation-service;1", - "nsIAnnotationService"); - -let bookmarksObserver = { - onBeginUpdateBatch: function() {}, - onEndUpdateBatch: function() { - let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0); - do_check_neq(itemId, -1); - if (anno.itemHasAnnotation(itemId, "Places/SmartBookmark")) - continue_test(); - }, - onItemAdded: function() {}, - onItemRemoved: function(id, folder, index, itemType) {}, - onItemChanged: function() {}, - onItemVisited: function(id, visitID, time) {}, - onItemMoved: function() {}, - QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]) -}; - -function run_test() { - do_test_pending(); - - // Create bookmarks.html in the profile. - create_bookmarks_html("bookmarks.glue.html"); - // Remove JSON backup from profile. - remove_all_JSON_backups(); - - // Remove current database file. - let db = gProfD.clone(); - db.append("places.sqlite"); - if (db.exists()) { - db.remove(false); - do_check_false(db.exists()); - } - // Create a corrupt database. - let corruptDB = gTestDir.clone(); - corruptDB.append("corruptDB.sqlite"); - corruptDB.copyTo(gProfD, "places.sqlite"); - do_check_true(db.exists()); - - // Initialize nsBrowserGlue before Places. - Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue); - - // Initialize Places through the History Service. - let hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); - // Check the database was corrupt. - // nsBrowserGlue uses databaseStatus to manage initialization. - do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CORRUPT); - - // The test will continue once import has finished and smart bookmarks - // have been created. - bs.addObserver(bookmarksObserver, false); -} - -function continue_test() { - // Check that bookmarks html has been restored. - let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR); - do_check_eq(bs.getItemTitle(itemId), "example"); - - remove_bookmarks_html(); - - do_test_finished(); -} diff --git a/browser/components/places/tests/unit/test_browserGlue_corrupt_nobackup_default.js b/browser/components/places/tests/unit/test_browserGlue_corrupt_nobackup_default.js deleted file mode 100644 index 3d554ce98..000000000 --- a/browser/components/places/tests/unit/test_browserGlue_corrupt_nobackup_default.js +++ /dev/null @@ -1,80 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Tests that nsBrowserGlue correctly restores default bookmarks if database is - * corrupt, nor a JSON backup nor bookmarks.html are available. - */ - -Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); - -XPCOMUtils.defineLazyServiceGetter(this, "bs", - "@mozilla.org/browser/nav-bookmarks-service;1", - "nsINavBookmarksService"); -XPCOMUtils.defineLazyServiceGetter(this, "anno", - "@mozilla.org/browser/annotation-service;1", - "nsIAnnotationService"); - -let bookmarksObserver = { - onBeginUpdateBatch: function() {}, - onEndUpdateBatch: function() { - let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0); - do_check_neq(itemId, -1); - if (anno.itemHasAnnotation(itemId, "Places/SmartBookmark")) - continue_test(); - }, - onItemAdded: function() {}, - onItemRemoved: function(id, folder, index, itemType) {}, - onItemChanged: function() {}, - onItemVisited: function(id, visitID, time) {}, - onItemMoved: function() {}, - QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]) -}; - -function run_test() { - do_test_pending(); - - // Remove bookmarks.html from profile. - remove_bookmarks_html(); - // Remove JSON backup from profile. - remove_all_JSON_backups(); - - // Remove current database file. - let db = gProfD.clone(); - db.append("places.sqlite"); - if (db.exists()) { - db.remove(false); - do_check_false(db.exists()); - } - // Create a corrupt database. - let corruptDB = gTestDir.clone(); - corruptDB.append("corruptDB.sqlite"); - corruptDB.copyTo(gProfD, "places.sqlite"); - do_check_true(db.exists()); - - // Initialize nsBrowserGlue before Places. - Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue); - - // Initialize Places through the History Service. - let hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); - // Check the database was corrupt. - // nsBrowserGlue uses databaseStatus to manage initialization. - do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CORRUPT); - - // The test will continue once import has finished and smart bookmarks - // have been created. - bs.addObserver(bookmarksObserver, false); -} - -function continue_test() { - // Check that default bookmarks have been restored. - let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR); - do_check_true(itemId > 0); - do_check_eq(bs.getItemTitle(itemId), "Getting Started"); - - do_test_finished(); -} diff --git a/browser/components/places/tests/unit/test_browserGlue_distribution.js b/browser/components/places/tests/unit/test_browserGlue_distribution.js deleted file mode 100644 index 49839ef7a..000000000 --- a/browser/components/places/tests/unit/test_browserGlue_distribution.js +++ /dev/null @@ -1,103 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -/** - * Tests that nsBrowserGlue correctly imports bookmarks from distribution.ini. - */ - -const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion"; -const PREF_BMPROCESSED = "distribution.516444.bookmarksProcessed"; -const PREF_DISTRIBUTION_ID = "distribution.id"; - -const TOPICDATA_DISTRIBUTION_CUSTOMIZATION = "force-distribution-customization"; -const TOPIC_CUSTOMIZATION_COMPLETE = "distribution-customization-complete"; -const TOPIC_BROWSERGLUE_TEST = "browser-glue-test"; - -function run_test() -{ - do_test_pending(); - - // Copy distribution.ini file to our app dir. - let distroDir = Services.dirsvc.get("XREExeF", Ci.nsIFile); - distroDir.leafName = "distribution"; - let iniFile = distroDir.clone(); - iniFile.append("distribution.ini"); - if (iniFile.exists()) { - iniFile.remove(false); - print("distribution.ini already exists, did some test forget to cleanup?"); - } - let testDistributionFile = gTestDir.clone(); - testDistributionFile.append("distribution.ini"); - testDistributionFile.copyTo(distroDir, "distribution.ini"); - do_check_true(testDistributionFile.exists()); - - // Disable Smart Bookmarks creation. - Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1); - - // Initialize Places through the History Service and check that a new - // database has been created. - do_check_eq(PlacesUtils.history.databaseStatus, - PlacesUtils.history.DATABASE_STATUS_CREATE); - - // Force distribution. - Cc["@mozilla.org/browser/browserglue;1"]. - getService(Ci.nsIObserver).observe(null, - TOPIC_BROWSERGLUE_TEST, - TOPICDATA_DISTRIBUTION_CUSTOMIZATION); - - // Test will continue on customization complete notification. - Services.obs.addObserver(function(aSubject, aTopic, aData) { - Services.obs.removeObserver(arguments.callee, - TOPIC_CUSTOMIZATION_COMPLETE, - false); - do_execute_soon(onCustomizationComplete); - }, TOPIC_CUSTOMIZATION_COMPLETE, false); -} - -function onCustomizationComplete() -{ - // Check the custom bookmarks exist on menu. - let menuItemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0); - do_check_neq(menuItemId, -1); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(menuItemId), - "Menu Link Before"); - menuItemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, - 1 + DEFAULT_BOOKMARKS_ON_MENU); - do_check_neq(menuItemId, -1); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(menuItemId), - "Menu Link After"); - - // Check the custom bookmarks exist on toolbar. - let toolbarItemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_neq(toolbarItemId, -1); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(toolbarItemId), - "Toolbar Link Before"); - toolbarItemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, - 1 + DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_neq(toolbarItemId, -1); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(toolbarItemId), - "Toolbar Link After"); - - // Check the bmprocessed pref has been created. - do_check_true(Services.prefs.getBoolPref(PREF_BMPROCESSED)); - - // Check distribution prefs have been created. - do_check_eq(Services.prefs.getCharPref(PREF_DISTRIBUTION_ID), "516444"); - - do_test_finished(); -} - -do_register_cleanup(function() { - // Remove the distribution file, even if the test failed, otherwise all - // next tests will import it. - let iniFile = Services.dirsvc.get("XREExeF", Ci.nsIFile); - iniFile.leafName = "distribution"; - iniFile.append("distribution.ini"); - if (iniFile.exists()) - iniFile.remove(false); - do_check_false(iniFile.exists()); -}); diff --git a/browser/components/places/tests/unit/test_browserGlue_migrate.js b/browser/components/places/tests/unit/test_browserGlue_migrate.js deleted file mode 100644 index 001f066d3..000000000 --- a/browser/components/places/tests/unit/test_browserGlue_migrate.js +++ /dev/null @@ -1,88 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -/** - * Tests that nsBrowserGlue does not overwrite bookmarks imported from the - * migrators. They usually run before nsBrowserGlue, so if we find any - * bookmark on init, we should not try to import. - */ - -const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion"; - -function run_test() { - do_test_pending(); - - // Create our bookmarks.html copying bookmarks.glue.html to the profile - // folder. It should be ignored. - create_bookmarks_html("bookmarks.glue.html"); - - // Remove current database file. - let db = gProfD.clone(); - db.append("places.sqlite"); - if (db.exists()) { - db.remove(false); - do_check_false(db.exists()); - } - - // Initialize Places through the History Service and check that a new - // database has been created. - do_check_eq(PlacesUtils.history.databaseStatus, - PlacesUtils.history.DATABASE_STATUS_CREATE); - - // A migrator would run before nsBrowserGlue Places initialization, so mimic - // that behavior adding a bookmark and notifying the migration. - let bg = Cc["@mozilla.org/browser/browserglue;1"]. - getService(Ci.nsIObserver); - - bg.observe(null, "initial-migration-will-import-default-bookmarks", null); - - PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarks.bookmarksMenuFolder, uri("http://mozilla.org/"), - PlacesUtils.bookmarks.DEFAULT_INDEX, "migrated"); - - let bookmarksObserver = { - onBeginUpdateBatch: function() {}, - onEndUpdateBatch: function() { - // Check if the currently finished batch created the smart bookmarks. - let itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_neq(itemId, -1); - if (PlacesUtils.annotations - .itemHasAnnotation(itemId, "Places/SmartBookmark")) { - do_execute_soon(onSmartBookmarksCreation); - } - }, - onItemAdded: function() {}, - onItemRemoved: function(id, folder, index, itemType) {}, - onItemChanged: function() {}, - onItemVisited: function(id, visitID, time) {}, - onItemMoved: function() {}, - QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]) - }; - // The test will continue once import has finished and smart bookmarks - // have been created. - PlacesUtils.bookmarks.addObserver(bookmarksObserver, false); - - bg.observe(null, "initial-migration-did-import-default-bookmarks", null); -} - -function onSmartBookmarksCreation() { - // Check the created bookmarks still exist. - let itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, - SMART_BOOKMARKS_ON_MENU); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "migrated"); - - // Check that we have not imported any new bookmark. - itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, - SMART_BOOKMARKS_ON_MENU + 1) - do_check_eq(itemId, -1); - itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, - SMART_BOOKMARKS_ON_MENU) - do_check_eq(itemId, -1); - - remove_bookmarks_html(); - - do_test_finished(); -} diff --git a/browser/components/places/tests/unit/test_browserGlue_prefs.js b/browser/components/places/tests/unit/test_browserGlue_prefs.js deleted file mode 100644 index e8366a614..000000000 --- a/browser/components/places/tests/unit/test_browserGlue_prefs.js +++ /dev/null @@ -1,282 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -/** - * Tests that nsBrowserGlue is correctly interpreting the preferences settable - * by the user or by other components. - */ - -const PREF_IMPORT_BOOKMARKS_HTML = "browser.places.importBookmarksHTML"; -const PREF_RESTORE_DEFAULT_BOOKMARKS = "browser.bookmarks.restore_default_bookmarks"; -const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion"; -const PREF_AUTO_EXPORT_HTML = "browser.bookmarks.autoExportHTML"; - -const TOPIC_BROWSERGLUE_TEST = "browser-glue-test"; -const TOPICDATA_FORCE_PLACES_INIT = "force-places-init"; - -let bg = Cc["@mozilla.org/browser/browserglue;1"]. - getService(Ci.nsIBrowserGlue); - -function waitForImportAndSmartBookmarks(aCallback) { - Services.obs.addObserver(function waitImport() { - Services.obs.removeObserver(waitImport, "bookmarks-restore-success"); - // Delay to test eventual smart bookmarks creation. - do_execute_soon(function () { - promiseAsyncUpdates().then(aCallback); - }); - }, "bookmarks-restore-success", false); -} - -[ - - // This test must be the first one. - function test_checkPreferences() { - // Initialize Places through the History Service and check that a new - // database has been created. - do_check_eq(PlacesUtils.history.databaseStatus, - PlacesUtils.history.DATABASE_STATUS_CREATE); - - // Wait for Places init notification. - Services.obs.addObserver(function(aSubject, aTopic, aData) { - Services.obs.removeObserver(arguments.callee, - "places-browser-init-complete"); - do_execute_soon(function () { - // Ensure preferences status. - do_check_false(Services.prefs.getBoolPref(PREF_AUTO_EXPORT_HTML)); - - try { - do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML)); - do_throw("importBookmarksHTML pref should not exist"); - } - catch(ex) {} - - try { - do_check_false(Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS)); - do_throw("importBookmarksHTML pref should not exist"); - } - catch(ex) {} - - run_next_test(); - }); - }, "places-browser-init-complete", false); - }, - - function test_import() - { - do_log_info("Import from bookmarks.html if importBookmarksHTML is true."); - - remove_all_bookmarks(); - // Sanity check: we should not have any bookmark on the toolbar. - let itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_eq(itemId, -1); - - // Set preferences. - Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true); - - waitForImportAndSmartBookmarks(function () { - // Check bookmarks.html has been imported, and a smart bookmark has been - // created. - itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, - SMART_BOOKMARKS_ON_TOOLBAR); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "example"); - // Check preferences have been reverted. - do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML)); - - run_next_test(); - }); - // Force nsBrowserGlue::_initPlaces(). - do_log_info("Simulate Places init"); - bg.QueryInterface(Ci.nsIObserver).observe(null, - TOPIC_BROWSERGLUE_TEST, - TOPICDATA_FORCE_PLACES_INIT); - }, - - function test_import_noSmartBookmarks() - { - do_log_info("import from bookmarks.html, but don't create smart bookmarks \ - if they are disabled"); - - remove_all_bookmarks(); - // Sanity check: we should not have any bookmark on the toolbar. - let itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_eq(itemId, -1); - - // Set preferences. - Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1); - Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true); - - waitForImportAndSmartBookmarks(function () { - // Check bookmarks.html has been imported, but smart bookmarks have not - // been created. - itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "example"); - // Check preferences have been reverted. - do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML)); - - run_next_test(); - }); - // Force nsBrowserGlue::_initPlaces(). - do_log_info("Simulate Places init"); - bg.QueryInterface(Ci.nsIObserver).observe(null, - TOPIC_BROWSERGLUE_TEST, - TOPICDATA_FORCE_PLACES_INIT); - }, - - function test_import_autoExport_updatedSmartBookmarks() - { - do_log_info("Import from bookmarks.html, but don't create smart bookmarks \ - if autoExportHTML is true and they are at latest version"); - - remove_all_bookmarks(); - // Sanity check: we should not have any bookmark on the toolbar. - let itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_eq(itemId, -1); - - // Set preferences. - Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 999); - Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, true); - Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true); - - waitForImportAndSmartBookmarks(function () { - // Check bookmarks.html has been imported, but smart bookmarks have not - // been created. - itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "example"); - do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML)); - // Check preferences have been reverted. - Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, false); - - run_next_test(); - }); - // Force nsBrowserGlue::_initPlaces() - do_log_info("Simulate Places init"); - bg.QueryInterface(Ci.nsIObserver).observe(null, - TOPIC_BROWSERGLUE_TEST, - TOPICDATA_FORCE_PLACES_INIT); - }, - - function test_import_autoExport_oldSmartBookmarks() - { - do_log_info("Import from bookmarks.html, and create smart bookmarks if \ - autoExportHTML is true and they are not at latest version."); - - remove_all_bookmarks(); - // Sanity check: we should not have any bookmark on the toolbar. - let itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_eq(itemId, -1); - - // Set preferences. - Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 0); - Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, true); - Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true); - - waitForImportAndSmartBookmarks(function () { - // Check bookmarks.html has been imported, but smart bookmarks have not - // been created. - itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, - SMART_BOOKMARKS_ON_TOOLBAR); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "example"); - do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML)); - // Check preferences have been reverted. - Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, false); - - run_next_test(); - }); - // Force nsBrowserGlue::_initPlaces() - do_log_info("Simulate Places init"); - bg.QueryInterface(Ci.nsIObserver).observe(null, - TOPIC_BROWSERGLUE_TEST, - TOPICDATA_FORCE_PLACES_INIT); - }, - - function test_restore() - { - do_log_info("restore from default bookmarks.html if \ - restore_default_bookmarks is true."); - - remove_all_bookmarks(); - // Sanity check: we should not have any bookmark on the toolbar. - let itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_eq(itemId, -1); - - // Set preferences. - Services.prefs.setBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS, true); - - waitForImportAndSmartBookmarks(function () { - // Check bookmarks.html has been restored. - itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, - SMART_BOOKMARKS_ON_TOOLBAR); - do_check_true(itemId > 0); - // Check preferences have been reverted. - do_check_false(Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS)); - - run_next_test(); - }); - // Force nsBrowserGlue::_initPlaces() - do_log_info("Simulate Places init"); - bg.QueryInterface(Ci.nsIObserver).observe(null, - TOPIC_BROWSERGLUE_TEST, - TOPICDATA_FORCE_PLACES_INIT); - - }, - - function test_restore_import() - { - do_log_info("setting both importBookmarksHTML and \ - restore_default_bookmarks should restore defaults."); - - remove_all_bookmarks(); - // Sanity check: we should not have any bookmark on the toolbar. - let itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_eq(itemId, -1); - - // Set preferences. - Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true); - Services.prefs.setBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS, true); - - waitForImportAndSmartBookmarks(function () { - // Check bookmarks.html has been restored. - itemId = - PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, - SMART_BOOKMARKS_ON_TOOLBAR); - do_check_true(itemId > 0); - // Check preferences have been reverted. - do_check_false(Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS)); - do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML)); - - run_next_test(); - }); - // Force nsBrowserGlue::_initPlaces() - do_log_info("Simulate Places init"); - bg.QueryInterface(Ci.nsIObserver).observe(null, - TOPIC_BROWSERGLUE_TEST, - TOPICDATA_FORCE_PLACES_INIT); - } - -].forEach(add_test); - -do_register_cleanup(function () { - remove_all_bookmarks(); - remove_bookmarks_html(); - remove_all_JSON_backups(); -}); - -function run_test() -{ - // Create our bookmarks.html from bookmarks.glue.html. - create_bookmarks_html("bookmarks.glue.html"); - // Create our JSON backup from bookmarks.glue.json. - create_JSON_backup("bookmarks.glue.json"); - - run_next_test(); -} diff --git a/browser/components/places/tests/unit/test_browserGlue_restore.js b/browser/components/places/tests/unit/test_browserGlue_restore.js deleted file mode 100644 index eb7320617..000000000 --- a/browser/components/places/tests/unit/test_browserGlue_restore.js +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Tests that nsBrowserGlue correctly restores bookmarks from a JSON backup if - * database has been created and one backup is available. - */ - -Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); - -XPCOMUtils.defineLazyServiceGetter(this, "bs", - "@mozilla.org/browser/nav-bookmarks-service;1", - "nsINavBookmarksService"); -XPCOMUtils.defineLazyServiceGetter(this, "anno", - "@mozilla.org/browser/annotation-service;1", - "nsIAnnotationService"); - -let bookmarksObserver = { - onBeginUpdateBatch: function() {}, - onEndUpdateBatch: function() { - let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0); - do_check_neq(itemId, -1); - if (anno.itemHasAnnotation(itemId, "Places/SmartBookmark")) - continue_test(); - }, - onItemAdded: function() {}, - onItemRemoved: function(id, folder, index, itemType) {}, - onItemChanged: function() {}, - onItemVisited: function(id, visitID, time) {}, - onItemMoved: function() {}, - QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]) -}; - -function run_test() { - do_test_pending(); - - // Create our bookmarks.html copying bookmarks.glue.html to the profile - // folder. It will be ignored. - create_bookmarks_html("bookmarks.glue.html"); - - // Create our JSON backup copying bookmarks.glue.json to the profile - // folder. It will be ignored. - create_JSON_backup("bookmarks.glue.json"); - - // Remove current database file. - let db = gProfD.clone(); - db.append("places.sqlite"); - if (db.exists()) { - db.remove(false); - do_check_false(db.exists()); - } - - // Initialize nsBrowserGlue before Places. - Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue); - - // Initialize Places through the History Service. - let hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); - // Check a new database has been created. - // nsBrowserGlue uses databaseStatus to manage initialization. - do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CREATE); - - // The test will continue once restore has finished and smart bookmarks - // have been created. - bs.addObserver(bookmarksObserver, false); -} - -function continue_test() { - // Check that JSON backup has been restored. - // Notice restore from JSON notification is fired before smart bookmarks creation. - let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR); - do_check_eq(bs.getItemTitle(itemId), "examplejson"); - - remove_bookmarks_html(); - remove_all_JSON_backups(); - - do_test_finished(); -} diff --git a/browser/components/places/tests/unit/test_browserGlue_shutdown.js b/browser/components/places/tests/unit/test_browserGlue_shutdown.js deleted file mode 100644 index 83e5fd32f..000000000 --- a/browser/components/places/tests/unit/test_browserGlue_shutdown.js +++ /dev/null @@ -1,162 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Tests that nsBrowserGlue is correctly exporting based on preferences values, - * and creating bookmarks backup if one does not exist for today. - */ - -// Initialize nsBrowserGlue after Places. -let bg = Cc["@mozilla.org/browser/browserglue;1"]. - getService(Ci.nsIBrowserGlue); - -// Initialize Places through Bookmarks Service. -let bs = PlacesUtils.bookmarks; - -// Get other services. -let ps = Services.prefs; -let os = Services.obs; - -const PREF_AUTO_EXPORT_HTML = "browser.bookmarks.autoExportHTML"; - -let tests = []; - -//------------------------------------------------------------------------------ - -tests.push({ - description: "Export to bookmarks.html if autoExportHTML is true.", - exec: function() { - // Sanity check: we should have bookmarks on the toolbar. - do_check_true(bs.getIdForItemAt(bs.toolbarFolder, 0) > 0); - - // Set preferences. - ps.setBoolPref(PREF_AUTO_EXPORT_HTML, true); - - // Force nsBrowserGlue::_shutdownPlaces(). - bg.QueryInterface(Ci.nsIObserver).observe(null, - PlacesUtils.TOPIC_SHUTDOWN, - null); - - // Check bookmarks.html has been created. - check_bookmarks_html(); - // Check JSON backup has been created. - check_JSON_backup(); - - // Check preferences have not been reverted. - do_check_true(ps.getBoolPref(PREF_AUTO_EXPORT_HTML)); - // Reset preferences. - ps.setBoolPref(PREF_AUTO_EXPORT_HTML, false); - - next_test(); - } -}); - -//------------------------------------------------------------------------------ - -tests.push({ - description: "Export to bookmarks.html if autoExportHTML is true and a bookmarks.html exists.", - exec: function() { - // Sanity check: we should have bookmarks on the toolbar. - do_check_true(bs.getIdForItemAt(bs.toolbarFolder, 0) > 0); - - // Set preferences. - ps.setBoolPref(PREF_AUTO_EXPORT_HTML, true); - - // Create a bookmarks.html in the profile. - let profileBookmarksHTMLFile = create_bookmarks_html("bookmarks.glue.html"); - // Get file lastModified and size. - let lastMod = profileBookmarksHTMLFile.lastModifiedTime; - let fileSize = profileBookmarksHTMLFile.fileSize; - - // Force nsBrowserGlue::_shutdownPlaces(). - bg.QueryInterface(Ci.nsIObserver).observe(null, - PlacesUtils.TOPIC_SHUTDOWN, - null); - - // Check a new bookmarks.html has been created. - let profileBookmarksHTMLFile = check_bookmarks_html(); - //XXX not working on Linux unit boxes. Could be filestats caching issue. - let isLinux = ("@mozilla.org/gnome-gconf-service;1" in Cc); - if (!isLinux) { - //XXX this test does not working on Mac boxes as well. - let isOSX = ("nsILocalFileMac" in Ci); - if (!isOSX) { - do_check_true(profileBookmarksHTMLFile.lastModifiedTime > lastMod); - } - do_check_neq(profileBookmarksHTMLFile.fileSize, fileSize); - } - - // Check preferences have not been reverted. - do_check_true(ps.getBoolPref(PREF_AUTO_EXPORT_HTML)); - // Reset preferences. - ps.setBoolPref(PREF_AUTO_EXPORT_HTML, false); - - next_test(); - } -}); - -//------------------------------------------------------------------------------ - -tests.push({ - description: "Backup to JSON should be a no-op if a backup for today already exists.", - exec: function() { - // Sanity check: we should have bookmarks on the toolbar. - do_check_true(bs.getIdForItemAt(bs.toolbarFolder, 0) > 0); - - // Create a JSON backup in the profile. - let profileBookmarksJSONFile = create_JSON_backup("bookmarks.glue.json"); - // Get file lastModified and size. - let lastMod = profileBookmarksJSONFile.lastModifiedTime; - let fileSize = profileBookmarksJSONFile.fileSize; - - // Force nsBrowserGlue::_shutdownPlaces(). - bg.QueryInterface(Ci.nsIObserver).observe(null, - PlacesUtils.TOPIC_SHUTDOWN, - null); - - // Check a new JSON backup has not been created. - do_check_true(profileBookmarksJSONFile.exists()); - do_check_eq(profileBookmarksJSONFile.lastModifiedTime, lastMod); - do_check_eq(profileBookmarksJSONFile.fileSize, fileSize); - - do_test_finished(); - } -}); - -//------------------------------------------------------------------------------ - -function finish_test() { - do_test_finished(); -} - -var testIndex = 0; -function next_test() { - // Remove bookmarks.html from profile. - remove_bookmarks_html(); - // Remove JSON backups from profile. - remove_all_JSON_backups(); - - // Execute next test. - let test = tests.shift(); - dump("\nTEST " + (++testIndex) + ": " + test.description); - test.exec(); -} - -function run_test() { - do_test_pending(); - - // Clean up bookmarks. - remove_all_bookmarks(); - - // Create some bookmarks. - bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://mozilla.org/"), - bs.DEFAULT_INDEX, "bookmark-on-menu"); - bs.insertBookmark(bs.toolbarFolder, uri("http://mozilla.org/"), - bs.DEFAULT_INDEX, "bookmark-on-toolbar"); - - // Kick-off tests. - next_test(); -} diff --git a/browser/components/places/tests/unit/test_browserGlue_smartBookmarks.js b/browser/components/places/tests/unit/test_browserGlue_smartBookmarks.js deleted file mode 100644 index 8fdfca29c..000000000 --- a/browser/components/places/tests/unit/test_browserGlue_smartBookmarks.js +++ /dev/null @@ -1,346 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Tests that nsBrowserGlue is correctly interpreting the preferences settable - * by the user or by other components. - */ - -const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion"; -const PREF_AUTO_EXPORT_HTML = "browser.bookmarks.autoExportHTML"; -const PREF_IMPORT_BOOKMARKS_HTML = "browser.places.importBookmarksHTML"; -const PREF_RESTORE_DEFAULT_BOOKMARKS = "browser.bookmarks.restore_default_bookmarks"; - -const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark"; - -/** - * Rebuilds smart bookmarks listening to console output to report any message or - * exception generated when calling ensurePlacesDefaultQueriesInitialized(). - */ -function rebuildSmartBookmarks() { - let consoleListener = { - observe: function(aMsg) { - print("Got console message: " + aMsg.message); - }, - - QueryInterface: XPCOMUtils.generateQI([ - Ci.nsIConsoleListener - ]), - }; - Services.console.reset(); - Services.console.registerListener(consoleListener); - Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue) - .ensurePlacesDefaultQueriesInitialized(); - Services.console.unregisterListener(consoleListener); -} - - -let tests = []; -//------------------------------------------------------------------------------ - -tests.push({ - description: "All smart bookmarks are created if smart bookmarks version is 0.", - exec: function() { - // Sanity check: we should have default bookmark. - do_check_neq(PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0), -1); - do_check_neq(PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0), -1); - - // Set preferences. - Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 0); - - rebuildSmartBookmarks(); - - // Count items. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - // Check version has been updated. - do_check_eq(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION), - SMART_BOOKMARKS_VERSION); - - next_test(); - } -}); - -//------------------------------------------------------------------------------ - -tests.push({ - description: "An existing smart bookmark is replaced when version changes.", - exec: function() { - // Sanity check: we have a smart bookmark on the toolbar. - let itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_neq(itemId, -1); - do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId, SMART_BOOKMARKS_ANNO)); - // Change its title. - PlacesUtils.bookmarks.setItemTitle(itemId, "new title"); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "new title"); - - // Sanity check items. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - // Set preferences. - Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 1); - - rebuildSmartBookmarks(); - - // Count items. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - // Check smart bookmark has been replaced, itemId has changed. - itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); - do_check_neq(itemId, -1); - do_check_neq(PlacesUtils.bookmarks.getItemTitle(itemId), "new title"); - do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId, SMART_BOOKMARKS_ANNO)); - - // Check version has been updated. - do_check_eq(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION), - SMART_BOOKMARKS_VERSION); - - next_test(); - } -}); - -//------------------------------------------------------------------------------ - -tests.push({ - description: "bookmarks position is retained when version changes.", - exec: function() { - // Sanity check items. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - let itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0); - do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId, SMART_BOOKMARKS_ANNO)); - let firstItemTitle = PlacesUtils.bookmarks.getItemTitle(itemId); - - itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 1); - do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId, SMART_BOOKMARKS_ANNO)); - let secondItemTitle = PlacesUtils.bookmarks.getItemTitle(itemId); - - // Set preferences. - Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 1); - - rebuildSmartBookmarks(); - - // Count items. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - // Check smart bookmarks are still in correct position. - itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0); - do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId, SMART_BOOKMARKS_ANNO)); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), firstItemTitle); - - itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 1); - do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId, SMART_BOOKMARKS_ANNO)); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), secondItemTitle); - - // Check version has been updated. - do_check_eq(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION), - SMART_BOOKMARKS_VERSION); - - next_test(); - } -}); - -//------------------------------------------------------------------------------ - -tests.push({ - description: "moved bookmarks position is retained when version changes.", - exec: function() { - // Sanity check items. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - let itemId1 = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0); - do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId1, SMART_BOOKMARKS_ANNO)); - let firstItemTitle = PlacesUtils.bookmarks.getItemTitle(itemId1); - - let itemId2 = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 1); - do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId2, SMART_BOOKMARKS_ANNO)); - let secondItemTitle = PlacesUtils.bookmarks.getItemTitle(itemId2); - - // Move the first smart bookmark to the end of the menu. - PlacesUtils.bookmarks.moveItem(itemId1, PlacesUtils.bookmarksMenuFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX); - - do_check_eq(itemId1, PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX)); - - // Set preferences. - Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 1); - - rebuildSmartBookmarks(); - - // Count items. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - // Check smart bookmarks are still in correct position. - itemId2 = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0); - do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId2, SMART_BOOKMARKS_ANNO)); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId2), secondItemTitle); - - itemId1 = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX); - do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId1, SMART_BOOKMARKS_ANNO)); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId1), firstItemTitle); - - // Move back the smart bookmark to the original position. - PlacesUtils.bookmarks.moveItem(itemId1, PlacesUtils.bookmarksMenuFolderId, 1); - - // Check version has been updated. - do_check_eq(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION), - SMART_BOOKMARKS_VERSION); - - next_test(); - } -}); - -//------------------------------------------------------------------------------ - -tests.push({ - description: "An explicitly removed smart bookmark should not be recreated.", - exec: function() { - // Remove toolbar's smart bookmarks - PlacesUtils.bookmarks.removeItem(PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0)); - - // Sanity check items. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - // Set preferences. - Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 1); - - rebuildSmartBookmarks(); - - // Count items. - // We should not have recreated the smart bookmark on toolbar. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - // Check version has been updated. - do_check_eq(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION), - SMART_BOOKMARKS_VERSION); - - next_test(); - } -}); - -//------------------------------------------------------------------------------ - -tests.push({ - description: "Even if a smart bookmark has been removed recreate it if version is 0.", - exec: function() { - // Sanity check items. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - // Set preferences. - Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 0); - - rebuildSmartBookmarks(); - - // Count items. - // We should not have recreated the smart bookmark on toolbar. - do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId), - SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR); - do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId), - SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU); - - // Check version has been updated. - do_check_eq(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION), - SMART_BOOKMARKS_VERSION); - - next_test(); - } -}); -//------------------------------------------------------------------------------ - -function countFolderChildren(aFolderItemId) { - let rootNode = PlacesUtils.getFolderContents(aFolderItemId).root; - let cc = rootNode.childCount; - // Dump contents. - for (let i = 0; i < cc ; i++) { - let node = rootNode.getChild(i); - let title = PlacesUtils.nodeIsSeparator(node) ? "---" : node.title; - print("Found child(" + i + "): " + title); - } - rootNode.containerOpen = false; - return cc; -} - -function next_test() { - if (tests.length) { - // Execute next test. - let test = tests.shift(); - print("\nTEST: " + test.description); - test.exec(); - } - else { - // Clean up database from all bookmarks. - remove_all_bookmarks(); - do_test_finished(); - } -} - -function run_test() { - do_test_pending(); - - remove_bookmarks_html(); - remove_all_JSON_backups(); - - // Initialize browserGlue, but remove it's listener to places-init-complete. - let bg = Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIObserver); - // Initialize Places. - PlacesUtils.history; - // Usually places init would async notify to glue, but we want to avoid - // randomness here, thus we fire the notification synchronously. - bg.observe(null, "places-init-complete", null); - - // Ensure preferences status. - do_check_false(Services.prefs.getBoolPref(PREF_AUTO_EXPORT_HTML)); - do_check_false(Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS)); - try { - do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML)); - do_throw("importBookmarksHTML pref should not exist"); - } - catch(ex) {} - - waitForImportAndSmartBookmarks(next_test); -} - -function waitForImportAndSmartBookmarks(aCallback) { - Services.obs.addObserver(function waitImport() { - Services.obs.removeObserver(waitImport, "bookmarks-restore-success"); - // Delay to test eventual smart bookmarks creation. - do_execute_soon(function () { - promiseAsyncUpdates().then(aCallback); - }); - }, "bookmarks-restore-success", false); -} diff --git a/browser/components/places/tests/unit/test_clearHistory_shutdown.js b/browser/components/places/tests/unit/test_clearHistory_shutdown.js deleted file mode 100644 index a3b198008..000000000 --- a/browser/components/places/tests/unit/test_clearHistory_shutdown.js +++ /dev/null @@ -1,183 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Tests that requesting clear history at shutdown will really clear history. - */ - -const URIS = [ - "http://a.example1.com/" -, "http://b.example1.com/" -, "http://b.example2.com/" -, "http://c.example3.com/" -]; - -const TOPIC_CONNECTION_CLOSED = "places-connection-closed"; - -let EXPECTED_NOTIFICATIONS = [ - "places-shutdown" -, "places-will-close-connection" -, "places-expiration-finished" -, "places-connection-closed" -]; - -const UNEXPECTED_NOTIFICATIONS = [ - "xpcom-shutdown" -]; - -const URL = "ftp://localhost/clearHistoryOnShutdown/"; - -// Send the profile-after-change notification to the form history component to ensure -// that it has been initialized. -var formHistoryStartup = Cc["@mozilla.org/satchel/form-history-startup;1"]. - getService(Ci.nsIObserver); -formHistoryStartup.observe(null, "profile-after-change", null); - -let notificationIndex = 0; - -let notificationsObserver = { - observe: function observe(aSubject, aTopic, aData) { - print("Received notification: " + aTopic); - - // Note that some of these notifications could arrive multiple times, for - // example in case of sync, we allow that. - if (EXPECTED_NOTIFICATIONS[notificationIndex] != aTopic) - notificationIndex++; - do_check_eq(EXPECTED_NOTIFICATIONS[notificationIndex], aTopic); - - if (aTopic != TOPIC_CONNECTION_CLOSED) - return; - - getDistinctNotifications().forEach( - function (topic) Services.obs.removeObserver(notificationsObserver, topic) - ); - - print("Looking for uncleared stuff."); - - let stmt = DBConn().createStatement( - "SELECT id FROM moz_places WHERE url = :page_url " - ); - - try { - URIS.forEach(function(aUrl) { - stmt.params.page_url = aUrl; - do_check_false(stmt.executeStep()); - stmt.reset(); - }); - } finally { - stmt.finalize(); - } - - // Check cache. - checkCache(URL); - } -} - -let timeInMicroseconds = Date.now() * 1000; - -function run_test() { - run_next_test(); -} - -add_task(function test_execute() { - do_test_pending(); - - print("Initialize browserglue before Places"); - - // Avoid default bookmarks import. - let glue = Cc["@mozilla.org/browser/browserglue;1"]. - getService(Ci.nsIObserver); - glue.observe(null, "initial-migration-will-import-default-bookmarks", null); - - Services.prefs.setBoolPref("privacy.clearOnShutdown.cache", true); - Services.prefs.setBoolPref("privacy.clearOnShutdown.cookies", true); - Services.prefs.setBoolPref("privacy.clearOnShutdown.offlineApps", true); - Services.prefs.setBoolPref("privacy.clearOnShutdown.history", true); - Services.prefs.setBoolPref("privacy.clearOnShutdown.downloads", true); - Services.prefs.setBoolPref("privacy.clearOnShutdown.cookies", true); - Services.prefs.setBoolPref("privacy.clearOnShutdown.formData", true); - Services.prefs.setBoolPref("privacy.clearOnShutdown.passwords", true); - Services.prefs.setBoolPref("privacy.clearOnShutdown.sessions", true); - Services.prefs.setBoolPref("privacy.clearOnShutdown.siteSettings", true); - - Services.prefs.setBoolPref("privacy.sanitize.sanitizeOnShutdown", true); - - print("Add visits."); - for (let aUrl of URIS) { - yield promiseAddVisits({uri: uri(aUrl), visitDate: timeInMicroseconds++, - transition: PlacesUtils.history.TRANSITION_TYPED}) - } - print("Add cache."); - storeCache(URL, "testData"); -}); - -function run_test_continue() -{ - print("Simulate and wait shutdown."); - getDistinctNotifications().forEach( - function (topic) - Services.obs.addObserver(notificationsObserver, topic, false) - ); - - shutdownPlaces(); - - // Shutdown the download manager. - Services.obs.notifyObservers(null, "quit-application", null); -} - -function getDistinctNotifications() { - let ar = EXPECTED_NOTIFICATIONS.concat(UNEXPECTED_NOTIFICATIONS); - return [ar[i] for (i in ar) if (ar.slice(0, i).indexOf(ar[i]) == -1)]; -} - -function storeCache(aURL, aContent) { - let cache = Cc["@mozilla.org/network/cache-service;1"]. - getService(Ci.nsICacheService); - let session = cache.createSession("FTP", Ci.nsICache.STORE_ANYWHERE, - Ci.nsICache.STREAM_BASED); - - var storeCacheListener = { - onCacheEntryAvailable: function (entry, access, status) { - do_check_eq(status, Cr.NS_OK); - - entry.setMetaDataElement("servertype", "0"); - var os = entry.openOutputStream(0); - - var written = os.write(aContent, aContent.length); - if (written != aContent.length) { - do_throw("os.write has not written all data!\n" + - " Expected: " + written + "\n" + - " Actual: " + aContent.length + "\n"); - } - os.close(); - entry.close(); - do_execute_soon(run_test_continue); - } - }; - - session.asyncOpenCacheEntry(aURL, - Ci.nsICache.ACCESS_READ_WRITE, - storeCacheListener); -} - - -function checkCache(aURL) { - let cache = Cc["@mozilla.org/network/cache-service;1"]. - getService(Ci.nsICacheService); - let session = cache.createSession("FTP", Ci.nsICache.STORE_ANYWHERE, - Ci.nsICache.STREAM_BASED); - - var checkCacheListener = { - onCacheEntryAvailable: function (entry, access, status) { - do_check_eq(status, Cr.NS_ERROR_CACHE_KEY_NOT_FOUND); - do_test_finished(); - } - }; - - session.asyncOpenCacheEntry(aURL, - Ci.nsICache.ACCESS_READ, - checkCacheListener); -} diff --git a/browser/components/places/tests/unit/test_leftpane_corruption_handling.js b/browser/components/places/tests/unit/test_leftpane_corruption_handling.js deleted file mode 100644 index a88c2b6d2..000000000 --- a/browser/components/places/tests/unit/test_leftpane_corruption_handling.js +++ /dev/null @@ -1,198 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Tests that we build a working leftpane in various corruption situations. - */ - -// Used to store the original leftPaneFolderId getter. -let gLeftPaneFolderIdGetter; -let gAllBookmarksFolderIdGetter; -// Used to store the original left Pane status as a JSON string. -let gReferenceJSON; -let gLeftPaneFolderId; -// Third party annotated folder. -let gFolderId; - -// Corruption cases. -let gTests = [ - - function test1() { - print("1. Do nothing, checks test calibration."); - }, - - function test2() { - print("2. Delete the left pane folder."); - PlacesUtils.bookmarks.removeItem(gLeftPaneFolderId); - }, - - function test3() { - print("3. Delete a child of the left pane folder."); - let id = PlacesUtils.bookmarks.getIdForItemAt(gLeftPaneFolderId, 0); - PlacesUtils.bookmarks.removeItem(id); - }, - - function test4() { - print("4. Delete AllBookmarks."); - PlacesUtils.bookmarks.removeItem(PlacesUIUtils.allBookmarksFolderId); - }, - - function test5() { - print("5. Create a duplicated left pane folder."); - let id = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId, - "PlacesRoot", - PlacesUtils.bookmarks.DEFAULT_INDEX); - PlacesUtils.annotations.setItemAnnotation(id, ORGANIZER_FOLDER_ANNO, - "PlacesRoot", 0, - PlacesUtils.annotations.EXPIRE_NEVER); - }, - - function test6() { - print("6. Create a duplicated left pane query."); - let id = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId, - "AllBookmarks", - PlacesUtils.bookmarks.DEFAULT_INDEX); - PlacesUtils.annotations.setItemAnnotation(id, ORGANIZER_QUERY_ANNO, - "AllBookmarks", 0, - PlacesUtils.annotations.EXPIRE_NEVER); - }, - - function test7() { - print("7. Remove the left pane folder annotation."); - PlacesUtils.annotations.removeItemAnnotation(gLeftPaneFolderId, - ORGANIZER_FOLDER_ANNO); - }, - - function test8() { - print("8. Remove a left pane query annotation."); - PlacesUtils.annotations.removeItemAnnotation(PlacesUIUtils.allBookmarksFolderId, - ORGANIZER_QUERY_ANNO); - }, - - function test9() { - print("9. Remove a child of AllBookmarks."); - let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUIUtils.allBookmarksFolderId, 0); - PlacesUtils.bookmarks.removeItem(id); - }, - -]; - -function run_test() { - // We want empty roots. - remove_all_bookmarks(); - - // Sanity check. - do_check_true(!!PlacesUIUtils); - - // Check getters. - gLeftPaneFolderIdGetter = PlacesUIUtils.__lookupGetter__("leftPaneFolderId"); - do_check_eq(typeof(gLeftPaneFolderIdGetter), "function"); - gAllBookmarksFolderIdGetter = PlacesUIUtils.__lookupGetter__("allBookmarksFolderId"); - do_check_eq(typeof(gAllBookmarksFolderIdGetter), "function"); - - // Add a third party bogus annotated item. Should not be removed. - gFolderId = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId, - "test", - PlacesUtils.bookmarks.DEFAULT_INDEX); - PlacesUtils.annotations.setItemAnnotation(gFolderId, ORGANIZER_QUERY_ANNO, - "test", 0, - PlacesUtils.annotations.EXPIRE_NEVER); - - // Create the left pane, and store its current status, it will be used - // as reference value. - gLeftPaneFolderId = PlacesUIUtils.leftPaneFolderId; - - do_test_pending(); - - Task.spawn(function() { - gReferenceJSON = yield folderToJSON(gLeftPaneFolderId); - - // Kick-off tests. - do_timeout(0, run_next_test); - }); -} - -function run_next_test() { - if (gTests.length) { - // Create corruption. - let test = gTests.shift(); - test(); - // Regenerate getters. - PlacesUIUtils.__defineGetter__("leftPaneFolderId", gLeftPaneFolderIdGetter); - gLeftPaneFolderId = PlacesUIUtils.leftPaneFolderId; - PlacesUIUtils.__defineGetter__("allBookmarksFolderId", gAllBookmarksFolderIdGetter); - // Check the new left pane folder. - Task.spawn(function() { - let leftPaneJSON = yield folderToJSON(gLeftPaneFolderId); - do_check_true(compareJSON(gReferenceJSON, leftPaneJSON)); - do_check_eq(PlacesUtils.bookmarks.getItemTitle(gFolderId), "test"); - // Go to next test. - do_timeout(0, run_next_test); - }); - } - else { - // All tests finished. - remove_all_bookmarks(); - do_test_finished(); - } -} - -/** - * Convert a folder item id to a JSON representation of it and its contents. - */ -function folderToJSON(aItemId) { - return Task.spawn(function() { - let query = PlacesUtils.history.getNewQuery(); - query.setFolders([aItemId], 1); - let options = PlacesUtils.history.getNewQueryOptions(); - options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS; - let root = PlacesUtils.history.executeQuery(query, options).root; - let writer = { - value: "", - write: function PU_wrapNode__write(aStr, aLen) { - this.value += aStr; - } - }; - yield BookmarkJSONUtils.serializeNodeAsJSONToOutputStream(root, writer, - false, false); - do_check_true(writer.value.length > 0); - throw new Task.Result(writer.value); - }); -} - -/** - * Compare the JSON representation of 2 nodes, skipping everchanging properties - * like dates. - */ -function compareJSON(aNodeJSON_1, aNodeJSON_2) { - let node1 = JSON.parse(aNodeJSON_1); - let node2 = JSON.parse(aNodeJSON_2); - - // List of properties we should not compare (expected to be different). - const SKIP_PROPS = ["dateAdded", "lastModified", "id"]; - - function compareObjects(obj1, obj2) { - function count(o) { var n = 0; for (let p in o) n++; return n; } - do_check_eq(count(obj1), count(obj2)); - for (let prop in obj1) { - // Skip everchanging values. - if (SKIP_PROPS.indexOf(prop) != -1) - continue; - // Skip undefined objects, otherwise we hang on them. - if (!obj1[prop]) - continue; - if (typeof(obj1[prop]) == "object") - return compareObjects(obj1[prop], obj2[prop]); - if (obj1[prop] !== obj2[prop]) { - print(prop + ": " + obj1[prop] + "!=" + obj2[prop]); - return false; - } - } - return true; - } - - return compareObjects(node1, node2); -} diff --git a/browser/components/places/tests/unit/xpcshell.ini b/browser/components/places/tests/unit/xpcshell.ini deleted file mode 100644 index e8b2576f6..000000000 --- a/browser/components/places/tests/unit/xpcshell.ini +++ /dev/null @@ -1,18 +0,0 @@ -[DEFAULT] -head = head_bookmarks.js -tail = -firefox-appdir = browser - -[test_421483.js] -[test_browserGlue_corrupt.js] -[test_browserGlue_corrupt_nobackup.js] -[test_browserGlue_corrupt_nobackup_default.js] -[test_browserGlue_distribution.js] -[test_browserGlue_migrate.js] -[test_browserGlue_prefs.js] -[test_browserGlue_restore.js] -[test_browserGlue_shutdown.js] -[test_browserGlue_smartBookmarks.js] -[test_clearHistory_shutdown.js] -[test_leftpane_corruption_handling.js] -[test_PUIU_makeTransaction.js] diff --git a/browser/components/preferences/moz.build b/browser/components/preferences/moz.build index 0a6b67fd8..8deb0b138 100644 --- a/browser/components/preferences/moz.build +++ b/browser/components/preferences/moz.build @@ -4,4 +4,4 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -TEST_DIRS += ['tests'] + diff --git a/browser/components/preferences/tests/Makefile.in b/browser/components/preferences/tests/Makefile.in deleted file mode 100644 index 459a4e974..000000000 --- a/browser/components/preferences/tests/Makefile.in +++ /dev/null @@ -1,31 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -DEPTH = @DEPTH@ -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ -relativesrcdir = @relativesrcdir@ - -include $(DEPTH)/config/autoconf.mk - -MOCHITEST_BROWSER_FILES := \ - head.js \ - browser_advanced_update.js \ - browser_bug705422.js \ - browser_permissions.js \ - browser_chunk_permissions.js \ - browser_privacypane_1.js \ - browser_privacypane_3.js \ - browser_privacypane_4.js \ - browser_privacypane_5.js \ - browser_privacypane_8.js \ - privacypane_tests_perwindow.js \ - $(NULL) - -ifdef MOZ_SERVICES_HEALTHREPORT -MOCHITEST_BROWSER_FILES += browser_healthreport.js -endif - -include $(topsrcdir)/config/rules.mk diff --git a/browser/components/preferences/tests/browser_advanced_update.js b/browser/components/preferences/tests/browser_advanced_update.js deleted file mode 100644 index 3de2c44dc..000000000 --- a/browser/components/preferences/tests/browser_advanced_update.js +++ /dev/null @@ -1,36 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -function test() { - waitForExplicitFinish(); - resetPreferences(); - - registerCleanupFunction(resetPreferences); - - function observer(win, topic, data) { - Services.obs.removeObserver(observer, "advanced-pane-loaded"); - runTest(win); - } - Services.obs.addObserver(observer, "advanced-pane-loaded", false); - - Services.prefs.setBoolPref("browser.search.update", false); - openDialog("chrome://browser/content/preferences/preferences.xul", "Preferences", - "chrome,titlebar,toolbar,centerscreen,dialog=no", "paneAdvanced"); -} - -function runTest(win) { - let doc = win.document; - let enableSearchUpdate = doc.getElementById("enableSearchUpdate"); - - // Ensure that the update pref dialog reflects the actual pref value. - ok(!enableSearchUpdate.checked, "Ensure search updates are disabled"); - Services.prefs.setBoolPref("browser.search.update", true); - ok(enableSearchUpdate.checked, "Ensure search updates are enabled"); - - win.close(); - finish(); -} - -function resetPreferences() { - Services.prefs.clearUserPref("browser.search.update"); -} diff --git a/browser/components/preferences/tests/browser_bug410900.js b/browser/components/preferences/tests/browser_bug410900.js deleted file mode 100644 index bfb52303d..000000000 --- a/browser/components/preferences/tests/browser_bug410900.js +++ /dev/null @@ -1,51 +0,0 @@ -function test() { - waitForExplicitFinish(); - - // Setup a phony handler to ensure the app pane will be populated. - var handler = Cc["@mozilla.org/uriloader/web-handler-app;1"]. - createInstance(Ci.nsIWebHandlerApp); - handler.name = "App pane alive test"; - handler.uriTemplate = "http://test.mozilla.org/%s"; - - var extps = Cc["@mozilla.org/uriloader/external-protocol-service;1"]. - getService(Ci.nsIExternalProtocolService); - var info = extps.getProtocolHandlerInfo("apppanetest"); - info.possibleApplicationHandlers.appendElement(handler, false); - - var hserv = Cc["@mozilla.org/uriloader/handler-service;1"]. - getService(Ci.nsIHandlerService); - hserv.store(info); - - function observer(win, topic, data) { - if (topic != "app-handler-pane-loaded") - return; - - Services.obs.removeObserver(observer, "app-handler-pane-loaded"); - runTest(win); - } - Services.obs.addObserver(observer, "app-handler-pane-loaded", false); - - openDialog("chrome://browser/content/preferences/preferences.xul", "Preferences", - "chrome,titlebar,toolbar,centerscreen,dialog=no", "paneApplications"); -} - -function runTest(win) { - var sel = win.document.documentElement.getAttribute("lastSelected"); - ok(sel == "paneApplications", "Specified pane was opened"); - - var rbox = win.document.getElementById("handlersView"); - ok(rbox, "handlersView is present"); - - var items = rbox && rbox.getElementsByTagName("richlistitem"); - ok(items && items.length > 0, "App handler list populated"); - - var handlerAdded = false; - for (let i = 0; i < items.length; i++) { - if (items[i].type == "apppanetest") - handlerAdded = true; - } - ok(handlerAdded, "apppanetest protocol handler was successfully added"); - - win.close(); - finish(); -} diff --git a/browser/components/preferences/tests/browser_bug705422.js b/browser/components/preferences/tests/browser_bug705422.js deleted file mode 100644 index b24f60453..000000000 --- a/browser/components/preferences/tests/browser_bug705422.js +++ /dev/null @@ -1,145 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -function test() { - waitForExplicitFinish(); - // Allow all cookies, then actually set up the test - SpecialPowers.pushPrefEnv({"set": [["network.cookie.cookieBehavior", 0]]}, initTest); -} - -function initTest() { - const searchTerm = "example"; - const dummyTerm = "elpmaxe"; - - var cm = Components.classes["@mozilla.org/cookiemanager;1"] - .getService(Components.interfaces.nsICookieManager); - - // delete all cookies (might be left over from other tests) - cm.removeAll(); - - // data for cookies - var vals = [[searchTerm+".com", dummyTerm, dummyTerm], // match - [searchTerm+".org", dummyTerm, dummyTerm], // match - [dummyTerm+".com", searchTerm, dummyTerm], // match - [dummyTerm+".edu", searchTerm+dummyTerm, dummyTerm],// match - [dummyTerm+".net", dummyTerm, searchTerm], // match - [dummyTerm+".org", dummyTerm, searchTerm+dummyTerm],// match - [dummyTerm+".int", dummyTerm, dummyTerm]]; // no match - - // matches must correspond to above data - const matches = 6; - - var ios = Components.classes["@mozilla.org/network/io-service;1"] - .getService(Components.interfaces.nsIIOService); - var cookieSvc = Components.classes["@mozilla.org/cookieService;1"] - .getService(Components.interfaces.nsICookieService); - var v; - // inject cookies - for (v in vals) { - let [host, name, value] = vals[v]; - var cookieUri = ios.newURI("http://"+host, null, null); - cookieSvc.setCookieString(cookieUri, null, name+"="+value+";", null); - } - - // open cookie manager - var cmd = window.openDialog("chrome://browser/content/preferences/cookies.xul", - "Browser:Cookies", "", {}); - - // when it has loaded, run actual tests - cmd.addEventListener("load", function() {executeSoon(function() {runTest(cmd, searchTerm, vals.length, matches);});}, false); -} - -function isDisabled(win, expectation) { - var disabled = win.document.getElementById("removeAllCookies").disabled; - is(disabled, expectation, "Remove all cookies button has correct state: "+(expectation?"disabled":"enabled")); -} - -function runTest(win, searchTerm, cookies, matches) { - var cm = Components.classes["@mozilla.org/cookiemanager;1"] - .getService(Components.interfaces.nsICookieManager); - - - // number of cookies should match injected cookies - var cnt = 0, - enumerator = cm.enumerator; - while (enumerator.hasMoreElements()) { - cnt++; - enumerator.getNext(); - } - is(cnt, cookies, "Number of cookies match injected cookies"); - - // "delete all cookies" should be enabled - isDisabled(win, false); - - // filter cookies and count matches - win.gCookiesWindow.setFilter(searchTerm); - is(win.gCookiesWindow._view.rowCount, matches, "Correct number of cookies shown after filter is applied"); - - // "delete all cookies" should be enabled - isDisabled(win, false); - - - // select first cookie and delete - var tree = win.document.getElementById("cookiesList"); - var deleteButton = win.document.getElementById("removeCookie"); - var x = {}, y = {}, width = {}, height = {}; - tree.treeBoxObject.getCoordsForCellItem(0, tree.columns[0], "cell", x, y, width, height); - EventUtils.synthesizeMouse(tree.body, x.value + width.value / 2, y.value + height.value / 2, {}, win); - EventUtils.synthesizeMouseAtCenter(deleteButton, {}, win); - - // count cookies should be matches-1 - is(win.gCookiesWindow._view.rowCount, matches-1, "Deleted selected cookie"); - - // select two adjacent cells and delete - EventUtils.synthesizeMouse(tree.body, x.value + width.value / 2, y.value + height.value / 2, {}, win); - deleteButton = win.document.getElementById("removeCookies"); - var eventObj = {}; - if (navigator.platform.indexOf("Mac") >= 0) - eventObj.metaKey = true; - else - eventObj.ctrlKey = true; - tree.treeBoxObject.getCoordsForCellItem(1, tree.columns[0], "cell", x, y, width, height); - EventUtils.synthesizeMouse(tree.body, x.value + width.value / 2, y.value + height.value / 2, eventObj, win); - EventUtils.synthesizeMouseAtCenter(deleteButton, {}, win); - - // count cookies should be matches-3 - is(win.gCookiesWindow._view.rowCount, matches-3, "Deleted selected two adjacent cookies"); - - // "delete all cookies" should be enabled - isDisabled(win, false); - - // delete all cookies and count - var deleteAllButton = win.document.getElementById("removeAllCookies"); - EventUtils.synthesizeMouseAtCenter(deleteAllButton, {}, win); - is(win.gCookiesWindow._view.rowCount, 0, "Deleted all matching cookies"); - - // "delete all cookies" should be disabled - isDisabled(win, true); - - // clear filter and count should be cookies-matches - win.gCookiesWindow.setFilter(""); - is(win.gCookiesWindow._view.rowCount, cookies-matches, "Unmatched cookies remain"); - - // "delete all cookies" should be enabled - isDisabled(win, false); - - // delete all cookies and count should be 0 - EventUtils.synthesizeMouseAtCenter(deleteAllButton, {}, win); - is(win.gCookiesWindow._view.rowCount, 0, "Deleted all cookies"); - - // check that datastore is also at 0 - var cnt = 0, - enumerator = cm.enumerator; - while (enumerator.hasMoreElements()) { - cnt++; - enumerator.getNext(); - } - is(cnt, 0, "Zero cookies remain"); - - // "delete all cookies" should be disabled - isDisabled(win, true); - - // clean up - win.close(); - finish(); -} diff --git a/browser/components/preferences/tests/browser_chunk_permissions.js b/browser/components/preferences/tests/browser_chunk_permissions.js deleted file mode 100644 index 4bd387229..000000000 --- a/browser/components/preferences/tests/browser_chunk_permissions.js +++ /dev/null @@ -1,150 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -Components.utils.import("resource://gre/modules/PlacesUtils.jsm"); -Components.utils.import("resource://gre/modules/NetUtil.jsm"); -Components.utils.import("resource://gre/modules/ForgetAboutSite.jsm"); - -const ABOUT_PERMISSIONS_SPEC = "about:permissions"; - -const TEST_URI_1 = NetUtil.newURI("http://mozilla.com/"); -const TEST_URI_2 = NetUtil.newURI("http://mozilla.org/"); -const TEST_URI_3 = NetUtil.newURI("http://wikipedia.org/"); - -// values from DefaultPermissions object -const PERM_UNKNOWN = 0; -const PERM_ALLOW = 1; -const PERM_DENY = 2; - -// used to set permissions on test sites -const TEST_PERMS = { - "password": PERM_ALLOW, - "cookie": PERM_ALLOW, - "geo": PERM_UNKNOWN, - "indexedDB": PERM_UNKNOWN, - "popup": PERM_DENY -}; - -function test() { - waitForExplicitFinish(); - registerCleanupFunction(cleanUp); - setup(function() { - runNextTest(); - }); -} - -function setup(aCallback) { - // add test history visit - addVisits(TEST_URI_1, function() { - // set permissions ourselves to avoid problems with different defaults - // from test harness configuration - for (let type in TEST_PERMS) { - if (type == "password") { - Services.logins.setLoginSavingEnabled(TEST_URI_2.prePath, true); - } else { - // set permissions on a site without history visits to test enumerateServices - Services.perms.add(TEST_URI_2, type, TEST_PERMS[type]); - } - } - - Services.perms.add(TEST_URI_3, "popup", TEST_PERMS["popup"]); - aCallback(); - }); -} - -function cleanUp() { - for (let type in TEST_PERMS) { - if (type != "password") { - Services.perms.remove(TEST_URI_1.host, type); - Services.perms.remove(TEST_URI_2.host, type); - Services.perms.remove(TEST_URI_3.host, type); - } - } -} - -function runNextTest() { - if (gTestIndex == tests.length) { - waitForClearHistory(finish); - return; - } - - let nextTest = tests[gTestIndex++]; - info(nextTest.desc); - - function preinit_observer() { - Services.obs.removeObserver(preinit_observer, "browser-permissions-preinit"); - nextTest.preInit(); - } - Services.obs.addObserver(preinit_observer, "browser-permissions-preinit", false); - - function init_observer() { - Services.obs.removeObserver(init_observer, "browser-permissions-initialized"); - nextTest.run(); - } - Services.obs.addObserver(init_observer, "browser-permissions-initialized", false); - - // open about:permissions - let tab = gBrowser.selectedTab = gBrowser.addTab("about:permissions"); - registerCleanupFunction(function() { - gBrowser.removeTab(tab); - }); -} - -var gSitesList; - -var gTestIndex = 0; -var tests = [ - // 'preInit' occurs after opening about:permissions, before sites-list is populated - // 'run' occurs after sites-list is populated - { - desc: "test filtering before sites-list is fully constructed.", - preInit: function() { - let sitesFilter = gBrowser.contentDocument.getElementById("sites-filter"); - sitesFilter.value = TEST_URI_2.host; - sitesFilter.doCommand(); - }, - run: function() { - let testSite1 = getSiteItem(TEST_URI_1.host); - ok(testSite1.collapsed, "test site 1 is collapsed after early filtering"); - let testSite2 = getSiteItem(TEST_URI_2.host); - ok(!testSite2.collapsed, "test site 2 is not collapsed after early filtering"); - let testSite3 = getSiteItem(TEST_URI_3.host); - ok(testSite3.collapsed, "test site 3 is collapsed after early filtering"); - - runNextTest(); - } - }, - { - desc: "test removing from sites-list before it is fully constructed.", - preInit: function() { - ForgetAboutSite.removeDataFromDomain(TEST_URI_2.host); - }, - run: function() { - let testSite1 = getSiteItem(TEST_URI_1.host); - ok(!testSite2, "test site 1 was not removed from sites list"); - let testSite2 = getSiteItem(TEST_URI_2.host); - ok(!testSite2, "test site 2 was pre-removed from sites list"); - let testSite3 = getSiteItem(TEST_URI_3.host); - ok(!testSite2, "test site 3 was not removed from sites list"); - - runNextTest(); - } - } -]; - -function getSiteItem(aHost) { - return gBrowser.contentDocument. - querySelector(".site[value='" + aHost + "']"); -} - -// copied from toolkit/components/places/tests/head_common.js -function waitForClearHistory(aCallback) { - let observer = { - observe: function(aSubject, aTopic, aData) { - Services.obs.removeObserver(this, PlacesUtils.TOPIC_EXPIRATION_FINISHED); - aCallback(); - } - }; - Services.obs.addObserver(observer, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false); - PlacesUtils.bhistory.removeAllPages(); -} diff --git a/browser/components/preferences/tests/browser_healthreport.js b/browser/components/preferences/tests/browser_healthreport.js deleted file mode 100644 index 161b1d782..000000000 --- a/browser/components/preferences/tests/browser_healthreport.js +++ /dev/null @@ -1,50 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. -* http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -function test() { - waitForExplicitFinish(); - resetPreferences(); - registerCleanupFunction(resetPreferences); - - function observer(win, topic, data) { - Services.obs.removeObserver(observer, "advanced-pane-loaded"); - runTest(win); - } - Services.obs.addObserver(observer, "advanced-pane-loaded", false); - openDialog("chrome://browser/content/preferences/preferences.xul", "Preferences", - "chrome,titlebar,toolbar,centerscreen,dialog=no", "paneAdvanced"); -} - -function runTest(win) { - let doc = win.document; - - let policy = Components.classes["@mozilla.org/datareporting/service;1"] - .getService(Components.interfaces.nsISupports) - .wrappedJSObject - .policy; - ok(policy); - is(policy.dataSubmissionPolicyAccepted, false, "Data submission policy not accepted."); - is(policy.healthReportUploadEnabled, true, "Health Report upload enabled on app first run."); - - let checkbox = doc.getElementById("submitHealthReportBox"); - ok(checkbox); - is(checkbox.checked, true, "Health Report checkbox is checked on app first run."); - - checkbox.checked = false; - checkbox.doCommand(); - is(policy.healthReportUploadEnabled, false, "Unchecking checkbox opts out of FHR upload."); - - checkbox.checked = true; - checkbox.doCommand(); - is(policy.healthReportUploadEnabled, true, "Checking checkbox allows FHR upload."); - - win.close(); - finish(); -} - -function resetPreferences() { - Services.prefs.clearUserPref("datareporting.healthreport.uploadEnabled"); -} - diff --git a/browser/components/preferences/tests/browser_permissions.js b/browser/components/preferences/tests/browser_permissions.js deleted file mode 100644 index ad978eb77..000000000 --- a/browser/components/preferences/tests/browser_permissions.js +++ /dev/null @@ -1,342 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -Components.utils.import("resource://gre/modules/PlacesUtils.jsm"); -Components.utils.import("resource://gre/modules/NetUtil.jsm"); - -const ABOUT_PERMISSIONS_SPEC = "about:permissions"; - -const TEST_URI_1 = NetUtil.newURI("http://mozilla.com/"); -const TEST_URI_2 = NetUtil.newURI("http://mozilla.org/"); - -const TEST_PRINCIPAL_1 = Services.scriptSecurityManager.getNoAppCodebasePrincipal(TEST_URI_1); -const TEST_PRINCIPAL_2 = Services.scriptSecurityManager.getNoAppCodebasePrincipal(TEST_URI_2); - -// values from DefaultPermissions object -const PERM_UNKNOWN = 0; -const PERM_ALLOW = 1; -const PERM_DENY = 2; -// cookie specific permissions -const PERM_FIRST_PARTY_ONLY = 9; - -// used to set permissions on test sites -const TEST_PERMS = { - "password": PERM_ALLOW, - "cookie": PERM_ALLOW, - "geo": PERM_UNKNOWN, - "indexedDB": PERM_UNKNOWN, - "popup": PERM_DENY, - "plugins" : PERM_ALLOW, - "fullscreen" : PERM_UNKNOWN, -}; - -const NO_GLOBAL_ALLOW = [ - "geo", - "indexedDB", - "fullscreen" -]; - -// number of managed permissions in the interface -const TEST_PERMS_COUNT = 7; - -function test() { - waitForExplicitFinish(); - registerCleanupFunction(cleanUp); - - // add test history visit - addVisits(TEST_URI_1, function() { - // set permissions ourselves to avoid problems with different defaults - // from test harness configuration - for (let type in TEST_PERMS) { - if (type == "password") { - Services.logins.setLoginSavingEnabled(TEST_URI_2.prePath, true); - } else { - // set permissions on a site without history visits to test enumerateServices - Services.perms.addFromPrincipal(TEST_PRINCIPAL_2, type, TEST_PERMS[type]); - } - } - - // open about:permissions - gBrowser.selectedTab = gBrowser.addTab("about:permissions"); - }); - - function observer() { - Services.obs.removeObserver(observer, "browser-permissions-initialized"); - runNextTest(); - } - Services.obs.addObserver(observer, "browser-permissions-initialized", false); -} - -function cleanUp() { - for (let type in TEST_PERMS) { - if (type != "password") { - Services.perms.removeFromPrincipal(TEST_PRINCIPAL_1, type); - Services.perms.removeFromPrincipal(TEST_PRINCIPAL_2, type); - } - } - - gBrowser.removeTab(gBrowser.selectedTab); -} - -function runNextTest() { - if (gTestIndex == tests.length) { - waitForClearHistory(finish); - return; - } - - let nextTest = tests[gTestIndex++]; - info("[" + nextTest.name + "] running test"); - nextTest(); -} - -var gSitesList; -var gHeaderDeck; -var gSiteLabel; - -var gTestIndex = 0; -var tests = [ - function test_page_load() { - is(gBrowser.currentURI.spec, ABOUT_PERMISSIONS_SPEC, "about:permissions loaded"); - - gSitesList = gBrowser.contentDocument.getElementById("sites-list"); - ok(gSitesList, "got sites list"); - - gHeaderDeck = gBrowser.contentDocument.getElementById("header-deck"); - ok(gHeaderDeck, "got header deck"); - - gSiteLabel = gBrowser.contentDocument.getElementById("site-label"); - ok(gSiteLabel, "got site label"); - - runNextTest(); - }, - - function test_sites_list() { - is(gSitesList.firstChild.id, "all-sites-item", - "all sites is the first item in the sites list"); - - ok(getSiteItem(TEST_URI_1.host), "site item from places db exists"); - ok(getSiteItem(TEST_URI_2.host), "site item from enumerating services exists"); - - runNextTest(); - }, - - function test_filter_sites_list() { - // set filter to test host - let sitesFilter = gBrowser.contentDocument.getElementById("sites-filter"); - sitesFilter.value = TEST_URI_1.host; - sitesFilter.doCommand(); - - // make sure correct sites are collapsed/showing - let testSite1 = getSiteItem(TEST_URI_1.host); - ok(!testSite1.collapsed, "test site 1 is not collapsed"); - let testSite2 = getSiteItem(TEST_URI_2.host); - ok(testSite2.collapsed, "test site 2 is collapsed"); - - // clear filter - sitesFilter.value = ""; - sitesFilter.doCommand(); - - runNextTest(); - }, - - function test_all_sites() { - // "All Sites" item should be selected when the page is first loaded - is(gSitesList.selectedItem, gBrowser.contentDocument.getElementById("all-sites-item"), - "all sites item is selected"); - - let defaultsHeader = gBrowser.contentDocument.getElementById("defaults-header"); - is(defaultsHeader, gHeaderDeck.selectedPanel, - "correct header shown for all sites"); - - ok(gBrowser.contentDocument.getElementById("passwords-count").hidden, - "passwords count is hidden"); - ok(gBrowser.contentDocument.getElementById("cookies-count").hidden, - "cookies count is hidden"); - - // Test to make sure "Allow" items hidden for certain permission types - NO_GLOBAL_ALLOW.forEach(function(aType) { - let menuitem = gBrowser.contentDocument.getElementById(aType + "-" + PERM_ALLOW); - ok(menuitem.hidden, aType + " allow menuitem hidden for all sites"); - }); - - runNextTest(); - }, - - function test_all_sites_permission() { - // apply the old default of allowing all cookies - Services.prefs.setIntPref("network.cookie.cookieBehavior", 0); - - // there should be no user-set pref for cookie behavior - is(Services.prefs.getIntPref("network.cookie.cookieBehavior"), PERM_UNKNOWN, - "network.cookie.cookieBehavior is expected default"); - - // the default behavior is to allow cookies - let cookieMenulist = getPermissionMenulist("cookie"); - is(cookieMenulist.value, PERM_ALLOW, - "menulist correctly shows that cookies are allowed"); - - // set the pref to block cookies - Services.prefs.setIntPref("network.cookie.cookieBehavior", PERM_DENY); - // check to make sure this change is reflected in the UI - is(cookieMenulist.value, PERM_DENY, "menulist correctly shows that cookies are blocked"); - - // clear the pref - Services.prefs.clearUserPref("network.cookie.cookieBehavior"); - - runNextTest(); - }, - - function test_manage_all_passwords() { - // make sure "Manage All Passwords..." button opens the correct dialog - addWindowListener("chrome://passwordmgr/content/passwordManager.xul", runNextTest); - gBrowser.contentDocument.getElementById("passwords-manage-all-button").doCommand(); - - }, - - function test_manage_all_cookies() { - // make sure "Manage All Cookies..." button opens the correct dialog - addWindowListener("chrome://browser/content/preferences/cookies.xul", runNextTest); - gBrowser.contentDocument.getElementById("cookies-manage-all-button").doCommand(); - }, - - function test_select_site() { - // select the site that has the permissions we set at the beginning of the test - let testSiteItem = getSiteItem(TEST_URI_2.host); - gSitesList.selectedItem = testSiteItem; - - let siteHeader = gBrowser.contentDocument.getElementById("site-header"); - is(siteHeader, gHeaderDeck.selectedPanel, - "correct header shown for a specific site"); - is(gSiteLabel.value, TEST_URI_2.host, "header updated for selected site"); - - ok(!gBrowser.contentDocument.getElementById("passwords-count").hidden, - "passwords count is not hidden"); - ok(!gBrowser.contentDocument.getElementById("cookies-count").hidden, - "cookies count is not hidden"); - - // Test to make sure "Allow" items are *not* hidden for certain permission types - NO_GLOBAL_ALLOW.forEach(function(aType) { - let menuitem = gBrowser.contentDocument.getElementById(aType + "-" + PERM_ALLOW); - ok(!menuitem.hidden, aType + " allow menuitem not hidden for single site"); - }); - - runNextTest(); - }, - - function test_permissions() { - let menulists = gBrowser.contentDocument.getElementsByClassName("pref-menulist"); - is(menulists.length, TEST_PERMS_COUNT, "got expected number of managed permissions"); - - for (let i = 0; i < menulists.length; i++) { - let permissionMenulist = menulists.item(i); - let permissionType = permissionMenulist.getAttribute("type"); - - // permissions should reflect what we set at the beginning of the test - is(permissionMenulist.value, TEST_PERMS[permissionType], - "got expected value for " + permissionType + " permission"); - } - - runNextTest(); - }, - - function test_permission_change() { - let geoMenulist = getPermissionMenulist("geo"); - is(geoMenulist.value, PERM_UNKNOWN, "menulist correctly shows that geolocation permission is unspecified"); - - // change a permission programatically - Services.perms.addFromPrincipal(TEST_PRINCIPAL_2, "geo", PERM_DENY); - // check to make sure this change is reflected in the UI - is(geoMenulist.value, PERM_DENY, "menulist shows that geolocation is blocked"); - - // change a permisssion in the UI - let geoAllowItem = gBrowser.contentDocument.getElementById("geo-" + PERM_ALLOW); - geoMenulist.selectedItem = geoAllowItem; - geoMenulist.doCommand(); - // check to make sure this change is reflected in the permission manager - is(Services.perms.testPermissionFromPrincipal(TEST_PRINCIPAL_2, "geo"), PERM_ALLOW, - "permission manager shows that geolocation is allowed"); - - - // change a site-specific cookie permission, just for fun - let cookieMenuList = getPermissionMenulist("cookie"); - let cookieItem = gBrowser.contentDocument.getElementById("cookie-" + PERM_FIRST_PARTY_ONLY); - cookieMenuList.selectedItem = cookieItem; - cookieMenuList.doCommand(); - is(cookieMenuList.value, PERM_FIRST_PARTY_ONLY, "menulist correctly shows that " + - "first party only cookies are allowed"); - is(Services.perms.testPermissionFromPrincipal(TEST_PRINCIPAL_2, "cookie"), - PERM_FIRST_PARTY_ONLY, "permission manager shows that first party cookies " + - "are allowed"); - - runNextTest(); - }, - - function test_forget_site() { - // click "Forget About This Site" button - gBrowser.contentDocument.getElementById("forget-site-button").doCommand(); - waitForClearHistory(function() { - is(gSiteLabel.value, "", "site label cleared"); - - let allSitesItem = gBrowser.contentDocument.getElementById("all-sites-item"); - is(gSitesList.selectedItem, allSitesItem, - "all sites item selected after forgetting selected site"); - - // check to make sure site is gone from sites list - let testSiteItem = getSiteItem(TEST_URI_2.host); - ok(!testSiteItem, "site removed from sites list"); - - // check to make sure we forgot all permissions corresponding to site - for (let type in TEST_PERMS) { - if (type == "password") { - ok(Services.logins.getLoginSavingEnabled(TEST_URI_2.prePath), - "password saving should be enabled by default"); - } else { - is(Services.perms.testPermissionFromPrincipal(TEST_PRINCIPAL_2, type), PERM_UNKNOWN, - type + " permission should not be set for test site 2"); - } - } - - runNextTest(); - }); - } -]; - -function getPermissionMenulist(aType) { - return gBrowser.contentDocument.getElementById(aType + "-menulist"); -} - -function getSiteItem(aHost) { - return gBrowser.contentDocument. - querySelector(".site[value='" + aHost + "']"); -} - -function addWindowListener(aURL, aCallback) { - Services.wm.addListener({ - onOpenWindow: function(aXULWindow) { - info("window opened, waiting for focus"); - Services.wm.removeListener(this); - - var domwindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIDOMWindow); - waitForFocus(function() { - is(domwindow.document.location.href, aURL, "should have seen the right window open"); - domwindow.close(); - aCallback(); - }, domwindow); - }, - onCloseWindow: function(aXULWindow) { }, - onWindowTitleChange: function(aXULWindow, aNewTitle) { } - }); -} - -// copied from toolkit/components/places/tests/head_common.js -function waitForClearHistory(aCallback) { - let observer = { - observe: function(aSubject, aTopic, aData) { - Services.obs.removeObserver(this, PlacesUtils.TOPIC_EXPIRATION_FINISHED); - aCallback(); - } - }; - Services.obs.addObserver(observer, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false); - PlacesUtils.bhistory.removeAllPages(); -} diff --git a/browser/components/preferences/tests/browser_privacypane_1.js b/browser/components/preferences/tests/browser_privacypane_1.js deleted file mode 100644 index f478b1aca..000000000 --- a/browser/components/preferences/tests/browser_privacypane_1.js +++ /dev/null @@ -1,27 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]. - getService(Ci.mozIJSSubScriptLoader); - - let rootDir = getRootDirectory(gTestPath); - let jar = getJar(rootDir); - if (jar) { - let tmpdir = extractJarToTmp(jar); - rootDir = "file://" + tmpdir.path + '/'; - } - loader.loadSubScript(rootDir + "privacypane_tests_perwindow.js", this); - - run_test_subset([ - test_pane_visibility, - test_dependent_elements, - test_dependent_cookie_elements, - test_dependent_clearonclose_elements, - test_dependent_prefs, - - // reset all preferences to their default values once we're done - reset_preferences - ]); -} diff --git a/browser/components/preferences/tests/browser_privacypane_3.js b/browser/components/preferences/tests/browser_privacypane_3.js deleted file mode 100644 index 8ef887a35..000000000 --- a/browser/components/preferences/tests/browser_privacypane_3.js +++ /dev/null @@ -1,26 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]. - getService(Ci.mozIJSSubScriptLoader); - let rootDir = getRootDirectory(gTestPath); - let jar = getJar(rootDir); - if (jar) { - let tmpdir = extractJarToTmp(jar); - rootDir = "file://" + tmpdir.path + '/'; - } - loader.loadSubScript(rootDir + "privacypane_tests_perwindow.js", this); - - run_test_subset([ - test_custom_retention("rememberHistory", "remember"), - test_custom_retention("rememberHistory", "custom"), - test_custom_retention("rememberForms", "remember"), - test_custom_retention("rememberForms", "custom"), - test_historymode_retention("remember", "remember"), - - // reset all preferences to their default values once we're done - reset_preferences - ]); -} diff --git a/browser/components/preferences/tests/browser_privacypane_4.js b/browser/components/preferences/tests/browser_privacypane_4.js deleted file mode 100644 index 55609e542..000000000 --- a/browser/components/preferences/tests/browser_privacypane_4.js +++ /dev/null @@ -1,31 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]. - getService(Ci.mozIJSSubScriptLoader); - let rootDir = getRootDirectory(gTestPath); - let jar = getJar(rootDir); - if (jar) { - let tmpdir = extractJarToTmp(jar); - rootDir = "file://" + tmpdir.path + '/'; - } - loader.loadSubScript(rootDir + "privacypane_tests_perwindow.js", this); - - run_test_subset([ - test_custom_retention("acceptCookies", "remember"), - test_custom_retention("acceptCookies", "custom"), - test_custom_retention("acceptThirdPartyMenu", "remember", "visited"), - test_custom_retention("acceptThirdPartyMenu", "custom", "always"), - test_custom_retention("keepCookiesUntil", "remember", 1), - test_custom_retention("keepCookiesUntil", "custom", 2), - test_custom_retention("keepCookiesUntil", "custom", 0), - test_custom_retention("alwaysClear", "remember"), - test_custom_retention("alwaysClear", "custom"), - test_historymode_retention("remember", "remember"), - - // reset all preferences to their default values once we're done - reset_preferences - ]); -} diff --git a/browser/components/preferences/tests/browser_privacypane_5.js b/browser/components/preferences/tests/browser_privacypane_5.js deleted file mode 100644 index 48a4feb91..000000000 --- a/browser/components/preferences/tests/browser_privacypane_5.js +++ /dev/null @@ -1,26 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]. - getService(Ci.mozIJSSubScriptLoader); - let rootDir = getRootDirectory(gTestPath); - let jar = getJar(rootDir); - if (jar) { - let tmpdir = extractJarToTmp(jar); - rootDir = "file://" + tmpdir.path + '/'; - } - loader.loadSubScript(rootDir + "privacypane_tests_perwindow.js", this); - - run_test_subset([ - test_locbar_suggestion_retention(-1, undefined), - test_locbar_suggestion_retention(1, -1), - test_locbar_suggestion_retention(2, 1), - test_locbar_suggestion_retention(0, 2), - test_locbar_suggestion_retention(0, 0), - - // reset all preferences to their default values once we're done - reset_preferences - ]); -} diff --git a/browser/components/preferences/tests/browser_privacypane_8.js b/browser/components/preferences/tests/browser_privacypane_8.js deleted file mode 100644 index bb21d6646..000000000 --- a/browser/components/preferences/tests/browser_privacypane_8.js +++ /dev/null @@ -1,35 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]. - getService(Ci.mozIJSSubScriptLoader); - let rootDir = getRootDirectory(gTestPath); - let jar = getJar(rootDir); - if (jar) { - let tmpdir = extractJarToTmp(jar); - rootDir = "file://" + tmpdir.path + '/'; - } - loader.loadSubScript(rootDir + "privacypane_tests_perwindow.js", this); - - run_test_subset([ - // history mode should be initialized to remember - test_historymode_retention("remember", undefined), - - // history mode should remain remember; toggle acceptCookies checkbox - test_custom_retention("acceptCookies", "remember"), - - // history mode should now be custom; set history mode to dontremember - test_historymode_retention("dontremember", "custom"), - - // history mode should remain custom; set history mode to remember - test_historymode_retention("remember", "custom"), - - // history mode should now be remember - test_historymode_retention("remember", "remember"), - - // reset all preferences to their default values once we're done - reset_preferences - ]); -} diff --git a/browser/components/preferences/tests/head.js b/browser/components/preferences/tests/head.js deleted file mode 100644 index b86de7c40..000000000 --- a/browser/components/preferences/tests/head.js +++ /dev/null @@ -1,57 +0,0 @@ -Components.utils.import("resource://gre/modules/PlacesUtils.jsm"); - -/** - * Asynchronously adds visits to a page, invoking a callback function when done. - * - * @param aPlaceInfo - * Can be an nsIURI, in such a case a single LINK visit will be added. - * Otherwise can be an object describing the visit to add, or an array - * of these objects: - * { uri: nsIURI of the page, - * transition: one of the TRANSITION_* from nsINavHistoryService, - * [optional] title: title of the page, - * [optional] visitDate: visit date in microseconds from the epoch - * [optional] referrer: nsIURI of the referrer for this visit - * } - * @param [optional] aCallback - * Function to be invoked on completion. - */ -function addVisits(aPlaceInfo, aCallback) { - let places = []; - if (aPlaceInfo instanceof Ci.nsIURI) { - places.push({ uri: aPlaceInfo }); - } - else if (Array.isArray(aPlaceInfo)) { - places = places.concat(aPlaceInfo); - } else { - places.push(aPlaceInfo) - } - - // Create mozIVisitInfo for each entry. - let now = Date.now(); - for (let i = 0; i < places.length; i++) { - if (!places[i].title) { - places[i].title = "test visit for " + places[i].uri.spec; - } - places[i].visits = [{ - transitionType: places[i].transition === undefined ? PlacesUtils.history.TRANSITION_LINK - : places[i].transition, - visitDate: places[i].visitDate || (now++) * 1000, - referrerURI: places[i].referrer - }]; - } - - PlacesUtils.asyncHistory.updatePlaces( - places, - { - handleError: function AAV_handleError() { - throw("Unexpected error in adding visit."); - }, - handleResult: function () {}, - handleCompletion: function UP_handleCompletion() { - if (aCallback) - aCallback(); - } - } - ); -}
\ No newline at end of file diff --git a/browser/components/preferences/tests/moz.build b/browser/components/preferences/tests/moz.build deleted file mode 100644 index 895d11993..000000000 --- a/browser/components/preferences/tests/moz.build +++ /dev/null @@ -1,6 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - diff --git a/browser/components/preferences/tests/privacypane_tests_perwindow.js b/browser/components/preferences/tests/privacypane_tests_perwindow.js deleted file mode 100644 index eefa1d995..000000000 --- a/browser/components/preferences/tests/privacypane_tests_perwindow.js +++ /dev/null @@ -1,360 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function runTestOnPrivacyPrefPane(testFunc) { - let observer = { - observe: function(aSubject, aTopic, aData) { - if (aTopic == "domwindowopened") { - Services.ww.unregisterNotification(this); - - let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget); - win.addEventListener("load", function() { - win.removeEventListener("load", arguments.callee, false); - testFunc(dialog.document.defaultView); - - Services.ww.registerNotification(observer); - dialog.close(); - }, false); - } else if (aTopic == "domwindowclosed") { - Services.ww.unregisterNotification(this); - testRunner.runNext(); - } - } - }; - Services.ww.registerNotification(observer); - - let dialog = openDialog("chrome://browser/content/preferences/preferences.xul", "Preferences", - "chrome,titlebar,toolbar,centerscreen,dialog=no", "panePrivacy"); -} - -function controlChanged(element) { - element.doCommand(); -} - -// We can only test the panes that don't trigger a preference update -function test_pane_visibility(win) { - let modes = { - "remember": "historyRememberPane", - "custom": "historyCustomPane" - }; - - let historymode = win.document.getElementById("historyMode"); - ok(historymode, "history mode menulist should exist"); - let historypane = win.document.getElementById("historyPane"); - ok(historypane, "history mode pane should exist"); - - for (let mode in modes) { - historymode.value = mode; - controlChanged(historymode); - is(historypane.selectedPanel, win.document.getElementById(modes[mode]), - "The correct pane should be selected for the " + mode + " mode"); - } -} - -function test_dependent_elements(win) { - let historymode = win.document.getElementById("historyMode"); - ok(historymode, "history mode menulist should exist"); - let pbautostart = win.document.getElementById("privateBrowsingAutoStart"); - ok(pbautostart, "the private browsing auto-start checkbox should exist"); - let controls = [ - win.document.getElementById("rememberHistory"), - win.document.getElementById("rememberForms"), - win.document.getElementById("keepUntil"), - win.document.getElementById("keepCookiesUntil"), - win.document.getElementById("alwaysClear"), - ]; - controls.forEach(function(control) { - ok(control, "the dependent controls should exist"); - }); - let independents = [ - win.document.getElementById("acceptCookies"), - win.document.getElementById("acceptThirdPartyLabel"), - win.document.getElementById("acceptThirdPartyMenu") - ]; - independents.forEach(function(control) { - ok(control, "the independent controls should exist"); - }); - let cookieexceptions = win.document.getElementById("cookieExceptions"); - ok(cookieexceptions, "the cookie exceptions button should exist"); - let keepuntil = win.document.getElementById("keepCookiesUntil"); - ok(keepuntil, "the keep cookies until menulist should exist"); - let alwaysclear = win.document.getElementById("alwaysClear"); - ok(alwaysclear, "the clear data on close checkbox should exist"); - let rememberhistory = win.document.getElementById("rememberHistory"); - ok(rememberhistory, "the remember history checkbox should exist"); - let rememberforms = win.document.getElementById("rememberForms"); - ok(rememberforms, "the remember forms checkbox should exist"); - let alwaysclearsettings = win.document.getElementById("clearDataSettings"); - ok(alwaysclearsettings, "the clear data settings button should exist"); - - function expect_disabled(disabled) { - controls.forEach(function(control) { - is(control.disabled, disabled, - control.getAttribute("id") + " should " + (disabled ? "" : "not ") + "be disabled"); - }); - is(keepuntil.value, disabled ? 2 : 0, - "the keep cookies until menulist value should be as expected"); - if (disabled) { - ok(!alwaysclear.checked, - "the clear data on close checkbox value should be as expected"); - ok(!rememberhistory.checked, - "the remember history checkbox value should be as expected"); - ok(!rememberforms.checked, - "the remember forms checkbox value should be as expected"); - } - } - function check_independents(expected) { - independents.forEach(function(control) { - is(control.disabled, expected, - control.getAttribute("id") + " should " + (expected ? "" : "not ") + "be disabled"); - }); - ok(!cookieexceptions.disabled, - "the cookie exceptions button should never be disabled"); - ok(alwaysclearsettings.disabled, - "the clear data settings button should always be disabled"); - } - - // controls should only change in custom mode - historymode.value = "remember"; - controlChanged(historymode); - expect_disabled(false); - check_independents(false); - - // setting the mode to custom shouldn't change anything - historymode.value = "custom"; - controlChanged(historymode); - expect_disabled(false); - check_independents(false); -} - -function test_dependent_cookie_elements(win) { - let historymode = win.document.getElementById("historyMode"); - ok(historymode, "history mode menulist should exist"); - let pbautostart = win.document.getElementById("privateBrowsingAutoStart"); - ok(pbautostart, "the private browsing auto-start checkbox should exist"); - let controls = [ - win.document.getElementById("acceptThirdPartyLabel"), - win.document.getElementById("acceptThirdPartyMenu"), - win.document.getElementById("keepUntil"), - win.document.getElementById("keepCookiesUntil"), - ]; - controls.forEach(function(control) { - ok(control, "the dependent cookie controls should exist"); - }); - let acceptcookies = win.document.getElementById("acceptCookies"); - ok(acceptcookies, "the accept cookies checkbox should exist"); - - function expect_disabled(disabled) { - controls.forEach(function(control) { - is(control.disabled, disabled, - control.getAttribute("id") + " should " + (disabled ? "" : "not ") + "be disabled"); - }); - } - - historymode.value = "custom"; - controlChanged(historymode); - pbautostart.checked = false; - controlChanged(pbautostart); - expect_disabled(false); - - acceptcookies.checked = false; - controlChanged(acceptcookies); - expect_disabled(true); - - acceptcookies.checked = true; - controlChanged(acceptcookies); - expect_disabled(false); - - let accessthirdparty = controls.shift(); - acceptcookies.checked = false; - controlChanged(acceptcookies); - expect_disabled(true); - ok(accessthirdparty.disabled, "access third party button should be disabled"); - - pbautostart.checked = false; - controlChanged(pbautostart); - expect_disabled(true); - ok(accessthirdparty.disabled, "access third party button should be disabled"); - - acceptcookies.checked = true; - controlChanged(acceptcookies); - expect_disabled(false); - ok(!accessthirdparty.disabled, "access third party button should be enabled"); -} - -function test_dependent_clearonclose_elements(win) { - let historymode = win.document.getElementById("historyMode"); - ok(historymode, "history mode menulist should exist"); - let pbautostart = win.document.getElementById("privateBrowsingAutoStart"); - ok(pbautostart, "the private browsing auto-start checkbox should exist"); - let alwaysclear = win.document.getElementById("alwaysClear"); - ok(alwaysclear, "the clear data on close checkbox should exist"); - let alwaysclearsettings = win.document.getElementById("clearDataSettings"); - ok(alwaysclearsettings, "the clear data settings button should exist"); - - function expect_disabled(disabled) { - is(alwaysclearsettings.disabled, disabled, - "the clear data settings should " + (disabled ? "" : "not ") + "be disabled"); - } - - historymode.value = "custom"; - controlChanged(historymode); - pbautostart.checked = false; - controlChanged(pbautostart); - alwaysclear.checked = false; - controlChanged(alwaysclear); - expect_disabled(true); - - alwaysclear.checked = true; - controlChanged(alwaysclear); - expect_disabled(false); - - alwaysclear.checked = false; - controlChanged(alwaysclear); - expect_disabled(true); -} - -function test_dependent_prefs(win) { - let historymode = win.document.getElementById("historyMode"); - ok(historymode, "history mode menulist should exist"); - let controls = [ - win.document.getElementById("rememberHistory"), - win.document.getElementById("rememberForms"), - win.document.getElementById("acceptCookies"), - ]; - controls.forEach(function(control) { - ok(control, "the micro-management controls should exist"); - }); - - let thirdPartyCookieMenu = win.document.getElementById("acceptThirdPartyMenu"); - ok(thirdPartyCookieMenu, "the third-party cookie control should exist"); - - function expect_checked(checked) { - controls.forEach(function(control) { - is(control.checked, checked, - control.getAttribute("id") + " should " + (checked ? "not " : "") + "be checked"); - }); - - is(thirdPartyCookieMenu.value == "always" || thirdPartyCookieMenu.value == "visited", checked, "third-party cookies should " + (checked ? "not " : "") + "be limited"); - } - - // controls should be checked in remember mode - historymode.value = "remember"; - controlChanged(historymode); - expect_checked(true); - - // even if they're unchecked in custom mode - historymode.value = "custom"; - controlChanged(historymode); - thirdPartyCookieMenu.value = "never"; - controlChanged(thirdPartyCookieMenu); - controls.forEach(function(control) { - control.checked = false; - controlChanged(control); - }); - expect_checked(false); - historymode.value = "remember"; - controlChanged(historymode); - expect_checked(true); -} - -function test_historymode_retention(mode, expect) { - return function(win) { - let historymode = win.document.getElementById("historyMode"); - ok(historymode, "history mode menulist should exist"); - - if ((historymode.value == "remember" && mode == "dontremember") || - (historymode.value == "dontremember" && mode == "remember") || - (historymode.value == "custom" && mode == "dontremember")) { - return; - } - - if (expect !== undefined) { - is(historymode.value, expect, - "history mode is expected to remain " + expect); - } - - historymode.value = mode; - controlChanged(historymode); - }; -} - -function test_custom_retention(controlToChange, expect, valueIncrement) { - return function(win) { - let historymode = win.document.getElementById("historyMode"); - ok(historymode, "history mode menulist should exist"); - - if (expect !== undefined) { - is(historymode.value, expect, - "history mode is expected to remain " + expect); - } - - historymode.value = "custom"; - controlChanged(historymode); - - controlToChange = win.document.getElementById(controlToChange); - ok(controlToChange, "the control to change should exist"); - switch (controlToChange.localName) { - case "checkbox": - controlToChange.checked = !controlToChange.checked; - break; - case "textbox": - controlToChange.value = parseInt(controlToChange.value) + valueIncrement; - break; - case "menulist": - controlToChange.value = valueIncrement; - break; - } - controlChanged(controlToChange); - }; -} - -function test_locbar_suggestion_retention(mode, expect) { - return function(win) { - let locbarsuggest = win.document.getElementById("locationBarSuggestion"); - ok(locbarsuggest, "location bar suggestion menulist should exist"); - - if (expect !== undefined) { - is(locbarsuggest.value, expect, - "location bar suggestion is expected to remain " + expect); - } - - locbarsuggest.value = mode; - controlChanged(locbarsuggest); - }; -} - -function reset_preferences(win) { - let prefs = win.document.getElementsByTagName("preference"); - for (let i = 0; i < prefs.length; ++i) - if (prefs[i].hasUserValue) - prefs[i].reset(); -} - -let testRunner; -function run_test_subset(subset) { - let instantApplyOrig = Services.prefs.getBoolPref("browser.preferences.instantApply"); - Services.prefs.setBoolPref("browser.preferences.instantApply", true); - - waitForExplicitFinish(); - - testRunner = { - tests: subset, - counter: 0, - runNext: function() { - if (this.counter == this.tests.length) { - // cleanup - Services.prefs.setBoolPref("browser.preferences.instantApply", instantApplyOrig); - finish(); - } else { - let self = this; - setTimeout(function() { - runTestOnPrivacyPrefPane(self.tests[self.counter++]); - }, 0); - } - } - }; - - testRunner.runNext(); -} diff --git a/browser/components/privatebrowsing/moz.build b/browser/components/privatebrowsing/moz.build index 443915d0d..b90585f09 100644 --- a/browser/components/privatebrowsing/moz.build +++ b/browser/components/privatebrowsing/moz.build @@ -4,7 +4,5 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -TEST_DIRS += ['test'] - MODULE = 'privatebrowsing' diff --git a/browser/components/privatebrowsing/test/browser/Makefile.in b/browser/components/privatebrowsing/test/browser/Makefile.in deleted file mode 100644 index f15d6056b..000000000 --- a/browser/components/privatebrowsing/test/browser/Makefile.in +++ /dev/null @@ -1,58 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -DEPTH = @DEPTH@ -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ -relativesrcdir = @relativesrcdir@ - -include $(DEPTH)/config/autoconf.mk - -MOCHITEST_BROWSER_FILES = \ - head.js \ - browser_privatebrowsing_aboutHomeButtonAfterWindowClose.js \ - browser_privatebrowsing_aboutSessionRestore.js \ - browser_privatebrowsing_certexceptionsui.js \ - browser_privatebrowsing_concurrent.js \ - browser_privatebrowsing_concurrent_page.html \ - browser_privatebrowsing_cookieacceptdialog.js \ - browser_privatebrowsing_cookieacceptdialog.html \ - browser_privatebrowsing_crh.js \ - browser_privatebrowsing_downloadLastDir.js \ - browser_privatebrowsing_downloadLastDir_c.js \ - browser_privatebrowsing_downloadLastDir_toggle.js \ - browser_privatebrowsing_DownloadLastDirWithCPS.js \ - browser_privatebrowsing_geoprompt.js \ - browser_privatebrowsing_geoprompt_page.html \ - browser_privatebrowsing_lastpbcontextexited.js \ - browser_privatebrowsing_localStorage.js \ - browser_privatebrowsing_localStorage_before_after.js \ - browser_privatebrowsing_localStorage_before_after_page.html \ - browser_privatebrowsing_localStorage_before_after_page2.html \ - browser_privatebrowsing_localStorage_page1.html \ - browser_privatebrowsing_localStorage_page2.html \ - browser_privatebrowsing_nonbrowser.js \ - browser_privatebrowsing_noSessionRestoreMenuOption.js \ - browser_privatebrowsing_opendir.js \ - browser_privatebrowsing_openlocation.js \ - browser_privatebrowsing_openLocationLastURL.js \ - browser_privatebrowsing_placestitle.js \ - browser_privatebrowsing_placesTitleNoUpdate.js \ - browser_privatebrowsing_placesTitleNoUpdate.html \ - browser_privatebrowsing_popupblocker.js \ - browser_privatebrowsing_protocolhandler.js \ - browser_privatebrowsing_protocolhandler_page.html \ - browser_privatebrowsing_theming.js \ - browser_privatebrowsing_ui.js \ - browser_privatebrowsing_urlbarfocus.js \ - browser_privatebrowsing_windowtitle.js \ - browser_privatebrowsing_windowtitle_page.html \ - browser_privatebrowsing_zoom.js \ - browser_privatebrowsing_zoomrestore.js \ - popup.html \ - title.sjs \ - $(NULL) - -include $(topsrcdir)/config/rules.mk diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_DownloadLastDirWithCPS.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_DownloadLastDirWithCPS.js deleted file mode 100644 index 29c95e179..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_DownloadLastDirWithCPS.js +++ /dev/null @@ -1,279 +0,0 @@ -/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -let gTests; -function test() { - waitForExplicitFinish(); - requestLongerTimeout(2); - gTests = runTest(); - gTests.next(); -} - -/* - * ================ - * Helper functions - * ================ - */ - -function moveAlong(aResult) { - try { - gTests.send(aResult); - } catch (x if x instanceof StopIteration) { - finish(); - } -} - -function createWindow(aOptions) { - whenNewWindowLoaded(aOptions, function(win) { - moveAlong(win); - }); -} - -function getFile(downloadLastDir, aURI) { - downloadLastDir.getFileAsync(aURI, function(result) { - moveAlong(result); - }); -} - -function setFile(downloadLastDir, aURI, aValue) { - downloadLastDir.setFile(aURI, aValue); - executeSoon(moveAlong); -} - -function clearHistoryAndWait() { - clearHistory(); - executeSoon(function() executeSoon(moveAlong)); -} - -/* - * =================== - * Function with tests - * =================== - */ - -function runTest() { - let FileUtils = - Cu.import("resource://gre/modules/FileUtils.jsm", {}).FileUtils; - let DownloadLastDir = - Cu.import("resource://gre/modules/DownloadLastDir.jsm", {}).DownloadLastDir; - - let tmpDir = FileUtils.getDir("TmpD", [], true); - let dir1 = newDirectory(); - let dir2 = newDirectory(); - let dir3 = newDirectory(); - - let uri1 = Services.io.newURI("http://test1.com/", null, null); - let uri2 = Services.io.newURI("http://test2.com/", null, null); - let uri3 = Services.io.newURI("http://test3.com/", null, null); - let uri4 = Services.io.newURI("http://test4.com/", null, null); - - // cleanup functions registration - registerCleanupFunction(function () { - Services.prefs.clearUserPref("browser.download.lastDir.savePerSite"); - Services.prefs.clearUserPref("browser.download.lastDir"); - [dir1, dir2, dir3].forEach(function(dir) dir.remove(true)); - win.close(); - pbWin.close(); - }); - - function checkDownloadLastDir(gDownloadLastDir, aLastDir) { - is(gDownloadLastDir.file.path, aLastDir.path, - "gDownloadLastDir should point to the expected last directory"); - getFile(gDownloadLastDir, uri1); - } - - function checkDownloadLastDirNull(gDownloadLastDir) { - is(gDownloadLastDir.file, null, "gDownloadLastDir should be null"); - getFile(gDownloadLastDir, uri1); - } - - /* - * ================================ - * Create a regular and a PB window - * ================================ - */ - - let win = yield createWindow({private: false}); - let pbWin = yield createWindow({private: true}); - - let downloadLastDir = new DownloadLastDir(win); - let pbDownloadLastDir = new DownloadLastDir(pbWin); - - /* - * ================== - * Beginning of tests - * ================== - */ - - is(typeof downloadLastDir, "object", - "downloadLastDir should be a valid object"); - is(downloadLastDir.file, null, - "LastDir pref should be null to start with"); - - // set up last dir - yield setFile(downloadLastDir, null, tmpDir); - is(downloadLastDir.file.path, tmpDir.path, - "LastDir should point to the tmpDir"); - isnot(downloadLastDir.file, tmpDir, - "downloadLastDir.file should not be pointing to tmpDir"); - - // set uri1 to dir1, all should now return dir1 - // also check that a new object is returned - yield setFile(downloadLastDir, uri1, dir1); - is(downloadLastDir.file.path, dir1.path, - "downloadLastDir should return dir1"); - isnot(downloadLastDir.file, dir1, - "downloadLastDir.file should not return dir1"); - is((yield getFile(downloadLastDir, uri1)).path, dir1.path, - "uri1 should return dir1"); // set in CPS - isnot((yield getFile(downloadLastDir, uri1)), dir1, - "getFile on uri1 should not return dir1"); - is((yield getFile(downloadLastDir, uri2)).path, dir1.path, - "uri2 should return dir1"); // fallback - isnot((yield getFile(downloadLastDir, uri2)), dir1, - "getFile on uri2 should not return dir1"); - is((yield getFile(downloadLastDir, uri3)).path, dir1.path, - "uri3 should return dir1"); // fallback - isnot((yield getFile(downloadLastDir, uri3)), dir1, - "getFile on uri3 should not return dir1"); - is((yield getFile(downloadLastDir, uri4)).path, dir1.path, - "uri4 should return dir1"); // fallback - isnot((yield getFile(downloadLastDir, uri4)), dir1, - "getFile on uri4 should not return dir1"); - - // set uri2 to dir2, all except uri1 should now return dir2 - yield setFile(downloadLastDir, uri2, dir2); - is(downloadLastDir.file.path, dir2.path, - "downloadLastDir should point to dir2"); - is((yield getFile(downloadLastDir, uri1)).path, dir1.path, - "uri1 should return dir1"); // set in CPS - is((yield getFile(downloadLastDir, uri2)).path, dir2.path, - "uri2 should return dir2"); // set in CPS - is((yield getFile(downloadLastDir, uri3)).path, dir2.path, - "uri3 should return dir2"); // fallback - is((yield getFile(downloadLastDir, uri4)).path, dir2.path, - "uri4 should return dir2"); // fallback - - // set uri3 to dir3, all except uri1 and uri2 should now return dir3 - yield setFile(downloadLastDir, uri3, dir3); - is(downloadLastDir.file.path, dir3.path, - "downloadLastDir should point to dir3"); - is((yield getFile(downloadLastDir, uri1)).path, dir1.path, - "uri1 should return dir1"); // set in CPS - is((yield getFile(downloadLastDir, uri2)).path, dir2.path, - "uri2 should return dir2"); // set in CPS - is((yield getFile(downloadLastDir, uri3)).path, dir3.path, - "uri3 should return dir3"); // set in CPS - is((yield getFile(downloadLastDir, uri4)).path, dir3.path, - "uri4 should return dir4"); // fallback - - // set uri1 to dir2, all except uri3 should now return dir2 - yield setFile(downloadLastDir, uri1, dir2); - is(downloadLastDir.file.path, dir2.path, - "downloadLastDir should point to dir2"); - is((yield getFile(downloadLastDir, uri1)).path, dir2.path, - "uri1 should return dir2"); // set in CPS - is((yield getFile(downloadLastDir, uri2)).path, dir2.path, - "uri2 should return dir2"); // set in CPS - is((yield getFile(downloadLastDir, uri3)).path, dir3.path, - "uri3 should return dir3"); // set in CPS - is((yield getFile(downloadLastDir, uri4)).path, dir2.path, - "uri4 should return dir2"); // fallback - - yield clearHistoryAndWait(); - - // check clearHistory removes all data - is(downloadLastDir.file, null, "clearHistory removes all data"); - //is(Services.contentPrefs.hasPref(uri1, "browser.download.lastDir", null), - // false, "LastDir preference should be absent"); - is((yield getFile(downloadLastDir, uri1)), null, "uri1 should point to null"); - is((yield getFile(downloadLastDir, uri2)), null, "uri2 should point to null"); - is((yield getFile(downloadLastDir, uri3)), null, "uri3 should point to null"); - is((yield getFile(downloadLastDir, uri4)), null, "uri4 should point to null"); - - yield setFile(downloadLastDir, null, tmpDir); - - // check data set outside PB mode is remembered - is((yield checkDownloadLastDir(pbDownloadLastDir, tmpDir)).path, tmpDir.path, "uri1 should return the expected last directory"); - is((yield checkDownloadLastDir(downloadLastDir, tmpDir)).path, tmpDir.path, "uri1 should return the expected last directory"); - yield clearHistoryAndWait(); - - yield setFile(downloadLastDir, uri1, dir1); - - // check data set using CPS outside PB mode is remembered - is((yield checkDownloadLastDir(pbDownloadLastDir, dir1)).path, dir1.path, "uri1 should return the expected last directory"); - is((yield checkDownloadLastDir(downloadLastDir, dir1)).path, dir1.path, "uri1 should return the expected last directory"); - yield clearHistoryAndWait(); - - // check data set inside PB mode is forgotten - yield setFile(pbDownloadLastDir, null, tmpDir); - - is((yield checkDownloadLastDir(pbDownloadLastDir, tmpDir)).path, tmpDir.path, "uri1 should return the expected last directory"); - is((yield checkDownloadLastDirNull(downloadLastDir)), null, "uri1 should return the expected last directory"); - - yield clearHistoryAndWait(); - - // check data set using CPS inside PB mode is forgotten - yield setFile(pbDownloadLastDir, uri1, dir1); - - is((yield checkDownloadLastDir(pbDownloadLastDir, dir1)).path, dir1.path, "uri1 should return the expected last directory"); - is((yield checkDownloadLastDirNull(downloadLastDir)), null, "uri1 should return the expected last directory"); - - // check data set outside PB mode but changed inside is remembered correctly - yield setFile(downloadLastDir, uri1, dir1); - yield setFile(pbDownloadLastDir, uri1, dir2); - is((yield checkDownloadLastDir(pbDownloadLastDir, dir2)).path, dir2.path, "uri1 should return the expected last directory"); - is((yield checkDownloadLastDir(downloadLastDir, dir1)).path, dir1.path, "uri1 should return the expected last directory"); - - /* - * ==================== - * Create new PB window - * ==================== - */ - - // check that the last dir store got cleared in a new PB window - pbWin.close(); - let pbWin = yield createWindow({private: true}); - let pbDownloadLastDir = new DownloadLastDir(pbWin); - - is((yield checkDownloadLastDir(pbDownloadLastDir, dir1)).path, dir1.path, "uri1 should return the expected last directory"); - - yield clearHistoryAndWait(); - - // check clearHistory inside PB mode clears data outside PB mode - yield setFile(pbDownloadLastDir, uri1, dir2); - - yield clearHistoryAndWait(); - - is((yield checkDownloadLastDirNull(downloadLastDir)), null, "uri1 should return the expected last directory"); - is((yield checkDownloadLastDirNull(pbDownloadLastDir)), null, "uri1 should return the expected last directory"); - - // check that disabling CPS works - Services.prefs.setBoolPref("browser.download.lastDir.savePerSite", false); - - yield setFile(downloadLastDir, uri1, dir1); - is(downloadLastDir.file.path, dir1.path, "LastDir should be set to dir1"); - is((yield getFile(downloadLastDir, uri1)).path, dir1.path, "uri1 should return dir1"); - is((yield getFile(downloadLastDir, uri2)).path, dir1.path, "uri2 should return dir1"); - is((yield getFile(downloadLastDir, uri3)).path, dir1.path, "uri3 should return dir1"); - is((yield getFile(downloadLastDir, uri4)).path, dir1.path, "uri4 should return dir1"); - - downloadLastDir.setFile(uri2, dir2); - is(downloadLastDir.file.path, dir2.path, "LastDir should be set to dir2"); - is((yield getFile(downloadLastDir, uri1)).path, dir2.path, "uri1 should return dir2"); - is((yield getFile(downloadLastDir, uri2)).path, dir2.path, "uri2 should return dir2"); - is((yield getFile(downloadLastDir, uri3)).path, dir2.path, "uri3 should return dir2"); - is((yield getFile(downloadLastDir, uri4)).path, dir2.path, "uri4 should return dir2"); - - Services.prefs.clearUserPref("browser.download.lastDir.savePerSite"); - - // check that passing null to setFile clears the stored value - yield setFile(downloadLastDir, uri3, dir3); - is((yield getFile(downloadLastDir, uri3)).path, dir3.path, "LastDir should be set to dir3"); - yield setFile(downloadLastDir, uri3, null); - is((yield getFile(downloadLastDir, uri3)), null, "uri3 should return null"); - - yield clearHistoryAndWait(); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_aboutHomeButtonAfterWindowClose.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_aboutHomeButtonAfterWindowClose.js deleted file mode 100644 index dc61c1e00..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_aboutHomeButtonAfterWindowClose.js +++ /dev/null @@ -1,50 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test checks that the Session Restore about:home button -// is disabled in private mode - -function test() { - waitForExplicitFinish(); - - function testNoSessionRestoreButton() { - let win = OpenBrowserWindow({private: true}); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - executeSoon(function() { - info("The second private window got loaded"); - let newTab = win.gBrowser.addTab(); - win.gBrowser.selectedTab = newTab; - let tabBrowser = win.gBrowser.getBrowserForTab(newTab); - tabBrowser.addEventListener("load", function tabLoadListener() { - if (win.content.location != "about:home") { - win.content.location = "about:home"; - return; - } - tabBrowser.removeEventListener("load", tabLoadListener, true); - executeSoon(function() { - info("about:home got loaded"); - let sessionRestoreButton = win.gBrowser - .contentDocument - .getElementById("restorePreviousSession"); - is(win.getComputedStyle(sessionRestoreButton).display, - "none", "The Session Restore about:home button should be disabled"); - win.close(); - finish(); - }); - }, true); - }); - }, false); - } - - let win = OpenBrowserWindow({private: true}); - win.addEventListener("load", function onload() { - win.removeEventListener("load", onload, false); - executeSoon(function() { - info("The first private window got loaded"); - win.close(); - testNoSessionRestoreButton(); - }); - }, false); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_aboutSessionRestore.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_aboutSessionRestore.js deleted file mode 100644 index 610304fc1..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_aboutSessionRestore.js +++ /dev/null @@ -1,49 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test checks that the session restore button from about:sessionrestore -// is disabled in private mode - -function test() { - waitForExplicitFinish(); - - function testNoSessionRestoreButton() { - let win = OpenBrowserWindow({private: true}); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - executeSoon(function() { - info("The second private window got loaded"); - let newTab = win.gBrowser.addTab("about:sessionrestore"); - win.gBrowser.selectedTab = newTab; - let tabBrowser = win.gBrowser.getBrowserForTab(newTab); - tabBrowser.addEventListener("load", function tabLoadListener() { - if (win.gBrowser.contentWindow.location != "about:sessionrestore") { - win.gBrowser.selectedBrowser.loadURI("about:sessionrestore"); - return; - } - tabBrowser.removeEventListener("load", tabLoadListener, true); - executeSoon(function() { - info("about:sessionrestore got loaded"); - let restoreButton = win.gBrowser.contentDocument - .getElementById("errorTryAgain"); - ok(restoreButton.disabled, - "The Restore about:sessionrestore button should be disabled"); - win.close(); - finish(); - }); - }, true); - }); - }, false); - } - - let win = OpenBrowserWindow({private: true}); - win.addEventListener("load", function onload() { - win.removeEventListener("load", onload, false); - executeSoon(function() { - info("The first private window got loaded"); - win.close(); - testNoSessionRestoreButton(); - }); - }, false); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_certexceptionsui.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_certexceptionsui.js deleted file mode 100644 index 519f43475..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_certexceptionsui.js +++ /dev/null @@ -1,53 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test makes sure that certificate exceptions UI behaves correctly -// in private browsing windows, based on whether it's opened from the prefs -// window or from the SSL error page (see bug 461627). - -function test() { - const EXCEPTIONS_DLG_URL = 'chrome://pippki/content/exceptionDialog.xul'; - const EXCEPTIONS_DLG_FEATURES = 'chrome,centerscreen'; - const INVALID_CERT_LOCATION = 'https://nocert.example.com/'; - waitForExplicitFinish(); - - // open a private browsing window - var pbWin = OpenBrowserWindow({private: true}); - pbWin.addEventListener("load", function onLoad() { - pbWin.removeEventListener("load", onLoad, false); - doTest(); - }, false); - - // Test the certificate exceptions dialog - function doTest() { - let params = { - exceptionAdded : false, - location: INVALID_CERT_LOCATION, - prefetchCert: true, - }; - function testCheckbox() { - win.removeEventListener("load", testCheckbox, false); - Services.obs.addObserver(function onCertUI(aSubject, aTopic, aData) { - Services.obs.removeObserver(onCertUI, "cert-exception-ui-ready"); - ok(win.gCert, "The certificate information should be available now"); - - let checkbox = win.document.getElementById("permanent"); - ok(checkbox.hasAttribute("disabled"), - "the permanent checkbox should be disabled when handling the private browsing mode"); - ok(!checkbox.hasAttribute("checked"), - "the permanent checkbox should not be checked when handling the private browsing mode"); - win.close(); - cleanup(); - }, "cert-exception-ui-ready", false); - } - var win = pbWin.openDialog(EXCEPTIONS_DLG_URL, "", EXCEPTIONS_DLG_FEATURES, params); - win.addEventListener("load", testCheckbox, false); - } - - function cleanup() { - // close the private browsing window - pbWin.close(); - finish(); - } -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_concurrent.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_concurrent.js deleted file mode 100644 index c06c7c05a..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_concurrent.js +++ /dev/null @@ -1,73 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// Test opening two tabs that share a localStorage, but keep one in private mode. -// Ensure that values from one don't leak into the other, and that values from -// earlier private storage sessions aren't visible later. - -// Step 1: create new tab, load a page that sets test=value in non-private storage -// Step 2: create a new tab, load a page that sets test2=value2 in private storage -// Step 3: load a page in the tab from step 1 that checks the value of test2 is value2 and the total count in non-private storage is 1 -// Step 4: load a page in the tab from step 2 that checks the value of test is value and the total count in private storage is 1 - -function test() { - let prefix = 'http://mochi.test:8888/browser/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_concurrent_page.html'; - waitForExplicitFinish(); - gBrowser.selectedTab = gBrowser.addTab(); - let non_private_tab = gBrowser.selectedBrowser; - non_private_tab.addEventListener('load', function() { - non_private_tab.removeEventListener('load', arguments.callee, true); - gBrowser.selectedTab = gBrowser.addTab(); - let private_tab = gBrowser.selectedBrowser; - private_tab.docShell.QueryInterface(Ci.nsILoadContext).usePrivateBrowsing = true; - private_tab.addEventListener('load', function() { - private_tab.removeEventListener('load', arguments.callee, true); - - non_private_tab.addEventListener('load', function() { - non_private_tab.removeEventListener('load', arguments.callee, true); - var elts = non_private_tab.contentWindow.document.title.split('|'); - isnot(elts[0], 'value2', "public window shouldn't see private storage"); - is(elts[1], '1', "public window should only see public items"); - - private_tab.addEventListener('load', function() { - private_tab.removeEventListener('load', arguments.callee, true); - var elts = private_tab.contentWindow.document.title.split('|'); - isnot(elts[0], 'value', "private window shouldn't see public storage"); - is(elts[1], '1', "private window should only see private items"); - private_tab.docShell.QueryInterface(Ci.nsILoadContext).usePrivateBrowsing = false; - - Components.utils.schedulePreciseGC(function() { - private_tab.addEventListener('load', function() { - private_tab.removeEventListener('load', arguments.callee, true); - var elts = private_tab.contentWindow.document.title.split('|'); - isnot(elts[0], 'value2', "public window shouldn't see cleared private storage"); - is(elts[1], '1', "public window should only see public items"); - - private_tab.docShell.QueryInterface(Ci.nsILoadContext).usePrivateBrowsing = true; - private_tab.addEventListener('load', function() { - private_tab.removeEventListener('load', arguments.callee, true); - var elts = private_tab.contentWindow.document.title.split('|'); - is(elts[1], '1', "private window should only see new private items"); - - non_private_tab.addEventListener('load', function() { - gBrowser.removeCurrentTab(); - gBrowser.removeCurrentTab(); - finish(); - }, true); - non_private_tab.loadURI(prefix + '?final=true'); - - }, true); - private_tab.loadURI(prefix + '?action=set&name=test3&value=value3'); - }, true); - private_tab.loadURI(prefix + '?action=get&name=test2'); - }); - }, true); - private_tab.loadURI(prefix + '?action=get&name=test'); - }, true); - non_private_tab.loadURI(prefix + '?action=get&name=test2'); - }, true); - private_tab.loadURI(prefix + '?action=set&name=test2&value=value2'); - }, true); - non_private_tab.loadURI(prefix + '?action=set&name=test&value=value&initial=true'); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_concurrent_page.html b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_concurrent_page.html deleted file mode 100644 index db35b114d..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_concurrent_page.html +++ /dev/null @@ -1,33 +0,0 @@ -<html xmlns="http://www.w3.org/1999/xhtml"> -<head> -<script type="text/javascript"> - var oGetVars = {}; - - if (window.location.search.length > 1) { - for (var aItKey, nKeyId = 0, aCouples = window.location.search.substr(1).split("&"); - nKeyId < aCouples.length; - nKeyId++) { - aItKey = aCouples[nKeyId].split("="); - oGetVars[unescape(aItKey[0])] = aItKey.length > 1 ? unescape(aItKey[1]) : ""; - } - } - - if (oGetVars.initial == 'true') { - localStorage.clear(); - } - - if (oGetVars.action == 'set') { - localStorage.setItem(oGetVars.name, oGetVars.value); - document.title = localStorage.getItem(oGetVars.name) + "|" + localStorage.length; - } else if (oGetVars.action == 'get') { - document.title = localStorage.getItem(oGetVars.name) + "|" + localStorage.length; - } - - if (oGetVars.final == 'true') { - localStorage.clear(); - } -</script> -</head> -<body> -</body> -</html> diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cookieacceptdialog.html b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cookieacceptdialog.html deleted file mode 100644 index 80ac1bd64..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cookieacceptdialog.html +++ /dev/null @@ -1,11 +0,0 @@ -<!DOCTYPE HTML> -<html> -<head> - <title>browser_privatebrowsing_cookieacceptdialog.html</title> - <script type="application/javascript"> - document.cookie = "foo=bar"; - </script> -</head> -<body> -</body> -</html> diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cookieacceptdialog.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cookieacceptdialog.js deleted file mode 100644 index a21aa7c31..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cookieacceptdialog.js +++ /dev/null @@ -1,161 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test makes sure that private browsing mode disables the "remember" -// option in the cookie accept dialog. - -function test() { - // initialization - const TEST_URL = "http://mochi.test:8888/browser/browser/components/" + - "privatebrowsing/test/browser/" + - "browser_privatebrowsing_cookieacceptdialog.html"; - const BLANK_URL = "http://mochi.test:8888/"; - let cp = Cc["@mozilla.org/embedcomp/cookieprompt-service;1"]. - getService(Ci.nsICookiePromptService); - - waitForExplicitFinish(); - - function checkRememberOption(expectedDisabled, aWindow, callback) { - function observer(aSubject, aTopic, aData) { - if (aTopic != "domwindowopened") - return; - - Services.ww.unregisterNotification(observer); - let win = aSubject.QueryInterface(Ci.nsIDOMWindow); - win.addEventListener("load", function onLoad(event) { - win.removeEventListener("load", onLoad, false); - - executeSoon(function () { - let doc = win.document; - let remember = doc.getElementById("persistDomainAcceptance"); - ok(remember, "The remember checkbox should exist"); - - if (expectedDisabled) - is(remember.getAttribute("disabled"), "true", - "The checkbox should be disabled"); - else - ok(!remember.hasAttribute("disabled"), - "The checkbox should not be disabled"); - - waitForWindowClose(win, callback); - }); - }, false); - } - Services.ww.registerNotification(observer); - - let remember = {}; - const time = (new Date("Jan 1, 2030")).getTime() / 1000; - let cookie = { - name: "foo", - value: "bar", - isDomain: true, - host: "mozilla.org", - path: "/baz", - isSecure: false, - expires: time, - status: 0, - policy: 0, - isSession: false, - expiry: time, - isHttpOnly: true, - QueryInterface: function(iid) { - const validIIDs = [Ci.nsISupports, Ci.nsICookie, Ci.nsICookie2]; - for (var i = 0; i < validIIDs.length; ++i) - if (iid == validIIDs[i]) - return this; - throw Cr.NS_ERROR_NO_INTERFACE; - } - }; - cp.cookieDialog(aWindow, cookie, "mozilla.org", 10, false, remember); - } - - function checkSettingDialog(aIsPrivateWindow, aWindow, aCallback) { - let selectedBrowser = aWindow.gBrowser.selectedBrowser; - - function onLoad() { - if (aWindow.content.location.href != TEST_URL) { - selectedBrowser.loadURI(TEST_URL); - return; - } - selectedBrowser.removeEventListener("load", onLoad, true); - Services.ww.unregisterNotification(observer); - - ok(aIsPrivateWindow, - "Confirm setting dialog is not displayed for private window"); - - executeSoon(aCallback); - } - selectedBrowser.addEventListener("load", onLoad, true); - - function observer(aSubject, aTopic, aData) { - if (aTopic != "domwindowopened") - return; - selectedBrowser.removeEventListener("load", onLoad, true); - Services.ww.unregisterNotification(observer); - ok(!aIsPrivateWindow, - "Confirm setting dialog is displayed for normal window"); - let win = aSubject.QueryInterface(Ci.nsIDOMWindow); - executeSoon(function () { - info("Wait for window close"); - waitForWindowClose(win, aCallback); - }); - } - Services.ww.registerNotification(observer); - - selectedBrowser.loadURI(TEST_URL); - } - - let windowsToClose = []; - function testOnWindow(aIsPrivate, aCallback) { - whenNewWindowLoaded({private: aIsPrivate}, function(aWin) { - windowsToClose.push(aWin); - let selectedBrowser = aWin.gBrowser.selectedBrowser; - selectedBrowser.addEventListener("load", function onLoad() { - if (aWin.content.location.href != BLANK_URL) { - selectedBrowser.loadURI(BLANK_URL); - return; - } - selectedBrowser.removeEventListener("load", onLoad, true); - executeSoon(function() aCallback(aWin)); - }, true); - selectedBrowser.loadURI(BLANK_URL); - }); - } - - registerCleanupFunction(function() { - Services.prefs.clearUserPref("network.cookie.lifetimePolicy"); - windowsToClose.forEach(function(aWin) { - aWin.close(); - }); - }); - - // Ask all cookies - Services.prefs.setIntPref("network.cookie.lifetimePolicy", 1); - - testOnWindow(false, function(aWin) { - info("Test on public window"); - checkRememberOption(false, aWin, function() { - checkSettingDialog(false, aWin, function() { - testOnWindow(true, function(aPrivWin) { - info("Test on private window"); - checkRememberOption(true, aPrivWin, function() { - checkSettingDialog(true, aPrivWin, finish); - }); - }); - }); - }); - }); -} - -function waitForWindowClose(aWin, aCallback) { - function observer(aSubject, aTopic, aData) { - if (aTopic == "domwindowclosed") { - info("Window closed"); - Services.ww.unregisterNotification(observer); - executeSoon(aCallback); - } - } - Services.ww.registerNotification(observer); - aWin.close(); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_crh.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_crh.js deleted file mode 100644 index 14f62448b..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_crh.js +++ /dev/null @@ -1,59 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test makes sure that the Clear Recent History menu item and command -// is disabled inside the private browsing mode. - -function test() { - waitForExplicitFinish(); - - function checkDisableOption(aPrivateMode, aWindow, aCallback) { - executeSoon(function() { - let crhCommand = aWindow.document.getElementById("Tools:Sanitize"); - ok(crhCommand, "The clear recent history command should exist"); - - is(PrivateBrowsingUtils.isWindowPrivate(aWindow), aPrivateMode, - "PrivateBrowsingUtils should report the correct per-window private browsing status"); - is(crhCommand.hasAttribute("disabled"), aPrivateMode, - "Clear Recent History command should be disabled according to the private browsing mode"); - - executeSoon(aCallback); - }); - }; - - let windowsToClose = []; - let testURI = "http://mochi.test:8888/"; - - function testOnWindow(aIsPrivate, aCallback) { - whenNewWindowLoaded({private: aIsPrivate}, function(aWin) { - windowsToClose.push(aWin); - aWin.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - if (aWin.content.location.href != testURI) { - aWin.gBrowser.loadURI(testURI); - return; - } - aWin.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); - executeSoon(function() aCallback(aWin)); - }, true); - - aWin.gBrowser.loadURI(testURI); - }); - }; - - registerCleanupFunction(function() { - windowsToClose.forEach(function(aWin) { - aWin.close(); - }); - }); - - testOnWindow(true, function(aWin) { - info("Test on private window"); - checkDisableOption(true, aWin, function() { - testOnWindow(false, function(aPrivWin) { - info("Test on public window"); - checkDisableOption(false, aPrivWin, finish); - }); - }); - }); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_downloadLastDir.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_downloadLastDir.js deleted file mode 100644 index 0012442bd..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_downloadLastDir.js +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - waitForExplicitFinish(); - - let FileUtils = - Cu.import("resource://gre/modules/FileUtils.jsm", {}).FileUtils; - let DownloadLastDir = - Cu.import("resource://gre/modules/DownloadLastDir.jsm", {}).DownloadLastDir; - let MockFilePicker = SpecialPowers.MockFilePicker; - let launcher = { - source: Services.io.newURI("http://test1.com/file", null, null) - }; - - MockFilePicker.init(window); - MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK; - - let prefs = Services.prefs.getBranch("browser.download."); - let launcherDialog = - Cc["@mozilla.org/helperapplauncherdialog;1"]. - getService(Ci.nsIHelperAppLauncherDialog); - let tmpDir = FileUtils.getDir("TmpD", [], true); - let dir1 = newDirectory(); - let dir2 = newDirectory(); - let dir3 = newDirectory(); - let file1 = newFileInDirectory(dir1); - let file2 = newFileInDirectory(dir2); - let file3 = newFileInDirectory(dir3); - - // cleanup functions registration - registerCleanupFunction(function () { - Services.prefs.clearUserPref("browser.download.lastDir"); - [dir1, dir2, dir3].forEach(function(dir) dir.remove(true)); - MockFilePicker.cleanup(); - }); - prefs.setComplexValue("lastDir", Ci.nsIFile, tmpDir); - - function testOnWindow(aPrivate, aCallback) { - whenNewWindowLoaded({private: aPrivate}, function(win) { - let gDownloadLastDir = new DownloadLastDir(win); - aCallback(win, gDownloadLastDir); - gDownloadLastDir.cleanupPrivateFile(); - }); - } - - function testDownloadDir(aWin, gDownloadLastDir, aFile, aDisplayDir, aLastDir, - aGlobalLastDir, aCallback) { - let context = aWin.gBrowser.selectedBrowser.contentWindow; - - // Check lastDir preference. - is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, aDisplayDir.path, - "LastDir should be the expected display dir"); - // Check gDownloadLastDir value. - is(gDownloadLastDir.file.path, aDisplayDir.path, - "gDownloadLastDir should be the expected display dir"); - - MockFilePicker.returnFiles = [aFile]; - MockFilePicker.displayDirectory = null; - - launcher.saveDestinationAvailable = function (file) { - ok(!!file, "promptForSaveToFile correctly returned a file"); - - // File picker should start with expected display dir. - is(MockFilePicker.displayDirectory.path, aDisplayDir.path, - "File picker should start with browser.download.lastDir"); - // browser.download.lastDir should be modified on not private windows - is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, aLastDir.path, - "LastDir should be the expected last dir"); - // gDownloadLastDir should be usable outside of private windows - is(gDownloadLastDir.file.path, aGlobalLastDir.path, - "gDownloadLastDir should be the expected global last dir"); - - launcher.saveDestinationAvailable = null; - aWin.close(); - aCallback(); - }; - - launcherDialog.promptForSaveToFileAsync(launcher, context, null, null, null); - } - - testOnWindow(false, function(win, downloadDir) { - testDownloadDir(win, downloadDir, file1, tmpDir, dir1, dir1, function() { - testOnWindow(true, function(win, downloadDir) { - testDownloadDir(win, downloadDir, file2, dir1, dir1, dir2, function() { - testOnWindow(false, function(win, downloadDir) { - testDownloadDir(win, downloadDir, file3, dir1, dir3, dir3, finish); - }); - }); - }); - }); - }); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_downloadLastDir_c.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_downloadLastDir_c.js deleted file mode 100644 index 1444d3d93..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_downloadLastDir_c.js +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - waitForExplicitFinish(); - - let FileUtils = - Cu.import("resource://gre/modules/FileUtils.jsm", {}).FileUtils; - let DownloadLastDir = - Cu.import("resource://gre/modules/DownloadLastDir.jsm", {}).DownloadLastDir; - let MockFilePicker = SpecialPowers.MockFilePicker; - - MockFilePicker.init(window); - MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK; - - let validateFileNameToRestore = validateFileName; - let prefs = Services.prefs.getBranch("browser.download."); - let tmpDir = FileUtils.getDir("TmpD", [], true); - let dir1 = newDirectory(); - let dir2 = newDirectory(); - let dir3 = newDirectory(); - let file1 = newFileInDirectory(dir1); - let file2 = newFileInDirectory(dir2); - let file3 = newFileInDirectory(dir3); - - // cleanup function registration - registerCleanupFunction(function () { - Services.prefs.clearUserPref("browser.download.lastDir"); - [dir1, dir2, dir3].forEach(function(dir) dir.remove(true)); - MockFilePicker.cleanup(); - validateFileName = validateFileNameToRestore; - }); - - // Overwrite validateFileName to validate everything - validateFileName = function(foo) foo; - - let params = { - fileInfo: new FileInfo("test.txt", "test.txt", "test", "txt", "http://mozilla.org/test.txt"), - contentType: "text/plain", - saveMode: SAVEMODE_FILEONLY, - saveAsType: kSaveAsType_Complete, - file: null - }; - - prefs.setComplexValue("lastDir", Ci.nsIFile, tmpDir); - - function testOnWindow(aPrivate, aCallback) { - whenNewWindowLoaded({private: aPrivate}, function(win) { - let gDownloadLastDir = new DownloadLastDir(win); - aCallback(win, gDownloadLastDir); - gDownloadLastDir.cleanupPrivateFile(); - win.close(); - }); - } - - function testDownloadDir(aWin, gDownloadLastDir, aFile, aDisplayDir, aLastDir, - aGlobalLastDir, aCallback) { - // Check lastDir preference. - is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, aDisplayDir.path, - "LastDir should be the expected display dir"); - // Check gDownloadLastDir value. - is(gDownloadLastDir.file.path, aDisplayDir.path, - "gDownloadLastDir should be the expected display dir"); - - MockFilePicker.returnFiles = [aFile]; - MockFilePicker.displayDirectory = null; - aWin.getTargetFile(params, function() { - // File picker should start with expected display dir. - is(MockFilePicker.displayDirectory.path, aDisplayDir.path, - "File picker should start with browser.download.lastDir"); - // browser.download.lastDir should be modified on not private windows - is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, aLastDir.path, - "LastDir should be the expected last dir"); - // gDownloadLastDir should be usable outside of private windows - is(gDownloadLastDir.file.path, aGlobalLastDir.path, - "gDownloadLastDir should be the expected global last dir"); - - aCallback(); - }); - } - - testOnWindow(false, function(win, downloadDir) { - testDownloadDir(win, downloadDir, file1, tmpDir, dir1, dir1, function() { - testOnWindow(true, function(win, downloadDir) { - testDownloadDir(win, downloadDir, file2, dir1, dir1, dir2, function() { - testOnWindow(false, function(win, downloadDir) { - testDownloadDir(win, downloadDir, file3, dir1, dir3, dir3, finish); - }); - }); - }); - }); - }); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_downloadLastDir_toggle.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_downloadLastDir_toggle.js deleted file mode 100644 index 56ac4cab6..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_downloadLastDir_toggle.js +++ /dev/null @@ -1,97 +0,0 @@ -/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - waitForExplicitFinish(); - - let FileUtils = - Cu.import("resource://gre/modules/FileUtils.jsm", {}).FileUtils; - let DownloadLastDir = - Cu.import("resource://gre/modules/DownloadLastDir.jsm", {}).DownloadLastDir; - - let tmpDir = FileUtils.getDir("TmpD", [], true); - let dir1 = newDirectory(); - - registerCleanupFunction(function () { - Services.prefs.clearUserPref("browser.download.lastDir"); - dir1.remove(true); - }); - - function testOnWindow(aPrivate, aCallback) { - whenNewWindowLoaded({private: aPrivate}, function(win) { - let gDownloadLastDir = new DownloadLastDir(win); - aCallback(win, gDownloadLastDir); - gDownloadLastDir.cleanupPrivateFile(); - win.close(); - }); - } - - function checkDownloadLastDirInit(aWin, gDownloadLastDir, aCallback) { - is(typeof gDownloadLastDir, "object", - "gDownloadLastDir should be a valid object"); - is(gDownloadLastDir.file, null, - "gDownloadLastDir.file should be null to start with"); - - gDownloadLastDir.file = tmpDir; - is(gDownloadLastDir.file.path, tmpDir.path, - "LastDir should point to the temporary directory"); - isnot(gDownloadLastDir.file, tmpDir, - "gDownloadLastDir.file should not be pointing to the tmpDir"); - - gDownloadLastDir.file = 1; // not an nsIFile - is(gDownloadLastDir.file, null, "gDownloadLastDir.file should be null"); - - gDownloadLastDir.file = tmpDir; - clearHistory(); - is(gDownloadLastDir.file, null, "gDownloadLastDir.file should be null"); - - gDownloadLastDir.file = tmpDir; - aCallback(); - } - - function checkDownloadLastDir(aWin, gDownloadLastDir, aLastDir, aUpdate, aCallback) { - if (aUpdate) - gDownloadLastDir.file = aLastDir; - is(gDownloadLastDir.file.path, aLastDir.path, - "gDownloadLastDir should point to the expected last directory"); - isnot(gDownloadLastDir.file, aLastDir, - "gDownloadLastDir.file should not be pointing to the last directory"); - aCallback(); - } - - function checkDownloadLastDirNull(aWin, gDownloadLastDir, aCallback) { - is(gDownloadLastDir.file, null, "gDownloadLastDir should be null"); - aCallback(); - } - - testOnWindow(false, function(win, downloadDir) { - checkDownloadLastDirInit(win, downloadDir, function() { - testOnWindow(true, function(win, downloadDir) { - checkDownloadLastDir(win, downloadDir, tmpDir, false, function() { - testOnWindow(false, function(win, downloadDir) { - checkDownloadLastDir(win, downloadDir, tmpDir, false, function() { - testOnWindow(true, function(win, downloadDir) { - checkDownloadLastDir(win, downloadDir, dir1, true, function() { - testOnWindow(false, function(win, downloadDir) { - checkDownloadLastDir(win, downloadDir, tmpDir, false, function() { - testOnWindow(true, function(win, downloadDir) { - clearHistory(); - checkDownloadLastDirNull(win, downloadDir, function() { - testOnWindow(false, function(win, downloadDir) { - checkDownloadLastDirNull(win, downloadDir, finish); - }); - }); - }); - }); - }); - }); - }); - }); - }); - }); - }); - }); - }); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_geoprompt.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_geoprompt.js deleted file mode 100644 index 1e0a49231..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_geoprompt.js +++ /dev/null @@ -1,69 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test makes sure that the geolocation prompt does not show a remember -// control inside the private browsing mode. - -function test() { - const testPageURL = "http://mochi.test:8888/browser/" + - "browser/components/privatebrowsing/test/browser/browser_privatebrowsing_geoprompt_page.html"; - waitForExplicitFinish(); - - function checkGeolocation(aPrivateMode, aWindow, aCallback) { - executeSoon(function() { - aWindow.gBrowser.selectedTab = aWindow.gBrowser.addTab(); - aWindow.gBrowser.selectedBrowser.addEventListener("load", function () { - if (aWindow.content.location != testPageURL) { - aWindow.content.location = testPageURL; - return; - } - aWindow.gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); - - function runTest() { - let notification = aWindow.PopupNotifications.getNotification("geolocation"); - if (!notification) { - // Wait until the notification is available - executeSoon(runTest); - return; - } - if (aPrivateMode) { - // Make sure the notification is correctly displayed without a remember control - is(notification.secondaryActions.length, 0, "Secondary actions shouldn't exist (always/never remember)"); - } else { - ok(notification.secondaryActions.length > 1, "Secondary actions should exist (always/never remember)"); - } - notification.remove(); - - aWindow.gBrowser.removeCurrentTab(); - aCallback(); - } - runTest(); - }, true); - }); - }; - - let windowsToClose = []; - function testOnWindow(options, callback) { - let win = OpenBrowserWindow(options); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - windowsToClose.push(win); - callback(win); - }, false); - }; - - registerCleanupFunction(function() { - windowsToClose.forEach(function(win) { - win.close(); - }); - }); - - testOnWindow({private: false}, function(win) { - checkGeolocation(false, win, function() { - testOnWindow({private: true}, function(win) { - checkGeolocation(true, win, finish); - }); - }); - }); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_geoprompt_page.html b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_geoprompt_page.html deleted file mode 100644 index 36d5e3cec..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_geoprompt_page.html +++ /dev/null @@ -1,13 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> -<html> - <head> - <title>Geolocation invoker</title> - </head> - <body> - <script type="text/javascript"> - navigator.geolocation.getCurrentPosition(function (pos) { - // ignore - }); - </script> - </body> -</html> diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_lastpbcontextexited.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_lastpbcontextexited.js deleted file mode 100644 index dbe8ed060..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_lastpbcontextexited.js +++ /dev/null @@ -1,49 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - // We need to open a new window for this so that its docshell would get destroyed - // when clearing the PB mode flag. - function runTest(aCloseWindow, aCallback) { - let newWin = OpenBrowserWindow({private: true}); - SimpleTest.waitForFocus(function() { - let expectedExiting = true; - let expectedExited = false; - let observerExiting = { - observe: function(aSubject, aTopic, aData) { - is(aTopic, "last-pb-context-exiting", "Correct topic should be dispatched (exiting)"); - is(expectedExiting, true, "notification not expected yet (exiting)"); - expectedExited = true; - Services.obs.removeObserver(observerExiting, "last-pb-context-exiting"); - } - }; - let observerExited = { - observe: function(aSubject, aTopic, aData) { - is(aTopic, "last-pb-context-exited", "Correct topic should be dispatched (exited)"); - is(expectedExited, true, "notification not expected yet (exited)"); - Services.obs.removeObserver(observerExited, "last-pb-context-exited"); - aCallback(); - } - }; - Services.obs.addObserver(observerExiting, "last-pb-context-exiting", false); - Services.obs.addObserver(observerExited, "last-pb-context-exited", false); - expectedExiting = true; - aCloseWindow(newWin); - newWin = null; - SpecialPowers.forceGC(); - }, newWin); - } - - waitForExplicitFinish(); - - runTest(function(newWin) { - // Simulate pressing the window close button - newWin.document.getElementById("cmd_closeWindow").doCommand(); - }, function () { - runTest(function(newWin) { - // Simulate closing the last tab - newWin.document.getElementById("cmd_close").doCommand(); - }, finish); - }); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage.js deleted file mode 100644 index de39209e2..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage.js +++ /dev/null @@ -1,53 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - waitForExplicitFinish(); - - const page1 = 'http://mochi.test:8888/browser/browser/components/privatebrowsing/test/browser/' + - 'browser_privatebrowsing_localStorage_page1.html' - - function checkLocalStorage(aWindow, aCallback) { - executeSoon(function() { - let tab = aWindow.gBrowser.selectedTab = aWindow.gBrowser.addTab(); - let browser = aWindow.gBrowser.selectedBrowser; - browser.addEventListener('load', function() { - if (browser.contentWindow.location != page1) { - browser.loadURI(page1); - return; - } - browser.removeEventListener('load', arguments.callee, true); - let tab2 = aWindow.gBrowser.selectedTab = aWindow.gBrowser.addTab(); - browser.contentWindow.location = 'http://mochi.test:8888/browser/browser/components/privatebrowsing/test/browser/' + - 'browser_privatebrowsing_localStorage_page2.html'; - browser.addEventListener('load', function() { - browser.removeEventListener('load', arguments.callee, true); - is(browser.contentWindow.document.title, '2', "localStorage should contain 2 items"); - aCallback(); - }, true); - }, true); - }); - } - - let windowsToClose = []; - function testOnWindow(options, callback) { - let win = OpenBrowserWindow(options); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - windowsToClose.push(win); - callback(win); - }, false); - }; - - registerCleanupFunction(function() { - windowsToClose.forEach(function(win) { - win.close(); - }); - }); - - testOnWindow({private: true}, function(win) { - checkLocalStorage(win, finish); - }); - -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_before_after.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_before_after.js deleted file mode 100644 index 5cbee92b1..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_before_after.js +++ /dev/null @@ -1,66 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// Ensure that a storage instance used by both private and public sessions at different times does not -// allow any data to leak due to cached values. - -// Step 1: Load browser_privatebrowsing_localStorage_before_after_page.html in a private tab, causing a storage -// item to exist. Close the tab. -// Step 2: Load the same page in a non-private tab, ensuring that the storage instance reports only one item -// existing. - -function test() { - // initialization - waitForExplicitFinish(); - let windowsToClose = []; - let testURI = "about:blank"; - let prefix = 'http://mochi.test:8888/browser/browser/components/privatebrowsing/test/browser/'; - - function doTest(aIsPrivateMode, aWindow, aCallback) { - aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); - - if (aIsPrivateMode) { - // do something when aIsPrivateMode is true - is(aWindow.gBrowser.contentWindow.document.title, '1', "localStorage should contain 1 item"); - } else { - // do something when aIsPrivateMode is false - is(aWindow.gBrowser.contentWindow.document.title, 'null|0', 'localStorage should contain 0 items'); - } - - aCallback(); - }, true); - - aWindow.gBrowser.selectedBrowser.loadURI(testURI); - } - - function testOnWindow(aOptions, aCallback) { - whenNewWindowLoaded(aOptions, function(aWin) { - windowsToClose.push(aWin); - // execute should only be called when need, like when you are opening - // web pages on the test. If calling executeSoon() is not necesary, then - // call whenNewWindowLoaded() instead of testOnWindow() on your test. - executeSoon(function() aCallback(aWin)); - }); - }; - - // this function is called after calling finish() on the test. - registerCleanupFunction(function() { - windowsToClose.forEach(function(aWin) { - aWin.close(); - }); - }); - - // test first when on private mode - testOnWindow({private: true}, function(aWin) { - testURI = prefix + 'browser_privatebrowsing_localStorage_before_after_page.html'; - doTest(true, aWin, function() { - // then test when not on private mode - testOnWindow({}, function(aWin) { - testURI = prefix + 'browser_privatebrowsing_localStorage_before_after_page2.html'; - doTest(false, aWin, finish); - }); - }); - }); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_before_after_page.html b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_before_after_page.html deleted file mode 100644 index 143fea4e7..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_before_after_page.html +++ /dev/null @@ -1,11 +0,0 @@ -<html xmlns="http://www.w3.org/1999/xhtml"> -<head> -<script type="text/javascript"> - localStorage.clear(); - localStorage.setItem('zzztest', 'zzzvalue'); - document.title = localStorage.length; -</script> -</head> -<body> -</body> -</html> diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_before_after_page2.html b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_before_after_page2.html deleted file mode 100644 index 9a7e2da63..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_before_after_page2.html +++ /dev/null @@ -1,10 +0,0 @@ -<html xmlns="http://www.w3.org/1999/xhtml"> -<head> -<script type="text/javascript"> - document.title = localStorage.getItem('zzztest', 'zzzvalue') + '|' + localStorage.length; - localStorage.clear(); -</script> -</head> -<body> -</body> -</html> diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_page1.html b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_page1.html deleted file mode 100644 index 3e79a01bf..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_page1.html +++ /dev/null @@ -1,10 +0,0 @@ -<html xmlns="http://www.w3.org/1999/xhtml"> -<head> -<script type="text/javascript"> - localStorage.clear(); - localStorage.setItem('test1', 'value1'); -</script> -</head> -<body> -</body> -</html> diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_page2.html b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_page2.html deleted file mode 100644 index 8c9b28fd8..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_localStorage_page2.html +++ /dev/null @@ -1,10 +0,0 @@ -<html xmlns="http://www.w3.org/1999/xhtml"> -<head> -<script type="text/javascript"> - localStorage.setItem('test2', 'value2'); - document.title = localStorage.length; -</script> -</head> -<body> -</body> -</html> diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_noSessionRestoreMenuOption.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_noSessionRestoreMenuOption.js deleted file mode 100644 index 32919c834..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_noSessionRestoreMenuOption.js +++ /dev/null @@ -1,34 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test checks that the Session Restore menu option is not enabled in private mode - -function test() { - waitForExplicitFinish(); - - function testNoSessionRestoreMenuItem() { - let win = OpenBrowserWindow({private: true}); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - ok(true, "The second private window got loaded"); - let srCommand = win.document.getElementById("Browser:RestoreLastSession"); - ok(srCommand, "The Session Restore command should exist"); - is(PrivateBrowsingUtils.isWindowPrivate(win), true, - "PrivateBrowsingUtils should report the correct per-window private browsing status"); - is(srCommand.hasAttribute("disabled"), true, - "The Session Restore command should be disabled in private browsing mode"); - win.close(); - finish(); - }, false); - } - - let win = OpenBrowserWindow({private: true}); - win.addEventListener("load", function onload() { - win.removeEventListener("load", onload, false); - ok(true, "The first private window got loaded"); - win.gBrowser.addTab("about:mozilla"); - win.close(); - testNoSessionRestoreMenuItem(); - }, false); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_nonbrowser.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_nonbrowser.js deleted file mode 100644 index 4a9957e9c..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_nonbrowser.js +++ /dev/null @@ -1,33 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - waitForExplicitFinish(); - - let windowsToClose = []; - registerCleanupFunction(function() { - windowsToClose.forEach(function(win) { - win.close(); - }); - }); - - let win = OpenBrowserWindow({private: true}); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - let consoleWin = win.open("chrome://global/content/console.xul", "_blank", "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar"); - consoleWin.addEventListener("load", function consoleLoad() { - consoleWin.removeEventListener("load", consoleLoad, false); - win.close(); - }, false); - windowsToClose.push(consoleWin); - }, false); - - let observer = function() { - is(true, true, "observer fired"); - Services.obs.removeObserver(observer, "last-pb-context-exited"); - executeSoon(finish); - }; - Services.obs.addObserver(observer, "last-pb-context-exited", false); - windowsToClose.push(win); -}
\ No newline at end of file diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_openLocationLastURL.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_openLocationLastURL.js deleted file mode 100644 index e68aaec3c..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_openLocationLastURL.js +++ /dev/null @@ -1,63 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - waitForExplicitFinish(); - const URL_1 = "mozilla.org"; - const URL_2 = "mozilla.com"; - - function testURL(aOpenLocation, aTestNumber, aValue) { - is(aOpenLocation.value, aValue, - "Test: " + aTestNumber + ": Validate last url value."); - } - - whenNewWindowLoaded({private: false}, function(normalWindow) { - whenNewWindowLoaded({private: true}, function(privateWindow) { - let openLocationLastURL = getLocationModule(normalWindow); - let openLocationLastURLPB = getLocationModule(privateWindow); - - // Clean to start testing. - is(typeof openLocationLastURL, "object", "Validate Normal type of last url."); - is(typeof openLocationLastURLPB, "object", "Validate PB type of last url."); - openLocationLastURL.reset(); - openLocationLastURLPB.reset(); - testURL(openLocationLastURL, 1, ""); - - // Test without private browsing. - openLocationLastURL.value = URL_1; - testURL(openLocationLastURL, 2, URL_1); - openLocationLastURL.value = ""; - testURL(openLocationLastURL, 3, ""); - openLocationLastURL.value = URL_2; - testURL(openLocationLastURL, 4, URL_2); - clearHistory(); - testURL(openLocationLastURL, 5, ""); - - // Test changing private browsing. - openLocationLastURL.value = URL_2; - testURL(openLocationLastURLPB, 6, ""); - testURL(openLocationLastURL, 7, URL_2); - openLocationLastURLPB.value = URL_1; - testURL(openLocationLastURLPB, 8, URL_1); - testURL(openLocationLastURL, 9, URL_2); - openLocationLastURLPB.value = URL_1; - testURL(openLocationLastURLPB, 10, URL_1); - - // Test cleaning history. - clearHistory(); - testURL(openLocationLastURLPB, 11, ""); - testURL(openLocationLastURL, 12, ""); - - privateWindow.close(); - normalWindow.close(); - finish(); - }); - }); -} - -function getLocationModule(aWindow) { - let openLocationModule = {}; - Cu.import("resource:///modules/openLocationLastURL.jsm", openLocationModule); - return new openLocationModule.OpenLocationLastURL(aWindow); -}
\ No newline at end of file diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_opendir.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_opendir.js deleted file mode 100644 index 1a14385a3..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_opendir.js +++ /dev/null @@ -1,133 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test makes sure that the last open directory used inside the private -// browsing mode is not remembered after leaving that mode. - -var windowsToClose = []; -function testOnWindow(options, callback) { - var win = OpenBrowserWindow(options); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - windowsToClose.push(win); - callback(win); - }, false); -} - -registerCleanupFunction(function() { - windowsToClose.forEach(function(win) { - win.close(); - }); -}); - -function test() { - // initialization - waitForExplicitFinish(); - let ds = Cc["@mozilla.org/file/directory_service;1"]. - getService(Ci.nsIProperties); - let dir1 = ds.get("ProfD", Ci.nsIFile); - let dir2 = ds.get("TmpD", Ci.nsIFile); - let file = dir2.clone(); - file.append("pbtest.file"); - file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0600); - - const kPrefName = "browser.open.lastDir"; - - function setupCleanSlate(win) { - win.gLastOpenDirectory.reset(); - gPrefService.clearUserPref(kPrefName); - } - - setupCleanSlate(window); - - // open one regular and one private window - testOnWindow(undefined, function(nonPrivateWindow) { - setupCleanSlate(nonPrivateWindow); - testOnWindow({private: true}, function(privateWindow) { - setupCleanSlate(privateWindow); - - // Test 1: general workflow test - - // initial checks - ok(!nonPrivateWindow.gLastOpenDirectory.path, - "Last open directory path should be initially empty"); - nonPrivateWindow.gLastOpenDirectory.path = dir2; - is(nonPrivateWindow.gLastOpenDirectory.path.path, dir2.path, - "The path should be successfully set"); - nonPrivateWindow.gLastOpenDirectory.path = null; - is(nonPrivateWindow.gLastOpenDirectory.path.path, dir2.path, - "The path should be not change when assigning it to null"); - nonPrivateWindow.gLastOpenDirectory.path = dir1; - is(nonPrivateWindow.gLastOpenDirectory.path.path, dir1.path, - "The path should be successfully outside of the private browsing mode"); - - // test the private window - is(privateWindow.gLastOpenDirectory.path.path, dir1.path, - "The path should not change when entering the private browsing mode"); - privateWindow.gLastOpenDirectory.path = dir2; - is(privateWindow.gLastOpenDirectory.path.path, dir2.path, - "The path should successfully change inside the private browsing mode"); - - // test the non-private window - is(nonPrivateWindow.gLastOpenDirectory.path.path, dir1.path, - "The path should be reset to the same path as before entering the private browsing mode"); - - setupCleanSlate(nonPrivateWindow); - setupCleanSlate(privateWindow); - - // Test 2: the user first tries to open a file inside the private browsing mode - - // test the private window - ok(!privateWindow.gLastOpenDirectory.path, - "No original path should exist inside the private browsing mode"); - privateWindow.gLastOpenDirectory.path = dir1; - is(privateWindow.gLastOpenDirectory.path.path, dir1.path, - "The path should be successfully set inside the private browsing mode"); - // test the non-private window - ok(!nonPrivateWindow.gLastOpenDirectory.path, - "The path set inside the private browsing mode should not leak when leaving that mode"); - - setupCleanSlate(nonPrivateWindow); - setupCleanSlate(privateWindow); - - // Test 3: the last open directory is set from a previous session, it should be used - // in normal mode - - gPrefService.setComplexValue(kPrefName, Ci.nsILocalFile, dir1); - is(nonPrivateWindow.gLastOpenDirectory.path.path, dir1.path, - "The pref set from last session should take effect outside the private browsing mode"); - - setupCleanSlate(nonPrivateWindow); - setupCleanSlate(privateWindow); - - // Test 4: the last open directory is set from a previous session, it should be used - // in private browsing mode mode - - gPrefService.setComplexValue(kPrefName, Ci.nsILocalFile, dir1); - // test the private window - is(privateWindow.gLastOpenDirectory.path.path, dir1.path, - "The pref set from last session should take effect inside the private browsing mode"); - // test the non-private window - is(nonPrivateWindow.gLastOpenDirectory.path.path, dir1.path, - "The pref set from last session should remain in effect after leaving the private browsing mode"); - - setupCleanSlate(nonPrivateWindow); - setupCleanSlate(privateWindow); - - // Test 5: setting the path to a file shouldn't work - - nonPrivateWindow.gLastOpenDirectory.path = file; - ok(!nonPrivateWindow.gLastOpenDirectory.path, - "Setting the path to a file shouldn't work when it's originally null"); - nonPrivateWindow.gLastOpenDirectory.path = dir1; - nonPrivateWindow.gLastOpenDirectory.path = file; - is(nonPrivateWindow.gLastOpenDirectory.path.path, dir1.path, - "Setting the path to a file shouldn't work when it's not originally null"); - - // cleanup - file.remove(false); - finish(); - }); - }); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_openlocation.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_openlocation.js deleted file mode 100644 index 0707004ba..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_openlocation.js +++ /dev/null @@ -1,100 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test makes sure that Open Location dialog is usable inside the private browsing -// mode without leaving any trace of the URLs visited. - -function test() { - // initialization - waitForExplicitFinish(); - - function openLocation(aWindow, url, autofilled, callback) { - function observer(aSubject, aTopic, aData) { - switch (aTopic) { - case "domwindowopened": - let dialog = aSubject.QueryInterface(Ci.nsIDOMWindow); - dialog.addEventListener("load", function () { - dialog.removeEventListener("load", arguments.callee, false); - - let browser = aWindow.gBrowser.selectedBrowser; - browser.addEventListener("load", function() { - // Ignore non-related loads (could be about:privatebrowsing for example, see bug 817932) - if (browser.currentURI.spec != url) { - return; - } - - browser.removeEventListener("load", arguments.callee, true); - - executeSoon(callback); - }, true); - - SimpleTest.waitForFocus(function() { - let input = dialog.document.getElementById("dialog.input"); - is(input.value, autofilled, "The input field should be correctly auto-filled"); - input.focus(); - for (let i = 0; i < url.length; ++i) - EventUtils.synthesizeKey(url[i], {}, dialog); - EventUtils.synthesizeKey("VK_RETURN", {}, dialog); - }, dialog); - }, false); - break; - - case "domwindowclosed": - Services.ww.unregisterNotification(arguments.callee); - break; - } - } - - executeSoon(function() { - Services.ww.registerNotification(observer); - gPrefService.setIntPref("general.open_location.last_window_choice", 0); - aWindow.openDialog("chrome://browser/content/openLocation.xul", "_blank", - "chrome,titlebar", aWindow); - }); - } - - let windowsToClose = []; - function testOnWindow(options, callback) { - let win = OpenBrowserWindow(options); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - windowsToClose.push(win); - callback(win); - }, false); - }; - - registerCleanupFunction(function() { - windowsToClose.forEach(function(win) { - win.close(); - }); - }); - - if (gPrefService.prefHasUserValue("general.open_location.last_url")) - gPrefService.clearUserPref("general.open_location.last_url"); - - testOnWindow({private: false}, function(win) { - openLocation(win, "http://example.com/", "", function() { - testOnWindow({private: false}, function(win) { - openLocation(win, "http://example.org/", "http://example.com/", function() { - testOnWindow({private: true}, function(win) { - openLocation(win, "about:logo", "", function() { - testOnWindow({private: true}, function(win) { - openLocation(win, "about:buildconfig", "about:logo", function() { - testOnWindow({private: false}, function(win) { - openLocation(win, "about:blank", "http://example.org/", function() { - gPrefService.clearUserPref("general.open_location.last_url"); - if (gPrefService.prefHasUserValue("general.open_location.last_window_choice")) - gPrefService.clearUserPref("general.open_location.last_window_choice"); - finish(); - }); - }); - }); - }); - }); - }); - }); - }); - }); - }); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placesTitleNoUpdate.html b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placesTitleNoUpdate.html deleted file mode 100644 index f5bb3212f..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placesTitleNoUpdate.html +++ /dev/null @@ -1,8 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> -<html> - <head> - <title>Title 1</title> - </head> - <body> - </body> -</html> diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placesTitleNoUpdate.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placesTitleNoUpdate.js deleted file mode 100644 index 2d9d73652..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placesTitleNoUpdate.js +++ /dev/null @@ -1,123 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// Test to make sure that the visited page titles do not get updated inside the -// private browsing mode. - -Cu.import("resource://gre/modules/Services.jsm"); -Cu.import("resource://gre/modules/PlacesUtils.jsm"); - -function test() { - waitForExplicitFinish(); - const TEST_URL = "http://mochi.test:8888/browser/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placesTitleNoUpdate.html" - const TEST_URI = Services.io.newURI(TEST_URL, null, null); - const TITLE_1 = "Title 1"; - const TITLE_2 = "Title 2"; - - let selectedWin = null; - let windowsToClose = []; - let tabToClose = null; - let testNumber = 0; - let historyObserver; - - - registerCleanupFunction(function() { - PlacesUtils.history.removeObserver(historyObserver, false); - windowsToClose.forEach(function(aWin) { - aWin.close(); - }); - gBrowser.removeTab(tabToClose); - }); - - - waitForClearHistory(function () { - historyObserver = { - onTitleChanged: function(aURI, aPageTitle) { - switch (++testNumber) { - case 1: - afterFirstVisit(); - break; - case 2: - afterUpdateVisit(); - break; - } - }, - onBeginUpdateBatch: function () {}, - onEndUpdateBatch: function () {}, - onVisit: function () {}, - onDeleteURI: function () {}, - onClearHistory: function () {}, - onPageChanged: function () {}, - onDeleteVisits: function() {}, - QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver]) - }; - PlacesUtils.history.addObserver(historyObserver, false); - - tabToClose = gBrowser.addTab(); - gBrowser.selectedTab = tabToClose; - whenPageLoad(window, function() {}); - }); - - function afterFirstVisit() { - is(PlacesUtils.history.getPageTitle(TEST_URI), TITLE_1, "The title matches the orignal title after first visit"); - - let place = { - uri: TEST_URI, - title: TITLE_2, - visits: [{ - visitDate: Date.now() * 1000, - transitionType: Ci.nsINavHistoryService.TRANSITION_LINK - }] - }; - PlacesUtils.asyncHistory.updatePlaces(place, { - handleError: function () do_throw("Unexpected error in adding visit."), - handleResult: function () { }, - handleCompletion: function () {} - }); - } - - function afterUpdateVisit() { - is(PlacesUtils.history.getPageTitle(TEST_URI), TITLE_2, "The title matches the updated title after updating visit"); - - testOnWindow(true, function(aWin) { - whenPageLoad(aWin, function() { - executeSoon(afterFirstVisitInPrivateWindow); - }); - }); - } - - function afterFirstVisitInPrivateWindow() { - is(PlacesUtils.history.getPageTitle(TEST_URI), TITLE_2, "The title remains the same after visiting in private window"); - waitForClearHistory(finish); - } - - function whenPageLoad(aWin, aCallback) { - aWin.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - aWin.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); - aCallback(); - }, true); - aWin.gBrowser.selectedBrowser.loadURI(TEST_URL); - } - - function testOnWindow(aPrivate, aCallback) { - whenNewWindowLoaded({ private: aPrivate }, function(aWin) { - selectedWin = aWin; - windowsToClose.push(aWin); - executeSoon(function() { aCallback(aWin) }); - }); - } - - function waitForClearHistory(aCallback) { - let observer = { - observe: function(aSubject, aTopic, aData) { - Services.obs.removeObserver(this, PlacesUtils.TOPIC_EXPIRATION_FINISHED); - aCallback(); - } - }; - Services.obs.addObserver(observer, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false); - - PlacesUtils.bhistory.removeAllPages(); - } -} - diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placestitle.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placestitle.js deleted file mode 100644 index 613036462..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placestitle.js +++ /dev/null @@ -1,108 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test makes sure that the title of existing history entries does not -// change inside a private window. - -function test() { - waitForExplicitFinish(); - - const TEST_URL = "http://mochi.test:8888/browser/browser/components/" + - "privatebrowsing/test/browser/title.sjs"; - let cm = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager); - - function waitForCleanup(aCallback) { - // delete all cookies - cm.removeAll(); - // delete all history items - Services.obs.addObserver(function observeCH(aSubject, aTopic, aData) { - Services.obs.removeObserver(observeCH, PlacesUtils.TOPIC_EXPIRATION_FINISHED); - aCallback(); - }, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false); - PlacesUtils.bhistory.removeAllPages(); - } - - let testNumber = 0; - let historyObserver = { - onTitleChanged: function(aURI, aPageTitle) { - if (aURI.spec != TEST_URL) - return; - switch (++testNumber) { - case 1: - // The first time that the page is loaded - is(aPageTitle, "No Cookie", - "The page should be loaded without any cookie for the first time"); - openTestPage(selectedWin); - break; - case 2: - // The second time that the page is loaded - is(aPageTitle, "Cookie", - "The page should be loaded with a cookie for the second time"); - waitForCleanup(function () { - openTestPage(selectedWin); - }); - break; - case 3: - // After clean up - is(aPageTitle, "No Cookie", - "The page should be loaded without any cookie again"); - testOnWindow(true, function(win) { - whenPageLoad(win, function() { - waitForCleanup(finish); - }); - }); - break; - default: - // Checks that opening the page in a private window should not fire a - // title change. - ok(false, "Title changed. Unexpected pass: " + testNumber); - } - }, - - onBeginUpdateBatch: function () {}, - onEndUpdateBatch: function () {}, - onVisit: function () {}, - onDeleteURI: function () {}, - onClearHistory: function () {}, - onPageChanged: function () {}, - onDeleteVisits: function() {}, - QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver]) - }; - PlacesUtils.history.addObserver(historyObserver, false); - - let selectedWin = null; - let windowsToClose = []; - registerCleanupFunction(function() { - PlacesUtils.history.removeObserver(historyObserver); - windowsToClose.forEach(function(win) { - win.close(); - }); - }); - - function openTestPage(aWin) { - aWin.gBrowser.selectedTab = aWin.gBrowser.addTab(TEST_URL); - } - - function whenPageLoad(aWin, aCallback) { - aWin.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - aWin.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); - aCallback(); - }, true); - aWin.gBrowser.selectedBrowser.loadURI(TEST_URL); - } - - function testOnWindow(aPrivate, aCallback) { - whenNewWindowLoaded({ private: aPrivate }, function(win) { - selectedWin = win; - windowsToClose.push(win); - executeSoon(function() { aCallback(win) }); - }); - } - - waitForCleanup(function() { - testOnWindow(false, function(win) { - openTestPage(win); - }); - }); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_popupblocker.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_popupblocker.js deleted file mode 100644 index 468f45b4b..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_popupblocker.js +++ /dev/null @@ -1,86 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test makes sure that private browsing mode disables the remember option -// for the popup blocker menu. -function test() { - // initialization - waitForExplicitFinish(); - - let testURI = "http://mochi.test:8888/browser/browser/components/privatebrowsing/test/browser/popup.html"; - let windowsToClose = []; - let oldPopupPolicy = gPrefService.getBoolPref("dom.disable_open_during_load"); - gPrefService.setBoolPref("dom.disable_open_during_load", true); - - function testPopupBlockerMenuItem(aExpectedDisabled, aWindow, aCallback) { - - aWindow.gBrowser.addEventListener("DOMUpdatePageReport", function() { - aWindow.gBrowser.removeEventListener("DOMUpdatePageReport", arguments.callee, false); - - executeSoon(function() { - let notification = aWindow.gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"); - ok(notification, "The notification box should be displayed"); - - function checkMenuItem(callback) { - dump("CMI: in\n"); - aWindow.document.addEventListener("popupshown", function(event) { - dump("CMI: popupshown\n"); - aWindow.document.removeEventListener("popupshown", arguments.callee, false); - - if (aExpectedDisabled) - is(aWindow.document.getElementById("blockedPopupAllowSite").getAttribute("disabled"), "true", - "The allow popups menu item should be disabled"); - - event.originalTarget.hidePopup(); - dump("CMI: calling back\n"); - callback(); - dump("CMI: called back\n"); - }, false); - dump("CMI: out\n"); - } - - checkMenuItem(function() { - aCallback(); - }); - notification.querySelector("button").doCommand(); - }); - - }, false); - - aWindow.gBrowser.selectedBrowser.loadURI(testURI); - } - - function finishTest() { - // cleanup - gPrefService.setBoolPref("dom.disable_open_during_load", oldPopupPolicy); - finish(); - }; - - function testOnWindow(options, callback) { - let win = OpenBrowserWindow(options); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - windowsToClose.push(win); - executeSoon(function() callback(win)); - }, false); - }; - - registerCleanupFunction(function() { - windowsToClose.forEach(function(win) { - win.close(); - }); - }); - - testOnWindow({}, function(win) { - testPopupBlockerMenuItem(false, win, - testOnWindow({private: true}, function(win) { - testPopupBlockerMenuItem(true, win, - testOnWindow({}, function(win) { - testPopupBlockerMenuItem(false, win, finishTest); - }) - ); - }) - ); - }); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_protocolhandler.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_protocolhandler.js deleted file mode 100644 index ac978898a..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_protocolhandler.js +++ /dev/null @@ -1,65 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test makes sure that the web pages can't register protocol handlers -// inside the private browsing mode. - -function test() { - // initialization - waitForExplicitFinish(); - let windowsToClose = []; - let notificationValue = "Protocol Registration: testprotocol"; - let testURI = "http://example.com/browser/" + - "browser/components/privatebrowsing/test/browser/browser_privatebrowsing_protocolhandler_page.html"; - - function doTest(aIsPrivateMode, aWindow, aCallback) { - aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); - - setTimeout(function() { - let notificationBox = aWindow.gBrowser.getNotificationBox(); - let notification = notificationBox.getNotificationWithValue(notificationValue); - - if (aIsPrivateMode) { - // Make sure the notification is correctly displayed without a remember control - ok(!notification, "Notification box should not be displayed inside of private browsing mode"); - } else { - // Make sure the notification is correctly displayed with a remember control - ok(notification, "Notification box should be displaying outside of private browsing mode"); - } - - aCallback(); - }, 100); // remember control is added in a setTimeout(0) call - }, true); - - aWindow.gBrowser.selectedBrowser.loadURI(testURI); - } - - function testOnWindow(aOptions, aCallback) { - whenNewWindowLoaded(aOptions, function(aWin) { - windowsToClose.push(aWin); - // execute should only be called when need, like when you are opening - // web pages on the test. If calling executeSoon() is not necesary, then - // call whenNewWindowLoaded() instead of testOnWindow() on your test. - executeSoon(function() aCallback(aWin)); - }); - }; - - // this function is called after calling finish() on the test. - registerCleanupFunction(function() { - windowsToClose.forEach(function(aWin) { - aWin.close(); - }); - }); - - // test first when not on private mode - testOnWindow({}, function(aWin) { - doTest(false, aWin, function() { - // then test when on private mode - testOnWindow({private: true}, function(aWin) { - doTest(true, aWin, finish); - }); - }); - }); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_protocolhandler_page.html b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_protocolhandler_page.html deleted file mode 100644 index 74f846d54..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_protocolhandler_page.html +++ /dev/null @@ -1,13 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> -<html> - <head> - <title>Protocol registrar page</title> - </head> - <body> - <script type="text/javascript"> - navigator.registerProtocolHandler("testprotocol", - "https://example.com/foobar?uri=%s", - "Test Protocol"); - </script> - </body> -</html> diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_theming.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_theming.js deleted file mode 100644 index 432f47748..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_theming.js +++ /dev/null @@ -1,38 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test makes sure that privatebrowsingmode attribute of the window is correctly -// adjusted based on whether the window is a private window. - -var windowsToClose = []; -function testOnWindow(options, callback) { - var win = OpenBrowserWindow(options); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - windowsToClose.push(win); - executeSoon(function() callback(win)); - }, false); -} - -registerCleanupFunction(function() { - windowsToClose.forEach(function(win) { - win.close(); - }); -}); - -function test() { - // initialization - waitForExplicitFinish(); - - ok(!document.documentElement.hasAttribute("privatebrowsingmode"), - "privatebrowsingmode should not be present in normal mode"); - - // open a private window - testOnWindow({private: true}, function(win) { - is(win.document.documentElement.getAttribute("privatebrowsingmode"), "temporary", - "privatebrowsingmode should be \"temporary\" inside the private browsing mode"); - - finish(); - }); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_ui.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_ui.js deleted file mode 100644 index adb67d433..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_ui.js +++ /dev/null @@ -1,82 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test makes sure that the gPrivateBrowsingUI object, the Private Browsing -// menu item and its XUL <command> element work correctly. - -function test() { - // initialization - waitForExplicitFinish(); - let windowsToClose = []; - let testURI = "about:blank"; - let pbMenuItem; - let cmd; - - function doTest(aIsPrivateMode, aWindow, aCallback) { - aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); - - ok(aWindow.gPrivateBrowsingUI, "The gPrivateBrowsingUI object exists"); - - pbMenuItem = aWindow.document.getElementById("menu_newPrivateWindow"); - ok(pbMenuItem, "The Private Browsing menu item exists"); - - cmd = aWindow.document.getElementById("Tools:PrivateBrowsing"); - isnot(cmd, null, "XUL command object for the private browsing service exists"); - - is(pbMenuItem.getAttribute("label"), "New Private Window", - "The Private Browsing menu item should read \"New Private Window\""); - is(PrivateBrowsingUtils.isWindowPrivate(aWindow), aIsPrivateMode, - "PrivateBrowsingUtils should report the correct per-window private browsing status (privateBrowsing should be " + - aIsPrivateMode + ")"); - - aCallback(); - }, true); - - aWindow.gBrowser.selectedBrowser.loadURI(testURI); - }; - - function openPrivateBrowsingModeByUI(aWindow, aCallback) { - Services.obs.addObserver(function observer(aSubject, aTopic, aData) { - aSubject.addEventListener("load", function() { - aSubject.removeEventListener("load", arguments.callee); - Services.obs.removeObserver(observer, "domwindowopened"); - windowsToClose.push(aSubject); - aCallback(aSubject); - }, false); - }, "domwindowopened", false); - - cmd = aWindow.document.getElementById("Tools:PrivateBrowsing"); - var func = new Function("", cmd.getAttribute("oncommand")); - func.call(cmd); - }; - - function testOnWindow(aOptions, aCallback) { - whenNewWindowLoaded(aOptions, function(aWin) { - windowsToClose.push(aWin); - // execute should only be called when need, like when you are opening - // web pages on the test. If calling executeSoon() is not necesary, then - // call whenNewWindowLoaded() instead of testOnWindow() on your test. - executeSoon(function() aCallback(aWin)); - }); - }; - - // this function is called after calling finish() on the test. - registerCleanupFunction(function() { - windowsToClose.forEach(function(aWin) { - aWin.close(); - }); - }); - - // test first when not on private mode - testOnWindow({}, function(aWin) { - doTest(false, aWin, function() { - // then test when on private mode, opening a new private window from the - // user interface. - openPrivateBrowsingModeByUI(aWin, function(aPrivateWin) { - doTest(true, aPrivateWin, finish); - }); - }); - }); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_urlbarfocus.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_urlbarfocus.js deleted file mode 100644 index ff25f3cc0..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_urlbarfocus.js +++ /dev/null @@ -1,67 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test makes sure that the URL bar is focused when entering the private window. - -function test() { - waitForExplicitFinish(); - - const TEST_URL = "data:text/plain,test"; - - function checkUrlbarFocus(aWin, aIsPrivate, aCallback) { - let urlbar = aWin.gURLBar; - if (aIsPrivate) { - is(aWin.document.commandDispatcher.focusedElement, urlbar.inputField, - "URL Bar should be focused inside the private window"); - is(urlbar.value, "", - "URL Bar should be empty inside the private window"); - } else { - isnot(aWin.document.commandDispatcher.focusedElement, urlbar.inputField, - "URL Bar should not be focused after opening window"); - isnot(urlbar.value, "", - "URL Bar should not be empty after opening window"); - } - aCallback(); - } - - let windowsToClose = []; - function testOnWindow(aPrivate, aCallback) { - whenNewWindowLoaded({private: aPrivate}, function(win) { - windowsToClose.push(win); - executeSoon(function() aCallback(win)); - }); - } - - registerCleanupFunction(function() { - windowsToClose.forEach(function(win) { - win.close(); - }); - }); - - function whenLoadTab(aPrivate, aCallback) { - testOnWindow(aPrivate, function(win) { - let browser = win.gBrowser.selectedBrowser; - browser.addEventListener("load", function() { - browser.removeEventListener("load", arguments.callee, true); - aCallback(win); - }, true); - if (!aPrivate) { - browser.focus(); - browser.loadURI(TEST_URL); - } - }); - } - - whenLoadTab(false, function(win) { - checkUrlbarFocus(win, false, function() { - whenLoadTab(true, function(win) { - checkUrlbarFocus(win, true, function() { - whenLoadTab(false, function(win) { - checkUrlbarFocus(win, false, finish); - }); - }); - }); - }); - }); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_windowtitle.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_windowtitle.js deleted file mode 100644 index 3b6aa964d..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_windowtitle.js +++ /dev/null @@ -1,99 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test makes sure that the window title changes correctly while switching -// from and to private browsing mode. - -function test() { - const testPageURL = "http://mochi.test:8888/browser/" + - "browser/components/privatebrowsing/test/browser/browser_privatebrowsing_windowtitle_page.html"; - waitForExplicitFinish(); - requestLongerTimeout(2); - - // initialization of expected titles - let test_title = "Test title"; - let app_name = document.documentElement.getAttribute("title"); - const isOSX = ("nsILocalFileMac" in Ci); - let page_with_title; - let page_without_title; - let about_pb_title; - let pb_page_with_title; - let pb_page_without_title; - let pb_about_pb_title; - if (isOSX) { - page_with_title = test_title; - page_without_title = app_name; - about_pb_title = "Would you like to start Private Browsing?"; - pb_page_with_title = test_title + " - (Private Browsing)"; - pb_page_without_title = app_name + " - (Private Browsing)"; - pb_about_pb_title = pb_page_without_title; - } - else { - page_with_title = test_title + " - " + app_name; - page_without_title = app_name; - about_pb_title = "Would you like to start Private Browsing?" + " - " + app_name; - pb_page_with_title = test_title + " - " + app_name + " (Private Browsing)"; - pb_page_without_title = app_name + " (Private Browsing)"; - pb_about_pb_title = "Private Browsing - " + app_name + " (Private Browsing)"; - } - - function testTabTitle(aWindow, url, insidePB, expected_title, funcNext) { - executeSoon(function () { - let tab = aWindow.gBrowser.selectedTab = aWindow.gBrowser.addTab(); - let browser = aWindow.gBrowser.selectedBrowser; - browser.stop(); - // ensure that the test is run after the titlebar has been updated - browser.addEventListener("pageshow", function () { - browser.removeEventListener("pageshow", arguments.callee, false); - executeSoon(function () { - is(aWindow.document.title, expected_title, "The window title for " + url + - " is correct (" + (insidePB ? "inside" : "outside") + - " private browsing mode)"); - - let win = aWindow.gBrowser.replaceTabWithWindow(tab); - win.addEventListener("load", function() { - win.removeEventListener("load", arguments.callee, false); - - executeSoon(function() { - is(win.document.title, expected_title, "The window title for " + url + - " detached tab is correct (" + (insidePB ? "inside" : "outside") + - " private browsing mode)"); - win.close(); - aWindow.close(); - - setTimeout(funcNext, 0); - }); - }, false); - }); - }, false); - - browser.loadURI(url); - }); - } - - whenNewWindowLoaded({private: false}, function(win) { - testTabTitle(win, "about:blank", false, page_without_title, function() { - whenNewWindowLoaded({private: false}, function(win) { - testTabTitle(win, testPageURL, false, page_with_title, function() { - whenNewWindowLoaded({private: false}, function(win) { - testTabTitle(win, "about:privatebrowsing", false, about_pb_title, function() { - whenNewWindowLoaded({private: true}, function(win) { - testTabTitle(win, "about:blank", true, pb_page_without_title, function() { - whenNewWindowLoaded({private: true}, function(win) { - testTabTitle(win, testPageURL, true, pb_page_with_title, function() { - whenNewWindowLoaded({private: true}, function(win) { - testTabTitle(win, "about:privatebrowsing", true, pb_about_pb_title, finish); - }); - }); - }); - }); - }); - }); - }); - }); - }); - }); - }); - return; -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_windowtitle_page.html b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_windowtitle_page.html deleted file mode 100644 index 760bde7d1..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_windowtitle_page.html +++ /dev/null @@ -1,9 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> -<html> - <head> - <title>Test title</title> - </head> - <body> - Test page for the window title test - </body> -</html> diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_zoom.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_zoom.js deleted file mode 100644 index 8ed67de18..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_zoom.js +++ /dev/null @@ -1,60 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test makes sure that private browsing turns off doesn't cause zoom -// settings to be reset on tab switch (bug 464962) - -function test() { - waitForExplicitFinish(); - - function testZoom(aWindow, aCallback) { - executeSoon(function() { - let tabAbout = aWindow.gBrowser.addTab(); - aWindow.gBrowser.selectedTab = tabAbout; - - let aboutBrowser = aWindow.gBrowser.getBrowserForTab(tabAbout); - aboutBrowser.addEventListener("load", function onAboutBrowserLoad() { - aboutBrowser.removeEventListener("load", onAboutBrowserLoad, true); - let tabMozilla = aWindow.gBrowser.addTab(); - aWindow.gBrowser.selectedTab = tabMozilla; - - let mozillaBrowser = aWindow.gBrowser.getBrowserForTab(tabMozilla); - mozillaBrowser.addEventListener("load", function onMozillaBrowserLoad() { - mozillaBrowser.removeEventListener("load", onMozillaBrowserLoad, true); - let mozillaZoom = aWindow.ZoomManager.zoom; - - // change the zoom on the mozilla page - aWindow.FullZoom.enlarge(); - // make sure the zoom level has been changed - isnot(aWindow.ZoomManager.zoom, mozillaZoom, "Zoom level can be changed"); - mozillaZoom = aWindow.ZoomManager.zoom; - - // switch to about: tab - aWindow.gBrowser.selectedTab = tabAbout; - - // switch back to mozilla tab - aWindow.gBrowser.selectedTab = tabMozilla; - - // make sure the zoom level has not changed - is(aWindow.ZoomManager.zoom, mozillaZoom, - "Entering private browsing should not reset the zoom on a tab"); - - // cleanup - aWindow.FullZoom.reset(); - aWindow.gBrowser.removeTab(tabMozilla); - aWindow.gBrowser.removeTab(tabAbout); - aWindow.close(); - aCallback(); - - }, true); - mozillaBrowser.contentWindow.location = "about:mozilla"; - }, true); - aboutBrowser.contentWindow.location = "about:"; - }); - } - - whenNewWindowLoaded({private: true}, function(privateWindow) { - testZoom(privateWindow, finish); - }); -} diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_zoomrestore.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_zoomrestore.js deleted file mode 100644 index 0d664525a..000000000 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_zoomrestore.js +++ /dev/null @@ -1,85 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test makes sure that about:privatebrowsing does not appear zoomed in -// if there is already a zoom site pref for about:blank (bug 487656). - -function test() { - // initialization - waitForExplicitFinish(); - let windowsToClose = []; - let windowsToReset = []; - - function doTestWhenReady(aIsZoomedWindow, aWindow, aCallback) { - // Need to wait on two things, the ordering of which is not guaranteed: - // (1) the page load, and (2) FullZoom's update to the new page's zoom - // level. FullZoom broadcasts "browser-fullZoom:locationChange" when its - // update is done. (See bug 856366 for details.) - - let n = 0; - - let browser = aWindow.gBrowser.selectedBrowser; - browser.addEventListener("load", function onLoad() { - browser.removeEventListener("load", onLoad, true); - if (++n == 2) - doTest(aIsZoomedWindow, aWindow, aCallback); - }, true); - - let topic = "browser-fullZoom:locationChange"; - Services.obs.addObserver(function onLocationChange() { - Services.obs.removeObserver(onLocationChange, topic); - if (++n == 2) - doTest(aIsZoomedWindow, aWindow, aCallback); - }, topic, false); - - browser.loadURI("about:blank"); - } - - function doTest(aIsZoomedWindow, aWindow, aCallback) { - if (aIsZoomedWindow) { - is(aWindow.ZoomManager.zoom, 1, - "Zoom level for freshly loaded about:blank should be 1"); - // change the zoom on the blank page - aWindow.FullZoom.enlarge(); - isnot(aWindow.ZoomManager.zoom, 1, "Zoom level for about:blank should be changed"); - aCallback(); - return; - } - // make sure the zoom level is set to 1 - is(aWindow.ZoomManager.zoom, 1, "Zoom level for about:privatebrowsing should be reset"); - aCallback(); - } - - function finishTest() { - // cleanup - windowsToReset.forEach(function(win) { - win.FullZoom.reset(); - }); - finish(); - } - - function testOnWindow(options, callback) { - let win = OpenBrowserWindow(options); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - windowsToClose.push(win); - windowsToReset.push(win); - executeSoon(function() callback(win)); - }, false); - }; - - registerCleanupFunction(function() { - windowsToClose.forEach(function(win) { - win.close(); - }); - }); - - testOnWindow({}, function(win) { - doTestWhenReady(true, win, function() { - testOnWindow({private: true}, function(win) { - doTestWhenReady(false, win, finishTest); - }); - }); - }); -} diff --git a/browser/components/privatebrowsing/test/browser/head.js b/browser/components/privatebrowsing/test/browser/head.js deleted file mode 100644 index cabaa7d08..000000000 --- a/browser/components/privatebrowsing/test/browser/head.js +++ /dev/null @@ -1,40 +0,0 @@ -function whenNewWindowLoaded(aOptions, aCallback) { - let win = OpenBrowserWindow(aOptions); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - aCallback(win); - }, false); -} - -function newDirectory() { - let FileUtils = - Cu.import("resource://gre/modules/FileUtils.jsm", {}).FileUtils; - let tmpDir = FileUtils.getDir("TmpD", [], true); - let dir = tmpDir.clone(); - dir.append("testdir"); - dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); - return dir; -} - -function newFileInDirectory(aDir) { - let FileUtils = - Cu.import("resource://gre/modules/FileUtils.jsm", {}).FileUtils; - let file = aDir.clone(); - file.append("testfile"); - file.createUnique(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_FILE); - return file; -} - -function clearHistory() { - // simulate clearing the private data - Services.obs.notifyObservers(null, "browser:purge-session-history", ""); -} - -function _initTest() { - // Don't use about:home as the homepage for new windows - Services.prefs.setIntPref("browser.startup.page", 0); - registerCleanupFunction(function() Services.prefs.clearUserPref("browser.startup.page")); -} - -_initTest(); - diff --git a/browser/components/privatebrowsing/test/browser/moz.build b/browser/components/privatebrowsing/test/browser/moz.build deleted file mode 100644 index ac649901e..000000000 --- a/browser/components/privatebrowsing/test/browser/moz.build +++ /dev/null @@ -1,9 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - - -MODULE = 'test_privatebrowsing' - diff --git a/browser/components/privatebrowsing/test/browser/popup.html b/browser/components/privatebrowsing/test/browser/popup.html deleted file mode 100644 index 333a30346..000000000 --- a/browser/components/privatebrowsing/test/browser/popup.html +++ /dev/null @@ -1,11 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> -<html> - <head> - <title>Page creating a popup</title> - </head> - <body> - <script type="text/javascript"> - window.open("data:text/plain,test", "testwin"); - </script> - </body> -</html> diff --git a/browser/components/privatebrowsing/test/browser/title.sjs b/browser/components/privatebrowsing/test/browser/title.sjs deleted file mode 100644 index 568e235be..000000000 --- a/browser/components/privatebrowsing/test/browser/title.sjs +++ /dev/null @@ -1,22 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This provides the tests with a page with different titles based on whether -// a cookie is present or not. - -function handleRequest(request, response) { - response.setStatusLine(request.httpVersion, 200, "OK"); - response.setHeader("Content-Type", "text/html", false); - - var cookie = "name=value"; - var title = "No Cookie"; - if (request.hasHeader("Cookie") && request.getHeader("Cookie") == cookie) - title = "Cookie"; - else - response.setHeader("Set-Cookie", cookie, false); - - response.write("<html><head><title>"); - response.write(title); - response.write("</title><body>test page</body></html>"); -} diff --git a/browser/components/privatebrowsing/test/moz.build b/browser/components/privatebrowsing/test/moz.build deleted file mode 100644 index 38cb43f17..000000000 --- a/browser/components/privatebrowsing/test/moz.build +++ /dev/null @@ -1,10 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -DIRS += ['browser'] - -MODULE = 'test_privatebrowsing' - diff --git a/browser/components/safebrowsing/content/test/Makefile.in b/browser/components/safebrowsing/content/test/Makefile.in deleted file mode 100644 index 1ca03dbe0..000000000 --- a/browser/components/safebrowsing/content/test/Makefile.in +++ /dev/null @@ -1,27 +0,0 @@ -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -DEPTH = @DEPTH@ -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ -relativesrcdir = @relativesrcdir@ - -include $(DEPTH)/config/autoconf.mk - -MOCHITEST_BROWSER_FILES := \ - head.js \ - browser_bug400731.js \ - $(NULL) - -# The browser chrome test for bug 415846 doesn't run on Mac because of its -# bizarre special-and-unique snowflake of a help menu. -ifneq (cocoa,$(MOZ_WIDGET_TOOLKIT)) -MOCHITEST_BROWSER_FILES += \ - browser_bug415846.js \ - $(NULL) -endif - -include $(topsrcdir)/config/rules.mk diff --git a/browser/components/safebrowsing/content/test/browser_bug400731.js b/browser/components/safebrowsing/content/test/browser_bug400731.js deleted file mode 100644 index 313237269..000000000 --- a/browser/components/safebrowsing/content/test/browser_bug400731.js +++ /dev/null @@ -1,49 +0,0 @@ -/* Check for the intended visibility of the "Ignore this warning" text*/ - -function test() { - waitForExplicitFinish(); - - gBrowser.selectedTab = gBrowser.addTab(); - - // Navigate to malware site. Can't use an onload listener here since - // error pages don't fire onload. Also can't register the DOMContentLoaded - // handler here because registering it too soon would mean that we might - // get it for about:blank, and not about:blocked. - gBrowser.addTabsProgressListener({ - onLocationChange: function(aTab, aWebProgress, aRequest, aLocation, aFlags) { - if (aFlags & Ci.nsIWebProgressListener.LOCATION_CHANGE_ERROR_PAGE) { - gBrowser.removeTabsProgressListener(this); - window.addEventListener("DOMContentLoaded", testMalware, true); - } - } - }); - content.location = "http://www.mozilla.org/firefox/its-an-attack.html"; -} - -function testMalware() { - window.removeEventListener("DOMContentLoaded", testMalware, true); - - // Confirm that "Ignore this warning" is visible - bug 422410 - var el = content.document.getElementById("ignoreWarningButton"); - ok(el, "Ignore warning button should be present for malware"); - - var style = content.getComputedStyle(el, null); - is(style.display, "inline-block", "Ignore Warning button should be display:inline-block for malware"); - - // Now launch the phishing test - window.addEventListener("DOMContentLoaded", testPhishing, true); - content.location = "http://www.mozilla.org/firefox/its-a-trap.html"; -} - -function testPhishing() { - window.removeEventListener("DOMContentLoaded", testPhishing, true); - - var el = content.document.getElementById("ignoreWarningButton"); - ok(el, "Ignore warning button should be present for phishing"); - - var style = content.getComputedStyle(el, null); - is(style.display, "inline-block", "Ignore Warning button should be display:inline-block for phishing"); - - gBrowser.removeCurrentTab(); - finish(); -} diff --git a/browser/components/safebrowsing/content/test/browser_bug415846.js b/browser/components/safebrowsing/content/test/browser_bug415846.js deleted file mode 100644 index 079283c8e..000000000 --- a/browser/components/safebrowsing/content/test/browser_bug415846.js +++ /dev/null @@ -1,62 +0,0 @@ -/* Check for the correct behaviour of the report web forgery/not a web forgery -menu items. - -Mac makes this astonishingly painful to test since their help menu is special magic, -but we can at least test it on the other platforms.*/ -var menu; - -function test() { - waitForExplicitFinish(); - - gBrowser.selectedTab = gBrowser.addTab(); - - // Navigate to a normal site - gBrowser.addEventListener("DOMContentLoaded", testNormal, false); - content.location = "http://example.com/"; -} - -function testNormal() { - gBrowser.removeEventListener("DOMContentLoaded", testNormal, false); - - // open the menu, to force it to update - menu = document.getElementById("menu_HelpPopup"); - ok(menu, "Help menu should exist!"); - - menu.addEventListener("popupshown", testNormal_PopupListener, false); - menu.openPopup(null, "", 0, 0, false, null); -} - -function testNormal_PopupListener() { - menu.removeEventListener("popupshown", testNormal_PopupListener, false); - - var reportMenu = document.getElementById("menu_HelpPopup_reportPhishingtoolmenu"); - var errorMenu = document.getElementById("menu_HelpPopup_reportPhishingErrortoolmenu"); - is(reportMenu.hidden, false, "Report phishing menu should be visible on normal sites"); - is(errorMenu.hidden, true, "Report error menu item should be hidden on normal sites"); - menu.hidePopup(); - - // Now launch the phishing test. Can't use onload here because error pages don't - // fire normal load events. - window.addEventListener("DOMContentLoaded", testPhishing, true); - content.location = "http://www.mozilla.org/firefox/its-a-trap.html"; -} - -function testPhishing() { - window.removeEventListener("DOMContentLoaded", testPhishing, true); - - menu.addEventListener("popupshown", testPhishing_PopupListener, false); - menu.openPopup(null, "", 0, 0, false, null); -} - -function testPhishing_PopupListener() { - menu.removeEventListener("popupshown", testPhishing_PopupListener, false); - - var reportMenu = document.getElementById("menu_HelpPopup_reportPhishingtoolmenu"); - var errorMenu = document.getElementById("menu_HelpPopup_reportPhishingErrortoolmenu"); - is(reportMenu.hidden, true, "Report phishing menu should be hidden on phishing sites"); - is(errorMenu.hidden, false, "Report error menu item should be visible on phishing sites"); - menu.hidePopup(); - - gBrowser.removeCurrentTab(); - finish(); -} diff --git a/browser/components/safebrowsing/content/test/head.js b/browser/components/safebrowsing/content/test/head.js deleted file mode 100644 index ca2b3723a..000000000 --- a/browser/components/safebrowsing/content/test/head.js +++ /dev/null @@ -1,3 +0,0 @@ -// Force SafeBrowsing to be initialized for the tests -SafeBrowsing.init(); - diff --git a/browser/components/safebrowsing/content/test/moz.build b/browser/components/safebrowsing/content/test/moz.build deleted file mode 100644 index 895d11993..000000000 --- a/browser/components/safebrowsing/content/test/moz.build +++ /dev/null @@ -1,6 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - diff --git a/browser/components/safebrowsing/moz.build b/browser/components/safebrowsing/moz.build index 9fb81cdcc..8deb0b138 100644 --- a/browser/components/safebrowsing/moz.build +++ b/browser/components/safebrowsing/moz.build @@ -4,5 +4,4 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -TEST_DIRS += ['content/test'] diff --git a/browser/components/search/moz.build b/browser/components/search/moz.build index 86ec46748..8deb0b138 100644 --- a/browser/components/search/moz.build +++ b/browser/components/search/moz.build @@ -4,4 +4,4 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -TEST_DIRS += ['test'] + diff --git a/browser/components/search/test/426329.xml b/browser/components/search/test/426329.xml deleted file mode 100644 index e4545cc77..000000000 --- a/browser/components/search/test/426329.xml +++ /dev/null @@ -1,11 +0,0 @@ -<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" - xmlns:moz="http://www.mozilla.org/2006/browser/search/"> - <ShortName>Bug 426329</ShortName> - <Description>426329 Search</Description> - <InputEncoding>utf-8</InputEncoding> - <Image width="16" height="16">data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGklEQVQoz2NgGB6AnZ1dUlJSXl4eSDIyMhLW4Ovr%2B%2Fr168uXL69Zs4YoG%2BLi4i5dusTExMTGxsbNzd3f37937976%2BnpmZmagbHR09J49e5YvX66kpATVEBYW9ubNm2nTphkbG7e2tp44cQLIuHfvXm5urpaWFlDKysqqu7v73LlzECMYIiIiHj58mJCQoKKicvXq1bS0NKBgW1vbjh074uPjgeqAXE1NzSdPnvDz84M0AEUvXLgAsW379u1z5swBen3jxo2zZ892cHB4%2BvQp0KlAfwI1cHJyghQFBwfv2rULokFXV%2FfixYu7d%2B8GGqGgoMDKyrpu3br9%2B%2FcDuXl5eVA%2FAEWBfoWHAdAYoNuAYQ0XAeoUERFhGDYAAPoUaT2dfWJuAAAAAElFTkSuQmCC</Image> - <Url type="text/html" method="GET" template="http://mochi.test:8888/browser/browser/components/search/test/test.html"> - <Param name="test" value="{searchTerms}"/> - </Url> - <moz:SearchForm>http://mochi.test:8888/browser/browser/components/search/test/test.html</moz:SearchForm> -</OpenSearchDescription> diff --git a/browser/components/search/test/483086-1.xml b/browser/components/search/test/483086-1.xml deleted file mode 100644 index 9dbba4886..000000000 --- a/browser/components/search/test/483086-1.xml +++ /dev/null @@ -1,10 +0,0 @@ -<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" - xmlns:moz="http://www.mozilla.org/2006/browser/search/"> - <ShortName>483086a</ShortName> - <Description>Bug 483086 Test 1</Description> - <Image width="16" height="16">data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGklEQVQoz2NgGB6AnZ1dUlJSXl4eSDIyMhLW4Ovr%2B%2Fr168uXL69Zs4YoG%2BLi4i5dusTExMTGxsbNzd3f37937976%2BnpmZmagbHR09J49e5YvX66kpATVEBYW9ubNm2nTphkbG7e2tp44cQLIuHfvXm5urpaWFlDKysqqu7v73LlzECMYIiIiHj58mJCQoKKicvXq1bS0NKBgW1vbjh074uPjgeqAXE1NzSdPnvDz84M0AEUvXLgAsW379u1z5swBen3jxo2zZ892cHB4%2BvQp0KlAfwI1cHJyghQFBwfv2rULokFXV%2FfixYu7d%2B8GGqGgoMDKyrpu3br9%2B%2FcDuXl5eVA%2FAEWBfoWHAdAYoNuAYQ0XAeoUERFhGDYAAPoUaT2dfWJuAAAAAElFTkSuQmCC</Image> - <Url type="text/html" method="GET" template="http://mochi.test:8888/browser/browser/components/search/test/?search"> - <Param name="test" value="{searchTerms}"/> - </Url> - <moz:SearchForm>foo://example.com</moz:SearchForm> -</OpenSearchDescription> diff --git a/browser/components/search/test/483086-2.xml b/browser/components/search/test/483086-2.xml deleted file mode 100644 index f130b9068..000000000 --- a/browser/components/search/test/483086-2.xml +++ /dev/null @@ -1,10 +0,0 @@ -<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" - xmlns:moz="http://www.mozilla.org/2006/browser/search/"> - <ShortName>483086b</ShortName> - <Description>Bug 483086 Test 2</Description> - <Image width="16" height="16">data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGklEQVQoz2NgGB6AnZ1dUlJSXl4eSDIyMhLW4Ovr%2B%2Fr168uXL69Zs4YoG%2BLi4i5dusTExMTGxsbNzd3f37937976%2BnpmZmagbHR09J49e5YvX66kpATVEBYW9ubNm2nTphkbG7e2tp44cQLIuHfvXm5urpaWFlDKysqqu7v73LlzECMYIiIiHj58mJCQoKKicvXq1bS0NKBgW1vbjh074uPjgeqAXE1NzSdPnvDz84M0AEUvXLgAsW379u1z5swBen3jxo2zZ892cHB4%2BvQp0KlAfwI1cHJyghQFBwfv2rULokFXV%2FfixYu7d%2B8GGqGgoMDKyrpu3br9%2B%2FcDuXl5eVA%2FAEWBfoWHAdAYoNuAYQ0XAeoUERFhGDYAAPoUaT2dfWJuAAAAAElFTkSuQmCC</Image> - <Url type="text/html" method="GET" template="http://mochi.test:8888/browser/browser/components/search/test/?search"> - <Param name="test" value="{searchTerms}"/> - </Url> - <moz:SearchForm>http://example.com</moz:SearchForm> -</OpenSearchDescription> diff --git a/browser/components/search/test/Makefile.in b/browser/components/search/test/Makefile.in deleted file mode 100644 index a9fa3f84c..000000000 --- a/browser/components/search/test/Makefile.in +++ /dev/null @@ -1,40 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -DEPTH = @DEPTH@ -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ -relativesrcdir = @relativesrcdir@ - -include $(DEPTH)/config/autoconf.mk - -MOCHITEST_BROWSER_FILES = \ - head.js \ - browser_405664.js \ - browser_addEngine.js \ - browser_contextmenu.js \ - browser_healthreport.js \ - browser_private_search_perwindowpb.js \ - testEngine.xml \ - testEngine_mozsearch.xml \ - testEngine.src \ - browser_426329.js \ - 426329.xml \ - browser_483086.js \ - 483086-1.xml \ - 483086-2.xml \ - test.html \ - $(NULL) - -ifdef ENABLE_TESTS -pp_mochitest_browser_files := \ - browser_google.js \ - $(NULL) -pp_mochitest_browser_files_PATH := $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir) -pp_mochitest_browser_files_FLAGS := -DMOZ_DISTRIBUTION_ID=$(MOZ_DISTRIBUTION_ID) -PP_TARGETS += pp_mochitest_browser_files -endif # ENABLE_TESTS - -include $(topsrcdir)/config/rules.mk diff --git a/browser/components/search/test/browser_405664.js b/browser/components/search/test/browser_405664.js deleted file mode 100644 index 2d3ee248f..000000000 --- a/browser/components/search/test/browser_405664.js +++ /dev/null @@ -1,29 +0,0 @@ -function test() { - var searchBar = BrowserSearch.searchBar; - ok(searchBar, "got search bar"); - - searchBar.focus(); - - var pbo = searchBar._popup.popupBoxObject; - ok(pbo, "popup is nsIPopupBoxObject"); - - EventUtils.synthesizeKey("VK_UP", { altKey: true }); - is(pbo.popupState, "showing", "popup is opening after Alt+Up"); - - EventUtils.synthesizeKey("VK_ESCAPE", {}); - is(pbo.popupState, "closed", "popup is closed after ESC"); - - EventUtils.synthesizeKey("VK_DOWN", { altKey: true }); - is(pbo.popupState, "showing", "popup is opening after Alt+Down"); - - EventUtils.synthesizeKey("VK_ESCAPE", {}); - is(pbo.popupState, "closed", "popup is closed after ESC 2"); - - if (!/Mac/.test(navigator.platform)) { - EventUtils.synthesizeKey("VK_F4", {}); - is(pbo.popupState, "showing", "popup is opening after F4"); - - EventUtils.synthesizeKey("VK_ESCAPE", {}); - is(pbo.popupState, "closed", "popup is closed after ESC 3"); - } -} diff --git a/browser/components/search/test/browser_426329.js b/browser/components/search/test/browser_426329.js deleted file mode 100644 index 4b2310cd5..000000000 --- a/browser/components/search/test/browser_426329.js +++ /dev/null @@ -1,299 +0,0 @@ -// Instead of loading ChromeUtils.js into the test scope in browser-test.js for all tests, -// we only need ChromeUtils.js for a few files which is why we are using loadSubScript. -var ChromeUtils = {}; -this._scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"]. - getService(Ci.mozIJSSubScriptLoader); -this._scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js", ChromeUtils); - -XPCOMUtils.defineLazyModuleGetter(this, "FormHistory", - "resource://gre/modules/FormHistory.jsm"); - -function test() { - waitForExplicitFinish(); - - const ENGINE_HTML_BASE = "http://mochi.test:8888/browser/browser/components/search/test/test.html"; - - var searchEntries = ["test", "More Text", "Some Text"]; - var searchBar = BrowserSearch.searchBar; - var searchButton = document.getAnonymousElementByAttribute(searchBar, - "anonid", "search-go-button"); - ok(searchButton, "got search-go-button"); - - searchBar.value = "test"; - - var ss = Services.search; - - let testIterator; - - function observer(aSub, aTopic, aData) { - switch (aData) { - case "engine-added": - var engine = ss.getEngineByName("Bug 426329"); - ok(engine, "Engine was added."); - ss.currentEngine = engine; - break; - case "engine-current": - ok(ss.currentEngine.name == "Bug 426329", "currentEngine set"); - testReturn(); - break; - case "engine-removed": - Services.obs.removeObserver(observer, "browser-search-engine-modified"); - finish(); - break; - } - } - - Services.obs.addObserver(observer, "browser-search-engine-modified", false); - ss.addEngine("http://mochi.test:8888/browser/browser/components/search/test/426329.xml", - Ci.nsISearchEngine.DATA_XML, "data:image/x-icon,%00", - false); - - var preSelectedBrowser, preTabNo; - function init() { - preSelectedBrowser = gBrowser.selectedBrowser; - preTabNo = gBrowser.tabs.length; - searchBar.focus(); - } - - function testReturn() { - init(); - EventUtils.synthesizeKey("VK_RETURN", {}); - doOnloadOnce(function(event) { - - is(gBrowser.tabs.length, preTabNo, "Return key did not open new tab"); - is(event.originalTarget, preSelectedBrowser.contentDocument, - "Return key loaded results in current tab"); - is(event.originalTarget.URL, expectedURL(searchBar.value), "Check URL of search page opened"); - - testAltReturn(); - }); - } - - function testAltReturn() { - init(); - EventUtils.synthesizeKey("VK_RETURN", { altKey: true }); - doOnloadOnce(function(event) { - - is(gBrowser.tabs.length, preTabNo + 1, "Alt+Return key added new tab"); - isnot(event.originalTarget, preSelectedBrowser.contentDocument, - "Alt+Return key loaded results in new tab"); - is(event.originalTarget, gBrowser.contentDocument, - "Alt+Return key loaded results in foreground tab"); - is(event.originalTarget.URL, expectedURL(searchBar.value), "Check URL of search page opened"); - - //Shift key has no effect for now, so skip it - //testShiftAltReturn(); - testLeftClick(); - }); - } - - function testShiftAltReturn() { - init(); - EventUtils.synthesizeKey("VK_RETURN", { shiftKey: true, altKey: true }); - doOnloadOnce(function(event) { - - is(gBrowser.tabs.length, preTabNo + 1, "Shift+Alt+Return key added new tab"); - isnot(event.originalTarget, preSelectedBrowser.contentDocument, - "Shift+Alt+Return key loaded results in new tab"); - isnot(event.originalTarget, gBrowser.contentDocument, - "Shift+Alt+Return key loaded results in background tab"); - is(event.originalTarget.URL, expectedURL(searchBar.value), "Check URL of search page opened"); - - testLeftClick(); - }); - } - - function testLeftClick() { - init(); - simulateClick({ button: 0 }, searchButton); - doOnloadOnce(function(event) { - - is(gBrowser.tabs.length, preTabNo, "LeftClick did not open new tab"); - is(event.originalTarget, preSelectedBrowser.contentDocument, - "LeftClick loaded results in current tab"); - is(event.originalTarget.URL, expectedURL(searchBar.value), "Check URL of search page opened"); - - testMiddleClick(); - }); - } - - function testMiddleClick() { - init(); - simulateClick({ button: 1 }, searchButton); - doOnloadOnce(function(event) { - - is(gBrowser.tabs.length, preTabNo + 1, "MiddleClick added new tab"); - isnot(event.originalTarget, preSelectedBrowser.contentDocument, - "MiddleClick loaded results in new tab"); - is(event.originalTarget, gBrowser.contentDocument, - "MiddleClick loaded results in foreground tab"); - is(event.originalTarget.URL, expectedURL(searchBar.value), "Check URL of search page opened"); - - testShiftMiddleClick(); - }); - } - - function testShiftMiddleClick() { - init(); - simulateClick({ button: 1, shiftKey: true }, searchButton); - doOnloadOnce(function(event) { - - is(gBrowser.tabs.length, preTabNo + 1, "Shift+MiddleClick added new tab"); - isnot(event.originalTarget, preSelectedBrowser.contentDocument, - "Shift+MiddleClick loaded results in new tab"); - isnot(event.originalTarget, gBrowser.contentDocument, - "Shift+MiddleClick loaded results in background tab"); - is(event.originalTarget.URL, expectedURL(searchBar.value), "Check URL of search page opened"); - - testDropText(); - }); - } - - // prevent the search buttonmenu from opening during the drag tests - function stopPopup(event) { event.preventDefault(); } - - function testDropText() { - init(); - searchBar.addEventListener("popupshowing", stopPopup, true); - // drop on the search button so that we don't need to worry about the - // default handlers for textboxes. - ChromeUtils.synthesizeDrop(searchBar.searchButton, searchBar.searchButton, [[ {type: "text/plain", data: "Some Text" } ]], "copy", window); - doOnloadOnce(function(event) { - is(searchBar.value, "Some Text", "drop text/plain on searchbar"); - testDropInternalText(); - }); - } - - function testDropInternalText() { - init(); - ChromeUtils.synthesizeDrop(searchBar.searchButton, searchBar.searchButton, [[ {type: "text/x-moz-text-internal", data: "More Text" } ]], "copy", window); - doOnloadOnce(function(event) { - is(searchBar.value, "More Text", "drop text/x-moz-text-internal on searchbar"); - testDropLink(); - }); - } - - function testDropLink() { - init(); - ChromeUtils.synthesizeDrop(searchBar.searchButton, searchBar.searchButton, [[ {type: "text/uri-list", data: "http://www.mozilla.org" } ]], "copy", window); - is(searchBar.value, "More Text", "drop text/uri-list on searchbar"); - SimpleTest.executeSoon(testRightClick); - } - - function testRightClick() { - init(); - searchBar.removeEventListener("popupshowing", stopPopup, true); - content.location.href = "about:blank"; - simulateClick({ button: 2 }, searchButton); - setTimeout(function() { - is(gBrowser.tabs.length, preTabNo, "RightClick did not open new tab"); - is(gBrowser.currentURI.spec, "about:blank", "RightClick did nothing"); - - testIterator = testSearchHistory(); - testIterator.next(); - }, 5000); - } - - function countEntries(name, value, message) { - let count = 0; - FormHistory.count({ fieldname: name, value: value }, - { handleResult: function(result) { count = result; }, - handleError: function(error) { throw error; }, - handleCompletion: function(reason) { - if (!reason) { - ok(count > 0, message); - testIterator.next(); - } - } - }); - } - - function testSearchHistory() { - var textbox = searchBar._textbox; - for (var i = 0; i < searchEntries.length; i++) { - yield countEntries(textbox.getAttribute("autocompletesearchparam"), searchEntries[i], - "form history entry '" + searchEntries[i] + "' should exist"); - } - testAutocomplete(); - } - - function testAutocomplete() { - var popup = searchBar.textbox.popup; - popup.addEventListener("popupshown", function testACPopupShowing() { - popup.removeEventListener("popupshown", testACPopupShowing); - checkMenuEntries(searchEntries); - testClearHistory(); - }); - searchBar.textbox.showHistoryPopup(); - } - - function testClearHistory() { - let controller = searchBar.textbox.controllers.getControllerForCommand("cmd_clearhistory") - ok(controller.isCommandEnabled("cmd_clearhistory"), "Clear history command enabled"); - controller.doCommand("cmd_clearhistory"); - let count = 0; - FormHistory.count({ }, - { handleResult: function(result) { count = result; }, - handleError: function(error) { throw error; }, - handleCompletion: function(reason) { - if (!reason) { - ok(count == 0, "History cleared"); - finalize(); - } - } - }); - } - - function finalize() { - searchBar.value = ""; - while (gBrowser.tabs.length != 1) { - gBrowser.removeTab(gBrowser.tabs[0]); - } - content.location.href = "about:blank"; - var engine = ss.getEngineByName("Bug 426329"); - ss.removeEngine(engine); - } - - function simulateClick(aEvent, aTarget) { - var event = document.createEvent("MouseEvent"); - var ctrlKeyArg = aEvent.ctrlKey || false; - var altKeyArg = aEvent.altKey || false; - var shiftKeyArg = aEvent.shiftKey || false; - var metaKeyArg = aEvent.metaKey || false; - var buttonArg = aEvent.button || 0; - event.initMouseEvent("click", true, true, window, - 0, 0, 0, 0, 0, - ctrlKeyArg, altKeyArg, shiftKeyArg, metaKeyArg, - buttonArg, null); - aTarget.dispatchEvent(event); - } - - function expectedURL(aSearchTerms) { - var textToSubURI = Cc["@mozilla.org/intl/texttosuburi;1"]. - getService(Ci.nsITextToSubURI); - var searchArg = textToSubURI.ConvertAndEscape("utf-8", aSearchTerms); - return ENGINE_HTML_BASE + "?test=" + searchArg; - } - - // modified from toolkit/components/satchel/test/test_form_autocomplete.html - function checkMenuEntries(expectedValues) { - var actualValues = getMenuEntries(); - is(actualValues.length, expectedValues.length, "Checking length of expected menu"); - for (var i = 0; i < expectedValues.length; i++) - is(actualValues[i], expectedValues[i], "Checking menu entry #" + i); - } - - function getMenuEntries() { - var entries = []; - var autocompleteMenu = searchBar.textbox.popup; - // Could perhaps pull values directly from the controller, but it seems - // more reliable to test the values that are actually in the tree? - var column = autocompleteMenu.tree.columns[0]; - var numRows = autocompleteMenu.tree.view.rowCount; - for (var i = 0; i < numRows; i++) { - entries.push(autocompleteMenu.tree.view.getValueAt(i, column)); - } - return entries; - } -} - diff --git a/browser/components/search/test/browser_483086.js b/browser/components/search/test/browser_483086.js deleted file mode 100644 index 223db0cc8..000000000 --- a/browser/components/search/test/browser_483086.js +++ /dev/null @@ -1,51 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -let gSS = Services.search; - -function test() { - waitForExplicitFinish(); - - function observer(aSubject, aTopic, aData) { - switch (aData) { - case "engine-added": - let engine = gSS.getEngineByName("483086a"); - ok(engine, "Test engine 1 installed"); - isnot(engine.searchForm, "foo://example.com", - "Invalid SearchForm URL dropped"); - gSS.removeEngine(engine); - break; - case "engine-removed": - Services.obs.removeObserver(observer, "browser-search-engine-modified"); - test2(); - break; - } - } - - Services.obs.addObserver(observer, "browser-search-engine-modified", false); - gSS.addEngine("http://mochi.test:8888/browser/browser/components/search/test/483086-1.xml", - Ci.nsISearchEngine.DATA_XML, "data:image/x-icon;%00", - false); -} - -function test2() { - function observer(aSubject, aTopic, aData) { - switch (aData) { - case "engine-added": - let engine = gSS.getEngineByName("483086b"); - ok(engine, "Test engine 2 installed"); - is(engine.searchForm, "http://example.com", "SearchForm is correct"); - gSS.removeEngine(engine); - break; - case "engine-removed": - Services.obs.removeObserver(observer, "browser-search-engine-modified"); - finish(); - break; - } - } - - Services.obs.addObserver(observer, "browser-search-engine-modified", false); - gSS.addEngine("http://mochi.test:8888/browser/browser/components/search/test/483086-2.xml", - Ci.nsISearchEngine.DATA_XML, "data:image/x-icon;%00", - false); -} diff --git a/browser/components/search/test/browser_addEngine.js b/browser/components/search/test/browser_addEngine.js deleted file mode 100644 index f546aead6..000000000 --- a/browser/components/search/test/browser_addEngine.js +++ /dev/null @@ -1,136 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -var gSS = Services.search; - -function observer(aSubject, aTopic, aData) { - if (!gCurrentTest) { - info("Observer called with no test active"); - return; - } - - let engine = aSubject.QueryInterface(Ci.nsISearchEngine); - info("Observer: " + aData + " for " + engine.name); - let method; - switch (aData) { - case "engine-added": - if (gCurrentTest.added) - method = "added" - break; - case "engine-current": - if (gCurrentTest.current) - method = "current"; - break; - case "engine-removed": - if (gCurrentTest.removed) - method = "removed"; - break; - } - - if (method) - gCurrentTest[method](engine); -} - -function checkEngine(checkObj, engineObj) { - info("Checking engine"); - for (var prop in checkObj) - is(checkObj[prop], engineObj[prop], prop + " is correct"); -} - -var gTests = [ - { - name: "opensearch install", - engine: { - name: "Foo", - alias: null, - description: "Foo Search", - searchForm: "http://mochi.test:8888/browser/browser/components/search/test/", - type: Ci.nsISearchEngine.TYPE_OPENSEARCH - }, - run: function () { - gSS.addEngine("http://mochi.test:8888/browser/browser/components/search/test/testEngine.xml", - Ci.nsISearchEngine.DATA_XML, "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGklEQVQoz2NgGB6AnZ1dUlJSXl4eSDIyMhLW4Ovr%2B%2Fr168uXL69Zs4YoG%2BLi4i5dusTExMTGxsbNzd3f37937976%2BnpmZmagbHR09J49e5YvX66kpATVEBYW9ubNm2nTphkbG7e2tp44cQLIuHfvXm5urpaWFlDKysqqu7v73LlzECMYIiIiHj58mJCQoKKicvXq1bS0NKBgW1vbjh074uPjgeqAXE1NzSdPnvDz84M0AEUvXLgAsW379u1z5swBen3jxo2zZ892cHB4%2BvQp0KlAfwI1cHJyghQFBwfv2rULokFXV%2FfixYu7d%2B8GGqGgoMDKyrpu3br9%2B%2FcDuXl5eVA%2FAEWBfoWHAdAYoNuAYQ0XAeoUERFhGDYAAPoUaT2dfWJuAAAAAElFTkSuQmCC", - false); - }, - added: function (engine) { - ok(engine, "engine was added."); - - checkEngine(this.engine, engine); - - let engineFromSS = gSS.getEngineByName(this.engine.name); - is(engine, engineFromSS, "engine is obtainable via getEngineByName"); - - let aEngine = gSS.getEngineByAlias("fooalias"); - ok(!aEngine, "Alias was not parsed from engine description"); - - gSS.currentEngine = engine; - }, - current: function (engine) { - let currentEngine = gSS.currentEngine; - is(engine, currentEngine, "engine is current"); - is(engine.name, this.engine.name, "current engine was changed successfully"); - - gSS.removeEngine(engine); - }, - removed: function (engine) { - let currentEngine = gSS.currentEngine; - ok(currentEngine, "An engine is present."); - isnot(currentEngine.name, this.engine.name, "Current engine reset after removal"); - - nextTest(); - } - }, - { - name: "sherlock install", - engine: { - name: "Test Sherlock", - alias: null, - description: "Test Description", - searchForm: "http://example.com/searchform", - type: Ci.nsISearchEngine.TYPE_SHERLOCK - }, - run: function () { - gSS.addEngine("http://mochi.test:8888/browser/browser/components/search/test/testEngine.src", - Ci.nsISearchEngine.DATA_TEXT, "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGklEQVQoz2NgGB6AnZ1dUlJSXl4eSDIyMhLW4Ovr%2B%2Fr168uXL69Zs4YoG%2BLi4i5dusTExMTGxsbNzd3f37937976%2BnpmZmagbHR09J49e5YvX66kpATVEBYW9ubNm2nTphkbG7e2tp44cQLIuHfvXm5urpaWFlDKysqqu7v73LlzECMYIiIiHj58mJCQoKKicvXq1bS0NKBgW1vbjh074uPjgeqAXE1NzSdPnvDz84M0AEUvXLgAsW379u1z5swBen3jxo2zZ892cHB4%2BvQp0KlAfwI1cHJyghQFBwfv2rULokFXV%2FfixYu7d%2B8GGqGgoMDKyrpu3br9%2B%2FcDuXl5eVA%2FAEWBfoWHAdAYoNuAYQ0XAeoUERFhGDYAAPoUaT2dfWJuAAAAAElFTkSuQmCC", - false); - }, - added: function (engine) { - ok(engine, "engine was added."); - checkEngine(this.engine, engine); - - let engineFromSS = gSS.getEngineByName(this.engine.name); - is(engineFromSS, engine, "engine is obtainable via getEngineByName"); - - gSS.removeEngine(engine); - }, - removed: function (engine) { - let currentEngine = gSS.currentEngine; - ok(currentEngine, "An engine is present."); - isnot(currentEngine.name, this.engine.name, "Current engine reset after removal"); - - nextTest(); - } - } -]; - -var gCurrentTest = null; -function nextTest() { - if (gTests.length) { - gCurrentTest = gTests.shift(); - info("Running " + gCurrentTest.name); - gCurrentTest.run(); - } else - executeSoon(finish); -} - -function test() { - waitForExplicitFinish(); - Services.obs.addObserver(observer, "browser-search-engine-modified", false); - registerCleanupFunction(cleanup); - - nextTest(); -} - -function cleanup() { - Services.obs.removeObserver(observer, "browser-search-engine-modified"); -} diff --git a/browser/components/search/test/browser_contextmenu.js b/browser/components/search/test/browser_contextmenu.js deleted file mode 100644 index f34bbc60b..000000000 --- a/browser/components/search/test/browser_contextmenu.js +++ /dev/null @@ -1,99 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * * http://creativecommons.org/publicdomain/zero/1.0/ */ -/* - * Test searching for the selected text using the context menu - */ - -function test() { - waitForExplicitFinish(); - - const ss = Services.search; - const ENGINE_NAME = "Foo"; - var contextMenu; - - function observer(aSub, aTopic, aData) { - switch (aData) { - case "engine-added": - var engine = ss.getEngineByName(ENGINE_NAME); - ok(engine, "Engine was added."); - ss.currentEngine = engine; - break; - case "engine-current": - is(ss.currentEngine.name, ENGINE_NAME, "currentEngine set"); - startTest(); - break; - case "engine-removed": - Services.obs.removeObserver(observer, "browser-search-engine-modified"); - finish(); - break; - } - } - - Services.obs.addObserver(observer, "browser-search-engine-modified", false); - ss.addEngine("http://mochi.test:8888/browser/browser/components/search/test/testEngine_mozsearch.xml", - Ci.nsISearchEngine.DATA_XML, "data:image/x-icon,%00", - false); - - function startTest() { - contextMenu = document.getElementById("contentAreaContextMenu"); - ok(contextMenu, "Got context menu XUL"); - - doOnloadOnce(testContextMenu); - let tab = gBrowser.selectedTab = gBrowser.addTab("data:text/plain;charset=utf8,test%20search"); - registerCleanupFunction(function () { - gBrowser.removeTab(tab); - }); - } - - function testContextMenu() { - function rightClickOnDocument() { - info("rightClickOnDocument: " + content.window.location); - waitForBrowserContextMenu(checkContextMenu); - var clickTarget = content.document.body; - var eventDetails = { type: "contextmenu", button: 2 }; - EventUtils.synthesizeMouseAtCenter(clickTarget, eventDetails, content); - } - - // check the search menu item and then perform a search - function checkContextMenu() { - info("checkContextMenu"); - var searchItem = contextMenu.getElementsByAttribute("id", "context-searchselect")[0]; - ok(searchItem, "Got search context menu item"); - is(searchItem.label, 'Search ' + ENGINE_NAME + ' for "test search"', "Check context menu label"); - is(searchItem.disabled, false, "Check that search context menu item is enabled"); - doOnloadOnce(checkSearchURL); - searchItem.click(); - contextMenu.hidePopup(); - } - - function checkSearchURL(event) { - is(event.originalTarget.URL, - "http://mochi.test:8888/browser/browser/components/search/test/?test=test+search&ie=utf-8&client=app&channel=contextsearch", - "Checking context menu search URL"); - // Remove the tab opened by the search - gBrowser.removeCurrentTab(); - ss.removeEngine(ss.currentEngine); - } - - var selectionListener = { - notifySelectionChanged: function(doc, sel, reason) { - if (reason != Ci.nsISelectionListener.SELECTALL_REASON || sel.toString() != "test search") - return; - info("notifySelectionChanged: Text selected"); - content.window.getSelection().QueryInterface(Ci.nsISelectionPrivate). - removeSelectionListener(selectionListener); - SimpleTest.executeSoon(rightClickOnDocument); - } - }; - - // Delay the select all to avoid intermittent selection failures. - setTimeout(function delaySelectAll() { - info("delaySelectAll: " + content.window.location.toString()); - // add a listener to know when the selection takes effect - content.window.getSelection().QueryInterface(Ci.nsISelectionPrivate). - addSelectionListener(selectionListener); - // select the text on the page - goDoCommand('cmd_selectAll'); - }, 500); - } -} diff --git a/browser/components/search/test/browser_google.js b/browser/components/search/test/browser_google.js deleted file mode 100644 index 94b4b6e09..000000000 --- a/browser/components/search/test/browser_google.js +++ /dev/null @@ -1,176 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -/* - * Test Google search plugin URLs - */ - -"use strict"; - -const BROWSER_SEARCH_PREF = "browser.search."; - -const MOZ_PARAM_LOCALE = /\{moz:locale\}/g; -const MOZ_PARAM_DIST_ID = /\{moz:distributionID\}/g; -const MOZ_PARAM_OFFICIAL = /\{moz:official\}/g; - -// Custom search parameters -#ifdef MOZ_OFFICIAL_BRANDING -const MOZ_OFFICIAL = "official"; -#else -const MOZ_OFFICIAL = "unofficial"; -#endif - -#if MOZ_UPDATE_CHANNEL == beta -const GOOGLE_CLIENT = "firefox-beta"; -#elif MOZ_UPDATE_CHANNEL == aurora -const GOOGLE_CLIENT = "firefox-aurora"; -#elif MOZ_UPDATE_CHANNEL == nightly -const GOOGLE_CLIENT = "firefox-nightly"; -#else -const GOOGLE_CLIENT = "firefox-a"; -#endif - -#expand const MOZ_DISTRIBUTION_ID = __MOZ_DISTRIBUTION_ID__; - -function getLocale() { - const localePref = "general.useragent.locale"; - return getLocalizedPref(localePref, Services.prefs.getCharPref(localePref)); -} - -/** - * Wrapper for nsIPrefBranch::getComplexValue. - * @param aPrefName - * The name of the pref to get. - * @returns aDefault if the requested pref doesn't exist. - */ -function getLocalizedPref(aPrefName, aDefault) { - try { - return Services.prefs.getComplexValue(aPrefName, Ci.nsIPrefLocalizedString).data; - } catch (ex) { - return aDefault; - } - - return aDefault; -} - -function test() { - let engine = Services.search.getEngineByName("Google"); - ok(engine, "Google"); - - is(Services.search.defaultEngine, engine, "Check that Google is the default search engine"); - - let distributionID; - try { - distributionID = Services.prefs.getCharPref(BROWSER_SEARCH_PREF + "distributionID"); - } catch (ex) { - distributionID = MOZ_DISTRIBUTION_ID; - } - - let base = "https://www.google.com/search?q=foo&ie=utf-8&oe=utf-8&aq=t&rls={moz:distributionID}:{moz:locale}:{moz:official}&client=" + GOOGLE_CLIENT; - base = base.replace(MOZ_PARAM_LOCALE, getLocale()); - base = base.replace(MOZ_PARAM_DIST_ID, distributionID); - base = base.replace(MOZ_PARAM_OFFICIAL, MOZ_OFFICIAL); - - let url; - - // Test search URLs (including purposes). - url = engine.getSubmission("foo").uri.spec; - is(url, base, "Check search URL for 'foo'"); - url = engine.getSubmission("foo", null, "contextmenu").uri.spec; - is(url, base + "&channel=rcs", "Check context menu search URL for 'foo'"); - url = engine.getSubmission("foo", null, "keyword").uri.spec; - is(url, base + "&channel=fflb", "Check keyword search URL for 'foo'"); - - // Check search suggestion URL. - url = engine.getSubmission("foo", "application/x-suggestions+json").uri.spec; - is(url, "https://www.google.com/complete/search?client=firefox&q=foo", "Check search suggestion URL for 'foo'"); - - // Check all other engine properties. - const EXPECTED_ENGINE = { - name: "Google", - alias: null, - description: "Google Search", - searchForm: "https://www.google.com/", - type: Ci.nsISearchEngine.TYPE_MOZSEARCH, - hidden: false, - wrappedJSObject: { - "_iconURL": "data:image/x-icon;base64,AAABAAIAEBAAAAAAAAB9AQAAJgAAACAgAAAAAAAA8gIAAKMBAACJUE5HDQoaCgAAAA1JSERSAAAAEAAAABAIBgAAAB/z/2EAAAFESURBVDjLpZNJSwNBEIXnt4lE4kHxovgT9BDwJHqPy0HEEOJBiAuCRg+KUdC4QS4KrpC4gCBGE3NQ48JsnZ6eZ3UOM6gjaePhQU93v6+qq2q0pqgeJj2S8EdJT1hr0OxBtKCD5iEd8QxDYpvhvOBAuMDKURX9C9aPu4GA1GEVkzvMg10UBfYveWAWgYAP00V01fa+R9M2bA51wJvhIn3qR+ybt3D3JNQBE5sMjCIOLFpoHzOwdsLRO22qA6R6kiZiWwxUvy/PUQZIhYZ1vFM9cvcOOsYNdcBgysISdSJBnZjJMlR0Fw8vAp0xoz5gao/h+NZBy4i/10XGwrPA+hmvDyhVRG2Avu/LwcrkFADZa16L1h330w1RNgc3DiJzCpPYRm1bpveXX11clQR28xwblHpk1vq1iP/5mcoS0CoXDZiL0vsJ+dzfl+3T/VYAAAAASUVORK5CYIKJUE5HDQoaCgAAAA1JSERSAAAAIAAAACAIBgAAAHN6evQAAAK5SURBVFjDxVfrSxRRFJ9/Jta/oyWjF5XQm6D6EkHRgygIIgjUTcueVgqVWSRRkppEUQYWWB8ye1iGWilWlo/Ude489s7M6Zw7D9dlt53dmd29cFiWvXvO77x+51xpaaUsoSxBaUWZQ4ECy5xji2xKZDyCMlMEw6lCNiOSgwZKJK1SkcKeSealfP64t0mBjl4Ow39MkDUL0p2RSROOtqhZdeUEYM1pBl39XCg/fEeFtWcY7G9W4csvUxjlBkCsQ4Nt9QyWVfvT6RsAKXw3aoDGATZeYIt+W1kjw7cJG0RctWDTRebbKd8A6h5pwsDb70ba3w/eUr3wt/cmwgfw6Yft4TNMQaY7o1P2ncm4FT4ANQH/jQBJ2xv7kqIXEADDql8eS3+n8bku7oxNm+EDIM/dU92upb3T/NJGeaNbDx/AsbsLRUY5Xn92caWXY5d8RV6gWllxSg4fAEnTC90DQW13BLlgXR2D3dcUeDVkwOthA1bXspxILWcm3HdThcfvufB26LcJpkOEAz9NKI/lzqpSEC7feol5EWnpSeSlIxCALUkApmULdjUqxQVAQnl3D/X/yQda4QBEq2TYc12By091MQ17Bg3R88nHKlQbVmHvj89awNBLYrwT9zXY2aBAxTkGFdiSxP/Jp6FLDw+AS7GfsdJTJ2EqSO5khD43nGfBARy/ZxOQgZHe7GPM1jzUvChUtmnBAXQPcKGMJp3fdFGq6NByEhiAO4b/YptFfQJwNyQ/bZkVQGcf90Ja25ndIyrKBOa/f8wIpwi3X1G8UcxNu7ozUS7tiH0jBswwS3RIaF1w6LYKU/ML2+8sGnjygQswtKrVIy/Qd9qQP6LnO64q4fPAKpxyZIymHo1jWk6p1ag2BsdNwQMHcC+M5kHFJX+YlPxpVlbCx2mZ5DzPI04k4kUwHHdskU3pH76iftG8yWlkAAAAAElFTkSuQmCC", - _urls : [ - { - type: "application/x-suggestions+json", - method: "GET", - template: "https://www.google.com/complete/search?client=firefox&q={searchTerms}", - params: "", - }, - { - type: "text/html", - method: "GET", - template: "https://www.google.com/search", - params: [ - { - "name": "q", - "value": "{searchTerms}", - "purpose": undefined, - }, - { - "name": "ie", - "value": "utf-8", - "purpose": undefined, - }, - { - "name": "oe", - "value": "utf-8", - "purpose": undefined, - }, - { - "name": "aq", - "value": "t", - "purpose": undefined, - }, - { - "name": "rls", - "value": "{moz:distributionID}:{moz:locale}:{moz:official}", - "purpose": undefined, - }, - { - "name": "client", - "value": GOOGLE_CLIENT, - "purpose": undefined, - }, - { - "name": "channel", - "value": "rcs", - "purpose": "contextmenu", - }, - { - "name": "channel", - "value": "fflb", - "purpose": "keyword", - }, - { - "name": "channel", - "value": "np", - "purpose": "homepage", - }, - { - "name": "source", - "value": "hp", - "purpose": "homepage", - }, - ], - mozparams: { - "client": { - "name": "client", - "falseValue": "firefox", - "trueValue": GOOGLE_CLIENT, - "condition": "defaultEngine", - "mozparam": true, - }, - }, - }, - ], - }, - }; - - isSubObjectOf(EXPECTED_ENGINE, engine, "Google"); -} diff --git a/browser/components/search/test/browser_healthreport.js b/browser/components/search/test/browser_healthreport.js deleted file mode 100644 index 0cbe2e88c..000000000 --- a/browser/components/search/test/browser_healthreport.js +++ /dev/null @@ -1,102 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -function test() { - requestLongerTimeout(2); - waitForExplicitFinish(); - - try { - let cm = Components.classes["@mozilla.org/categorymanager;1"] - .getService(Components.interfaces.nsICategoryManager); - cm.getCategoryEntry("healthreport-js-provider-default", "SearchesProvider"); - } catch (ex) { - // Health Report disabled, or no SearchesProvider. - // We need a test or else we'll be marked as failure. - ok(true, "Firefox Health Report is not enabled."); - finish(); - return; - } - - function testFHR() { - let reporter = Components.classes["@mozilla.org/datareporting/service;1"] - .getService() - .wrappedJSObject - .healthReporter; - ok(reporter, "Health Reporter available."); - reporter.onInit().then(function onInit() { - let provider = reporter.getProvider("org.mozilla.searches"); - let m = provider.getMeasurement("counts", 2); - - m.getValues().then(function onData(data) { - let now = new Date(); - let oldCount = 0; - - // Foo engine goes into "other" bucket. - let field = "other.searchbar"; - - if (data.days.hasDay(now)) { - let day = data.days.getDay(now); - if (day.has(field)) { - oldCount = day.get(field); - } - } - - // Now perform a search and ensure the count is incremented. - let tab = gBrowser.addTab(); - gBrowser.selectedTab = tab; - let searchBar = BrowserSearch.searchBar; - - searchBar.value = "firefox health report"; - searchBar.focus(); - - function afterSearch() { - searchBar.value = ""; - gBrowser.removeTab(tab); - - m.getValues().then(function onData(data) { - ok(data.days.hasDay(now), "Have data for today."); - let day = data.days.getDay(now); - - is(day.get(field), oldCount + 1, "Performing a search increments FHR count by 1."); - - let engine = Services.search.getEngineByName("Foo"); - Services.search.removeEngine(engine); - }); - } - - EventUtils.synthesizeKey("VK_RETURN", {}); - executeSoon(() => executeSoon(afterSearch)); - }); - }); - } - - function observer(subject, topic, data) { - switch (data) { - case "engine-added": - let engine = Services.search.getEngineByName("Foo"); - ok(engine, "Engine was added."); - Services.search.currentEngine = engine; - break; - - case "engine-current": - is(Services.search.currentEngine.name, "Foo", "Current engine is Foo"); - testFHR(); - break; - - case "engine-removed": - Services.obs.removeObserver(observer, "browser-search-engine-modified"); - finish(); - break; - } - } - - Services.obs.addObserver(observer, "browser-search-engine-modified", false); - Services.search.addEngine("http://mochi.test:8888/browser/browser/components/search/test/testEngine.xml", - Ci.nsISearchEngine.DATA_XML, - "data:image/x-icon,%00", - false); - -} - diff --git a/browser/components/search/test/browser_private_search_perwindowpb.js b/browser/components/search/test/browser_private_search_perwindowpb.js deleted file mode 100644 index 24c733e5e..000000000 --- a/browser/components/search/test/browser_private_search_perwindowpb.js +++ /dev/null @@ -1,116 +0,0 @@ -// This test performs a search in a public window, then a different -// search in a private window, and then checks in the public window -// whether there is an autocomplete entry for the private search. - -function test() { - // Don't use about:home as the homepage for new windows - Services.prefs.setIntPref("browser.startup.page", 0); - registerCleanupFunction(function() Services.prefs.clearUserPref("browser.startup.page")); - - waitForExplicitFinish(); - - let engineURL = - "http://mochi.test:8888/browser/browser/components/search/test/"; - let windowsToClose = []; - registerCleanupFunction(function() { - let engine = Services.search.getEngineByName("Bug 426329"); - Services.search.removeEngine(engine); - windowsToClose.forEach(function(win) { - win.close(); - }); - }); - - function onPageLoad(aWin, aCallback) { - aWin.gBrowser.addEventListener("DOMContentLoaded", function load(aEvent) { - let doc = aEvent.originalTarget; - info(doc.location.href); - if (doc.location.href.indexOf(engineURL) != -1) { - aWin.gBrowser.removeEventListener("DOMContentLoaded", load, false); - aCallback(); - } - }, false); - } - - function performSearch(aWin, aIsPrivate, aCallback) { - let searchBar = aWin.BrowserSearch.searchBar; - ok(searchBar, "got search bar"); - onPageLoad(aWin, aCallback); - - searchBar.value = aIsPrivate ? "private test" : "public test"; - searchBar.focus(); - EventUtils.synthesizeKey("VK_RETURN", {}, aWin); - } - - function addEngine(aCallback) { - let installCallback = { - onSuccess: function (engine) { - Services.search.currentEngine = engine; - aCallback(); - }, - onError: function (errorCode) { - ok(false, "failed to install engine: " + errorCode); - } - }; - Services.search.addEngine(engineURL + "426329.xml", - Ci.nsISearchEngine.DATA_XML, - "data:image/x-icon,%00", false, installCallback); - } - - function testOnWindow(aIsPrivate, aCallback) { - let win = OpenBrowserWindow({ private: aIsPrivate }); - waitForFocus(function() { - windowsToClose.push(win); - executeSoon(function() aCallback(win)); - }, win); - } - - addEngine(function() { - testOnWindow(false, function(win) { - performSearch(win, false, function() { - testOnWindow(true, function(win) { - performSearch(win, true, function() { - testOnWindow(false, function(win) { - checkSearchPopup(win, finish); - }); - }); - }); - }); - }); - }); -} - -function checkSearchPopup(aWin, aCallback) { - let searchBar = aWin.BrowserSearch.searchBar; - searchBar.value = "p"; - searchBar.focus(); - - let popup = searchBar.textbox.popup; - popup.addEventListener("popupshowing", function showing() { - popup.removeEventListener("popupshowing", showing, false); - - let entries = getMenuEntries(searchBar); - for (let i = 0; i < entries.length; i++) { - isnot(entries[i], "private test", - "shouldn't see private autocomplete entries"); - } - - searchBar.textbox.toggleHistoryPopup(); - searchBar.value = ""; - aCallback(); - }, false); - - searchBar.textbox.showHistoryPopup(); -} - -function getMenuEntries(searchBar) { - let entries = []; - let autocompleteMenu = searchBar.textbox.popup; - // Could perhaps pull values directly from the controller, but it seems - // more reliable to test the values that are actually in the tree? - let column = autocompleteMenu.tree.columns[0]; - let numRows = autocompleteMenu.tree.view.rowCount; - for (let i = 0; i < numRows; i++) { - entries.push(autocompleteMenu.tree.view.getValueAt(i, column)); - } - return entries; -} diff --git a/browser/components/search/test/head.js b/browser/components/search/test/head.js deleted file mode 100644 index f9db47879..000000000 --- a/browser/components/search/test/head.js +++ /dev/null @@ -1,53 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -/** - * Recursively compare two objects and check that every property of expectedObj has the same value - * on actualObj. - */ -function isSubObjectOf(expectedObj, actualObj, name) { - for (let prop in expectedObj) { - if (typeof expectedObj[prop] == 'function') - continue; - if (expectedObj[prop] instanceof Object) { - is(actualObj[prop].length, expectedObj[prop].length, name + "[" + prop + "]"); - isSubObjectOf(expectedObj[prop], actualObj[prop], name + "[" + prop + "]"); - } else { - is(actualObj[prop], expectedObj[prop], name + "[" + prop + "]"); - } - } -} - -function waitForPopupShown(aPopupId, aCallback) { - let popup = document.getElementById(aPopupId); - info("waitForPopupShown: got popup: " + popup.id); - function onPopupShown() { - info("onPopupShown"); - removePopupShownListener(); - SimpleTest.executeSoon(aCallback); - } - function removePopupShownListener() { - popup.removeEventListener("popupshown", onPopupShown); - } - popup.addEventListener("popupshown", onPopupShown); - registerCleanupFunction(removePopupShownListener); -} - -function waitForBrowserContextMenu(aCallback) { - waitForPopupShown(gBrowser.selectedBrowser.contextMenu, aCallback); -} - -function doOnloadOnce(aCallback) { - function doOnloadOnceListener(aEvent) { - info("doOnloadOnce: " + aEvent.originalTarget.location); - removeDoOnloadOnceListener(); - SimpleTest.executeSoon(function doOnloadOnceCallback() { - aCallback(aEvent); - }); - } - function removeDoOnloadOnceListener() { - gBrowser.removeEventListener("load", doOnloadOnceListener, true); - } - gBrowser.addEventListener("load", doOnloadOnceListener, true); - registerCleanupFunction(removeDoOnloadOnceListener); -} diff --git a/browser/components/search/test/moz.build b/browser/components/search/test/moz.build deleted file mode 100644 index 895d11993..000000000 --- a/browser/components/search/test/moz.build +++ /dev/null @@ -1,6 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - diff --git a/browser/components/search/test/test.html b/browser/components/search/test/test.html deleted file mode 100644 index a39bece4f..000000000 --- a/browser/components/search/test/test.html +++ /dev/null @@ -1,8 +0,0 @@ -<!DOCTYPE html> -<html> -<head> - <meta charset="utf-8" /> - <title>Bug 426329</title> -</head> -<body></body> -</html> diff --git a/browser/components/search/test/testEngine.src b/browser/components/search/test/testEngine.src deleted file mode 100644 index eb39fe826..000000000 --- a/browser/components/search/test/testEngine.src +++ /dev/null @@ -1,11 +0,0 @@ -<search - name="Test Sherlock" - description="Test Description" - method="GET" - searchform="http://example.com/searchform" - action="http://example.com/action" - queryCharset="UTF-8" -> - <input name="userParam" user> - <input name="param" value="value"> -</search> diff --git a/browser/components/search/test/testEngine.xml b/browser/components/search/test/testEngine.xml deleted file mode 100644 index 21ddc4b9a..000000000 --- a/browser/components/search/test/testEngine.xml +++ /dev/null @@ -1,12 +0,0 @@ -<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" - xmlns:moz="http://www.mozilla.org/2006/browser/search/"> - <ShortName>Foo</ShortName> - <Description>Foo Search</Description> - <InputEncoding>utf-8</InputEncoding> - <Image width="16" height="16">data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGklEQVQoz2NgGB6AnZ1dUlJSXl4eSDIyMhLW4Ovr%2B%2Fr168uXL69Zs4YoG%2BLi4i5dusTExMTGxsbNzd3f37937976%2BnpmZmagbHR09J49e5YvX66kpATVEBYW9ubNm2nTphkbG7e2tp44cQLIuHfvXm5urpaWFlDKysqqu7v73LlzECMYIiIiHj58mJCQoKKicvXq1bS0NKBgW1vbjh074uPjgeqAXE1NzSdPnvDz84M0AEUvXLgAsW379u1z5swBen3jxo2zZ892cHB4%2BvQp0KlAfwI1cHJyghQFBwfv2rULokFXV%2FfixYu7d%2B8GGqGgoMDKyrpu3br9%2B%2FcDuXl5eVA%2FAEWBfoWHAdAYoNuAYQ0XAeoUERFhGDYAAPoUaT2dfWJuAAAAAElFTkSuQmCC</Image> - <Url type="text/html" method="GET" template="http://mochi.test:8888/browser/browser/components/search/test/?search"> - <Param name="test" value="{searchTerms}"/> - </Url> - <moz:SearchForm>http://mochi.test:8888/browser/browser/components/search/test/</moz:SearchForm> - <moz:Alias>fooalias</moz:Alias> -</OpenSearchDescription> diff --git a/browser/components/search/test/testEngine_mozsearch.xml b/browser/components/search/test/testEngine_mozsearch.xml deleted file mode 100644 index 1f691965e..000000000 --- a/browser/components/search/test/testEngine_mozsearch.xml +++ /dev/null @@ -1,15 +0,0 @@ -<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/"> - <ShortName>Foo</ShortName> - <Description>Foo Search</Description> - <InputEncoding>utf-8</InputEncoding> - <Image width="16" height="16">data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGklEQVQoz2NgGB6AnZ1dUlJSXl4eSDIyMhLW4Ovr%2B%2Fr168uXL69Zs4YoG%2BLi4i5dusTExMTGxsbNzd3f37937976%2BnpmZmagbHR09J49e5YvX66kpATVEBYW9ubNm2nTphkbG7e2tp44cQLIuHfvXm5urpaWFlDKysqqu7v73LlzECMYIiIiHj58mJCQoKKicvXq1bS0NKBgW1vbjh074uPjgeqAXE1NzSdPnvDz84M0AEUvXLgAsW379u1z5swBen3jxo2zZ892cHB4%2BvQp0KlAfwI1cHJyghQFBwfv2rULokFXV%2FfixYu7d%2B8GGqGgoMDKyrpu3br9%2B%2FcDuXl5eVA%2FAEWBfoWHAdAYoNuAYQ0XAeoUERFhGDYAAPoUaT2dfWJuAAAAAElFTkSuQmCC</Image> - <Url type="application/x-suggestions+json" method="GET" template="http://mochi.test:8888/browser/browser/components/search/test/?suggestions&locale={moz:locale}&test={searchTerms}"/> - <Url type="text/html" method="GET" template="http://mochi.test:8888/browser/browser/components/search/test/"> - <Param name="test" value="{searchTerms}"/> - <Param name="ie" value="utf-8"/> - <MozParam name="client" condition="defaultEngine" trueValue="app-default" falseValue="app"/> - <MozParam name="channel" condition="purpose" purpose="keyword" value="keywordsearch"/> - <MozParam name="channel" condition="purpose" purpose="contextmenu" value="contextsearch"/> - </Url> - <SearchForm>http://mochi.test:8888/browser/browser/components/search/test/</SearchForm> -</SearchPlugin> diff --git a/browser/components/sessionstore/moz.build b/browser/components/sessionstore/moz.build index 9fbf063f7..11e98fb4d 100644 --- a/browser/components/sessionstore/moz.build +++ b/browser/components/sessionstore/moz.build @@ -5,7 +5,6 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DIRS += ['src'] -TEST_DIRS += ['test'] XPIDL_SOURCES += [ 'nsISessionStartup.idl', diff --git a/browser/components/sessionstore/test/Makefile.in b/browser/components/sessionstore/test/Makefile.in deleted file mode 100644 index 6c12283e9..000000000 --- a/browser/components/sessionstore/test/Makefile.in +++ /dev/null @@ -1,169 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -DEPTH = @DEPTH@ -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ -relativesrcdir = @relativesrcdir@ - -include $(DEPTH)/config/autoconf.mk - -# browser_506482.js is disabled because of frequent failures (bug 538672) -# browser_526613.js is disabled because of frequent failures (bug 534489) -# browser_589246.js is disabled for leaking browser windows (bug 752467) -# browser_580512.js is disabled for leaking browser windows (bug 752467) -# browser_707862.js & browser_705597.js are disabled whilst waiting for review (bug 861700 & bug 883592) - -MOCHITEST_BROWSER_FILES = \ - head.js \ - browser_attributes.js \ - browser_capabilities.js \ - browser_dying_cache.js \ - browser_form_restore_events.js \ - browser_form_restore_events_sample.html \ - browser_formdata_format.js \ - browser_formdata_format_sample.html \ - browser_input.js \ - browser_input_sample.html \ - browser_pageshow.js \ - browser_windowRestore_perwindowpb.js \ - browser_248970_b_perwindowpb.js \ - browser_248970_b_sample.html \ - browser_339445.js \ - browser_339445_sample.html \ - browser_345898.js \ - browser_346337.js \ - browser_346337_sample.html \ - browser_350525.js \ - browser_354894_perwindowpb.js \ - browser_367052.js \ - browser_393716.js \ - browser_394759_basic.js \ - browser_394759_behavior.js \ - browser_394759_perwindowpb.js \ - browser_394759_purge.js \ - browser_408470.js \ - browser_408470_sample.html \ - browser_423132.js \ - browser_423132_sample.html \ - browser_447951.js \ - browser_447951_sample.html \ - browser_448741.js \ - browser_454908.js \ - browser_454908_sample.html \ - browser_456342.js \ - browser_456342_sample.xhtml \ - browser_461634.js \ - browser_463205.js \ - browser_463205_helper.html \ - browser_463205_sample.html \ - browser_463206.js \ - browser_463206_sample.html \ - browser_464199.js \ - browser_465215.js \ - browser_465223.js \ - browser_466937.js \ - browser_466937_sample.html \ - browser_467409-backslashplosion.js \ - browser_477657.js \ - browser_480148.js \ - browser_480893.js \ - browser_483330.js \ - browser_485482.js \ - browser_485482_sample.html \ - browser_485563.js \ - browser_490040.js \ - browser_491168.js \ - browser_491577.js \ - browser_495495.js \ - browser_500328.js \ - browser_514751.js \ - browser_522375.js \ - browser_522545.js \ - browser_524745.js \ - browser_528776.js \ - browser_579868.js \ - browser_579879.js \ - browser_581593.js \ - browser_581937.js \ - browser_586147.js \ - browser_586068-apptabs.js \ - browser_586068-apptabs_ondemand.js \ - browser_586068-browser_state_interrupted.js \ - browser_586068-cascade.js \ - browser_586068-multi_window.js \ - browser_586068-reload.js \ - browser_586068-select.js \ - browser_586068-window_state.js \ - browser_586068-window_state_override.js \ - browser_588426.js \ - browser_590268.js \ - browser_590563.js \ - browser_595601-restore_hidden.js \ - browser_597315.js \ - browser_597315_index.html \ - browser_597315_a.html \ - browser_597315_b.html \ - browser_597315_c.html \ - browser_597315_c1.html \ - browser_597315_c2.html \ - browser_599909.js \ - browser_600545.js \ - browser_601955.js \ - browser_607016.js \ - browser_615394-SSWindowState_events.js \ - browser_618151.js \ - browser_623779.js \ - browser_624727.js \ - browser_625257.js \ - browser_628270.js \ - browser_635418.js \ - browser_636279.js \ - browser_637020.js \ - browser_637020_slow.sjs \ - browser_644409-scratchpads.js \ - browser_645428.js \ - browser_659591.js \ - browser_662743.js \ - browser_662743_sample.html \ - browser_662812.js \ - browser_665702-state_session.js \ - browser_682507.js \ - browser_687710.js \ - browser_687710_2.js \ - browser_694378.js \ - browser_701377.js \ - browser_739531.js \ - browser_739531_sample.html \ - browser_739805.js \ - browser_819510_perwindowpb.js \ - browser_833286_atomic_backup.js \ - $(filter disabled-for-intermittent-failures--bug-766044, browser_459906_empty.html) \ - $(filter disabled-for-intermittent-failures--bug-766044, browser_459906_sample.html) \ - $(filter disabled-for-intermittent-failures--bug-765389, browser_461743_sample.html) \ - $(NULL) - -# Disabled on Windows for frequent intermittent failures -ifneq ($(OS_ARCH), WINNT) -MOCHITEST_FILES += \ - browser_464620_a.js \ - browser_464620_a.html \ - browser_464620_b.js \ - browser_464620_b.html \ - browser_464620_xd.html \ - $(NULL) -else -$(filter disabled-for-intermittent-failures-on-windows--bug-552424, browser_464620_a.js) -$(filter disabled-for-intermittent-failures-on-windows--bug-552424, browser_464620_b.js) -endif - -ifneq ($(OS_ARCH),Darwin) -MOCHITEST_BROWSER_FILES += \ - browser_597071.js \ - browser_625016.js \ - $(NULL) -endif - -include $(topsrcdir)/config/rules.mk diff --git a/browser/components/sessionstore/test/browser_248970_b_perwindowpb.js b/browser/components/sessionstore/test/browser_248970_b_perwindowpb.js deleted file mode 100644 index 13334fb28..000000000 --- a/browser/components/sessionstore/test/browser_248970_b_perwindowpb.js +++ /dev/null @@ -1,167 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test (B) for Bug 248970 **/ - waitForExplicitFinish(); - - let windowsToClose = []; - let file = Services.dirsvc.get("TmpD", Ci.nsIFile); - let filePath = file.path; - let fieldList = { - "//input[@name='input']": Date.now().toString(), - "//input[@name='spaced 1']": Math.random().toString(), - "//input[3]": "three", - "//input[@type='checkbox']": true, - "//input[@name='uncheck']": false, - "//input[@type='radio'][1]": false, - "//input[@type='radio'][2]": true, - "//input[@type='radio'][3]": false, - "//select": 2, - "//select[@multiple]": [1, 3], - "//textarea[1]": "", - "//textarea[2]": "Some text... " + Math.random(), - "//textarea[3]": "Some more text\n" + new Date(), - "//input[@type='file']": filePath - }; - - registerCleanupFunction(function() { - windowsToClose.forEach(function(win) { - win.close(); - }); - }); - - function test(aLambda) { - try { - return aLambda() || true; - } catch(ex) { } - return false; - } - - function getElementByXPath(aTab, aQuery) { - let doc = aTab.linkedBrowser.contentDocument; - let xptype = Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE; - return doc.evaluate(aQuery, doc, null, xptype, null).singleNodeValue; - } - - function setFormValue(aTab, aQuery, aValue) { - let node = getElementByXPath(aTab, aQuery); - if (typeof aValue == "string") - node.value = aValue; - else if (typeof aValue == "boolean") - node.checked = aValue; - else if (typeof aValue == "number") - node.selectedIndex = aValue; - else - Array.forEach(node.options, function(aOpt, aIx) - (aOpt.selected = aValue.indexOf(aIx) > -1)); - } - - function compareFormValue(aTab, aQuery, aValue) { - let node = getElementByXPath(aTab, aQuery); - if (!node) - return false; - if (node instanceof Ci.nsIDOMHTMLInputElement) - return aValue == (node.type == "checkbox" || node.type == "radio" ? - node.checked : node.value); - if (node instanceof Ci.nsIDOMHTMLTextAreaElement) - return aValue == node.value; - if (!node.multiple) - return aValue == node.selectedIndex; - return Array.every(node.options, function(aOpt, aIx) - (aValue.indexOf(aIx) > -1) == aOpt.selected); - } - - ////////////////////////////////////////////////////////////////// - // Test (B) : Session data restoration between windows // - ////////////////////////////////////////////////////////////////// - - let rootDir = getRootDirectory(gTestPath); - const testURL = rootDir + "browser_248970_b_sample.html"; - const testURL2 = "http://mochi.test:8888/browser/" + - "browser/components/sessionstore/test/browser_248970_b_sample.html"; - - whenNewWindowLoaded(false, function(aWin) { - windowsToClose.push(aWin); - - // get closed tab count - let count = ss.getClosedTabCount(aWin); - let max_tabs_undo = - Services.prefs.getIntPref("browser.sessionstore.max_tabs_undo"); - ok(0 <= count && count <= max_tabs_undo, - "getClosedTabCount should return zero or at most max_tabs_undo"); - - // setup a state for tab (A) so we can check later that is restored - let key = "key"; - let value = "Value " + Math.random(); - let state = { entries: [{ url: testURL }], extData: { key: value } }; - - // public session, add new tab: (A) - let tab_A = aWin.gBrowser.addTab(testURL); - ss.setTabState(tab_A, JSON.stringify(state)); - whenBrowserLoaded(tab_A.linkedBrowser, function() { - // make sure that the next closed tab will increase getClosedTabCount - Services.prefs.setIntPref( - "browser.sessionstore.max_tabs_undo", max_tabs_undo + 1) - - // populate tab_A with form data - for (let i in fieldList) - setFormValue(tab_A, i, fieldList[i]); - - // public session, close tab: (A) - aWin.gBrowser.removeTab(tab_A); - - // verify that closedTabCount increased - ok(ss.getClosedTabCount(aWin) > count, - "getClosedTabCount has increased after closing a tab"); - - // verify tab: (A), in undo list - let tab_A_restored = test(function() ss.undoCloseTab(aWin, 0)); - ok(tab_A_restored, "a tab is in undo list"); - whenBrowserLoaded(tab_A_restored.linkedBrowser, function() { - is(testURL, tab_A_restored.linkedBrowser.currentURI.spec, - "it's the same tab that we expect"); - aWin.gBrowser.removeTab(tab_A_restored); - - whenNewWindowLoaded(true, function(aWin) { - windowsToClose.push(aWin); - - // setup a state for tab (B) so we can check that its duplicated - // properly - let key1 = "key1"; - let value1 = "Value " + Math.random(); - let state1 = { - entries: [{ url: testURL2 }], extData: { key1: value1 } - }; - - let tab_B = aWin.gBrowser.addTab(testURL2); - ss.setTabState(tab_B, JSON.stringify(state1)); - whenBrowserLoaded(tab_B.linkedBrowser, function() { - // populate tab: (B) with different form data - for (let item in fieldList) - setFormValue(tab_B, item, fieldList[item]); - - // duplicate tab: (B) - let tab_C = aWin.gBrowser.duplicateTab(tab_B); - whenBrowserLoaded(tab_C.linkedBrowser, function() { - // verify the correctness of the duplicated tab - is(ss.getTabValue(tab_C, key1), value1, - "tab successfully duplicated - correct state"); - - for (let item in fieldList) - ok(compareFormValue(tab_C, item, fieldList[item]), - "The value for \"" + item + "\" was correctly duplicated"); - - // private browsing session, close tab: (C) and (B) - aWin.gBrowser.removeTab(tab_C); - aWin.gBrowser.removeTab(tab_B); - - finish(); - }); - }); - }); - }); - }); - }); -} diff --git a/browser/components/sessionstore/test/browser_248970_b_sample.html b/browser/components/sessionstore/test/browser_248970_b_sample.html deleted file mode 100644 index 76c3ae1aa..000000000 --- a/browser/components/sessionstore/test/browser_248970_b_sample.html +++ /dev/null @@ -1,37 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> -<meta charset="utf-8"> -<title>Test for bug 248970</title> - -<h3>Text Fields</h3> -<input type="text" name="input"> -<input type="text" name="spaced 1"> -<input> - -<h3>Checkboxes and Radio buttons</h3> -<input type="checkbox" name="check"> Check 1 -<input type="checkbox" name="uncheck" checked> Check 2 -<p> -<input type="radio" name="group" value="1"> Radio 1 -<input type="radio" name="group" value="some"> Radio 2 -<input type="radio" name="group" checked> Radio 3 - -<h3>Selects</h3> -<select name="any"> - <option value="1"> Select 1 - <option value="some"> Select 2 - <option>Select 3 -</select> -<select multiple="multiple"> - <option value=1> Multi-select 1 - <option value=2> Multi-select 2 - <option value=3> Multi-select 3 - <option value=4> Multi-select 4 -</select> - -<h3>Text Areas</h3> -<textarea name="testarea"></textarea> -<textarea name="sized one" rows="5" cols="25"></textarea> -<textarea></textarea> - -<h3>File Selector</h3> -<input type="file"> diff --git a/browser/components/sessionstore/test/browser_339445.js b/browser/components/sessionstore/test/browser_339445.js deleted file mode 100644 index c130c019f..000000000 --- a/browser/components/sessionstore/test/browser_339445.js +++ /dev/null @@ -1,34 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 339445 **/ - - waitForExplicitFinish(); - - let testURL = "http://mochi.test:8888/browser/" + - "browser/components/sessionstore/test/browser_339445_sample.html"; - - let tab = gBrowser.addTab(testURL); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - this.removeEventListener("load", arguments.callee, true); - let doc = tab.linkedBrowser.contentDocument; - is(doc.getElementById("storageTestItem").textContent, "PENDING", - "sessionStorage value has been set"); - - let tab2 = gBrowser.duplicateTab(tab); - tab2.linkedBrowser.addEventListener("load", function(aEvent) { - this.removeEventListener("load", arguments.callee, true); - let doc2 = tab2.linkedBrowser.contentDocument; - is(doc2.getElementById("storageTestItem").textContent, "SUCCESS", - "sessionStorage value has been duplicated"); - - // clean up - gBrowser.removeTab(tab2); - gBrowser.removeTab(tab); - - finish(); - }, true); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_339445_sample.html b/browser/components/sessionstore/test/browser_339445_sample.html deleted file mode 100644 index 32656a8d9..000000000 --- a/browser/components/sessionstore/test/browser_339445_sample.html +++ /dev/null @@ -1,18 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> -<meta charset="utf-8"> -<title>Test for bug 339445</title> - -storageTestItem = <span id="storageTestItem">FAIL</span> - -<!-- - storageTestItem's textContent will be one of the following: - * FAIL : sessionStorage wasn't available - * PENDING : the test value has been initialized on first load - * SUCCESS : the test value was correctly retrieved ---> - -<script type="application/javascript"> - document.getElementById("storageTestItem").textContent = - sessionStorage["storageTestItem"] || "PENDING"; - sessionStorage["storageTestItem"] = "SUCCESS"; -</script> diff --git a/browser/components/sessionstore/test/browser_345898.js b/browser/components/sessionstore/test/browser_345898.js deleted file mode 100644 index c4dc7fbb4..000000000 --- a/browser/components/sessionstore/test/browser_345898.js +++ /dev/null @@ -1,43 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 345898 **/ - - function test(aLambda) { - try { - aLambda(); - return false; - } - catch (ex) { - return ex.name == "NS_ERROR_ILLEGAL_VALUE"; - } - } - - // all of the following calls with illegal arguments should throw NS_ERROR_ILLEGAL_VALUE - ok(test(function() ss.getWindowState({})), - "Invalid window for getWindowState throws"); - ok(test(function() ss.setWindowState({}, "", false)), - "Invalid window for setWindowState throws"); - ok(test(function() ss.getTabState({})), - "Invalid tab for getTabState throws"); - ok(test(function() ss.setTabState({}, "{}")), - "Invalid tab state for setTabState throws"); - ok(test(function() ss.setTabState({}, JSON.stringify({ entries: [] }))), - "Invalid tab for setTabState throws"); - ok(test(function() ss.duplicateTab({}, {})), - "Invalid tab for duplicateTab throws"); - ok(test(function() ss.duplicateTab({}, gBrowser.selectedTab)), - "Invalid window for duplicateTab throws"); - ok(test(function() ss.getClosedTabData({})), - "Invalid window for getClosedTabData throws"); - ok(test(function() ss.undoCloseTab({}, 0)), - "Invalid window for undoCloseTab throws"); - ok(test(function() ss.undoCloseTab(window, -1)), - "Invalid index for undoCloseTab throws"); - ok(test(function() ss.getWindowValue({}, "")), - "Invalid window for getWindowValue throws"); - ok(test(function() ss.setWindowValue({}, "", "")), - "Invalid window for setWindowValue throws"); -} diff --git a/browser/components/sessionstore/test/browser_346337.js b/browser/components/sessionstore/test/browser_346337.js deleted file mode 100644 index 8b000b365..000000000 --- a/browser/components/sessionstore/test/browser_346337.js +++ /dev/null @@ -1,126 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 346337 **/ - - var file = Components.classes["@mozilla.org/file/directory_service;1"] - .getService(Components.interfaces.nsIProperties) - .get("TmpD", Components.interfaces.nsILocalFile); - file.append("346337_test1.file"); - file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666); - var filePath1 = file.path; - file = Components.classes["@mozilla.org/file/directory_service;1"] - .getService(Components.interfaces.nsIProperties) - .get("TmpD", Components.interfaces.nsILocalFile); - file.append("346337_test2.file"); - file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666); - var filePath2 = file.path; - - let fieldList = { - "//input[@name='input']": Date.now().toString(), - "//input[@name='spaced 1']": Math.random().toString(), - "//input[3]": "three", - "//input[@type='checkbox']": true, - "//input[@name='uncheck']": false, - "//input[@type='radio'][1]": false, - "//input[@type='radio'][2]": true, - "//input[@type='radio'][3]": false, - "//select": 2, - "//select[@multiple]": [1, 3], - "//textarea[1]": "", - "//textarea[2]": "Some text... " + Math.random(), - "//textarea[3]": "Some more text\n" + new Date(), - "//input[@type='file'][1]": [filePath1], - "//input[@type='file'][2]": [filePath1, filePath2] - }; - - function getElementByXPath(aTab, aQuery) { - let doc = aTab.linkedBrowser.contentDocument; - let xptype = Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE; - return doc.evaluate(aQuery, doc, null, xptype, null).singleNodeValue; - } - - function setFormValue(aTab, aQuery, aValue) { - let node = getElementByXPath(aTab, aQuery); - if (typeof aValue == "string") - node.value = aValue; - else if (typeof aValue == "boolean") - node.checked = aValue; - else if (typeof aValue == "number") - node.selectedIndex = aValue; - else if (node instanceof Ci.nsIDOMHTMLInputElement && node.type == "file") - node.mozSetFileNameArray(aValue, aValue.length); - else - Array.forEach(node.options, function(aOpt, aIx) - (aOpt.selected = aValue.indexOf(aIx) > -1)); - } - - function compareFormValue(aTab, aQuery, aValue) { - let node = getElementByXPath(aTab, aQuery); - if (!node) - return false; - if (node instanceof Ci.nsIDOMHTMLInputElement) { - if (node.type == "file") { - let fileNames = node.mozGetFileNameArray(); - return fileNames.length == aValue.length && - Array.every(fileNames, function(aFile) aValue.indexOf(aFile) >= 0); - } - return aValue == (node.type == "checkbox" || node.type == "radio" ? - node.checked : node.value); - } - if (node instanceof Ci.nsIDOMHTMLTextAreaElement) - return aValue == node.value; - if (!node.multiple) - return aValue == node.selectedIndex; - return Array.every(node.options, function(aOpt, aIx) - (aValue.indexOf(aIx) > -1) == aOpt.selected); - } - - // test setup - let tabbrowser = gBrowser; - waitForExplicitFinish(); - - // make sure we don't save form data at all (except for tab duplication) - gPrefService.setIntPref("browser.sessionstore.privacy_level", 2); - - let rootDir = getRootDirectory(gTestPath); - let testURL = rootDir + "browser_346337_sample.html"; - let tab = tabbrowser.addTab(testURL); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - this.removeEventListener("load", arguments.callee, true); - for (let xpath in fieldList) - setFormValue(tab, xpath, fieldList[xpath]); - - let tab2 = tabbrowser.duplicateTab(tab); - tab2.linkedBrowser.addEventListener("load", function(aEvent) { - this.removeEventListener("load", arguments.callee, true); - for (let xpath in fieldList) - ok(compareFormValue(tab2, xpath, fieldList[xpath]), - "The value for \"" + xpath + "\" was correctly restored"); - - // clean up - tabbrowser.removeTab(tab2); - tabbrowser.removeTab(tab); - - tab = undoCloseTab(); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - this.removeEventListener("load", arguments.callee, true); - for (let xpath in fieldList) - if (fieldList[xpath]) - ok(!compareFormValue(tab, xpath, fieldList[xpath]), - "The value for \"" + xpath + "\" was correctly discarded"); - - if (gPrefService.prefHasUserValue("browser.sessionstore.privacy_level")) - gPrefService.clearUserPref("browser.sessionstore.privacy_level"); - // undoCloseTab can reuse a single blank tab, so we have to - // make sure not to close the window when closing our last tab - if (tabbrowser.tabs.length == 1) - tabbrowser.addTab(); - tabbrowser.removeTab(tab); - finish(); - }, true); - }, true); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_346337_sample.html b/browser/components/sessionstore/test/browser_346337_sample.html deleted file mode 100644 index 682162d6a..000000000 --- a/browser/components/sessionstore/test/browser_346337_sample.html +++ /dev/null @@ -1,37 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> -<title>Test for bug 346337</title> - -<h3>Text Fields</h3> -<input type="text" name="input"> -<input type="text" name="spaced 1"> -<input> - -<h3>Checkboxes and Radio buttons</h3> -<input type="checkbox" name="check"> Check 1 -<input type="checkbox" name="uncheck" checked> Check 2 -<p> -<input type="radio" name="group" value="1"> Radio 1 -<input type="radio" name="group" value="some"> Radio 2 -<input type="radio" name="group" checked> Radio 3 - -<h3>Selects</h3> -<select name="any"> - <option value="1"> Select 1 - <option value="some"> Select 2 - <option>Select 3 -</select> -<select multiple="multiple"> - <option value=1> Multi-select 1 - <option value=2> Multi-select 2 - <option value=3> Multi-select 3 - <option value=4> Multi-select 4 -</select> - -<h3>Text Areas</h3> -<textarea name="testarea"></textarea> -<textarea name="sized one" rows="5" cols="25"></textarea> -<textarea></textarea> - -<h3>File Selector</h3> -<input type="file"> -<input type="file" multiple> diff --git a/browser/components/sessionstore/test/browser_350525.js b/browser/components/sessionstore/test/browser_350525.js deleted file mode 100644 index 0dc23fe21..000000000 --- a/browser/components/sessionstore/test/browser_350525.js +++ /dev/null @@ -1,101 +0,0 @@ -function test() { - /** Test for Bug 350525 **/ - - function test(aLambda) { - try { - return aLambda() || true; - } - catch (ex) { } - return false; - } - - waitForExplicitFinish(); - - //////////////////////////// - // 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"); - - // test deleting a non-existent value - ok(test(function() ss.deleteWindowValue(window, key)), "delete non-existent window value"); - - ///////////////////////// - // setTabValue, et al. // - ///////////////////////// - key = "Unique name: " + Math.random(); - value = "Unique value: " + Date.now(); - let tab = gBrowser.addTab(); - tab.linkedBrowser.stop(); - - // 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"); - - // test deleting a non-existent value - ok(test(function() ss.deleteTabValue(tab, key)), "delete non-existent tab value"); - - // clean up - gBrowser.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 = gBrowser.addTab(testURL); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - this.removeEventListener("load", arguments.callee, true); - // make sure that the next closed tab will increase getClosedTabCount - gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo + 1); - - // remove tab - gBrowser.removeTab(tab); - - // getClosedTabCount - var newcount = ss.getClosedTabCount(window); - ok(newcount > count, "after closing a tab, getClosedTabCount has been incremented"); - - // undoCloseTab - tab = test(function() ss.undoCloseTab(window, 0)); - ok(tab, "undoCloseTab doesn't throw") - - tab.linkedBrowser.addEventListener("load", function(aEvent) { - this.removeEventListener("load", arguments.callee, true); - is(this.currentURI.spec, testURL, "correct tab was reopened"); - - // clean up - if (gPrefService.prefHasUserValue("browser.sessionstore.max_tabs_undo")) - gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo"); - gBrowser.removeTab(tab); - finish(); - }, true); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_354894_perwindowpb.js b/browser/components/sessionstore/test/browser_354894_perwindowpb.js deleted file mode 100644 index 78e861ba0..000000000 --- a/browser/components/sessionstore/test/browser_354894_perwindowpb.js +++ /dev/null @@ -1,513 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** - * Checks that restoring the last browser window in session is actually - * working: - * 1.1) Open a new browser window - * 1.2) Add some tabs - * 1.3) Close that window - * 1.4) Opening another window - * --> State is restored - * - * 2.1) Open a new browser window - * 2.2) Add some tabs - * 2.3) Enter private browsing mode - * 2.4) Close the window while still in private browsing mode - * 2.5) Opening a new window - * --> State is not restored, because private browsing mode is still active - * 2.6) Leaving private browsing mode - * 2.7) Open another window - * --> State (that was before entering PBM) is restored - * - * 3.1) Open a new browser window - * 3.2) Add some tabs - * 3.4) Open some popups - * 3.5) Add another tab to one popup (so that it gets stored) and close it again - * 3.5) Close the browser window - * 3.6) Open another browser window - * --> State of the closed browser window, but not of the popup, is restored - * - * 4.1) Open a popup - * 4.2) Add another tab to the popup (so that it gets stored) and close it again - * 4.3) Open a window - * --> Nothing at all should be restored - * - * 5.1) Open two browser windows and close them again - * 5.2) undoCloseWindow() one - * 5.3) Open another browser window - * --> Nothing at all should be restored - * - * Checks the new notifications are correctly posted and processed, that is - * for each successful -requested a -granted is received, but omitted if - * -requested was cnceled - * Said notifications are: - * - browser-lastwindow-close-requested - * - browser-lastwindow-close-granted - * Tests are: - * 6) Cancel closing when first observe a -requested - * --> Window is kept open - * 7) Count the number of notifications - * --> count(-requested) == count(-granted) + 1 - * --> (The first -requested was canceled, so off-by-one) - * 8) (Mac only) Mac version of Test 5 additionally preparing Test 6 - * - * @see https://bugzilla.mozilla.org/show_bug.cgi?id=354894 - * @note It is implicitly tested that restoring the last window works when - * non-browser windows are around. The "Run Tests" window as well as the main - * browser window (wherein the test code gets executed) won't be considered - * browser windows. To achiveve this said main browser window has it's windowtype - * attribute modified so that it's not considered a browser window any longer. - * This is crucial, because otherwise there would be two browser windows around, - * said main test window and the one opened by the tests, and hence the new - * logic wouldn't be executed at all. - * @note Mac only tests the new notifications, as restoring the last window is - * not enabled on that platform (platform shim; the application is kept running - * although there are no windows left) - * @note There is a difference when closing a browser window with - * BrowserTryToCloseWindow() as opposed to close(). The former will make - * nsSessionStore restore a window next time it gets a chance and will post - * notifications. The latter won't. - */ - -function browserWindowsCount(expected, msg) { - if (typeof expected == "number") - expected = [expected, expected]; - let count = 0; - let e = Services.wm.getEnumerator("navigator:browser"); - while (e.hasMoreElements()) { - if (!e.getNext().closed) - ++count; - } - is(count, expected[0], msg + " (nsIWindowMediator)"); - let state = ss.getBrowserState(); - is(JSON.parse(state).windows.length, expected[1], msg + " (getBrowserState)"); -} - -function test() { - browserWindowsCount(1, "Only one browser window should be open initially"); - - waitForExplicitFinish(); - // This test takes some time to run, and it could timeout randomly. - // So we require a longer timeout. See bug 528219. - requestLongerTimeout(2); - - // Some urls that might be opened in tabs and/or popups - // Do not use about:blank: - // That one is reserved for special purposes in the tests - const TEST_URLS = ["about:mozilla", "about:buildconfig"]; - - // Number of -request notifications to except - // remember to adjust when adding new tests - const NOTIFICATIONS_EXPECTED = 6; - - // Window features of popup windows - const POPUP_FEATURES = "toolbar=no,resizable=no,status=no"; - - // Window features of browser windows - const CHROME_FEATURES = "chrome,all,dialog=no"; - - // Store the old window type for cleanup - let oldWinType = ""; - // Store the old tabs.warnOnClose pref so that we may reset it during - // cleanup - let oldWarnTabsOnClose = gPrefService.getBoolPref("browser.tabs.warnOnClose"); - - // Observe these, and also use to count the number of hits - let observing = { - "browser-lastwindow-close-requested": 0, - "browser-lastwindow-close-granted": 0 - }; - - /** - * Helper: Will observe and handle the notifications for us - */ - let hitCount = 0; - function observer(aCancel, aTopic, aData) { - // count so that we later may compare - observing[aTopic]++; - - // handle some tests - if (++hitCount == 1) { - // Test 6 - aCancel.QueryInterface(Ci.nsISupportsPRBool).data = true; - } - } - - /** - * Helper: Sets prefs as the testsuite requires - * @note Will be reset in cleanTestSuite just before finishing the tests - */ - function setPrefs() { - gPrefService.setIntPref("browser.startup.page", 3); - gPrefService.setBoolPref( - "browser.privatebrowsing.keep_current_session", - true - ); - gPrefService.setBoolPref("browser.tabs.warnOnClose", false); - } - - /** - * Helper: Sets up this testsuite - */ - function setupTestsuite(testFn) { - // Register our observers - for (let o in observing) - Services.obs.addObserver(observer, o, false); - - // Make the main test window not count as a browser window any longer - oldWinType = document.documentElement.getAttribute("windowtype"); - document.documentElement.setAttribute("windowtype", "navigator:testrunner"); - } - - /** - * Helper: Cleans up behind the testsuite - */ - function cleanupTestsuite(callback) { - // Finally remove observers again - for (let o in observing) - Services.obs.removeObserver(observer, o); - - // Reset the prefs we touched - [ - "browser.startup.page", - "browser.privatebrowsing.keep_current_session" - ].forEach(function (pref) { - if (gPrefService.prefHasUserValue(pref)) - gPrefService.clearUserPref(pref); - }); - gPrefService.setBoolPref("browser.tabs.warnOnClose", oldWarnTabsOnClose); - - // Reset the window type - document.documentElement.setAttribute("windowtype", oldWinType); - } - - /** - * Helper: sets the prefs and a new window with our test tabs - */ - function setupTestAndRun(aIsPrivateWindow, testFn) { - // Prepare the prefs - setPrefs(); - - // Prepare a window; open it and add more tabs - let options = {}; - if (aIsPrivateWindow) { - options = {private: true}; - } - - let newWin = OpenBrowserWindow(options); - newWin.addEventListener("load", function(aEvent) { - newWin.removeEventListener("load", arguments.callee, false); - newWin.gBrowser.addEventListener("load", function(aEvent) { - newWin.gBrowser.removeEventListener("load", arguments.callee, true); - TEST_URLS.forEach(function (url) { - newWin.gBrowser.addTab(url); - }); - - executeSoon(function() testFn(newWin)); - }, true); - }, false); - } - - /** - * Test 1: Normal in-session restore - * @note: Non-Mac only - */ - function testOpenCloseNormal(nextFn) { - setupTestAndRun(false, function(newWin) { - // Close the window - // window.close doesn't push any close events, - // so use BrowserTryToCloseWindow - newWin.BrowserTryToCloseWindow(); - - // The first request to close is denied by our observer (Test 6) - ok(!newWin.closed, "First close request was denied"); - if (!newWin.closed) { - newWin.BrowserTryToCloseWindow(); - ok(newWin.closed, "Second close request was granted"); - } - - // Open a new window - // The previously closed window should be restored - newWin = OpenBrowserWindow({}); - newWin.addEventListener("load", function() { - this.removeEventListener("load", arguments.callee, true); - executeSoon(function() { - is(newWin.gBrowser.browsers.length, TEST_URLS.length + 1, - "Restored window in-session with otherpopup windows around"); - - // Cleanup - newWin.close(); - - // Next please - executeSoon(nextFn); - }); - }, true); - }); - } - - /** - * Test 2: PrivateBrowsing in-session restore - * @note: Non-Mac only - */ - function testOpenClosePrivateBrowsing(nextFn) { - setupTestAndRun(false, function(newWin) { - // Close the window - newWin.BrowserTryToCloseWindow(); - - // Enter private browsing mode - // Open a new window. - // The previously closed window should NOT be restored - newWin = OpenBrowserWindow({private: true}); - newWin.addEventListener("load", function() { - this.removeEventListener("load", arguments.callee, true); - executeSoon(function() { - is(newWin.gBrowser.browsers.length, 1, - "Did not restore in private browing mode"); - - // Cleanup - newWin.BrowserTryToCloseWindow(); - - // Exit private browsing mode again - newWin = OpenBrowserWindow({}); - newWin.addEventListener("load", function() { - this.removeEventListener("load", arguments.callee, true); - executeSoon(function() { - is(newWin.gBrowser.browsers.length, TEST_URLS.length + 1, - "Restored after leaving private browsing again"); - - newWin.close(); - - // Next please - executeSoon(nextFn); - }); - }, true); - }); - }, true); - }); - } - - /** - * Test 3: Open some popup windows to check those aren't restored, but - * the browser window is - * @note: Non-Mac only - */ - function testOpenCloseWindowAndPopup(nextFn) { - setupTestAndRun(false, function(newWin) { - // open some popups - let popup = openDialog(location, "popup", POPUP_FEATURES, TEST_URLS[0]); - let popup2 = openDialog(location, "popup2", POPUP_FEATURES, TEST_URLS[1]); - popup2.addEventListener("load", function() { - popup2.removeEventListener("load", arguments.callee, false); - popup2.gBrowser.addEventListener("load", function() { - popup2.gBrowser.removeEventListener("load", arguments.callee, true); - popup2.gBrowser.addTab(TEST_URLS[0]); - // close the window - newWin.BrowserTryToCloseWindow(); - - // Close the popup window - // The test is successful when not this popup window is restored - // but instead newWin - popup2.close(); - - // open a new window the previously closed window should be restored to - newWin = OpenBrowserWindow({}); - newWin.addEventListener("load", function() { - this.removeEventListener("load", arguments.callee, true); - executeSoon(function() { - is(newWin.gBrowser.browsers.length, TEST_URLS.length + 1, - "Restored window and associated tabs in session"); - - // Cleanup - newWin.close(); - popup.close(); - - // Next please - executeSoon(nextFn); - }); - }, true); - }, true); - }, false); - }); - } - - /** - * Test 4: Open some popup window to check it isn't restored. - * Instead nothing at all should be restored - * @note: Non-Mac only - */ - function testOpenCloseOnlyPopup(nextFn) { - // prepare the prefs - setPrefs(); - - // This will cause nsSessionStore to restore a window the next time it - // gets a chance. - let popup = openDialog(location, "popup", POPUP_FEATURES, TEST_URLS[1]); - popup.addEventListener("load", function() { - this.removeEventListener("load", arguments.callee, true); - is(popup.gBrowser.browsers.length, 1, - "Did not restore the popup window (1)"); - popup.BrowserTryToCloseWindow(); - - // Real tests - popup = openDialog(location, "popup", POPUP_FEATURES, TEST_URLS[1]); - popup.addEventListener("load", function() { - popup.removeEventListener("load", arguments.callee, false); - popup.gBrowser.addEventListener("load", function() { - popup.gBrowser.removeEventListener("load", arguments.callee, true); - popup.gBrowser.addTab(TEST_URLS[0]); - - is(popup.gBrowser.browsers.length, 2, - "Did not restore to the popup window (2)"); - - // Close the popup window - // The test is successful when not this popup window is restored - // but instead a new window is opened without restoring anything - popup.close(); - - let newWin = OpenBrowserWindow({}); - newWin.addEventListener("load", function() { - newWin.removeEventListener("load", arguments.callee, true); - executeSoon(function() { - isnot(newWin.gBrowser.browsers.length, 2, - "Did not restore the popup window"); - is(TEST_URLS.indexOf(newWin.gBrowser.browsers[0].currentURI.spec), -1, - "Did not restore the popup window (2)"); - - // Cleanup - newWin.close(); - - // Next please - executeSoon(nextFn); - }); - }, true); - }, true); - }, false); - }, true); - } - - /** - * Test 5: Open some windows and do undoCloseWindow. This should prevent any - * restoring later in the test - * @note: Non-Mac only - */ - function testOpenCloseRestoreFromPopup(nextFn) { - setupTestAndRun(false, function(newWin) { - setupTestAndRun(false, function(newWin2) { - newWin.BrowserTryToCloseWindow(); - newWin2.BrowserTryToCloseWindow(); - - browserWindowsCount([0, 1], "browser windows while running testOpenCloseRestoreFromPopup"); - - newWin = undoCloseWindow(0); - - newWin2 = OpenBrowserWindow({}); - newWin2.addEventListener("load", function() { - newWin2.removeEventListener("load", arguments.callee, true); - executeSoon(function() { - is(newWin2.gBrowser.browsers.length, 1, - "Did not restore, as undoCloseWindow() was last called"); - is(TEST_URLS.indexOf(newWin2.gBrowser.browsers[0].currentURI.spec), -1, - "Did not restore, as undoCloseWindow() was last called (2)"); - - browserWindowsCount([2, 3], "browser windows while running testOpenCloseRestoreFromPopup"); - - // Cleanup - newWin.close(); - newWin2.close(); - - browserWindowsCount([0, 1], "browser windows while running testOpenCloseRestoreFromPopup"); - - // Next please - executeSoon(nextFn); - }); - }, true); - }); - }); - } - - /** - * Test 7: Check whether the right number of notifications was received during - * the tests - */ - function testNotificationCount(nextFn) { - is(observing["browser-lastwindow-close-requested"], NOTIFICATIONS_EXPECTED, - "browser-lastwindow-close-requested notifications observed"); - - // -request must be one more as we cancel the first one we hit, - // and hence won't produce a corresponding -grant - // @see observer.observe - is(observing["browser-lastwindow-close-requested"], - observing["browser-lastwindow-close-granted"] + 1, - "Notification count for -request and -grant matches"); - - executeSoon(nextFn); - } - - /** - * Test 8: Test if closing can be denied on Mac - * Futhermore prepares the testNotificationCount test (Test 7) - * @note: Mac only - */ - function testMacNotifications(nextFn, iteration) { - iteration = iteration || 1; - setupTestAndRun(false, function(newWin) { - // close the window - // window.close doesn't push any close events, - // so use BrowserTryToCloseWindow - newWin.BrowserTryToCloseWindow(); - if (iteration == 1) { - ok(!newWin.closed, "First close attempt denied"); - if (!newWin.closed) { - newWin.BrowserTryToCloseWindow(); - ok(newWin.closed, "Second close attempt granted"); - } - } - - if (iteration < NOTIFICATIONS_EXPECTED - 1) { - executeSoon(function() testMacNotifications(nextFn, ++iteration)); - } - else { - executeSoon(nextFn); - } - }); - } - - // Execution starts here - - setupTestsuite(); - if (navigator.platform.match(/Mac/)) { - // Mac tests - testMacNotifications(function () { - testNotificationCount(function () { - cleanupTestsuite(); - browserWindowsCount(1, "Only one browser window should be open eventually"); - finish(); - }); - }); - } - else { - // Non-Mac Tests - testOpenCloseNormal(function () { - browserWindowsCount([0, 1], "browser windows after testOpenCloseNormal"); - testOpenClosePrivateBrowsing(function () { - browserWindowsCount([0, 1], "browser windows after testOpenClosePrivateBrowsing"); - testOpenCloseWindowAndPopup(function () { - browserWindowsCount([0, 1], "browser windows after testOpenCloseWindowAndPopup"); - testOpenCloseOnlyPopup(function () { - browserWindowsCount([0, 1], "browser windows after testOpenCloseOnlyPopup"); - testOpenCloseRestoreFromPopup(function () { - browserWindowsCount([0, 1], "browser windows after testOpenCloseRestoreFromPopup"); - testNotificationCount(function () { - cleanupTestsuite(); - browserWindowsCount(1, "browser windows after testNotificationCount"); - finish(); - }); - }); - }); - }); - }); - }); - } -} diff --git a/browser/components/sessionstore/test/browser_367052.js b/browser/components/sessionstore/test/browser_367052.js deleted file mode 100644 index ba07a21f9..000000000 --- a/browser/components/sessionstore/test/browser_367052.js +++ /dev/null @@ -1,38 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 367052 **/ - - waitForExplicitFinish(); - - // make sure that the next closed tab will increase getClosedTabCount - let max_tabs_undo = gPrefService.getIntPref("browser.sessionstore.max_tabs_undo"); - gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo + 1); - let closedTabCount = ss.getClosedTabCount(window); - - // restore a blank tab - let tab = gBrowser.addTab("about:"); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - this.removeEventListener("load", arguments.callee, true); - - let history = tab.linkedBrowser.webNavigation.sessionHistory; - ok(history.count >= 1, "the new tab does have at least one history entry"); - - ss.setTabState(tab, JSON.stringify({ entries: [] })); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - this.removeEventListener("load", arguments.callee, true); - ok(history.count == 0, "the tab was restored without any history whatsoever"); - - gBrowser.removeTab(tab); - ok(ss.getClosedTabCount(window) == closedTabCount, - "The closed blank tab wasn't added to Recently Closed Tabs"); - - // clean up - if (gPrefService.prefHasUserValue("browser.sessionstore.max_tabs_undo")) - gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo"); - finish(); - }, true); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_393716.js b/browser/components/sessionstore/test/browser_393716.js deleted file mode 100644 index f6c6e6173..000000000 --- a/browser/components/sessionstore/test/browser_393716.js +++ /dev/null @@ -1,74 +0,0 @@ -function test() { - /** Test for Bug 393716 **/ - - waitForExplicitFinish(); - - ///////////////// - // getTabState // - ///////////////// - let key = "Unique key: " + Date.now(); - let value = "Unique value: " + Math.random(); - let testURL = "about:config"; - - // create a new tab - let tab = gBrowser.addTab(testURL); - ss.setTabValue(tab, key, value); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - this.removeEventListener("load", arguments.callee, true); - // get the tab's state - let state = ss.getTabState(tab); - ok(state, "get the tab's state"); - - // verify the tab state's integrity - state = JSON.parse(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 - gBrowser.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 = gBrowser.addTab(); - // set the tab's state - ss.setTabState(tab2, JSON.stringify(state)); - tab2.linkedBrowser.addEventListener("load", function(aEvent) { - this.removeEventListener("load", arguments.callee, true); - // 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.value = value3; - - // duplicate the tab - let duplicateTab = ss.duplicateTab(window, tab2); - gBrowser.removeTab(tab2); - - duplicateTab.linkedBrowser.addEventListener("load", function(aEvent) { - this.removeEventListener("load", arguments.callee, true); - // 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.value, value3, "also duplicated text data"); - - // clean up - gBrowser.removeTab(duplicateTab); - finish(); - }, true); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_394759_basic.js b/browser/components/sessionstore/test/browser_394759_basic.js deleted file mode 100644 index 5cf411d2d..000000000 --- a/browser/components/sessionstore/test/browser_394759_basic.js +++ /dev/null @@ -1,75 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - waitForExplicitFinish(); - - let testURL = "about:config"; - let uniqueKey = "bug 394759"; - let uniqueValue = "unik" + Date.now(); - let uniqueText = "pi != " + Math.random(); - - // Be consistent: let the page actually display, as we are "interacting" with it. - Services.prefs.setBoolPref("general.warnOnAboutConfig", false); - - // make sure that the next closed window will increase getClosedWindowCount - let max_windows_undo = Services.prefs.getIntPref("browser.sessionstore.max_windows_undo"); - Services.prefs.setIntPref("browser.sessionstore.max_windows_undo", max_windows_undo + 1); - let closedWindowCount = ss.getClosedWindowCount(); - - provideWindow(function onTestURLLoaded(newWin) { - newWin.gBrowser.addTab().linkedBrowser.stop(); - - // mark the window with some unique data to be restored later on - ss.setWindowValue(newWin, uniqueKey, uniqueValue); - let textbox = newWin.content.document.getElementById("textbox"); - textbox.value = uniqueText; - - newWin.close(); - - is(ss.getClosedWindowCount(), closedWindowCount + 1, - "The closed window was added to Recently Closed Windows"); - let data = JSON.parse(ss.getClosedWindowData())[0]; - ok(data.title == testURL && JSON.stringify(data).indexOf(uniqueText) > -1, - "The closed window data was stored correctly"); - - // reopen the closed window and ensure its integrity - let newWin2 = ss.undoCloseWindow(0); - - ok(newWin2 instanceof ChromeWindow, - "undoCloseWindow actually returned a window"); - is(ss.getClosedWindowCount(), closedWindowCount, - "The reopened window was removed from Recently Closed Windows"); - - // SSTabRestored will fire more than once, so we need to make sure we count them - let restoredTabs = 0; - let expectedTabs = data.tabs.length; - newWin2.addEventListener("SSTabRestored", function sstabrestoredListener(aEvent) { - ++restoredTabs; - info("Restored tab " + restoredTabs + "/" + expectedTabs); - if (restoredTabs < expectedTabs) { - return; - } - - newWin2.removeEventListener("SSTabRestored", sstabrestoredListener, true); - - is(newWin2.gBrowser.tabs.length, 2, - "The window correctly restored 2 tabs"); - is(newWin2.gBrowser.currentURI.spec, testURL, - "The window correctly restored the URL"); - - let textbox = newWin2.content.document.getElementById("textbox"); - is(textbox.value, uniqueText, - "The window correctly restored the form"); - is(ss.getWindowValue(newWin2, uniqueKey), uniqueValue, - "The window correctly restored the data associated with it"); - - // clean up - newWin2.close(); - Services.prefs.clearUserPref("browser.sessionstore.max_windows_undo"); - Services.prefs.clearUserPref("general.warnOnAboutConfig"); - finish(); - }, true); - }, testURL); -} diff --git a/browser/components/sessionstore/test/browser_394759_behavior.js b/browser/components/sessionstore/test/browser_394759_behavior.js deleted file mode 100644 index c0bf2f2af..000000000 --- a/browser/components/sessionstore/test/browser_394759_behavior.js +++ /dev/null @@ -1,64 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - // This test takes quite some time, and timeouts frequently, so we require - // more time to run. - // See Bug 518970. - requestLongerTimeout(2); - - waitForExplicitFinish(); - - // helper function that does the actual testing - function openWindowRec(windowsToOpen, expectedResults, recCallback) { - // do actual checking - if (!windowsToOpen.length) { - let closedWindowData = JSON.parse(ss.getClosedWindowData()); - let numPopups = closedWindowData.filter(function(el, i, arr) { - return el.isPopup; - }).length; - let numNormal = ss.getClosedWindowCount() - numPopups; - // #ifdef doesn't work in browser-chrome tests, so do a simple regex on platform - let oResults = navigator.platform.match(/Mac/) ? expectedResults.mac - : expectedResults.other; - is(numPopups, oResults.popup, - "There were " + oResults.popup + " popup windows to repoen"); - is(numNormal, oResults.normal, - "There were " + oResults.normal + " normal windows to repoen"); - - // cleanup & return - executeSoon(recCallback); - return; - } - - // hack to force window to be considered a popup (toolbar=no didn't work) - let winData = windowsToOpen.shift(); - let settings = "chrome,dialog=no," + - (winData.isPopup ? "all=no" : "all"); - let url = "http://example.com/?window=" + windowsToOpen.length; - - provideWindow(function onTestURLLoaded(win) { - win.close(); - openWindowRec(windowsToOpen, expectedResults, recCallback); - }, url, settings); - } - - let windowsToOpen = [{isPopup: false}, - {isPopup: false}, - {isPopup: true}, - {isPopup: true}, - {isPopup: true}]; - let expectedResults = {mac: {popup: 3, normal: 0}, - other: {popup: 3, normal: 1}}; - let windowsToOpen2 = [{isPopup: false}, - {isPopup: false}, - {isPopup: false}, - {isPopup: false}, - {isPopup: false}]; - let expectedResults2 = {mac: {popup: 0, normal: 3}, - other: {popup: 0, normal: 3}}; - openWindowRec(windowsToOpen, expectedResults, function() { - openWindowRec(windowsToOpen2, expectedResults2, finish); - }); -} diff --git a/browser/components/sessionstore/test/browser_394759_perwindowpb.js b/browser/components/sessionstore/test/browser_394759_perwindowpb.js deleted file mode 100644 index e16427f4e..000000000 --- a/browser/components/sessionstore/test/browser_394759_perwindowpb.js +++ /dev/null @@ -1,119 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/** Private Browsing Test for Bug 394759 **/ -function test() { - waitForExplicitFinish(); - - let windowsToClose = []; - let closedWindowCount = 0; - // Prevent VM timers issues, cache now and increment it manually. - let now = Date.now(); - const TESTS = [ - { url: "about:config", - key: "bug 394759 Non-PB", - value: "uniq" + (++now) }, - { url: "about:mozilla", - key: "bug 394759 PB", - value: "uniq" + (++now) }, - ]; - - registerCleanupFunction(function() { - Services.prefs.clearUserPref("browser.sessionstore.interval"); - windowsToClose.forEach(function(win) { - win.close(); - }); - }); - - function testOpenCloseWindow(aIsPrivate, aTest, aCallback) { - whenNewWindowLoaded(aIsPrivate, function(win) { - win.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - win.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); - executeSoon(function() { - // Mark the window with some unique data to be restored later on. - ss.setWindowValue(win, aTest.key, aTest.value); - // Close. - win.close(); - aCallback(); - }); - }, true); - win.gBrowser.selectedBrowser.loadURI(aTest.url); - }); - } - - function testOnWindow(aIsPrivate, aValue, aCallback) { - whenNewWindowLoaded(aIsPrivate, function(win) { - windowsToClose.push(win); - executeSoon(function() checkClosedWindows(aIsPrivate, aValue, aCallback)); - }); - } - - function checkClosedWindows(aIsPrivate, aValue, aCallback) { - let data = JSON.parse(ss.getClosedWindowData())[0]; - is(ss.getClosedWindowCount(), 1, "Check the closed window count"); - ok(JSON.stringify(data).indexOf(aValue) > -1, - "Check the closed window data was stored correctly"); - aCallback(); - } - - function setupBlankState(aCallback) { - // Set interval to a large time so state won't be written while we setup - // environment. - Services.prefs.setIntPref("browser.sessionstore.interval", 100000); - - // Set up the browser in a blank state. Popup windows in previous tests - // result in different states on different platforms. - let blankState = JSON.stringify({ - windows: [{ - tabs: [{ entries: [{ url: "about:blank" }] }], - _closedTabs: [] - }], - _closedWindows: [] - }); - ss.setBrowserState(blankState); - - // Wait for the sessionstore.js file to be written before going on. - // Note: we don't wait for the complete event, since if asyncCopy fails we - // would timeout. - Services.obs.addObserver(function (aSubject, aTopic, aData) { - Services.obs.removeObserver(arguments.callee, aTopic); - info("sessionstore.js is being written"); - - closedWindowCount = ss.getClosedWindowCount(); - is(closedWindowCount, 0, "Correctly set window count"); - - executeSoon(aCallback); - }, "sessionstore-state-write", false); - - // Remove the sessionstore.js file before setting the interval to 0 - let profilePath = Services.dirsvc.get("ProfD", Ci.nsIFile); - let sessionStoreJS = profilePath.clone(); - sessionStoreJS.append("sessionstore.js"); - if (sessionStoreJS.exists()) - sessionStoreJS.remove(false); - info("sessionstore.js was correctly removed: " + (!sessionStoreJS.exists())); - - // Make sure that sessionstore.js can be forced to be created by setting - // the interval pref to 0. - Services.prefs.setIntPref("browser.sessionstore.interval", 0); - } - - setupBlankState(function() { - testOpenCloseWindow(false, TESTS[0], function() { - testOpenCloseWindow(true, TESTS[1], function() { - testOnWindow(false, TESTS[0].value, function() { - testOnWindow(true, TESTS[0].value, finish); - }); - }); - }); - }); -} - -function whenNewWindowLoaded(aIsPrivate, aCallback) { - let win = OpenBrowserWindow({private: aIsPrivate}); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - aCallback(win); - }, false); -} diff --git a/browser/components/sessionstore/test/browser_394759_purge.js b/browser/components/sessionstore/test/browser_394759_purge.js deleted file mode 100644 index 3854ae4ab..000000000 --- a/browser/components/sessionstore/test/browser_394759_purge.js +++ /dev/null @@ -1,128 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -Components.utils.import("resource://gre/modules/ForgetAboutSite.jsm"); - -function waitForClearHistory(aCallback) { - let observer = { - observe: function(aSubject, aTopic, aData) { - Services.obs.removeObserver(this, "browser:purge-domain-data"); - setTimeout(aCallback, 0); - } - }; - Services.obs.addObserver(observer, "browser:purge-domain-data", false); -} - -function test() { - waitForExplicitFinish(); - // utility functions - function countClosedTabsByTitle(aClosedTabList, aTitle) - aClosedTabList.filter(function (aData) aData.title == aTitle).length; - - function countOpenTabsByTitle(aOpenTabList, aTitle) - aOpenTabList.filter(function (aData) aData.entries.some(function (aEntry) aEntry.title == aTitle)).length - - // backup old state - let oldState = ss.getBrowserState(); - let oldState_wins = JSON.parse(oldState).windows.length; - if (oldState_wins != 1) - ok(false, "oldState in test_purge has " + oldState_wins + " windows instead of 1"); - - // create a new state for testing - const REMEMBER = Date.now(), FORGET = Math.random(); - let testState = { - windows: [ { tabs: [{ entries: [{ url: "http://example.com/" }] }], selected: 1 } ], - _closedWindows : [ - // _closedWindows[0] - { - tabs: [ - { entries: [{ url: "http://example.com/", title: REMEMBER }] }, - { entries: [{ url: "http://mozilla.org/", title: FORGET }] } - ], - selected: 2, - title: "mozilla.org", - _closedTabs: [] - }, - // _closedWindows[1] - { - tabs: [ - { entries: [{ url: "http://mozilla.org/", title: FORGET }] }, - { entries: [{ url: "http://example.com/", title: REMEMBER }] }, - { entries: [{ url: "http://example.com/", title: REMEMBER }] }, - { entries: [{ url: "http://mozilla.org/", title: FORGET }] }, - { entries: [{ url: "http://example.com/", title: REMEMBER }] } - ], - selected: 5, - _closedTabs: [] - }, - // _closedWindows[2] - { - tabs: [ - { entries: [{ url: "http://example.com/", title: REMEMBER }] } - ], - selected: 1, - _closedTabs: [ - { - state: { - entries: [ - { url: "http://mozilla.org/", title: FORGET }, - { url: "http://mozilla.org/again", title: "doesn't matter" } - ] - }, - pos: 1, - title: FORGET - }, - { - state: { - entries: [ - { url: "http://example.com", title: REMEMBER } - ] - }, - title: REMEMBER - } - ] - } - ] - }; - - // set browser to test state - ss.setBrowserState(JSON.stringify(testState)); - - // purge domain & check that we purged correctly for closed windows - ForgetAboutSite.removeDataFromDomain("mozilla.org"); - waitForClearHistory(function() { - let closedWindowData = JSON.parse(ss.getClosedWindowData()); - - // First set of tests for _closedWindows[0] - tests basics - let win = closedWindowData[0]; - is(win.tabs.length, 1, "1 tab was removed"); - is(countOpenTabsByTitle(win.tabs, FORGET), 0, - "The correct tab was removed"); - is(countOpenTabsByTitle(win.tabs, REMEMBER), 1, - "The correct tab was remembered"); - is(win.selected, 1, "Selected tab has changed"); - is(win.title, REMEMBER, "The window title was correctly updated"); - - // Test more complicated case - win = closedWindowData[1]; - is(win.tabs.length, 3, "2 tabs were removed"); - is(countOpenTabsByTitle(win.tabs, FORGET), 0, - "The correct tabs were removed"); - is(countOpenTabsByTitle(win.tabs, REMEMBER), 3, - "The correct tabs were remembered"); - is(win.selected, 3, "Selected tab has changed"); - is(win.title, REMEMBER, "The window title was correctly updated"); - - // Tests handling of _closedTabs - win = closedWindowData[2]; - is(countClosedTabsByTitle(win._closedTabs, REMEMBER), 1, - "The correct number of tabs were removed, and the correct ones"); - is(countClosedTabsByTitle(win._closedTabs, FORGET), 0, - "All tabs to be forgotten were indeed removed"); - - // restore pre-test state - ss.setBrowserState(oldState); - finish(); - }); -} diff --git a/browser/components/sessionstore/test/browser_408470.js b/browser/components/sessionstore/test/browser_408470.js deleted file mode 100644 index 4435c743a..000000000 --- a/browser/components/sessionstore/test/browser_408470.js +++ /dev/null @@ -1,56 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 408470 **/ - - waitForExplicitFinish(); - - let pendingCount = 1; - let rootDir = getRootDirectory(gTestPath); - let testUrl = rootDir + "browser_408470_sample.html"; - let tab = gBrowser.addTab(testUrl); - - tab.linkedBrowser.addEventListener("load", function(aEvent) { - tab.linkedBrowser.removeEventListener("load", arguments.callee, true); - // enable all stylesheets and verify that they're correctly persisted - Array.forEach(tab.linkedBrowser.contentDocument.styleSheets, function(aSS, aIx) { - pendingCount++; - let ssTitle = aSS.title; - gPageStyleMenu.switchStyleSheet(ssTitle, tab.linkedBrowser.contentWindow); - - let newTab = gBrowser.duplicateTab(tab); - newTab.linkedBrowser.addEventListener("load", function(aEvent) { - newTab.linkedBrowser.removeEventListener("load", arguments.callee, true); - let states = Array.map(newTab.linkedBrowser.contentDocument.styleSheets, - function(aSS) !aSS.disabled); - let correct = states.indexOf(true) == aIx && states.indexOf(true, aIx + 1) == -1; - - if (/^fail_/.test(ssTitle)) - ok(!correct, "didn't restore stylesheet " + ssTitle); - else - ok(correct, "restored stylesheet " + ssTitle); - - gBrowser.removeTab(newTab); - if (--pendingCount == 0) - finish(); - }, true); - }); - - // disable all styles and verify that this is correctly persisted - tab.linkedBrowser.markupDocumentViewer.authorStyleDisabled = true; - let newTab = gBrowser.duplicateTab(tab); - newTab.linkedBrowser.addEventListener("load", function(aEvent) { - newTab.linkedBrowser.removeEventListener("load", arguments.callee, true); - is(newTab.linkedBrowser.markupDocumentViewer.authorStyleDisabled, true, - "disabled all stylesheets"); - - gBrowser.removeTab(newTab); - if (--pendingCount == 0) - finish(); - }, true); - - gBrowser.removeTab(tab); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_408470_sample.html b/browser/components/sessionstore/test/browser_408470_sample.html deleted file mode 100644 index 44122b945..000000000 --- a/browser/components/sessionstore/test/browser_408470_sample.html +++ /dev/null @@ -1,19 +0,0 @@ -<html> -<head> -<title>Test for bug 408470</title> - -<link href="404.css" title="default" rel="stylesheet"> -<link href="404.css" title="alternate" rel="alternate stylesheet"> -<link href="404.css" title="altERnate" rel=" styLEsheet altERnate "> -<link href="404.css" title="media_empty" rel="alternate stylesheet" media=""> -<link href="404.css" title="media_all" rel="alternate stylesheet" media="all"> -<link href="404.css" title="media_ALL" rel="alternate stylesheet" media=" ALL "> -<link href="404.css" title="media_screen" rel="alternate stylesheet" media="screen"> -<link href="404.css" title="media_print_screen" rel="alternate stylesheet" media="print,screen"> -<link href="404.css" title="fail_media_print" rel="alternate stylesheet" media="print"> -<link href="404.css" title="fail_media_projection" rel="stylesheet" media="projection"> -<link href="404.css" title="fail_media_invalid" rel="alternate stylesheet" media="hallo"> - -</head> -<body></body> -</html> diff --git a/browser/components/sessionstore/test/browser_423132.js b/browser/components/sessionstore/test/browser_423132.js deleted file mode 100644 index a59aa4c5c..000000000 --- a/browser/components/sessionstore/test/browser_423132.js +++ /dev/null @@ -1,73 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - // test that cookies are stored and restored correctly by sessionstore, - // bug 423132. - - waitForExplicitFinish(); - - let cs = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager2); - cs.removeAll(); - - // make sure that sessionstore.js can be forced to be created by setting - // the interval pref to 0 - gPrefService.setIntPref("browser.sessionstore.interval", 0); - - const testURL = "http://mochi.test:8888/browser/" + - "browser/components/sessionstore/test/browser_423132_sample.html"; - - // open a new window - let newWin = openDialog(location, "_blank", "chrome,all,dialog=no", "about:blank"); - - // make sure sessionstore saves the cookie data, then close the window - newWin.addEventListener("load", function (aEvent) { - newWin.removeEventListener("load", arguments.callee, false); - - newWin.gBrowser.loadURI(testURL, null, null); - - newWin.gBrowser.addEventListener("load", function (aEvent) { - newWin.gBrowser.removeEventListener("load", arguments.callee, true); - - // get the sessionstore state for the window - let state = ss.getWindowState(newWin); - - // verify our cookie got set during pageload - let e = cs.enumerator; - let cookie; - let i = 0; - while (e.hasMoreElements()) { - cookie = e.getNext().QueryInterface(Ci.nsICookie); - i++; - } - is(i, 1, "expected one cookie"); - - // remove the cookie - cs.removeAll(); - - // restore the window state - ss.setWindowState(newWin, state, true); - - // at this point, the cookie should be restored... - e = cs.enumerator; - let cookie2; - while (e.hasMoreElements()) { - cookie2 = e.getNext().QueryInterface(Ci.nsICookie); - if (cookie.name == cookie2.name) - break; - } - is(cookie.name, cookie2.name, "cookie name successfully restored"); - is(cookie.value, cookie2.value, "cookie value successfully restored"); - is(cookie.path, cookie2.path, "cookie path successfully restored"); - - // clean up - if (gPrefService.prefHasUserValue("browser.sessionstore.interval")) - gPrefService.clearUserPref("browser.sessionstore.interval"); - cs.removeAll(); - newWin.close(); - finish(); - }, true); - }, false); -} - diff --git a/browser/components/sessionstore/test/browser_423132_sample.html b/browser/components/sessionstore/test/browser_423132_sample.html deleted file mode 100644 index 6ff7e7aa3..000000000 --- a/browser/components/sessionstore/test/browser_423132_sample.html +++ /dev/null @@ -1,14 +0,0 @@ -<!DOCTYPE HTML> -<html> -<head> - <meta charset="utf-8"> - <script type="text/javascript"> - // generate an enormous random number... - var r = Math.floor(Math.random() * Math.pow(2, 62)).toString(); - - // ... and use it to set a randomly named cookie - document.cookie = r + "=value; path=/ohai"; - </script> -<body> -</body> -</html> diff --git a/browser/components/sessionstore/test/browser_447951.js b/browser/components/sessionstore/test/browser_447951.js deleted file mode 100644 index 73785efc2..000000000 --- a/browser/components/sessionstore/test/browser_447951.js +++ /dev/null @@ -1,50 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 447951 **/ - - waitForExplicitFinish(); - const baseURL = "http://mochi.test:8888/browser/" + - "browser/components/sessionstore/test/browser_447951_sample.html#"; - - let tab = gBrowser.addTab(); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - tab.linkedBrowser.removeEventListener("load", arguments.callee, true); - - let tabState = { entries: [] }; - let max_entries = gPrefService.getIntPref("browser.sessionhistory.max_entries"); - for (let i = 0; i < max_entries; i++) - tabState.entries.push({ url: baseURL + i }); - - ss.setTabState(tab, JSON.stringify(tabState)); - tab.addEventListener("SSTabRestored", function(aEvent) { - tab.removeEventListener("SSTabRestored", arguments.callee, false); - tabState = JSON.parse(ss.getTabState(tab)); - is(tabState.entries.length, max_entries, "session history filled to the limit"); - is(tabState.entries[0].url, baseURL + 0, "... but not more"); - - // visit yet another anchor (appending it to session history) - let doc = tab.linkedBrowser.contentDocument; - let event = doc.createEvent("MouseEvents"); - event.initMouseEvent("click", true, true, doc.defaultView, 1, - 0, 0, 0, 0, false, false, false, false, 0, null); - doc.querySelector("a").dispatchEvent(event); - - executeSoon(function() { - tabState = JSON.parse(ss.getTabState(tab)); - is(tab.linkedBrowser.currentURI.spec, baseURL + "end", - "the new anchor was loaded"); - is(tabState.entries[tabState.entries.length - 1].url, baseURL + "end", - "... and ignored"); - is(tabState.entries[0].url, baseURL + 1, - "... and the first item was removed"); - - // clean up - gBrowser.removeTab(tab); - finish(); - }); - }, false); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_447951_sample.html b/browser/components/sessionstore/test/browser_447951_sample.html deleted file mode 100644 index 00282f25e..000000000 --- a/browser/components/sessionstore/test/browser_447951_sample.html +++ /dev/null @@ -1,5 +0,0 @@ -<!DOCTYPE html> -<meta charset="utf-8"> -<title>Testcase for bug 447951</title> - -<a href="#end">click me</a> diff --git a/browser/components/sessionstore/test/browser_448741.js b/browser/components/sessionstore/test/browser_448741.js deleted file mode 100644 index 8ed6f66c8..000000000 --- a/browser/components/sessionstore/test/browser_448741.js +++ /dev/null @@ -1,62 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 448741 **/ - - waitForExplicitFinish(); - - let uniqueName = "bug 448741"; - let uniqueValue = "as good as unique: " + Date.now(); - - // set a unique value on a new, blank tab - var tab = gBrowser.addTab(); - tab.linkedBrowser.stop(); - ss.setTabValue(tab, uniqueName, uniqueValue); - let valueWasCleaned = false; - - // prevent our value from being written to disk - function cleaningObserver(aSubject, aTopic, aData) { - ok(aTopic == "sessionstore-state-write", "observed correct topic?"); - ok(aSubject instanceof Ci.nsISupportsString, "subject is a string?"); - ok(aSubject.data.indexOf(uniqueValue) > -1, "data contains our value?"); - - // find the data for the newly added tab and delete it - let state = JSON.parse(aSubject.data); - state.windows.forEach(function (winData) { - winData.tabs.forEach(function (tabData) { - if (tabData.extData && uniqueName in tabData.extData && - tabData.extData[uniqueName] == uniqueValue) { - delete tabData.extData[uniqueName]; - valueWasCleaned = true; - } - }); - }); - - ok(valueWasCleaned, "found and removed the specific tab value"); - aSubject.data = JSON.stringify(state); - Services.obs.removeObserver(cleaningObserver, aTopic); - } - - // make sure that all later observers don't see that value any longer - function checkingObserver(aSubject, aTopic, aData) { - ok(valueWasCleaned && aSubject instanceof Ci.nsISupportsString, - "ready to check the cleaned state?"); - ok(aSubject.data.indexOf(uniqueValue) == -1, "data no longer contains our value?"); - - // clean up - gBrowser.removeTab(tab); - Services.obs.removeObserver(checkingObserver, aTopic); - if (gPrefService.prefHasUserValue("browser.sessionstore.interval")) - gPrefService.clearUserPref("browser.sessionstore.interval"); - finish(); - } - - // last added observers are invoked first - Services.obs.addObserver(checkingObserver, "sessionstore-state-write", false); - Services.obs.addObserver(cleaningObserver, "sessionstore-state-write", false); - - // trigger an immediate save operation - gPrefService.setIntPref("browser.sessionstore.interval", 0); -} diff --git a/browser/components/sessionstore/test/browser_454908.js b/browser/components/sessionstore/test/browser_454908.js deleted file mode 100644 index 4edb591c8..000000000 --- a/browser/components/sessionstore/test/browser_454908.js +++ /dev/null @@ -1,52 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 454908 **/ - - waitForExplicitFinish(); - - let fieldValues = { - username: "User " + Math.random(), - passwd: "pwd" + Date.now() - }; - - // make sure we do save form data - gPrefService.setIntPref("browser.sessionstore.privacy_level", 0); - - let rootDir = getRootDirectory(gTestPath); - let testURL = rootDir + "browser_454908_sample.html"; - let tab = gBrowser.addTab(testURL); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - tab.linkedBrowser.removeEventListener("load", arguments.callee, true); - let doc = tab.linkedBrowser.contentDocument; - for (let id in fieldValues) - doc.getElementById(id).value = fieldValues[id]; - - gBrowser.removeTab(tab); - - tab = undoCloseTab(); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - tab.linkedBrowser.removeEventListener("load", arguments.callee, true); - let doc = tab.linkedBrowser.contentDocument; - for (let id in fieldValues) { - let node = doc.getElementById(id); - if (node.type == "password") - is(node.value, "", "password wasn't saved/restored"); - else - is(node.value, fieldValues[id], "username was saved/restored"); - } - - // clean up - if (gPrefService.prefHasUserValue("browser.sessionstore.privacy_level")) - gPrefService.clearUserPref("browser.sessionstore.privacy_level"); - // undoCloseTab can reuse a single blank tab, so we have to - // make sure not to close the window when closing our last tab - if (gBrowser.tabs.length == 1) - gBrowser.addTab(); - gBrowser.removeTab(tab); - finish(); - }, true); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_454908_sample.html b/browser/components/sessionstore/test/browser_454908_sample.html deleted file mode 100644 index 02f40bf20..000000000 --- a/browser/components/sessionstore/test/browser_454908_sample.html +++ /dev/null @@ -1,8 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> -<title>Test for bug 454908</title> - -<h3>Dummy Login</h3> -<form> -<p>Username: <input type="text" id="username"> -<p>Password: <input type="password" id="passwd"> -</form> diff --git a/browser/components/sessionstore/test/browser_456342.js b/browser/components/sessionstore/test/browser_456342.js deleted file mode 100644 index 4177ac304..000000000 --- a/browser/components/sessionstore/test/browser_456342.js +++ /dev/null @@ -1,53 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 456342 **/ - - waitForExplicitFinish(); - - // make sure we do save form data - gPrefService.setIntPref("browser.sessionstore.privacy_level", 0); - - let rootDir = getRootDirectory(gTestPath); - let testURL = rootDir + "browser_456342_sample.xhtml"; - let tab = gBrowser.addTab(testURL); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - this.removeEventListener("load", arguments.callee, true); - - let expectedValue = "try to save me"; - // Since bug 537289 we only save non-default values, so we need to set each - // form field's value after load. - let formEls = aEvent.originalTarget.forms[0].elements; - for (let i = 0; i < formEls.length; i++) - formEls[i].value = expectedValue; - - gBrowser.removeTab(tab); - - let undoItems = JSON.parse(ss.getClosedTabData(window)); - let savedFormData = undoItems[0].state.entries[0].formdata; - - let countGood = 0, countBad = 0; - for each (let value in savedFormData.id) { - if (value == expectedValue) - countGood++; - else - countBad++; - } - for each (let value in savedFormData.xpath) { - if (value == expectedValue) - countGood++; - else - countBad++; - } - - is(countGood, 4, "Saved text for non-standard input fields"); - is(countBad, 0, "Didn't save text for ignored field types"); - - // clean up - if (gPrefService.prefHasUserValue("browser.sessionstore.privacy_level")) - gPrefService.clearUserPref("browser.sessionstore.privacy_level"); - finish(); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_456342_sample.xhtml b/browser/components/sessionstore/test/browser_456342_sample.xhtml deleted file mode 100644 index f0b0005b7..000000000 --- a/browser/components/sessionstore/test/browser_456342_sample.xhtml +++ /dev/null @@ -1,28 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" -"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml"> - -<head><title>Test for bug 456342</title></head> - -<body> -<form> -<h3>Non-standard <input>s</h3> -<p>Search <input type="search" id="searchTerm"/></p> -<p>Image Search: <input type="image search" /></p> -<p>Autocomplete: <input type="autocomplete" name="fill-in"/></p> -<p>Mistyped: <input type="txet" name="mistyped"/></p> - -<h3>Ignored types</h3> -<input type="hidden" name="hideme"/> -<input type="HIDDEN" name="hideme2"/> -<input type="submit" name="submit"/> -<input type="reset" name="reset"/> -<input type="image" name="image"/> -<input type="button" name="button"/> -<input type="password" name="password"/> -<input type="PassWord" name="password2"/> -<input type="PASSWORD" name="password3"/> -</form> - -</body> -</html> diff --git a/browser/components/sessionstore/test/browser_459906.js b/browser/components/sessionstore/test/browser_459906.js deleted file mode 100644 index cadab3e5c..000000000 --- a/browser/components/sessionstore/test/browser_459906.js +++ /dev/null @@ -1,62 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 459906 **/ - - waitForExplicitFinish(); - - let testURL = "http://mochi.test:8888/browser/" + - "browser/components/sessionstore/test/browser_459906_sample.html"; - let uniqueValue = "<b>Unique:</b> " + Date.now(); - - var frameCount = 0; - let tab = gBrowser.addTab(testURL); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - // wait for all frames to load completely - if (frameCount++ < 2) - return; - tab.linkedBrowser.removeEventListener("load", arguments.callee, true); - - let iframes = tab.linkedBrowser.contentWindow.frames; - iframes[1].document.body.innerHTML = uniqueValue; - - frameCount = 0; - let tab2 = gBrowser.duplicateTab(tab); - tab2.linkedBrowser.addEventListener("load", function(aEvent) { - // wait for all frames to load (and reload!) completely - if (frameCount++ < 2) - return; - tab2.linkedBrowser.removeEventListener("load", arguments.callee, true); - - executeSoon(function() { - let iframes = tab2.linkedBrowser.contentWindow.frames; - if (iframes[1].document.body.innerHTML !== uniqueValue) { - // Poll again the value, since we can't ensure to run - // after SessionStore has injected innerHTML value. - // See bug 521802. - info("Polling for innerHTML value"); - setTimeout(arguments.callee, 100); - return; - } - - is(iframes[1].document.body.innerHTML, uniqueValue, - "rich textarea's content correctly duplicated"); - - let innerDomain = null; - try { - innerDomain = iframes[0].document.domain; - } - catch (ex) { /* throws for chrome: documents */ } - is(innerDomain, "mochi.test", "XSS exploit prevented!"); - - // clean up - gBrowser.removeTab(tab2); - gBrowser.removeTab(tab); - - finish(); - }); - }, true); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_459906_empty.html b/browser/components/sessionstore/test/browser_459906_empty.html deleted file mode 100644 index e01aaa339..000000000 --- a/browser/components/sessionstore/test/browser_459906_empty.html +++ /dev/null @@ -1,3 +0,0 @@ -<title>Cross Domain File for bug 459906</title> - -cheers from localhost diff --git a/browser/components/sessionstore/test/browser_459906_sample.html b/browser/components/sessionstore/test/browser_459906_sample.html deleted file mode 100644 index 39b789776..000000000 --- a/browser/components/sessionstore/test/browser_459906_sample.html +++ /dev/null @@ -1,41 +0,0 @@ -<!-- Testcase originally by David Bloom <bloom@google.com> --> - -<!DOCTYPE html> -<title>Test for bug 459906</title> - -<body> -<iframe src="data:text/html;charset=utf-8,not_on_localhost"></iframe> -<iframe></iframe> - -<script type="application/javascript"> - var loadCount = 0; - frames[0].addEventListener("DOMContentLoaded", handleLoad, false); - frames[1].addEventListener("DOMContentLoaded", handleLoad, false); - function handleLoad() { - if (++loadCount < 2) - return; - frames[0].removeEventListener("DOMContentLoaded", handleLoad, false); - frames[1].removeEventListener("DOMContentLoaded", handleLoad, false); - frames[0].document.designMode = "on"; - frames[0].document.__defineGetter__("designMode", function() { - // inject a cross domain file ... - var documentInjected = false; - document.getElementsByTagName("iframe")[0].onload = - function() { documentInjected = true; }; - frames[0].location = "browser_459906_empty.html"; - - // ... and ensure that it has time to load - for (var c = 0; !documentInjected && c < 20; c++) { - var r = new XMLHttpRequest(); - r.open("GET", location.href, false); - r.overrideMimeType("text/plain"); - r.send(null); - } - - return "on"; - }); - - frames[1].document.designMode = "on"; - }; -</script> -</body> diff --git a/browser/components/sessionstore/test/browser_461634.js b/browser/components/sessionstore/test/browser_461634.js deleted file mode 100644 index 931f12ccb..000000000 --- a/browser/components/sessionstore/test/browser_461634.js +++ /dev/null @@ -1,75 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 461634 **/ - - waitForExplicitFinish(); - - const REMEMBER = Date.now(), FORGET = Math.random(); - let test_state = { windows: [{ "tabs": [{ "entries": [] }], _closedTabs: [ - { state: { entries: [{ url: "http://www.example.net/" }] }, title: FORGET }, - { state: { entries: [{ url: "http://www.example.net/" }] }, title: REMEMBER }, - { state: { entries: [{ url: "http://www.example.net/" }] }, title: FORGET }, - { state: { entries: [{ url: "http://www.example.net/" }] }, title: REMEMBER }, - ] }] }; - let remember_count = 2; - - function countByTitle(aClosedTabList, aTitle) - aClosedTabList.filter(function(aData) aData.title == aTitle).length; - - function testForError(aFunction) { - try { - aFunction(); - return false; - } - catch (ex) { - return ex.name == "NS_ERROR_ILLEGAL_VALUE"; - } - } - - // open a window and add the above closed tab list - let newWin = openDialog(location, "", "chrome,all,dialog=no"); - newWin.addEventListener("load", function(aEvent) { - newWin.removeEventListener("load", arguments.callee, false); - - gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", - test_state.windows[0]._closedTabs.length); - ss.setWindowState(newWin, JSON.stringify(test_state), true); - - let closedTabs = JSON.parse(ss.getClosedTabData(newWin)); - is(closedTabs.length, test_state.windows[0]._closedTabs.length, - "Closed tab list has the expected length"); - is(countByTitle(closedTabs, FORGET), - test_state.windows[0]._closedTabs.length - remember_count, - "The correct amout of tabs are to be forgotten"); - is(countByTitle(closedTabs, REMEMBER), remember_count, - "Everything is set up."); - - // all of the following calls with illegal arguments should throw NS_ERROR_ILLEGAL_VALUE - ok(testForError(function() ss.forgetClosedTab({}, 0)), - "Invalid window for forgetClosedTab throws"); - ok(testForError(function() ss.forgetClosedTab(newWin, -1)), - "Invalid tab for forgetClosedTab throws"); - ok(testForError(function() ss.forgetClosedTab(newWin, test_state.windows[0]._closedTabs.length + 1)), - "Invalid tab for forgetClosedTab throws"); - - // Remove third tab, then first tab - ss.forgetClosedTab(newWin, 2); - ss.forgetClosedTab(newWin, null); - - closedTabs = JSON.parse(ss.getClosedTabData(newWin)); - is(closedTabs.length, remember_count, - "The correct amout of tabs was removed"); - is(countByTitle(closedTabs, FORGET), 0, - "All tabs specifically forgotten were indeed removed"); - is(countByTitle(closedTabs, REMEMBER), remember_count, - "... and tabs not specifically forgetten weren't."); - - // clean up - newWin.close(); - gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo"); - finish(); - }, false); -} diff --git a/browser/components/sessionstore/test/browser_461743.js b/browser/components/sessionstore/test/browser_461743.js deleted file mode 100644 index 263fff5f2..000000000 --- a/browser/components/sessionstore/test/browser_461743.js +++ /dev/null @@ -1,39 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 461743 **/ - - waitForExplicitFinish(); - - let testURL = "http://mochi.test:8888/browser/" + - "browser/components/sessionstore/test/browser_461743_sample.html"; - - let frameCount = 0; - let tab = gBrowser.addTab(testURL); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - // Wait for all frames to load completely. - if (frameCount++ < 2) - return; - tab.linkedBrowser.removeEventListener("load", arguments.callee, true); - let tab2 = gBrowser.duplicateTab(tab); - tab2.linkedBrowser.addEventListener("461743", function(aEvent) { - tab2.linkedBrowser.removeEventListener("461743", arguments.callee, true); - is(aEvent.data, "done", "XSS injection was attempted"); - - executeSoon(function() { - let iframes = tab2.linkedBrowser.contentWindow.frames; - let innerHTML = iframes[1].document.body.innerHTML; - isnot(innerHTML, Components.utils.reportError.toString(), - "chrome access denied!"); - - // Clean up. - gBrowser.removeTab(tab2); - gBrowser.removeTab(tab); - - finish(); - }); - }, true, true); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_461743_sample.html b/browser/components/sessionstore/test/browser_461743_sample.html deleted file mode 100644 index 22c478d4c..000000000 --- a/browser/components/sessionstore/test/browser_461743_sample.html +++ /dev/null @@ -1,55 +0,0 @@ -<!-- Testcase originally by <moz_bug_r_a4@yahoo.com> --> - -<!DOCTYPE html> -<title>Test for bug 461743</title> - -<body> -<iframe src="data:text/html;charset=utf-8,empty"></iframe> -<iframe></iframe> - -<script type="application/javascript"> - var chromeUrl = "chrome://global/content/mozilla.xhtml"; - var exploitUrl = "javascript:try { document.body.innerHTML = Components.utils.reportError; } catch (ex) { }"; - - var loadCount = 0; - frames[0].addEventListener("DOMContentLoaded", handleLoad, false); - frames[1].addEventListener("DOMContentLoaded", handleLoad, false); - function handleLoad() { - if (++loadCount < 2) - return; - frames[0].removeEventListener("DOMContentLoaded", handleLoad, false); - frames[1].removeEventListener("DOMContentLoaded", handleLoad, false); - - var flip = 0; - MutationEvent.prototype.toString = function() { - return flip++ == 0 ? chromeUrl : exploitUrl; - }; - - var href = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(frames[1].location), "href").get; - var loadChrome = { handleEvent: href }; - var loadExploit = { handleEvent: href }; - - function delay() { - var xhr = new XMLHttpRequest(); - xhr.open("GET", location.href, false); - xhr.send(null); - } - function done() { - var event = document.createEvent("MessageEvent"); - event.initMessageEvent("461743", true, false, "done", location.href, "", window); - document.dispatchEvent(event); - frames[0].document.removeEventListener("DOMNodeInserted", loadChrome, true); - frames[0].document.removeEventListener("DOMNodeInserted", delay, true); - frames[0].document.removeEventListener("DOMNodeInserted", loadExploit, true); - frames[0].document.removeEventListener("DOMNodeInserted", done, true); - } - - frames[0].document.addEventListener("DOMNodeInserted", loadChrome, true); - frames[0].document.addEventListener("DOMNodeInserted", delay, true); - frames[0].document.addEventListener("DOMNodeInserted", loadExploit, true); - frames[0].document.addEventListener("DOMNodeInserted", done, true); - - frames[0].document.designMode = "on"; - }; -</script> -</body> diff --git a/browser/components/sessionstore/test/browser_463205.js b/browser/components/sessionstore/test/browser_463205.js deleted file mode 100644 index 93ba1d8d1..000000000 --- a/browser/components/sessionstore/test/browser_463205.js +++ /dev/null @@ -1,123 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 463205 **/ - - waitForExplicitFinish(); - - let rootDir = "http://mochi.test:8888/browser/browser/components/sessionstore/test/"; - let testURL = rootDir + "browser_463205_sample.html"; - - let doneURL = "done"; - - let mainURL = testURL; - let frame1URL = "data:text/html;charset=utf-8,<input%20id='original'>"; - let frame2URL = rootDir + "browser_463205_helper.html"; - let frame3URL = "data:text/html;charset=utf-8,mark2"; - - let frameCount = 0; - - let tab = gBrowser.addTab(testURL); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - // wait for all frames to load completely - if (frame1URL != doneURL && aEvent.target.location.href == frame1URL) { - frame1URL = doneURL; - if (frameCount++ < 3) { - return; - } - } - if (frame2URL != doneURL && aEvent.target.location.href == frame2URL) { - frame2URL = doneURL; - if (frameCount++ < 3) { - return; - } - } - if (frame3URL != doneURL && aEvent.target.location.href == frame3URL) { - frame3URL = doneURL; - if (frameCount++ < 3) { - return; - } - } - if (mainURL != doneURL && aEvent.target.location.href == mainURL) { - mainURL = doneURL; - if (frameCount++ < 3) { - return; - } - } - if (frameCount < 3) { - return; - } - tab.linkedBrowser.removeEventListener("load", arguments.callee, true); - - function typeText(aTextField, aValue) { - aTextField.value = aValue; - - let event = aTextField.ownerDocument.createEvent("UIEvents"); - event.initUIEvent("input", true, true, aTextField.ownerDocument.defaultView, 0); - aTextField.dispatchEvent(event); - } - - let uniqueValue = "Unique: " + Math.random(); - let win = tab.linkedBrowser.contentWindow; - typeText(win.frames[0].document.getElementById("original"), uniqueValue); - typeText(win.frames[1].document.getElementById("original"), uniqueValue); - - mainURL = testURL; - frame1URL = "http://mochi.test:8888/browser/" + - "browser/components/sessionstore/test/browser_463205_helper.html"; - frame2URL = rootDir + "browser_463205_helper.html"; - frame3URL = "data:text/html;charset=utf-8,mark2"; - - frameCount = 0; - - let tab2 = gBrowser.duplicateTab(tab); - tab2.linkedBrowser.addEventListener("load", function(aEvent) { - // wait for all frames to load (and reload!) completely - if (frame1URL != doneURL && aEvent.target.location.href == frame1URL) { - frame1URL = doneURL; - if (frameCount++ < 3) { - return; - } - } - if (frame2URL != doneURL && (aEvent.target.location.href == frame2URL || - aEvent.target.location.href == frame2URL + "#original")) { - frame2URL = doneURL; - if (frameCount++ < 3) { - return; - } - } - if (frame3URL != doneURL && aEvent.target.location.href == frame3URL) { - frame3URL = doneURL; - if (frameCount++ < 3) { - return; - } - } - if (mainURL != doneURL && aEvent.target.location.href == mainURL) { - mainURL = doneURL; - if (frameCount++ < 3) { - return; - } - } - if (frameCount < 3) { - return; - } - tab2.linkedBrowser.removeEventListener("load", arguments.callee, true); - - let win = tab2.linkedBrowser.contentWindow; - isnot(win.frames[0].document.getElementById("original").value, uniqueValue, - "subframes must match URL to get text restored"); - is(win.frames[0].document.getElementById("original").value, "preserve me", - "subframes must match URL to get text restored"); - is(win.frames[1].document.getElementById("original").value, uniqueValue, - "text still gets restored for all other subframes"); - - // clean up - gBrowser.removeTab(tab2); - gBrowser.removeTab(tab); - - finish(); - }, true); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_463205_helper.html b/browser/components/sessionstore/test/browser_463205_helper.html deleted file mode 100644 index d6c2209d8..000000000 --- a/browser/components/sessionstore/test/browser_463205_helper.html +++ /dev/null @@ -1,5 +0,0 @@ -<!DOCTYPE html> -<meta charset="utf-8"> -<title>Test for bug 463205 (cross domain)</title> - -<input id="original" value="preserve me"> diff --git a/browser/components/sessionstore/test/browser_463205_sample.html b/browser/components/sessionstore/test/browser_463205_sample.html deleted file mode 100644 index 483ea3538..000000000 --- a/browser/components/sessionstore/test/browser_463205_sample.html +++ /dev/null @@ -1,24 +0,0 @@ -<!-- Testcase originally by <moz_bug_r_a4@yahoo.com> --> - -<!DOCTYPE html> -<meta charset="utf-8"> -<title>Test for bug 463205</title> - -<body onload="onLoad()"> -<iframe src="data:text/html;charset=utf-8,<input%20id='original'>"></iframe> -<iframe src="browser_463205_helper.html"></iframe> -<iframe src="data:text/html;charset=utf-8,mark1"></iframe> - -<script type="application/javascript"> - function onLoad() { - if (frames[2].document.location.href == "data:text/html;charset-utf-8,mark1") { - frames[2].document.location = "data:text/html;charset=utf-8,mark2"; - } - else { - frames[1].document.location.hash = "#original"; - frames[0].document.location = "http://mochi.test:8888/browser/" + - "browser/components/sessionstore/test/browser_463205_helper.html"; - } - } -</script> -</body> diff --git a/browser/components/sessionstore/test/browser_463206.js b/browser/components/sessionstore/test/browser_463206.js deleted file mode 100644 index 696a5aa9c..000000000 --- a/browser/components/sessionstore/test/browser_463206.js +++ /dev/null @@ -1,64 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 463206 **/ - - waitForExplicitFinish(); - - let testURL = "http://mochi.test:8888/browser/" + - "browser/components/sessionstore/test/browser_463206_sample.html"; - - var frameCount = 0; - let tab = gBrowser.addTab(testURL); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - // wait for all frames to load completely - if (frameCount++ < 5) - return; - tab.linkedBrowser.removeEventListener("load", arguments.callee, true); - - function typeText(aTextField, aValue) { - aTextField.value = aValue; - - let event = aTextField.ownerDocument.createEvent("UIEvents"); - event.initUIEvent("input", true, true, aTextField.ownerDocument.defaultView, 0); - aTextField.dispatchEvent(event); - } - - let doc = tab.linkedBrowser.contentDocument; - typeText(doc.getElementById("out1"), Date.now()); - typeText(doc.getElementsByName("1|#out2")[0], Math.random()); - typeText(doc.defaultView.frames[0].frames[1].document.getElementById("in1"), new Date()); - - frameCount = 0; - let tab2 = gBrowser.duplicateTab(tab); - tab2.linkedBrowser.addEventListener("load", function(aEvent) { - // wait for all frames to load completely - if (frameCount++ < 5) - return; - tab2.linkedBrowser.removeEventListener("load", arguments.callee, true); - - let doc = tab2.linkedBrowser.contentDocument; - let win = tab2.linkedBrowser.contentWindow; - isnot(doc.getElementById("out1").value, - win.frames[1].document.getElementById("out1").value, - "text isn't reused for frames"); - isnot(doc.getElementsByName("1|#out2")[0].value, "", - "text containing | and # is correctly restored"); - is(win.frames[1].document.getElementById("out2").value, "", - "id prefixes can't be faked"); - // Disabled for now, Bug 588077 - // isnot(win.frames[0].frames[1].document.getElementById("in1").value, "", - // "id prefixes aren't mixed up"); - is(win.frames[1].frames[0].document.getElementById("in1").value, "", - "id prefixes aren't mixed up"); - - // clean up - gBrowser.removeTab(tab2); - gBrowser.removeTab(tab); - - finish(); - }, true); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_463206_sample.html b/browser/components/sessionstore/test/browser_463206_sample.html deleted file mode 100644 index 0d31f2906..000000000 --- a/browser/components/sessionstore/test/browser_463206_sample.html +++ /dev/null @@ -1,11 +0,0 @@ -<!-- Testcase originally by <moz_bug_r_a4@yahoo.com> --> - -<!DOCTYPE html> -<meta charset="utf-8"> -<title>Test for bug 463206</title> - -<iframe src="data:text/html;charset=utf-8,<iframe></iframe><iframe%20src='data:text/html;charset=utf-8,<input%2520id=%2522in1%2522>'></iframe>"></iframe> -<iframe src="data:text/html;charset=utf-8,<input%20id='out1'><input%20id='out2'><iframe%20src='data:text/html;charset=utf-8,<input%2520id=%2522in1%2522>'>"></iframe> - -<input id="out1"> -<input name="1|#out2"> diff --git a/browser/components/sessionstore/test/browser_464199.js b/browser/components/sessionstore/test/browser_464199.js deleted file mode 100644 index f3593ae9e..000000000 --- a/browser/components/sessionstore/test/browser_464199.js +++ /dev/null @@ -1,87 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -Components.utils.import("resource://gre/modules/ForgetAboutSite.jsm"); - -function waitForClearHistory(aCallback) { - let observer = { - observe: function(aSubject, aTopic, aData) { - Services.obs.removeObserver(this, "browser:purge-domain-data"); - setTimeout(aCallback, 0); - } - }; - Services.obs.addObserver(observer, "browser:purge-domain-data", false); -} - -function test() { - /** Test for Bug 464199 **/ - - waitForExplicitFinish(); - - const REMEMBER = Date.now(), FORGET = Math.random(); - let test_state = { windows: [{ "tabs": [{ "entries": [] }], _closedTabs: [ - { state: { entries: [{ url: "http://www.example.net/" }] }, title: FORGET }, - { state: { entries: [{ url: "http://www.example.org/" }] }, title: REMEMBER }, - { state: { entries: [{ url: "http://www.example.net/" }, - { url: "http://www.example.org/" }] }, title: FORGET }, - { state: { entries: [{ url: "http://example.net/" }] }, title: FORGET }, - { state: { entries: [{ url: "http://sub.example.net/" }] }, title: FORGET }, - { state: { entries: [{ url: "http://www.example.net:8080/" }] }, title: FORGET }, - { state: { entries: [{ url: "about:license" }] }, title: REMEMBER }, - { state: { entries: [{ url: "http://www.example.org/frameset", - children: [ - { url: "http://www.example.org/frame" }, - { url: "http://www.example.org:8080/frame2" } - ] }] }, title: REMEMBER }, - { state: { entries: [{ url: "http://www.example.org/frameset", - children: [ - { url: "http://www.example.org/frame" }, - { url: "http://www.example.net/frame" } - ] }] }, title: FORGET }, - { state: { entries: [{ url: "http://www.example.org/form", - formdata: { id: { "url": "http://www.example.net/" } } - }] }, title: REMEMBER }, - { state: { entries: [{ url: "http://www.example.org/form" }], - extData: { "setTabValue": "http://example.net:80" } }, title: REMEMBER } - ] }] }; - let remember_count = 5; - - function countByTitle(aClosedTabList, aTitle) - aClosedTabList.filter(function(aData) aData.title == aTitle).length; - - // open a window and add the above closed tab list - let newWin = openDialog(location, "", "chrome,all,dialog=no"); - newWin.addEventListener("load", function(aEvent) { - newWin.removeEventListener("load", arguments.callee, false); - - gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", - test_state.windows[0]._closedTabs.length); - ss.setWindowState(newWin, JSON.stringify(test_state), true); - - let closedTabs = JSON.parse(ss.getClosedTabData(newWin)); - is(closedTabs.length, test_state.windows[0]._closedTabs.length, - "Closed tab list has the expected length"); - is(countByTitle(closedTabs, FORGET), - test_state.windows[0]._closedTabs.length - remember_count, - "The correct amout of tabs are to be forgotten"); - is(countByTitle(closedTabs, REMEMBER), remember_count, - "Everything is set up."); - - ForgetAboutSite.removeDataFromDomain("example.net"); - waitForClearHistory(function() { - closedTabs = JSON.parse(ss.getClosedTabData(newWin)); - is(closedTabs.length, remember_count, - "The correct amout of tabs was removed"); - is(countByTitle(closedTabs, FORGET), 0, - "All tabs to be forgotten were indeed removed"); - is(countByTitle(closedTabs, REMEMBER), remember_count, - "... and tabs to be remembered weren't."); - - // clean up - newWin.close(); - gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo"); - finish(); - }); - }, false); -} diff --git a/browser/components/sessionstore/test/browser_464620_a.html b/browser/components/sessionstore/test/browser_464620_a.html deleted file mode 100644 index 44dc07a93..000000000 --- a/browser/components/sessionstore/test/browser_464620_a.html +++ /dev/null @@ -1,53 +0,0 @@ -<!-- Testcase originally by <moz_bug_r_a4@yahoo.com> --> - -<title>Test for bug 464620 (injection on input)</title> - -<iframe></iframe> -<iframe onload="setup()"></iframe> - -<script> - var targetUrl = "http://mochi.test:8888/browser/" + - "browser/components/sessionstore/test/browser_464620_xd.html"; - var firstPass; - - function setup() { - if (firstPass !== undefined) - return; - firstPass = frames[1].location.href == "about:blank"; - if (firstPass) { - frames[0].location = 'data:text/html;charset=utf-8,<body onload="if (parent.firstPass) parent.step();"><input id="x" oninput="parent.xss()">XXX</body>'; - } - frames[1].location = targetUrl; - } - - function step() { - var x = frames[0].document.getElementById("x"); - if (x.value == "") - x.value = "ready"; - x.style.display = "none"; - frames[0].document.designMode = "on"; - } - - function xss() { - step(); - - var documentInjected = false; - document.getElementsByTagName("iframe")[0].onload = - function() { documentInjected = true; }; - frames[0].location = targetUrl; - - for (var c = 0; !documentInjected && c < 20; c++) { - var r = new XMLHttpRequest(); - r.open("GET", location.href, false); - r.overrideMimeType("text/plain"); - r.send(null); - } - document.getElementById("state").textContent = "done"; - - var event = document.createEvent("MessageEvent"); - event.initMessageEvent("464620_a", true, false, "done", location.href, "", window); - document.dispatchEvent(event); - } -</script> - -<p id="state">pending</p> diff --git a/browser/components/sessionstore/test/browser_464620_a.js b/browser/components/sessionstore/test/browser_464620_a.js deleted file mode 100644 index 9756fa703..000000000 --- a/browser/components/sessionstore/test/browser_464620_a.js +++ /dev/null @@ -1,48 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 464620 (injection on input) **/ - - waitForExplicitFinish(); - - let testURL = "http://mochi.test:8888/browser/" + - "browser/components/sessionstore/test/browser_464620_a.html"; - - var frameCount = 0; - let tab = gBrowser.addTab(testURL); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - // wait for all frames to load completely - if (frameCount++ < 4) - return; - this.removeEventListener("load", arguments.callee, true); - - executeSoon(function() { - frameCount = 0; - let tab2 = gBrowser.duplicateTab(tab); - tab2.linkedBrowser.addEventListener("464620_a", function(aEvent) { - tab2.linkedBrowser.removeEventListener("464620_a", arguments.callee, true); - is(aEvent.data, "done", "XSS injection was attempted"); - - // let form restoration complete and take into account the - // setTimeout(..., 0) in sss_restoreDocument_proxy - executeSoon(function() { - setTimeout(function() { - let win = tab2.linkedBrowser.contentWindow; - isnot(win.frames[0].document.location, testURL, - "cross domain document was loaded"); - ok(!/XXX/.test(win.frames[0].document.body.innerHTML), - "no content was injected"); - - // clean up - gBrowser.removeTab(tab2); - gBrowser.removeTab(tab); - - finish(); - }, 0); - }); - }, true, true); - }); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_464620_b.html b/browser/components/sessionstore/test/browser_464620_b.html deleted file mode 100644 index 4e2e10ae5..000000000 --- a/browser/components/sessionstore/test/browser_464620_b.html +++ /dev/null @@ -1,57 +0,0 @@ -<!-- Testcase originally by <moz_bug_r_a4@yahoo.com> --> - -<title>Test for bug 464620 (injection on DOM node insertion)</title> - -<iframe></iframe> -<iframe></iframe> -<iframe onload="setup()"></iframe> - -<script> - var targetUrl = "http://mochi.test:8888/browser/" + - "browser/components/sessionstore/test/browser_464620_xd.html"; - var firstPass; - - function setup() { - if (firstPass !== undefined) - return; - firstPass = frames[2].location.href == "about:blank"; - if (firstPass) { - frames[0].location = 'data:text/html;charset=utf-8,<body onload="parent.step()">a</body>'; - frames[1].location = 'data:text/html;charset=utf-8,<body onload="document.designMode=\'on\';">XXX</body>'; - } - frames[2].location = targetUrl; - } - - function step() { - frames[0].document.designMode = "on"; - if (firstPass) - return; - - var body = frames[0].document.body; - body.addEventListener("DOMNodeInserted", function() { - body.removeEventListener("DOMNodeInserted", arguments.callee, true); - xss(); - }, true); - } - - function xss() { - var documentInjected = false; - document.getElementsByTagName("iframe")[1].onload = - function() { documentInjected = true; }; - frames[1].location = targetUrl; - - for (var c = 0; !documentInjected && c < 20; c++) { - var r = new XMLHttpRequest(); - r.open("GET", location.href, false); - r.overrideMimeType("text/plain"); - r.send(null); - } - document.getElementById("state").textContent = "done"; - - var event = document.createEvent("MessageEvent"); - event.initMessageEvent("464620_b", true, false, "done", location.href, "", window); - document.dispatchEvent(event); - } -</script> - -<p id="state">pending</p> diff --git a/browser/components/sessionstore/test/browser_464620_b.js b/browser/components/sessionstore/test/browser_464620_b.js deleted file mode 100644 index cf23aa460..000000000 --- a/browser/components/sessionstore/test/browser_464620_b.js +++ /dev/null @@ -1,48 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 464620 (injection on DOM node insertion) **/ - - waitForExplicitFinish(); - - let testURL = "http://mochi.test:8888/browser/" + - "browser/components/sessionstore/test/browser_464620_b.html"; - - var frameCount = 0; - let tab = gBrowser.addTab(testURL); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - // wait for all frames to load completely - if (frameCount++ < 6) - return; - this.removeEventListener("load", arguments.callee, true); - - executeSoon(function() { - frameCount = 0; - let tab2 = gBrowser.duplicateTab(tab); - tab2.linkedBrowser.addEventListener("464620_b", function(aEvent) { - tab2.linkedBrowser.removeEventListener("464620_b", arguments.callee, true); - is(aEvent.data, "done", "XSS injection was attempted"); - - // let form restoration complete and take into account the - // setTimeout(..., 0) in sss_restoreDocument_proxy - executeSoon(function() { - setTimeout(function() { - let win = tab2.linkedBrowser.contentWindow; - isnot(win.frames[1].document.location, testURL, - "cross domain document was loaded"); - ok(!/XXX/.test(win.frames[1].document.body.innerHTML), - "no content was injected"); - - // clean up - gBrowser.removeTab(tab2); - gBrowser.removeTab(tab); - - finish(); - }, 0); - }); - }, true, true); - }); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_464620_xd.html b/browser/components/sessionstore/test/browser_464620_xd.html deleted file mode 100644 index 9ec51c4c7..000000000 --- a/browser/components/sessionstore/test/browser_464620_xd.html +++ /dev/null @@ -1,5 +0,0 @@ -<title>Cross Document File for bug 464620</title> - -<body onload="document.designMode='on';" bgcolor="red"> - This document is editable. -</body> diff --git a/browser/components/sessionstore/test/browser_465215.js b/browser/components/sessionstore/test/browser_465215.js deleted file mode 100644 index 471ffc70f..000000000 --- a/browser/components/sessionstore/test/browser_465215.js +++ /dev/null @@ -1,39 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 465215 **/ - - waitForExplicitFinish(); - - let uniqueName = "bug 465215"; - let uniqueValue1 = "as good as unique: " + Date.now(); - let uniqueValue2 = "as good as unique: " + Math.random(); - - // set a unique value on a new, blank tab - let tab1 = gBrowser.addTab(); - tab1.linkedBrowser.addEventListener("load", function() { - tab1.linkedBrowser.removeEventListener("load", arguments.callee, true); - ss.setTabValue(tab1, uniqueName, uniqueValue1); - - // duplicate the tab with that value - let tab2 = ss.duplicateTab(window, tab1); - is(ss.getTabValue(tab2, uniqueName), uniqueValue1, "tab value was duplicated"); - - ss.setTabValue(tab2, uniqueName, uniqueValue2); - isnot(ss.getTabValue(tab1, uniqueName), uniqueValue2, "tab values aren't sync'd"); - - // overwrite the tab with the value which should remove it - ss.setTabState(tab1, JSON.stringify({ entries: [] })); - tab1.linkedBrowser.addEventListener("load", function() { - tab1.linkedBrowser.removeEventListener("load", arguments.callee, true); - is(ss.getTabValue(tab1, uniqueName), "", "tab value was cleared"); - - // clean up - gBrowser.removeTab(tab2); - gBrowser.removeTab(tab1); - finish(); - }, true); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_465223.js b/browser/components/sessionstore/test/browser_465223.js deleted file mode 100644 index 4becc7d15..000000000 --- a/browser/components/sessionstore/test/browser_465223.js +++ /dev/null @@ -1,48 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 465223 **/ - - // test setup - waitForExplicitFinish(); - - let uniqueKey1 = "bug 465223.1"; - let uniqueKey2 = "bug 465223.2"; - let uniqueValue1 = "unik" + Date.now(); - let uniqueValue2 = "pi != " + Math.random(); - - // open a window and set a value on it - let newWin = openDialog(location, "_blank", "chrome,all,dialog=no"); - newWin.addEventListener("load", function(aEvent) { - newWin.removeEventListener("load", arguments.callee, false); - - ss.setWindowValue(newWin, uniqueKey1, uniqueValue1); - - let newState = { windows: [{ tabs:[{ entries: [] }], extData: {} }] }; - newState.windows[0].extData[uniqueKey2] = uniqueValue2; - ss.setWindowState(newWin, JSON.stringify(newState), false); - - is(newWin.gBrowser.tabs.length, 2, - "original tab wasn't overwritten"); - is(ss.getWindowValue(newWin, uniqueKey1), uniqueValue1, - "window value wasn't overwritten when the tabs weren't"); - is(ss.getWindowValue(newWin, uniqueKey2), uniqueValue2, - "new window value was correctly added"); - - newState.windows[0].extData[uniqueKey2] = uniqueValue1; - ss.setWindowState(newWin, JSON.stringify(newState), true); - - is(newWin.gBrowser.tabs.length, 1, - "original tabs were overwritten"); - is(ss.getWindowValue(newWin, uniqueKey1), "", - "window value was cleared"); - is(ss.getWindowValue(newWin, uniqueKey2), uniqueValue1, - "window value was correctly overwritten"); - - // clean up - newWin.close(); - finish(); - }, false); -} diff --git a/browser/components/sessionstore/test/browser_466937.js b/browser/components/sessionstore/test/browser_466937.js deleted file mode 100644 index 4a3b1239f..000000000 --- a/browser/components/sessionstore/test/browser_466937.js +++ /dev/null @@ -1,45 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 466937 **/ - - waitForExplicitFinish(); - - var file = Components.classes["@mozilla.org/file/directory_service;1"] - .getService(Components.interfaces.nsIProperties) - .get("TmpD", Components.interfaces.nsILocalFile); - file.append("466937_test.file"); - file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666); - let testPath = file.path; - - let testURL = "http://mochi.test:8888/browser/" + - "browser/components/sessionstore/test/browser_466937_sample.html"; - - let tab = gBrowser.addTab(testURL); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - tab.linkedBrowser.removeEventListener("load", arguments.callee, true); - let doc = tab.linkedBrowser.contentDocument; - doc.getElementById("reverse_thief").value = "/home/user/secret2"; - doc.getElementById("bystander").value = testPath; - - let tab2 = gBrowser.duplicateTab(tab); - tab2.linkedBrowser.addEventListener("load", function(aEvent) { - tab2.linkedBrowser.removeEventListener("load", arguments.callee, true); - doc = tab2.linkedBrowser.contentDocument; - is(doc.getElementById("thief").value, "", - "file path wasn't set to text field value"); - is(doc.getElementById("reverse_thief").value, "", - "text field value wasn't set to full file path"); - is(doc.getElementById("bystander").value, testPath, - "normal case: file path was correctly preserved"); - - // clean up - gBrowser.removeTab(tab2); - gBrowser.removeTab(tab); - - finish(); - }, true); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_466937_sample.html b/browser/components/sessionstore/test/browser_466937_sample.html deleted file mode 100644 index 1d46c649a..000000000 --- a/browser/components/sessionstore/test/browser_466937_sample.html +++ /dev/null @@ -1,22 +0,0 @@ -<!-- Testcase originally by <moz_bug_r_a4@yahoo.com> --> - -<!DOCTYPE html> -<meta charset="utf-8"> -<title>Test for bug 466937</title> - -<input id="thief" value="/home/user/secret"> -<input type="file" id="reverse_thief"> -<input type="file" id="bystander"> - -<script> - window.addEventListener("DOMContentLoaded", function() { - window.removeEventListener("DOMContentLoaded", arguments.callee, false); - if (!document.location.hash) { - document.location.hash = "#ready"; - } - else { - document.getElementById("thief").type = "file"; - document.getElementById("reverse_thief").type = "text"; - } - }, false); -</script> diff --git a/browser/components/sessionstore/test/browser_467409-backslashplosion.js b/browser/components/sessionstore/test/browser_467409-backslashplosion.js deleted file mode 100644 index aa3d85a8f..000000000 --- a/browser/components/sessionstore/test/browser_467409-backslashplosion.js +++ /dev/null @@ -1,91 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -// Test Summary: -// 1. Open about:sessionrestore via setBrowserState where formdata is a JS object, not a string -// 1a. Check that #sessionData on the page is readable after JSON.parse (skipped, checking formdata is sufficient) -// 1b. Check that there are no backslashes in the formdata -// 1c. Check that formdata (via getBrowserState) doesn't require JSON.parse -// -// 2. Use the current state (currently about:sessionrestore with data) and then open than in a new instance of about:sessionrestore -// 2a. Check that there are no backslashes in the formdata -// 2b. Check that formdata (via getBrowserState) doesn't require JSON.parse -// -// 3. [backwards compat] Use a stringified state as formdata when opening about:sessionrestore -// 3a. Make sure there are nodes in the tree on about:sessionrestore (skipped, checking formdata is sufficient) -// 3b. Check that there are no backslashes in the formdata -// 3c. Check that formdata (via getBrowserState) doesn't require JSON.parse - -function test() { - waitForExplicitFinish(); - ignoreAllUncaughtExceptions(); - - let blankState = { windows: [{ tabs: [{ entries: [{ url: "about:blank" }] }]}]}; - let crashState = { windows: [{ tabs: [{ entries: [{ url: "about:mozilla" }] }]}]}; - - let pagedata = { url: "about:sessionrestore", - formdata: { id: {"sessionData": crashState } } }; - let state = { windows: [{ tabs: [{ entries: [pagedata] }] }] }; - - // test1 calls test2 calls test3 calls finish - test1(state); - - - function test1(aState) { - waitForBrowserState(aState, function() { - checkState("test1", test2); - }); - } - - function test2(aState) { - let pagedata2 = { url: "about:sessionrestore", - formdata: { id: { "sessionData": aState } } }; - let state2 = { windows: [{ tabs: [{ entries: [pagedata2] }] }] }; - - waitForBrowserState(state2, function() { - checkState("test2", test3); - }); - } - - function test3(aState) { - let pagedata3 = { url: "about:sessionrestore", - formdata: { id: { "sessionData": JSON.stringify(crashState) } } }; - let state3 = { windows: [{ tabs: [{ entries: [pagedata3] }] }] }; - waitForBrowserState(state3, function() { - // In theory we should do inspection of the treeview on about:sessionrestore, - // but we don't actually need to. If we fail tests in checkState then - // about:sessionrestore won't be able to turn the form value into a usable page. - checkState("test3", function() waitForBrowserState(blankState, finish)); - }); - } - - function checkState(testName, callback) { - let curState = JSON.parse(ss.getBrowserState()); - let formdata = curState.windows[0].tabs[0].entries[0].formdata; - - ok(formdata.id["sessionData"], testName + ": we have form data for about:sessionrestore"); - - let sessionData_raw = JSON.stringify(formdata.id["sessionData"]); - ok(!/\\/.test(sessionData_raw), testName + ": #sessionData contains no backslashes"); - info(sessionData_raw); - - let gotError = false; - try { - JSON.parse(formdata.id["sessionData"]); - } - catch (e) { - info(testName + ": got error: " + e); - gotError = true; - } - ok(gotError, testName + ": attempting to JSON.parse form data threw error"); - - // Panorama sticks JSON into extData, which we stringify causing the - // naive backslash check to fail. extData doesn't matter in the grand - // scheme here, so we'll delete the extData so doesn't end up in future states. - delete curState.windows[0].extData; - delete curState.windows[0].tabs[0].extData; - callback(curState); - } - -} - diff --git a/browser/components/sessionstore/test/browser_477657.js b/browser/components/sessionstore/test/browser_477657.js deleted file mode 100644 index 7c6562166..000000000 --- a/browser/components/sessionstore/test/browser_477657.js +++ /dev/null @@ -1,63 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 477657 **/ - waitForExplicitFinish(); - - let newWin = openDialog(location, "_blank", "chrome,all,dialog=no"); - newWin.addEventListener("load", function(aEvent) { - newWin.removeEventListener("load", arguments.callee, false); - - let newState = { windows: [{ - tabs: [{ entries: [] }], - _closedTabs: [{ - state: { entries: [{ url: "about:" }]}, - title: "About:" - }], - sizemode: "maximized" - }] }; - - let uniqueKey = "bug 477657"; - let uniqueValue = "unik" + Date.now(); - - ss.setWindowValue(newWin, uniqueKey, uniqueValue); - is(ss.getWindowValue(newWin, uniqueKey), uniqueValue, - "window value was set before the window was overwritten"); - ss.setWindowState(newWin, JSON.stringify(newState), true); - - // use newWin.setTimeout(..., 0) to mirror sss_restoreWindowFeatures - newWin.setTimeout(function() { - is(ss.getWindowValue(newWin, uniqueKey), "", - "window value was implicitly cleared"); - - is(newWin.windowState, newWin.STATE_MAXIMIZED, - "the window was maximized"); - - is(JSON.parse(ss.getClosedTabData(newWin)).length, 1, - "the closed tab was added before the window was overwritten"); - delete newState.windows[0]._closedTabs; - delete newState.windows[0].sizemode; - ss.setWindowState(newWin, JSON.stringify(newState), true); - - newWin.setTimeout(function() { - is(JSON.parse(ss.getClosedTabData(newWin)).length, 0, - "closed tabs were implicitly cleared"); - - is(newWin.windowState, newWin.STATE_MAXIMIZED, - "the window remains maximized"); - newState.windows[0].sizemode = "normal"; - ss.setWindowState(newWin, JSON.stringify(newState), true); - - newWin.setTimeout(function() { - isnot(newWin.windowState, newWin.STATE_MAXIMIZED, - "the window was explicitly unmaximized"); - - newWin.close(); - finish(); - }, 0); - }, 0); - }, 0); - }, false); -} diff --git a/browser/components/sessionstore/test/browser_480148.js b/browser/components/sessionstore/test/browser_480148.js deleted file mode 100644 index a88882fe7..000000000 --- a/browser/components/sessionstore/test/browser_480148.js +++ /dev/null @@ -1,216 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 484108 **/ - waitForExplicitFinish(); - requestLongerTimeout(5); - - // builds the tests state based on a few parameters - function buildTestState(num, selected, hidden, pinned) { - let state = { windows: [ { "tabs": [], "selected": selected + 1 } ] }; - while (num--) { - state.windows[0].tabs.push({ - entries: [ - { url: "http://example.com/?t=" + state.windows[0].tabs.length } - ] - }); - let i = state.windows[0].tabs.length - 1; - if (hidden.length > 0 && i == hidden[0]) { - state.windows[0].tabs[i].hidden = true; - hidden.splice(0, 1); - } - if (pinned.length > 0 && i == pinned[0]) { - state.windows[0].tabs[i].pinned = true; - pinned.splice(0, 1); - } - } - return state; - } - - let tests = [ - { testNum: 1, - totalTabs: 13, - selectedTab: 0, - shownTabs: 6, - hiddenTabs: [], - pinnedTabs: [], - order: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] - }, - { testNum: 2, - totalTabs: 13, - selectedTab: 12, - shownTabs: 6, - hiddenTabs: [], - pinnedTabs: [], - order: [12, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6] - }, - { testNum: 3, - totalTabs: 13, - selectedTab: 3, - shownTabs: 6, - hiddenTabs: [], - pinnedTabs: [], - order: [3, 4, 5, 6, 7, 8, 0, 1, 2, 9, 10, 11, 12] - }, - { testNum: 4, - totalTabs: 13, - selectedTab: 10, - shownTabs: 6, - hiddenTabs: [], - pinnedTabs: [], - order: [10, 7, 8, 9, 11, 12, 0, 1, 2, 3, 4, 5, 6] - }, - { testNum: 5, - totalTabs: 13, - selectedTab: 12, - shownTabs: 6, - hiddenTabs: [0, 4, 9], - pinnedTabs: [], - order: [12, 6, 7, 8, 10, 11, 1, 2, 3, 5, 0, 4, 9] - }, - { testNum: 6, - totalTabs: 13, - selectedTab: 3, - shownTabs: 6, - hiddenTabs: [1, 7, 12], - pinnedTabs: [], - order: [3, 4, 5, 6, 8, 9, 0, 2, 10, 11, 1, 7, 12] - }, - { testNum: 7, - totalTabs: 13, - selectedTab: 3, - shownTabs: 6, - hiddenTabs: [0, 1, 2], - pinnedTabs: [], - order: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 0, 1, 2] - }, - { testNum: 8, - totalTabs: 13, - selectedTab: 0, - shownTabs: 6, - hiddenTabs: [], - pinnedTabs: [0], - order: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] - }, - { testNum: 9, - totalTabs: 13, - selectedTab: 1, - shownTabs: 6, - hiddenTabs: [], - pinnedTabs: [0], - order: [1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] - }, - { testNum: 10, - totalTabs: 13, - selectedTab: 3, - shownTabs: 6, - hiddenTabs: [2], - pinnedTabs: [0,1], - order: [3, 0, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 2] - }, - { testNum: 11, - totalTabs: 13, - selectedTab: 12, - shownTabs: 6, - hiddenTabs: [], - pinnedTabs: [0,1,2], - order: [12, 0, 1, 2, 7, 8, 9, 10, 11, 3, 4, 5, 6] - }, - { testNum: 12, - totalTabs: 13, - selectedTab: 6, - shownTabs: 6, - hiddenTabs: [3,4,5], - pinnedTabs: [0,1,2], - order: [6, 0, 1, 2, 7, 8, 9, 10, 11, 12, 3, 4, 5] - }, - { testNum: 13, - totalTabs: 13, - selectedTab: 1, - shownTabs: 6, - hiddenTabs: [3,4,5], - pinnedTabs: [0,1,2], - order: [1, 0, 2, 6, 7, 8, 9, 10, 11, 12, 3, 4, 5] - }, - { testNum: 14, - totalTabs: 13, - selectedTab: 2, - shownTabs: 6, - hiddenTabs: [], - pinnedTabs: [0,1,2], - order: [2, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] - }, - { testNum: 15, - totalTabs: 13, - selectedTab: 3, - shownTabs: 6, - hiddenTabs: [1,4], - pinnedTabs: [0,1,2], - order: [3, 0, 1, 2, 5, 6, 7, 8, 9, 10, 11, 12, 4] - } - ]; - - let tabMinWidth = - parseInt(getComputedStyle(gBrowser.selectedTab, null).minWidth); - let testIndex = 0; - - function runNextTest() { - if (tests.length == 0) { - finish(); - return; - } - - let wu = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) - .getInterface(Components.interfaces.nsIDOMWindowUtils); - wu.garbageCollect(); - - setTimeout(function() { - info ("Starting test " + (++testIndex)); - let test = tests.shift(); - let state = buildTestState(test.totalTabs, test.selectedTab, - test.hiddenTabs, test.pinnedTabs); - let tabbarWidth = Math.floor((test.shownTabs - 0.5) * tabMinWidth); - let win = openDialog(location, "_blank", "chrome,all,dialog=no"); - let tabsRestored = []; - - win.addEventListener("SSTabRestoring", function onSSTabRestoring(aEvent) { - let tab = aEvent.originalTarget; - let tabLink = tab.linkedBrowser.currentURI.spec; - let tabIndex = - tabLink.substring(tabLink.indexOf("?t=") + 3, tabLink.length); - - // we need to compare with the tab's restoring index, no with the - // position index, since the pinned tabs change the positions in the - // tabbar. - tabsRestored.push(tabIndex); - - if (tabsRestored.length < state.windows[0].tabs.length) - return; - - // all of the tabs should be restoring or restored by now - is(tabsRestored.length, state.windows[0].tabs.length, - "Test #" + testIndex + ": Number of restored tabs is as expected"); - - is(tabsRestored.join(" "), test.order.join(" "), - "Test #" + testIndex + ": 'visible' tabs restored first"); - - // cleanup - win.removeEventListener("SSTabRestoring", onSSTabRestoring, false); - win.close(); - executeSoon(runNextTest); - }, false); - - whenWindowLoaded(win, function(aEvent) { - let extent = - win.outerWidth - win.gBrowser.tabContainer.mTabstrip.scrollClientSize; - let windowWidth = tabbarWidth + extent; - win.resizeTo(windowWidth, win.outerHeight); - ss.setWindowState(win, JSON.stringify(state), true); - }); - }, 1000); - }; - - runNextTest(); -} diff --git a/browser/components/sessionstore/test/browser_480893.js b/browser/components/sessionstore/test/browser_480893.js deleted file mode 100644 index 719cacff1..000000000 --- a/browser/components/sessionstore/test/browser_480893.js +++ /dev/null @@ -1,55 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 480893 **/ - - waitForExplicitFinish(); - - // Test that starting a new session loads a blank page if Firefox is - // configured to display a blank page at startup (browser.startup.page = 0) - gPrefService.setIntPref("browser.startup.page", 0); - let tab = gBrowser.addTab("about:sessionrestore"); - gBrowser.selectedTab = tab; - let browser = tab.linkedBrowser; - browser.addEventListener("load", function(aEvent) { - browser.removeEventListener("load", arguments.callee, true); - let doc = browser.contentDocument; - - // click on the "Start New Session" button after about:sessionrestore is loaded - doc.getElementById("errorCancel").click(); - browser.addEventListener("load", function(aEvent) { - browser.removeEventListener("load", arguments.callee, true); - let doc = browser.contentDocument; - - is(doc.URL, "about:blank", "loaded page is about:blank"); - - // Test that starting a new session loads the homepage (set to http://mochi.test:8888) - // if Firefox is configured to display a homepage at startup (browser.startup.page = 1) - let homepage = "http://mochi.test:8888/"; - gPrefService.setCharPref("browser.startup.homepage", homepage); - gPrefService.setIntPref("browser.startup.page", 1); - gBrowser.loadURI("about:sessionrestore"); - browser.addEventListener("load", function(aEvent) { - browser.removeEventListener("load", arguments.callee, true); - let doc = browser.contentDocument; - - // click on the "Start New Session" button after about:sessionrestore is loaded - doc.getElementById("errorCancel").click(); - browser.addEventListener("load", function(aEvent) { - browser.removeEventListener("load", arguments.callee, true); - let doc = browser.contentDocument; - - is(doc.URL, homepage, "loaded page is the homepage"); - - // close tab, restore default values and finish the test - gBrowser.removeTab(tab); - gPrefService.clearUserPref("browser.startup.page"); - gPrefService.clearUserPref("browser.startup.homepage"); - finish(); - }, true); - }, true); - }, true); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_483330.js b/browser/components/sessionstore/test/browser_483330.js deleted file mode 100644 index 50f3a6a19..000000000 --- a/browser/components/sessionstore/test/browser_483330.js +++ /dev/null @@ -1,37 +0,0 @@ -function test() { - /** Test for Bug 483330 **/ - - waitForExplicitFinish(); - - let tab = gBrowser.addTab(); - gBrowser.selectedTab = tab; - - let browser = tab.linkedBrowser; - browser.addEventListener("load", function loadListener(e) { - browser.removeEventListener("load", arguments.callee, true); - - // Scroll the content document - browser.contentWindow.scrollTo(1100, 1200); - is(browser.contentWindow.scrollX, 1100, "scrolled horizontally"); - is(browser.contentWindow.scrollY, 1200, "scrolled vertically"); - - gBrowser.removeTab(tab); - - let newTab = ss.undoCloseTab(window, 0); - newTab.addEventListener("SSTabRestored", function tabRestored(e) { - newTab.removeEventListener("SSTabRestored", arguments.callee, true); - - let newBrowser = newTab.linkedBrowser; - - // check that the scroll position was restored - is(newBrowser.contentWindow.scrollX, 1100, "still scrolled horizontally"); - is(newBrowser.contentWindow.scrollY, 1200, "still scrolled vertically"); - - gBrowser.removeTab(newTab); - - finish(); - }, true); - }, true); - - browser.loadURI("data:text/html;charset=utf-8,<body style='width: 100000px; height: 100000px;'><p>top</p></body>"); -} diff --git a/browser/components/sessionstore/test/browser_485482.js b/browser/components/sessionstore/test/browser_485482.js deleted file mode 100644 index 19cfa0a2a..000000000 --- a/browser/components/sessionstore/test/browser_485482.js +++ /dev/null @@ -1,36 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 485482 **/ - - waitForExplicitFinish(); - - let uniqueValue = Math.random(); - - let rootDir = getRootDirectory(gTestPath); - let testURL = rootDir + "browser_485482_sample.html"; - let tab = gBrowser.addTab(testURL); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - tab.linkedBrowser.removeEventListener("load", arguments.callee, true); - let doc = tab.linkedBrowser.contentDocument; - doc.querySelector("input[type=text]").value = uniqueValue; - doc.querySelector("input[type=checkbox]").checked = true; - - let tab2 = gBrowser.duplicateTab(tab); - tab2.linkedBrowser.addEventListener("load", function(aEvent) { - tab2.linkedBrowser.removeEventListener("load", arguments.callee, true); - doc = tab2.linkedBrowser.contentDocument; - is(doc.querySelector("input[type=text]").value, uniqueValue, - "generated XPath expression was valid"); - ok(doc.querySelector("input[type=checkbox]").checked, - "generated XPath expression was valid"); - - // clean up - gBrowser.removeTab(tab2); - gBrowser.removeTab(tab); - finish(); - }, true); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_485482_sample.html b/browser/components/sessionstore/test/browser_485482_sample.html deleted file mode 100644 index c2097b593..000000000 --- a/browser/components/sessionstore/test/browser_485482_sample.html +++ /dev/null @@ -1,12 +0,0 @@ -<!DOCTYPE html> -<title>Test for bug 485482</title> - -<bad=name> - <input type="text"> -</bad=name> - -<worse=name> - <l0c@l+na~e"'§> - <input type="checkbox" name="check"> Check - </l0c@l+na~e"'§> -</worse=name> diff --git a/browser/components/sessionstore/test/browser_485563.js b/browser/components/sessionstore/test/browser_485563.js deleted file mode 100644 index 56e198477..000000000 --- a/browser/components/sessionstore/test/browser_485563.js +++ /dev/null @@ -1,27 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 485563 **/ - - waitForExplicitFinish(); - - let uniqueValue = Math.random() + "\u2028Second line\u2029Second paragraph\u2027"; - - let tab = gBrowser.addTab(); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - tab.linkedBrowser.removeEventListener("load", arguments.callee, true); - ss.setTabValue(tab, "bug485563", uniqueValue); - let tabState = JSON.parse(ss.getTabState(tab)); - is(tabState.extData["bug485563"], uniqueValue, - "unicode line separator wasn't over-encoded"); - ss.deleteTabValue(tab, "bug485563"); - ss.setTabState(tab, JSON.stringify(tabState)); - is(ss.getTabValue(tab, "bug485563"), uniqueValue, - "unicode line separator was correctly preserved"); - - gBrowser.removeTab(tab); - finish(); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_490040.js b/browser/components/sessionstore/test/browser_490040.js deleted file mode 100644 index 0cfdc9784..000000000 --- a/browser/components/sessionstore/test/browser_490040.js +++ /dev/null @@ -1,123 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 490040 **/ - - waitForExplicitFinish(); - - function testWithState(aState) { - // Ensure we can store the window if needed. - let curClosedWindowCount = ss.getClosedWindowCount(); - gPrefService.setIntPref("browser.sessionstore.max_windows_undo", - curClosedWindowCount + 1); - - var origWin; - function windowObserver(aSubject, aTopic, aData) { - let theWin = aSubject.QueryInterface(Ci.nsIDOMWindow); - if (origWin && theWin != origWin) - return; - - switch (aTopic) { - case "domwindowopened": - origWin = theWin; - theWin.addEventListener("load", function () { - theWin.removeEventListener("load", arguments.callee, false); - executeSoon(function () { - // Close the window as soon as the first tab loads, or - // immediately if there are no tabs. - if (aState.windowState.windows[0].tabs[0].entries.length) { - theWin.gBrowser.addEventListener("load", function() { - theWin.gBrowser.removeEventListener("load", - arguments.callee, true); - theWin.close(); - }, true); - } else { - executeSoon(function () { - theWin.close(); - }); - } - ss.setWindowState(theWin, JSON.stringify(aState.windowState), - true); - }); - }, false); - break; - - case "domwindowclosed": - Services.ww.unregisterNotification(windowObserver); - // Use executeSoon to ensure this happens after SS observer. - executeSoon(function () { - is(ss.getClosedWindowCount(), - curClosedWindowCount + (aState.shouldBeAdded ? 1 : 0), - "That window should " + (aState.shouldBeAdded ? "" : "not ") + - "be restorable"); - executeSoon(runNextTest); - }); - break; - } - } - Services.ww.registerNotification(windowObserver); - Services.ww.openWindow(null, - location, - "_blank", - "chrome,all,dialog=no", - null); - } - - // Only windows with open tabs are restorable. Windows where a lone tab is - // detached may have _closedTabs, but is left with just an empty tab. - let states = [ - { - shouldBeAdded: true, - windowState: { - windows: [{ - tabs: [{ entries: [{ url: "http://example.com", title: "example.com" }] }], - selected: 1, - _closedTabs: [] - }] - } - }, - { - shouldBeAdded: false, - windowState: { - windows: [{ - tabs: [{ entries: [] }], - _closedTabs: [] - }] - } - }, - { - shouldBeAdded: false, - windowState: { - windows: [{ - tabs: [{ entries: [] }], - _closedTabs: [{ state: { entries: [{ url: "http://example.com", index: 1 }] } }] - }] - } - }, - { - shouldBeAdded: false, - windowState: { - windows: [{ - tabs: [{ entries: [] }], - _closedTabs: [], - extData: { keyname: "pi != " + Math.random() } - }] - } - } - ]; - - function runNextTest() { - if (states.length) { - let state = states.shift(); - testWithState(state); - } - else { - gPrefService.clearUserPref("browser.sessionstore.max_windows_undo"); - finish(); - } - } - runNextTest(); -} - diff --git a/browser/components/sessionstore/test/browser_491168.js b/browser/components/sessionstore/test/browser_491168.js deleted file mode 100644 index 01572dc65..000000000 --- a/browser/components/sessionstore/test/browser_491168.js +++ /dev/null @@ -1,46 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 491168 **/ - - waitForExplicitFinish(); - - const REFERRER1 = "http://example.org/?" + Date.now(); - const REFERRER2 = "http://example.org/?" + Math.random(); - - let tab = gBrowser.addTab(); - gBrowser.selectedTab = tab; - - let browser = tab.linkedBrowser; - browser.addEventListener("load", function() { - browser.removeEventListener("load", arguments.callee, true); - - let tabState = JSON.parse(ss.getTabState(tab)); - is(tabState.entries[0].referrer, REFERRER1, - "Referrer retrieved via getTabState matches referrer set via loadURI."); - - tabState.entries[0].referrer = REFERRER2; - ss.setTabState(tab, JSON.stringify(tabState)); - - tab.addEventListener("SSTabRestored", function() { - tab.removeEventListener("SSTabRestored", arguments.callee, true); - is(window.content.document.referrer, REFERRER2, "document.referrer matches referrer set via setTabState."); - - gBrowser.removeTab(tab); - let newTab = ss.undoCloseTab(window, 0); - newTab.addEventListener("SSTabRestored", function() { - newTab.removeEventListener("SSTabRestored", arguments.callee, true); - - is(window.content.document.referrer, REFERRER2, "document.referrer is still correct after closing and reopening the tab."); - gBrowser.removeTab(newTab); - - finish(); - }, true); - }, true); - },true); - - let referrerURI = Services.io.newURI(REFERRER1, null, null); - browser.loadURI("http://example.org", referrerURI, null); -} diff --git a/browser/components/sessionstore/test/browser_491577.js b/browser/components/sessionstore/test/browser_491577.js deleted file mode 100644 index 7626db1a4..000000000 --- a/browser/components/sessionstore/test/browser_491577.js +++ /dev/null @@ -1,121 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 491577 **/ - - // test setup - waitForExplicitFinish(); - - const REMEMBER = Date.now(), FORGET = Math.random(); - let test_state = { - windows: [ { tabs: [{ entries: [{ url: "http://example.com/" }] }], selected: 1 } ], - _closedWindows : [ - // _closedWindows[0] - { - tabs: [ - { entries: [{ url: "http://example.com/", title: "title" }] }, - { entries: [{ url: "http://mozilla.org/", title: "title" }] } - ], - selected: 2, - title: FORGET, - _closedTabs: [] - }, - // _closedWindows[1] - { - tabs: [ - { entries: [{ url: "http://mozilla.org/", title: "title" }] }, - { entries: [{ url: "http://example.com/", title: "title" }] }, - { entries: [{ url: "http://mozilla.org/", title: "title" }] }, - ], - selected: 3, - title: REMEMBER, - _closedTabs: [] - }, - // _closedWindows[2] - { - tabs: [ - { entries: [{ url: "http://example.com/", title: "title" }] } - ], - selected: 1, - title: FORGET, - _closedTabs: [ - { - state: { - entries: [ - { url: "http://mozilla.org/", title: "title" }, - { url: "http://mozilla.org/again", title: "title" } - ] - }, - pos: 1, - title: "title" - }, - { - state: { - entries: [ - { url: "http://example.com", title: "title" } - ] - }, - title: "title" - } - ] - } - ] - }; - let remember_count = 1; - - function countByTitle(aClosedWindowList, aTitle) - aClosedWindowList.filter(function(aData) aData.title == aTitle).length; - - function testForError(aFunction) { - try { - aFunction(); - return false; - } - catch (ex) { - return ex.name == "NS_ERROR_ILLEGAL_VALUE"; - } - } - - // open a window and add the above closed window list - let newWin = openDialog(location, "_blank", "chrome,all,dialog=no"); - newWin.addEventListener("load", function(aEvent) { - this.removeEventListener("load", arguments.callee, false); - gPrefService.setIntPref("browser.sessionstore.max_windows_undo", - test_state._closedWindows.length); - ss.setWindowState(newWin, JSON.stringify(test_state), true); - - let closedWindows = JSON.parse(ss.getClosedWindowData()); - is(closedWindows.length, test_state._closedWindows.length, - "Closed window list has the expected length"); - is(countByTitle(closedWindows, FORGET), - test_state._closedWindows.length - remember_count, - "The correct amount of windows are to be forgotten"); - is(countByTitle(closedWindows, REMEMBER), remember_count, - "Everything is set up."); - - // all of the following calls with illegal arguments should throw NS_ERROR_ILLEGAL_VALUE - ok(testForError(function() ss.forgetClosedWindow(-1)), - "Invalid window for forgetClosedWindow throws"); - ok(testForError(function() ss.forgetClosedWindow(test_state._closedWindows.length + 1)), - "Invalid window for forgetClosedWindow throws"); - - // Remove third window, then first window - ss.forgetClosedWindow(2); - ss.forgetClosedWindow(null); - - closedWindows = JSON.parse(ss.getClosedWindowData()); - is(closedWindows.length, remember_count, - "The correct amount of windows were removed"); - is(countByTitle(closedWindows, FORGET), 0, - "All windows specifically forgotten were indeed removed"); - is(countByTitle(closedWindows, REMEMBER), remember_count, - "... and windows not specifically forgetten weren't."); - - // clean up - newWin.close(); - gPrefService.clearUserPref("browser.sessionstore.max_windows_undo"); - finish(); - }, false); -} diff --git a/browser/components/sessionstore/test/browser_495495.js b/browser/components/sessionstore/test/browser_495495.js deleted file mode 100644 index 982bcdcaf..000000000 --- a/browser/components/sessionstore/test/browser_495495.js +++ /dev/null @@ -1,54 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 495495 **/ - - waitForExplicitFinish(); - - let newWin = openDialog(location, "_blank", "chrome,all,dialog=no,toolbar=yes"); - newWin.addEventListener("load", function() { - newWin.removeEventListener("load", arguments.callee, false); - - executeSoon(function() { - let state1 = ss.getWindowState(newWin); - newWin.close(); - - newWin = openDialog(location, "_blank", - "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar=no,location,personal,directories,dialog=no"); - newWin.addEventListener("load", function() { - newWin.removeEventListener("load", arguments.callee, false); - - executeSoon(function() { - let state2 = ss.getWindowState(newWin); - newWin.close(); - - function testState(state, expected, callback) { - let win = openDialog(location, "_blank", "chrome,all,dialog=no"); - win.addEventListener("load", function() { - win.removeEventListener("load", arguments.callee, false); - - is(win.gURLBar.readOnly, false, - "URL bar should not be read-only before setting the state"); - is(win.gURLBar.getAttribute("enablehistory"), "true", - "URL bar autocomplete should be enabled before setting the state"); - ss.setWindowState(win, state, true); - is(win.gURLBar.readOnly, expected.readOnly, - "URL bar read-only state should be restored correctly"); - is(win.gURLBar.getAttribute("enablehistory"), expected.enablehistory, - "URL bar autocomplete state should be restored correctly"); - - win.close(); - executeSoon(callback); - }, false); - } - - testState(state1, {readOnly: false, enablehistory: "true"}, function() { - testState(state2, {readOnly: true, enablehistory: "false"}, finish); - }); - }); - }, false); - }); - }, false); -} diff --git a/browser/components/sessionstore/test/browser_500328.js b/browser/components/sessionstore/test/browser_500328.js deleted file mode 100644 index bd0c95131..000000000 --- a/browser/components/sessionstore/test/browser_500328.js +++ /dev/null @@ -1,114 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function checkState(tab) { - // Go back and then forward, and make sure that the state objects received - // from the popState event are as we expect them to be. - // - // We also add a node to the document's body when after going back and make - // sure it's still there after we go forward -- this is to test that the two - // history entries correspond to the same document. - - let popStateCount = 0; - - tab.linkedBrowser.addEventListener('popstate', function(aEvent) { - let contentWindow = tab.linkedBrowser.contentWindow; - if (popStateCount == 0) { - popStateCount++; - - is(tab.linkedBrowser.contentWindow.testState, 'foo', - 'testState after going back'); - - ok(aEvent.state, "Event should have a state property."); - is(JSON.stringify(tab.linkedBrowser.contentWindow.history.state), JSON.stringify({obj1:1}), - "first popstate object."); - - // Add a node with id "new-elem" to the document. - let doc = contentWindow.document; - ok(!doc.getElementById("new-elem"), - "doc shouldn't contain new-elem before we add it."); - let elem = doc.createElement("div"); - elem.id = "new-elem"; - doc.body.appendChild(elem); - - contentWindow.history.forward(); - } - else if (popStateCount == 1) { - popStateCount++; - is(aEvent.state.obj3.toString(), '/^a$/', "second popstate object."); - - // Make sure that the new-elem node is present in the document. If it's - // not, then this history entry has a different doc identifier than the - // previous entry, which is bad. - let doc = contentWindow.document; - let newElem = doc.getElementById("new-elem"); - ok(newElem, "doc should contain new-elem."); - newElem.parentNode.removeChild(newElem); - ok(!doc.getElementById("new-elem"), "new-elem should be removed."); - - // Clean up after ourselves and finish the test. - tab.linkedBrowser.removeEventListener("popstate", arguments.callee, true); - gBrowser.removeTab(tab); - finish(); - } - }, true); - - // Set some state in the page's window. When we go back(), the page should - // be retrieved from bfcache, and this state should still be there. - tab.linkedBrowser.contentWindow.testState = 'foo'; - - // Now go back. This should trigger the popstate event handler above. - tab.linkedBrowser.contentWindow.history.back(); -} - -function test() { - // Tests session restore functionality of history.pushState and - // history.replaceState(). (Bug 500328) - - waitForExplicitFinish(); - - // We open a new blank window, let it load, and then load in - // http://example.com. We need to load the blank window first, otherwise the - // docshell gets confused and doesn't have a current history entry. - let tab = gBrowser.addTab("about:blank"); - let tabBrowser = tab.linkedBrowser; - - tabBrowser.addEventListener("load", function(aEvent) { - tabBrowser.removeEventListener("load", arguments.callee, true); - - tabBrowser.loadURI("http://example.com", null, null); - - tabBrowser.addEventListener("load", function(aEvent) { - tabBrowser.removeEventListener("load", arguments.callee, true); - - // After these push/replaceState calls, the window should have three - // history entries: - // testURL (state object: null) <-- oldest - // testURL (state object: {obj1:1}) - // testURL?page2 (state object: {obj3:/^a$/}) <-- newest - let contentWindow = tab.linkedBrowser.contentWindow; - let history = contentWindow.history; - history.pushState({obj1:1}, "title-obj1"); - history.pushState({obj2:2}, "title-obj2", "?page2"); - history.replaceState({obj3:/^a$/}, "title-obj3"); - - let state = ss.getTabState(tab); - gBrowser.removeTab(tab); - - // Restore the state into a new tab. Things don't work well when we - // restore into the old tab, but that's not a real use case anyway. - let tab2 = gBrowser.addTab("about:blank"); - ss.setTabState(tab2, state, true); - - // Run checkState() once the tab finishes loading its restored state. - tab2.linkedBrowser.addEventListener("load", function() { - tab2.linkedBrowser.removeEventListener("load", arguments.callee, true); - SimpleTest.executeSoon(function() { - checkState(tab2); - }); - }, true); - - }, true); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_506482.js b/browser/components/sessionstore/test/browser_506482.js deleted file mode 100644 index 3d0a68d71..000000000 --- a/browser/components/sessionstore/test/browser_506482.js +++ /dev/null @@ -1,76 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 506482 **/ - - // test setup - waitForExplicitFinish(); - - // read the sessionstore.js mtime (picked from browser_248970_a.js) - let profilePath = Cc["@mozilla.org/file/directory_service;1"]. - getService(Ci.nsIProperties). - get("ProfD", Ci.nsIFile); - function getSessionstoreFile() { - let sessionStoreJS = profilePath.clone(); - sessionStoreJS.append("sessionstore.js"); - return sessionStoreJS; - } - function getSessionstorejsModificationTime() { - let file = getSessionstoreFile(); - if (file.exists()) - return file.lastModifiedTime; - else - return -1; - } - - // delete existing sessionstore.js, to make sure we're not reading - // the mtime of an old one initialy - let (sessionStoreJS = getSessionstoreFile()) { - if (sessionStoreJS.exists()) - sessionStoreJS.remove(false); - } - - // test content URL - const TEST_URL = "data:text/html;charset=utf-8," - + "<body style='width: 100000px; height: 100000px;'><p>top</p></body>" - - // preferences that we use - const PREF_INTERVAL = "browser.sessionstore.interval"; - - // make sure sessionstore.js is saved ASAP on all events - gPrefService.setIntPref(PREF_INTERVAL, 0); - - // get the initial sessionstore.js mtime (-1 if it doesn't exist yet) - let mtime0 = getSessionstorejsModificationTime(); - - // create and select a first tab - let tab = gBrowser.addTab(TEST_URL); - tab.linkedBrowser.addEventListener("load", function loadListener(e) { - tab.linkedBrowser.removeEventListener("load", arguments.callee, true); - - // step1: the above has triggered some saveStateDelayed(), sleep until - // it's done, and get the initial sessionstore.js mtime - setTimeout(function step1(e) { - let mtime1 = getSessionstorejsModificationTime(); - isnot(mtime1, mtime0, "initial sessionstore.js update"); - - // step2: test sessionstore.js is not updated on tab selection - // or content scrolling - gBrowser.selectedTab = tab; - tab.linkedBrowser.contentWindow.scrollTo(1100, 1200); - setTimeout(function step2(e) { - let mtime2 = getSessionstorejsModificationTime(); - is(mtime2, mtime1, - "tab selection and scrolling: sessionstore.js not updated"); - - // ok, done, cleanup and finish - if (gPrefService.prefHasUserValue(PREF_INTERVAL)) - gPrefService.clearUserPref(PREF_INTERVAL); - gBrowser.removeTab(tab); - finish(); - }, 3500); // end of sleep after tab selection and scrolling - }, 3500); // end of sleep after initial saveStateDelayed() - }, true); -} diff --git a/browser/components/sessionstore/test/browser_514751.js b/browser/components/sessionstore/test/browser_514751.js deleted file mode 100644 index b30807751..000000000 --- a/browser/components/sessionstore/test/browser_514751.js +++ /dev/null @@ -1,39 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 514751 (Wallpaper) **/ - - waitForExplicitFinish(); - - let state = { - windows: [{ - tabs: [{ - entries: [ - { url: "http://www.mozilla.org/projects/minefield/", title: "Minefield Start Page" }, - {} - ] - }] - }] - }; - - var theWin = openDialog(location, "", "chrome,all,dialog=no"); - theWin.addEventListener("load", function () { - theWin.removeEventListener("load", arguments.callee, false); - - executeSoon(function () { - var gotError = false; - try { - ss.setWindowState(theWin, JSON.stringify(state), true); - } catch (e) { - if (/NS_ERROR_MALFORMED_URI/.test(e)) - gotError = true; - } - ok(!gotError, "Didn't get a malformed URI error."); - theWin.close(); - finish(); - }); - }, false); -} - diff --git a/browser/components/sessionstore/test/browser_522375.js b/browser/components/sessionstore/test/browser_522375.js deleted file mode 100644 index 50b74d6cd..000000000 --- a/browser/components/sessionstore/test/browser_522375.js +++ /dev/null @@ -1,21 +0,0 @@ -function test() { - var startup_info = Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(Components.interfaces.nsIAppStartup).getStartupInfo(); - // No .process info on mac - - // Check if we encountered a telemetry error for the the process creation - // timestamp and turn the first test into a known failure. - var telemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry); - var snapshot = telemetry.getHistogramById("STARTUP_MEASUREMENT_ERRORS") - .snapshot(); - - if (snapshot.counts[0] == 0) - ok(startup_info.process <= startup_info.main, "process created before main is run " + uneval(startup_info)); - else - todo(false, "An error occurred while recording the process creation timestamp, skipping this test"); - - // on linux firstPaint can happen after everything is loaded (especially with remote X) - if (startup_info.firstPaint) - ok(startup_info.main <= startup_info.firstPaint, "main ran before first paint " + uneval(startup_info)); - - ok(startup_info.main < startup_info.sessionRestored, "Session restored after main " + uneval(startup_info)); -} diff --git a/browser/components/sessionstore/test/browser_522545.js b/browser/components/sessionstore/test/browser_522545.js deleted file mode 100644 index ac05865de..000000000 --- a/browser/components/sessionstore/test/browser_522545.js +++ /dev/null @@ -1,270 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 522545 **/ - - waitForExplicitFinish(); - requestLongerTimeout(2); - - // This tests the following use case: - // User opens a new tab which gets focus. The user types something into the - // address bar, then crashes or quits. - function test_newTabFocused() { - let state = { - windows: [{ - tabs: [ - { entries: [{ url: "about:mozilla" }] }, - { entries: [], userTypedValue: "example.com", userTypedClear: 0 } - ], - selected: 2 - }] - }; - - waitForBrowserState(state, function() { - let browser = gBrowser.selectedBrowser; - is(browser.currentURI.spec, "about:blank", - "No history entries still sets currentURI to about:blank"); - is(browser.userTypedValue, "example.com", - "userTypedValue was correctly restored"); - is(browser.userTypedClear, 0, - "userTypeClear restored as expected"); - is(gURLBar.value, "example.com", - "Address bar's value correctly restored"); - // Change tabs to make sure address bar value gets updated - gBrowser.selectedTab = gBrowser.tabContainer.getItemAtIndex(0); - is(gURLBar.value, "about:mozilla", - "Address bar's value correctly updated"); - runNextTest(); - }); - } - - // This tests the following use case: - // User opens a new tab which gets focus. The user types something into the - // address bar, switches back to the first tab, then crashes or quits. - function test_newTabNotFocused() { - let state = { - windows: [{ - tabs: [ - { entries: [{ url: "about:mozilla" }] }, - { entries: [], userTypedValue: "example.org", userTypedClear: 0 } - ], - selected: 1 - }] - }; - - waitForBrowserState(state, function() { - let browser = gBrowser.getBrowserAtIndex(1); - is(browser.currentURI.spec, "about:blank", - "No history entries still sets currentURI to about:blank"); - is(browser.userTypedValue, "example.org", - "userTypedValue was correctly restored"); - is(browser.userTypedClear, 0, - "userTypeClear restored as expected"); - is(gURLBar.value, "about:mozilla", - "Address bar's value correctly restored"); - // Change tabs to make sure address bar value gets updated - gBrowser.selectedTab = gBrowser.tabContainer.getItemAtIndex(1); - is(gURLBar.value, "example.org", - "Address bar's value correctly updated"); - runNextTest(); - }); - } - - // This tests the following use case: - // User is in a tab with session history, then types something in the - // address bar, then crashes or quits. - function test_existingSHEnd_noClear() { - let state = { - windows: [{ - tabs: [{ - entries: [{ url: "about:mozilla" }, { url: "about:config" }], - index: 2, - userTypedValue: "example.com", - userTypedClear: 0 - }] - }] - }; - - waitForBrowserState(state, function() { - let browser = gBrowser.selectedBrowser; - is(browser.currentURI.spec, "about:config", - "browser.currentURI set to current entry in SH"); - is(browser.userTypedValue, "example.com", - "userTypedValue was correctly restored"); - is(browser.userTypedClear, 0, - "userTypeClear restored as expected"); - is(gURLBar.value, "example.com", - "Address bar's value correctly restored to userTypedValue"); - runNextTest(); - }); - } - - // This tests the following use case: - // User is in a tab with session history, presses back at some point, then - // types something in the address bar, then crashes or quits. - function test_existingSHMiddle_noClear() { - let state = { - windows: [{ - tabs: [{ - entries: [{ url: "about:mozilla" }, { url: "about:config" }], - index: 1, - userTypedValue: "example.org", - userTypedClear: 0 - }] - }] - }; - - waitForBrowserState(state, function() { - let browser = gBrowser.selectedBrowser; - is(browser.currentURI.spec, "about:mozilla", - "browser.currentURI set to current entry in SH"); - is(browser.userTypedValue, "example.org", - "userTypedValue was correctly restored"); - is(browser.userTypedClear, 0, - "userTypeClear restored as expected"); - is(gURLBar.value, "example.org", - "Address bar's value correctly restored to userTypedValue"); - runNextTest(); - }); - } - - // This test simulates lots of tabs opening at once and then quitting/crashing. - function test_getBrowserState_lotsOfTabsOpening() { - gBrowser.stop(); - - let uris = []; - for (let i = 0; i < 25; i++) - uris.push("http://example.com/" + i); - - // We're waiting for the first location change, which should indicate - // one of the tabs has loaded and the others haven't. So one should - // be in a non-userTypedValue case, while others should still have - // userTypedValue and userTypedClear set. - gBrowser.addTabsProgressListener({ - onLocationChange: function (aBrowser) { - if (uris.indexOf(aBrowser.currentURI.spec) > -1) { - gBrowser.removeTabsProgressListener(this); - firstLocationChange(); - } - } - }); - - function firstLocationChange() { - let state = JSON.parse(ss.getBrowserState()); - let hasUTV = state.windows[0].tabs.some(function(aTab) { - return aTab.userTypedValue && aTab.userTypedClear && !aTab.entries.length; - }); - - ok(hasUTV, "At least one tab has a userTypedValue with userTypedClear with no loaded URL"); - - gBrowser.addEventListener("load", firstLoad, true); - } - - function firstLoad() { - gBrowser.removeEventListener("load", firstLoad, true); - - let state = JSON.parse(ss.getBrowserState()); - let hasSH = state.windows[0].tabs.some(function(aTab) { - return !("userTypedValue" in aTab) && aTab.entries[0].url; - }); - - ok(hasSH, "At least one tab has its entry in SH"); - - runNextTest(); - } - - gBrowser.loadTabs(uris); - } - - // This simulates setting a userTypedValue and ensures that just typing in the - // URL bar doesn't set userTypedClear as well. - function test_getBrowserState_userTypedValue() { - let state = { - windows: [{ - tabs: [{ entries: [] }] - }] - }; - - waitForBrowserState(state, function() { - let browser = gBrowser.selectedBrowser; - // Make sure this tab isn't loading and state is clear before we test. - is(browser.userTypedValue, null, "userTypedValue is empty to start"); - is(browser.userTypedClear, 0, "userTypedClear is 0 to start"); - - gURLBar.value = "example.org"; - let event = document.createEvent("Events"); - event.initEvent("input", true, false); - gURLBar.dispatchEvent(event); - - browser.addEventListener("load", function onLoad() { - browser.removeEventListener("load", onLoad, true); - - executeSoon(function () { - is(browser.userTypedValue, "example.org", - "userTypedValue was set when changing gURLBar.value"); - is(browser.userTypedClear, 0, - "userTypedClear was not changed when changing gURLBar.value"); - - // Now make sure ss gets these values too - let newState = JSON.parse(ss.getBrowserState()); - is(newState.windows[0].tabs[0].userTypedValue, "example.org", - "sessionstore got correct userTypedValue"); - is(newState.windows[0].tabs[0].userTypedClear, 0, - "sessionstore got correct userTypedClear"); - runNextTest(); - }); - }, true); - }); - } - - // test_getBrowserState_lotsOfTabsOpening tested userTypedClear in a few cases, - // but not necessarily any that had legitimate URIs in the state of loading - // (eg, "http://example.com"), so this test will cover that case. - function test_userTypedClearLoadURI() { - let state = { - windows: [{ - tabs: [ - { entries: [], userTypedValue: "http://example.com", userTypedClear: 2 } - ] - }] - }; - - waitForBrowserState(state, function() { - let browser = gBrowser.selectedBrowser; - is(browser.currentURI.spec, "http://example.com/", - "userTypedClear=2 caused userTypedValue to be loaded"); - is(browser.userTypedValue, null, - "userTypedValue was null after loading a URI"); - is(browser.userTypedClear, 0, - "userTypeClear reset to 0"); - is(gURLBar.value, gURLBar.trimValue("http://example.com/"), - "Address bar's value set after loading URI"); - runNextTest(); - }); - } - - - let tests = [test_newTabFocused, test_newTabNotFocused, - test_existingSHEnd_noClear, test_existingSHMiddle_noClear, - test_getBrowserState_lotsOfTabsOpening, - test_getBrowserState_userTypedValue, test_userTypedClearLoadURI]; - let originalState = ss.getBrowserState(); - let state = { - windows: [{ - tabs: [{ entries: [{ url: "about:blank" }] }] - }] - }; - function runNextTest() { - if (tests.length) { - waitForBrowserState(state, tests.shift()); - } else { - ss.setBrowserState(originalState); - executeSoon(finish); - } - } - - // Run the tests! - runNextTest(); -} diff --git a/browser/components/sessionstore/test/browser_524745.js b/browser/components/sessionstore/test/browser_524745.js deleted file mode 100644 index b531f4c8d..000000000 --- a/browser/components/sessionstore/test/browser_524745.js +++ /dev/null @@ -1,46 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 524745 **/ - - let uniqKey = "bug524745"; - let uniqVal = Date.now(); - - waitForExplicitFinish(); - - let window_B = openDialog(location, "_blank", "chrome,all,dialog=no"); - window_B.addEventListener("load", function(aEvent) { - window_B.removeEventListener("load", arguments.callee, false); - - waitForFocus(function() { - // Add identifying information to window_B - ss.setWindowValue(window_B, uniqKey, uniqVal); - let state = JSON.parse(ss.getBrowserState()); - let selectedWindow = state.windows[state.selectedWindow - 1]; - is(selectedWindow.extData && selectedWindow.extData[uniqKey], uniqVal, - "selectedWindow is window_B"); - - // Now minimize window_B. The selected window shouldn't have the secret data - window_B.minimize(); - waitForFocus(function() { - state = JSON.parse(ss.getBrowserState()); - selectedWindow = state.windows[state.selectedWindow - 1]; - ok(!selectedWindow.extData || !selectedWindow.extData[uniqKey], - "selectedWindow is not window_B after minimizing it"); - - // Now minimize the last open window (assumes no other tests left windows open) - window.minimize(); - state = JSON.parse(ss.getBrowserState()); - is(state.selectedWindow, 0, - "selectedWindow should be 0 when all windows are minimized"); - - // Cleanup - window.restore(); - window_B.close(); - finish(); - }); - }, window_B); - }, false); -} diff --git a/browser/components/sessionstore/test/browser_526613.js b/browser/components/sessionstore/test/browser_526613.js deleted file mode 100644 index 7e7fe8059..000000000 --- a/browser/components/sessionstore/test/browser_526613.js +++ /dev/null @@ -1,72 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 526613 **/ - - // test setup - waitForExplicitFinish(); - - function browserWindowsCount(expected) { - let count = 0; - let e = Services.wm.getEnumerator("navigator:browser"); - while (e.hasMoreElements()) { - if (!e.getNext().closed) - ++count; - } - is(count, expected, - "number of open browser windows according to nsIWindowMediator"); - let state = ss.getBrowserState(); - info(state); - is(JSON.parse(state).windows.length, expected, - "number of open browser windows according to getBrowserState"); - } - - browserWindowsCount(1); - - // backup old state - let oldState = ss.getBrowserState(); - // create a new state for testing - let testState = { - windows: [ - { tabs: [{ entries: [{ url: "http://example.com/" }] }], selected: 1 }, - { tabs: [{ entries: [{ url: "about:mozilla" }] }], selected: 1 }, - ], - // make sure the first window is focused, otherwise when restoring the - // old state, the first window is closed and the test harness gets unloaded - selectedWindow: 1 - }; - - let pass = 1; - function observer(aSubject, aTopic, aData) { - is(aTopic, "sessionstore-browser-state-restored", - "The sessionstore-browser-state-restored notification was observed"); - - if (pass++ == 1) { - browserWindowsCount(2); - - // let the first window be focused (see above) - function pollMostRecentWindow() { - if (Services.wm.getMostRecentWindow("navigator:browser") == window) { - ss.setBrowserState(oldState); - } else { - info("waiting for the current window to become active"); - setTimeout(pollMostRecentWindow, 0); - window.focus(); //XXX Why is this needed? - } - } - pollMostRecentWindow(); - } - else { - browserWindowsCount(1); - ok(!window.closed, "Restoring the old state should have left this window open"); - Services.obs.removeObserver(observer, "sessionstore-browser-state-restored"); - finish(); - } - } - Services.obs.addObserver(observer, "sessionstore-browser-state-restored", false); - - // set browser to test state - ss.setBrowserState(JSON.stringify(testState)); -} diff --git a/browser/components/sessionstore/test/browser_528776.js b/browser/components/sessionstore/test/browser_528776.js deleted file mode 100644 index b25812195..000000000 --- a/browser/components/sessionstore/test/browser_528776.js +++ /dev/null @@ -1,27 +0,0 @@ -function browserWindowsCount(expected) { - var count = 0; - var e = Services.wm.getEnumerator("navigator:browser"); - while (e.hasMoreElements()) { - if (!e.getNext().closed) - ++count; - } - is(count, expected, - "number of open browser windows according to nsIWindowMediator"); - is(JSON.parse(ss.getBrowserState()).windows.length, expected, - "number of open browser windows according to getBrowserState"); -} - -function test() { - waitForExplicitFinish(); - - browserWindowsCount(1); - - var win = openDialog(location, "", "chrome,all,dialog=no"); - win.addEventListener("load", function () { - win.removeEventListener("load", arguments.callee, false); - browserWindowsCount(2); - win.close(); - browserWindowsCount(1); - finish(); - }, false); -} diff --git a/browser/components/sessionstore/test/browser_579868.js b/browser/components/sessionstore/test/browser_579868.js deleted file mode 100644 index 683ead7c3..000000000 --- a/browser/components/sessionstore/test/browser_579868.js +++ /dev/null @@ -1,35 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - let tab1 = gBrowser.addTab("about:rights"); - let tab2 = gBrowser.addTab("about:mozilla"); - tab1.linkedBrowser.addEventListener("load", mainPart, true); - waitForExplicitFinish(); - - function mainPart() { - tab1.linkedBrowser.removeEventListener("load", mainPart, true); - - // Tell the session storer that the tab is pinned - let newTabState = '{"entries":[{"url":"about:rights"}],"pinned":true,"userTypedValue":"Hello World!"}'; - ss.setTabState(tab1, newTabState); - - // Undo pinning - gBrowser.unpinTab(tab1); - - is(tab1.linkedBrowser.__SS_tabStillLoading, true, - "_tabStillLoading should be true."); - - // Close and restore tab - gBrowser.removeTab(tab1); - let savedState = JSON.parse(ss.getClosedTabData(window))[0].state; - isnot(savedState.pinned, true, "Pinned should not be true"); - tab1 = ss.undoCloseTab(window, 0); - - isnot(tab1.pinned, true, "Should not be pinned"); - gBrowser.removeTab(tab1); - gBrowser.removeTab(tab2); - finish(); - } -} diff --git a/browser/components/sessionstore/test/browser_579879.js b/browser/components/sessionstore/test/browser_579879.js deleted file mode 100644 index e6c689d36..000000000 --- a/browser/components/sessionstore/test/browser_579879.js +++ /dev/null @@ -1,23 +0,0 @@ -function test() { - waitForExplicitFinish(); - - var tab1 = gBrowser.addTab("data:text/plain;charset=utf-8,foo"); - gBrowser.pinTab(tab1); - - tab1.linkedBrowser.addEventListener("load", function () { - tab1.linkedBrowser.removeEventListener("load", arguments.callee, true); - - var tab2 = gBrowser.addTab(); - gBrowser.pinTab(tab2); - - is(Array.indexOf(gBrowser.tabs, tab1), 0, "pinned tab 1 is at the first position"); - gBrowser.removeTab(tab1); - tab1 = undoCloseTab(); - ok(tab1.pinned, "pinned tab 1 has been restored as a pinned tab"); - is(Array.indexOf(gBrowser.tabs, tab1), 0, "pinned tab 1 has been restored to the first position"); - - gBrowser.removeTab(tab1); - gBrowser.removeTab(tab2); - finish(); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_580512.js b/browser/components/sessionstore/test/browser_580512.js deleted file mode 100644 index 9d385d29d..000000000 --- a/browser/components/sessionstore/test/browser_580512.js +++ /dev/null @@ -1,73 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const URIS_PINNED = ["about:license", "about:about"]; -const URIS_NORMAL_A = ["about:mozilla"]; -const URIS_NORMAL_B = ["about:buildconfig"]; - -function test() { - waitForExplicitFinish(); - - isnot(Services.prefs.getIntPref("browser.startup.page"), 3, - "pref to save session must not be set for this test"); - ok(!Services.prefs.getBoolPref("browser.sessionstore.resume_session_once"), - "pref to save session once must not be set for this test"); - - document.documentElement.setAttribute("windowtype", "navigator:browsertestdummy"); - - openWinWithCb(closeFirstWin, URIS_PINNED.concat(URIS_NORMAL_A)); -} - -function closeFirstWin(win) { - win.gBrowser.pinTab(win.gBrowser.tabs[0]); - win.gBrowser.pinTab(win.gBrowser.tabs[1]); - win.BrowserTryToCloseWindow(); - ok(win.closed, "window closed"); - - openWinWithCb(checkSecondWin, URIS_NORMAL_B, URIS_PINNED.concat(URIS_NORMAL_B)); -} - -function checkSecondWin(win) { - is(win.gBrowser.browsers[0].currentURI.spec, URIS_PINNED[0], "first pinned tab restored"); - is(win.gBrowser.browsers[1].currentURI.spec, URIS_PINNED[1], "second pinned tab restored"); - ok(win.gBrowser.tabs[0].pinned, "first pinned tab is still pinned"); - ok(win.gBrowser.tabs[1].pinned, "second pinned tab is still pinned"); - win.close(); - - // cleanup - document.documentElement.setAttribute("windowtype", "navigator:browser"); - finish(); -} - -function openWinWithCb(cb, argURIs, expectedURIs) { - if (!expectedURIs) - expectedURIs = argURIs; - - var win = openDialog(getBrowserURL(), "_blank", - "chrome,all,dialog=no", argURIs.join("|")); - - win.addEventListener("load", function () { - win.removeEventListener("load", arguments.callee, false); - info("the window loaded"); - - var expectedLoads = expectedURIs.length; - - win.gBrowser.addTabsProgressListener({ - onStateChange: function (aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) { - if (aRequest && - aStateFlags & Ci.nsIWebProgressListener.STATE_STOP && - aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK && - expectedURIs.indexOf(aRequest.QueryInterface(Ci.nsIChannel).originalURI.spec) > -1 && - --expectedLoads <= 0) { - win.gBrowser.removeTabsProgressListener(this); - info("all tabs loaded"); - is(win.gBrowser.tabs.length, expectedURIs.length, "didn't load any unexpected tabs"); - executeSoon(function () { - cb(win); - }); - } - } - }); - }, false); -} diff --git a/browser/components/sessionstore/test/browser_581593.js b/browser/components/sessionstore/test/browser_581593.js deleted file mode 100644 index 7544db3f9..000000000 --- a/browser/components/sessionstore/test/browser_581593.js +++ /dev/null @@ -1,52 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -let stateBackup = ss.getBrowserState(); - -function test() { - /** Test for bug 581593 **/ - waitForExplicitFinish(); - ignoreAllUncaughtExceptions(); - - let oldState = { windows: [{ tabs: [{ entries: [{ url: "example.com" }] }] }]}; - let pageData = { - url: "about:sessionrestore", - formdata: { id: { "sessionData": "(" + JSON.stringify(oldState) + ")" } } - }; - let state = { windows: [{ tabs: [{ entries: [pageData] }] }] }; - - // The form data will be restored before SSTabRestored, so we want to listen - // for that on the currently selected tab (it will be reused) - gBrowser.selectedTab.addEventListener("SSTabRestored", onSSTabRestored, true); - - ss.setBrowserState(JSON.stringify(state)); -} - -function onSSTabRestored(aEvent) { - info("SSTabRestored event"); - gBrowser.selectedTab.removeEventListener("SSTabRestored", onSSTabRestored, true); - gBrowser.selectedBrowser.addEventListener("input", onInput, true); -} - -function onInput(aEvent) { - info("input event"); - gBrowser.selectedBrowser.removeEventListener("input", onInput, true); - - // This is an ok way to check this because we will make sure that the text - // field is parsable. - let val = gBrowser.selectedBrowser.contentDocument.getElementById("sessionData").value; - try { - JSON.parse(val); - ok(true, "JSON.parse succeeded"); - } - catch (e) { - ok(false, "JSON.parse failed"); - } - cleanup(); -} - -function cleanup() { - ss.setBrowserState(stateBackup); - executeSoon(finish); -} diff --git a/browser/components/sessionstore/test/browser_581937.js b/browser/components/sessionstore/test/browser_581937.js deleted file mode 100644 index 71bb91e90..000000000 --- a/browser/components/sessionstore/test/browser_581937.js +++ /dev/null @@ -1,36 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// Tests that an about:blank tab with no history will not be saved into -// session store and thus, it will not show up in Recently Closed Tabs. - -let tab; -function test() { - waitForExplicitFinish(); - - gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", 0); - gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo"); - - is(ss.getClosedTabCount(window), 0, "should be no closed tabs"); - - gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, true); - - tab = gBrowser.addTab(); -} - -function onTabOpen(aEvent) { - gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, true); - - // Let other listeners react to the TabOpen event before removing the tab. - executeSoon(function() { - is(gBrowser.browsers[1].currentURI.spec, "about:blank", - "we will be removing an about:blank tab"); - - gBrowser.removeTab(tab); - - is(ss.getClosedTabCount(window), 0, "should still be no closed tabs"); - - executeSoon(finish); - }); -} diff --git a/browser/components/sessionstore/test/browser_586068-apptabs.js b/browser/components/sessionstore/test/browser_586068-apptabs.js deleted file mode 100644 index f94b5b539..000000000 --- a/browser/components/sessionstore/test/browser_586068-apptabs.js +++ /dev/null @@ -1,53 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand"; - -function test() { - TestRunner.run(); -} - -function runTests() { - Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, true); - registerCleanupFunction(function () { - Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND); - }); - - let state = { windows: [{ tabs: [ - { entries: [{ url: "http://example.org/#1" }], extData: { "uniq": r() }, pinned: true }, - { entries: [{ url: "http://example.org/#2" }], extData: { "uniq": r() }, pinned: true }, - { entries: [{ url: "http://example.org/#3" }], extData: { "uniq": r() }, pinned: true }, - { entries: [{ url: "http://example.org/#4" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#5" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#6" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#7" }], extData: { "uniq": r() } }, - ], selected: 5 }] }; - - let loadCount = 0; - gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { - loadCount++; - - // We'll make sure that the loads we get come from pinned tabs or the - // the selected tab. - - // get the tab - let tab; - for (let i = 0; i < window.gBrowser.tabs.length; i++) { - if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser) - tab = window.gBrowser.tabs[i]; - } - - ok(tab.pinned || tab.selected, - "load came from pinned or selected tab"); - - // We should get 4 loads: 3 app tabs + 1 normal selected tab - if (loadCount < 4) - return; - - gProgressListener.unsetCallback(); - executeSoon(next); - }); - - yield ss.setBrowserState(JSON.stringify(state)); -} diff --git a/browser/components/sessionstore/test/browser_586068-apptabs_ondemand.js b/browser/components/sessionstore/test/browser_586068-apptabs_ondemand.js deleted file mode 100644 index 3a9b0a35b..000000000 --- a/browser/components/sessionstore/test/browser_586068-apptabs_ondemand.js +++ /dev/null @@ -1,50 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand"; -const PREF_RESTORE_PINNED_TABS_ON_DEMAND = "browser.sessionstore.restore_pinned_tabs_on_demand"; - -function test() { - TestRunner.run(); -} - -function runTests() { - Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, true); - Services.prefs.setBoolPref(PREF_RESTORE_PINNED_TABS_ON_DEMAND, true); - - registerCleanupFunction(function () { - Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND); - Services.prefs.clearUserPref(PREF_RESTORE_PINNED_TABS_ON_DEMAND); - }); - - let state = { windows: [{ tabs: [ - { entries: [{ url: "http://example.org/#1" }], extData: { "uniq": r() }, pinned: true }, - { entries: [{ url: "http://example.org/#2" }], extData: { "uniq": r() }, pinned: true }, - { entries: [{ url: "http://example.org/#3" }], extData: { "uniq": r() }, pinned: true }, - { entries: [{ url: "http://example.org/#4" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#5" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#6" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#7" }], extData: { "uniq": r() } }, - ], selected: 5 }] }; - - gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { - // get the tab - let tab; - for (let i = 0; i < window.gBrowser.tabs.length; i++) { - if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser) - tab = window.gBrowser.tabs[i]; - } - - // Check that the load only comes from the selected tab. - ok(tab.selected, "load came from selected tab"); - is(aNeedRestore, 6, "six tabs left to restore"); - is(aRestoring, 1, "one tab is restoring"); - is(aRestored, 0, "no tabs have been restored, yet"); - - gProgressListener.unsetCallback(); - executeSoon(next); - }); - - yield ss.setBrowserState(JSON.stringify(state)); -} diff --git a/browser/components/sessionstore/test/browser_586068-browser_state_interrupted.js b/browser/components/sessionstore/test/browser_586068-browser_state_interrupted.js deleted file mode 100644 index 9a440fda9..000000000 --- a/browser/components/sessionstore/test/browser_586068-browser_state_interrupted.js +++ /dev/null @@ -1,108 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand"; - -function test() { - TestRunner.run(); -} - -function runTests() { - Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false); - registerCleanupFunction(function () { - Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND); - }); - - // The first state will be loaded using setBrowserState, followed by the 2nd - // state also being loaded using setBrowserState, interrupting the first restore. - let state1 = { windows: [ - { - tabs: [ - { entries: [{ url: "http://example.org#1" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org#2" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org#3" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org#4" }], extData: { "uniq": r() } } - ], - selected: 1 - }, - { - tabs: [ - { entries: [{ url: "http://example.com#1" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com#2" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com#3" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com#4" }], extData: { "uniq": r() } }, - ], - selected: 3 - } - ] }; - let state2 = { windows: [ - { - tabs: [ - { entries: [{ url: "http://example.org#5" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org#6" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org#7" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org#8" }], extData: { "uniq": r() } } - ], - selected: 3 - }, - { - tabs: [ - { entries: [{ url: "http://example.com#5" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com#6" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com#7" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com#8" }], extData: { "uniq": r() } }, - ], - selected: 1 - } - ] }; - - // interruptedAfter will be set after the selected tab from each window have loaded. - let interruptedAfter = 0; - let loadedWindow1 = false; - let loadedWindow2 = false; - let numTabs = state2.windows[0].tabs.length + state2.windows[1].tabs.length; - - let loadCount = 0; - gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { - loadCount++; - - if (aBrowser.currentURI.spec == state1.windows[0].tabs[2].entries[0].url) - loadedWindow1 = true; - if (aBrowser.currentURI.spec == state1.windows[1].tabs[0].entries[0].url) - loadedWindow2 = true; - - if (!interruptedAfter && loadedWindow1 && loadedWindow2) { - interruptedAfter = loadCount; - ss.setBrowserState(JSON.stringify(state2)); - return; - } - - if (loadCount < numTabs + interruptedAfter) - return; - - // We don't actually care about load order in this test, just that they all - // do load. - is(loadCount, numTabs + interruptedAfter, "all tabs were restored"); - is(aNeedRestore, 0, "there are no tabs left needing restore"); - - // Remove the progress listener from this window, it will be removed from - // theWin when that window is closed (in setBrowserState). - gProgressListener.unsetCallback(); - executeSoon(next); - }); - - // We also want to catch the extra windows (there should be 2), so we need to observe domwindowopened - Services.ww.registerNotification(function observer(aSubject, aTopic, aData) { - if (aTopic == "domwindowopened") { - let win = aSubject.QueryInterface(Ci.nsIDOMWindow); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); - Services.ww.unregisterNotification(observer); - win.gBrowser.addTabsProgressListener(gProgressListener); - }); - } - }); - - yield ss.setBrowserState(JSON.stringify(state1)); -} diff --git a/browser/components/sessionstore/test/browser_586068-cascade.js b/browser/components/sessionstore/test/browser_586068-cascade.js deleted file mode 100644 index 9c49bdf2d..000000000 --- a/browser/components/sessionstore/test/browser_586068-cascade.js +++ /dev/null @@ -1,51 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand"; - -function test() { - TestRunner.run(); -} - -function runTests() { - Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false); - registerCleanupFunction(function () { - Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND); - }); - - let state = { windows: [{ tabs: [ - { entries: [{ url: "http://example.com" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com" }], extData: { "uniq": r() } } - ] }] }; - - let expectedCounts = [ - [3, 3, 0], - [2, 3, 1], - [1, 3, 2], - [0, 3, 3], - [0, 2, 4], - [0, 1, 5] - ]; - - let loadCount = 0; - gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { - loadCount++; - let expected = expectedCounts[loadCount - 1]; - - is(aNeedRestore, expected[0], "load " + loadCount + " - # tabs that need to be restored"); - is(aRestoring, expected[1], "load " + loadCount + " - # tabs that are restoring"); - is(aRestored, expected[2], "load " + loadCount + " - # tabs that has been restored"); - - if (loadCount == state.windows[0].tabs.length) { - gProgressListener.unsetCallback(); - executeSoon(next); - } - }); - - yield ss.setBrowserState(JSON.stringify(state)); -} diff --git a/browser/components/sessionstore/test/browser_586068-multi_window.js b/browser/components/sessionstore/test/browser_586068-multi_window.js deleted file mode 100644 index f69de2e45..000000000 --- a/browser/components/sessionstore/test/browser_586068-multi_window.js +++ /dev/null @@ -1,66 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand"; - -function test() { - TestRunner.run(); -} - -function runTests() { - Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false); - registerCleanupFunction(function () { - Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND); - }); - - // The first window will be put into the already open window and the second - // window will be opened with _openWindowWithState, which is the source of the problem. - let state = { windows: [ - { - tabs: [ - { entries: [{ url: "http://example.org#0" }], extData: { "uniq": r() } } - ], - selected: 1 - }, - { - tabs: [ - { entries: [{ url: "http://example.com#1" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com#2" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com#3" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com#4" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com#5" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com#6" }], extData: { "uniq": r() } } - ], - selected: 4 - } - ] }; - let numTabs = state.windows[0].tabs.length + state.windows[1].tabs.length; - - let loadCount = 0; - gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { - if (++loadCount == numTabs) { - // We don't actually care about load order in this test, just that they all - // do load. - is(loadCount, numTabs, "all tabs were restored"); - is(aNeedRestore, 0, "there are no tabs left needing restore"); - - gProgressListener.unsetCallback(); - executeSoon(next); - } - }); - - // We also want to catch the 2nd window, so we need to observe domwindowopened - Services.ww.registerNotification(function observer(aSubject, aTopic, aData) { - if (aTopic == "domwindowopened") { - let win = aSubject.QueryInterface(Ci.nsIDOMWindow); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad); - Services.ww.unregisterNotification(observer); - win.gBrowser.addTabsProgressListener(gProgressListener); - }); - } - }); - - yield ss.setBrowserState(JSON.stringify(state)); -} diff --git a/browser/components/sessionstore/test/browser_586068-reload.js b/browser/components/sessionstore/test/browser_586068-reload.js deleted file mode 100644 index f68d7a0bb..000000000 --- a/browser/components/sessionstore/test/browser_586068-reload.js +++ /dev/null @@ -1,140 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand"; - -function test() { - TestRunner.run(); -} - -function runTests() { - // Request a longer timeout because the test takes quite a while - // to complete on slow Windows debug machines and we would otherwise - // see a lot of (not so) intermittent test failures. - requestLongerTimeout(2); - - Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, true); - registerCleanupFunction(function () { - Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND); - }); - - let state = { windows: [{ tabs: [ - { entries: [{ url: "http://example.org/#1" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#2" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#3" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#4" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#5" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#6" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#7" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#8" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#9" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#10" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#11" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#12" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#13" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#14" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#15" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#16" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#17" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org/#18" }], extData: { "uniq": r() } } - ], selected: 1 }] }; - - let loadCount = 0; - gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { - loadCount++; - is(aBrowser.currentURI.spec, state.windows[0].tabs[loadCount - 1].entries[0].url, - "load " + loadCount + " - browser loaded correct url"); - - if (loadCount <= state.windows[0].tabs.length) { - // double check that this tab was the right one - let expectedData = state.windows[0].tabs[loadCount - 1].extData.uniq; - let tab; - for (let i = 0; i < window.gBrowser.tabs.length; i++) { - if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser) - tab = window.gBrowser.tabs[i]; - } - is(ss.getTabValue(tab, "uniq"), expectedData, - "load " + loadCount + " - correct tab was restored"); - - if (loadCount == state.windows[0].tabs.length) { - gProgressListener.unsetCallback(); - executeSoon(function () { - reloadAllTabs(state, function () { - waitForBrowserState(TestRunner.backupState, testCascade); - }); - }); - } else { - // reload the next tab - window.gBrowser.reloadTab(window.gBrowser.tabs[loadCount]); - } - } - }); - - yield ss.setBrowserState(JSON.stringify(state)); -} - -function testCascade() { - Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false); - - let state = { windows: [{ tabs: [ - { entries: [{ url: "http://example.com/#1" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com/#2" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com/#3" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com/#4" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com/#5" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com/#6" }], extData: { "uniq": r() } } - ] }] }; - - let loadCount = 0; - gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { - if (++loadCount < state.windows[0].tabs.length) { - return; - } - - gProgressListener.unsetCallback(); - executeSoon(function () { - reloadAllTabs(state, next); - }); - }); - - ss.setBrowserState(JSON.stringify(state)); -} - -function reloadAllTabs(aState, aCallback) { - // Simulate a left mouse button click with no modifiers, which is what - // Command-R, or clicking reload does. - let fakeEvent = { - button: 0, - metaKey: false, - altKey: false, - ctrlKey: false, - shiftKey: false - }; - - let loadCount = 0; - gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { - if (++loadCount <= aState.windows[0].tabs.length) { - // double check that this tab was the right one - let expectedData = aState.windows[0].tabs[loadCount - 1].extData.uniq; - let tab; - for (let i = 0; i < window.gBrowser.tabs.length; i++) { - if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser) - tab = window.gBrowser.tabs[i]; - } - is(ss.getTabValue(tab, "uniq"), expectedData, - "load " + loadCount + " - correct tab was reloaded"); - - if (loadCount == aState.windows[0].tabs.length) { - gProgressListener.unsetCallback(); - executeSoon(aCallback); - } else { - // reload the next tab - window.gBrowser.selectTabAtIndex(loadCount); - BrowserReloadOrDuplicate(fakeEvent); - } - } - }, false); - - BrowserReloadOrDuplicate(fakeEvent); -} diff --git a/browser/components/sessionstore/test/browser_586068-select.js b/browser/components/sessionstore/test/browser_586068-select.js deleted file mode 100644 index 66a947236..000000000 --- a/browser/components/sessionstore/test/browser_586068-select.js +++ /dev/null @@ -1,66 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand"; - -function test() { - TestRunner.run(); -} - -function runTests() { - Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, true); - registerCleanupFunction(function () { - Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND); - }); - - let state = { windows: [{ tabs: [ - { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } } - ], selected: 1 }] }; - - let expectedCounts = [ - [5, 1, 0], - [4, 1, 1], - [3, 1, 2], - [2, 1, 3], - [1, 1, 4], - [0, 1, 5] - ]; - let tabOrder = [0, 5, 1, 4, 3, 2]; - - let loadCount = 0; - gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { - loadCount++; - let expected = expectedCounts[loadCount - 1]; - - is(aNeedRestore, expected[0], "load " + loadCount + " - # tabs that need to be restored"); - is(aRestoring, expected[1], "load " + loadCount + " - # tabs that are restoring"); - is(aRestored, expected[2], "load " + loadCount + " - # tabs that has been restored"); - - if (loadCount < state.windows[0].tabs.length) { - // double check that this tab was the right one - let expectedData = state.windows[0].tabs[tabOrder[loadCount - 1]].extData.uniq; - let tab; - for (let i = 0; i < window.gBrowser.tabs.length; i++) { - if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser) - tab = window.gBrowser.tabs[i]; - } - - is(ss.getTabValue(tab, "uniq"), expectedData, - "load " + loadCount + " - correct tab was restored"); - - // select the next tab - window.gBrowser.selectTabAtIndex(tabOrder[loadCount]); - } else { - gProgressListener.unsetCallback(); - executeSoon(next); - } - }); - - yield ss.setBrowserState(JSON.stringify(state)); -} diff --git a/browser/components/sessionstore/test/browser_586068-window_state.js b/browser/components/sessionstore/test/browser_586068-window_state.js deleted file mode 100644 index 9fb9424eb..000000000 --- a/browser/components/sessionstore/test/browser_586068-window_state.js +++ /dev/null @@ -1,60 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand"; - -function test() { - TestRunner.run(); -} - -function runTests() { - Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false); - registerCleanupFunction(function () { - Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND); - }); - - // We'll use 2 states so that we can make sure calling setWindowState doesn't - // wipe out currently restoring data. - let state1 = { windows: [{ tabs: [ - { entries: [{ url: "http://example.com#1" }] }, - { entries: [{ url: "http://example.com#2" }] }, - { entries: [{ url: "http://example.com#3" }] }, - { entries: [{ url: "http://example.com#4" }] }, - { entries: [{ url: "http://example.com#5" }] }, - ] }] }; - let state2 = { windows: [{ tabs: [ - { entries: [{ url: "http://example.org#1" }] }, - { entries: [{ url: "http://example.org#2" }] }, - { entries: [{ url: "http://example.org#3" }] }, - { entries: [{ url: "http://example.org#4" }] }, - { entries: [{ url: "http://example.org#5" }] } - ] }] }; - let numTabs = state1.windows[0].tabs.length + state2.windows[0].tabs.length; - - let loadCount = 0; - gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { - // When loadCount == 2, we'll also restore state2 into the window - if (++loadCount == 2) { - ss.setWindowState(window, JSON.stringify(state2), false); - } - - if (loadCount < numTabs) { - return; - } - - // We don't actually care about load order in this test, just that they all - // do load. - is(loadCount, numTabs, "test_setWindowStateNoOverwrite: all tabs were restored"); - // window.__SS_tabsToRestore isn't decremented until after the progress - // listener is called. Since we get in here before that, we still expect - // the count to be 1. - is(window.__SS_tabsToRestore, 1, "window doesn't think there are more tabs to restore"); - is(aNeedRestore, 0, "there are no tabs left needing restore"); - - gProgressListener.unsetCallback(); - executeSoon(next); - }); - - yield ss.setWindowState(window, JSON.stringify(state1), true); -} diff --git a/browser/components/sessionstore/test/browser_586068-window_state_override.js b/browser/components/sessionstore/test/browser_586068-window_state_override.js deleted file mode 100644 index f20eea13c..000000000 --- a/browser/components/sessionstore/test/browser_586068-window_state_override.js +++ /dev/null @@ -1,60 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand"; - -function test() { - TestRunner.run(); -} - -function runTests() { - Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false); - registerCleanupFunction(function () { - Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND); - }); - - // We'll use 2 states so that we can make sure calling setWindowState doesn't - // wipe out currently restoring data. - let state1 = { windows: [{ tabs: [ - { entries: [{ url: "http://example.com#1" }] }, - { entries: [{ url: "http://example.com#2" }] }, - { entries: [{ url: "http://example.com#3" }] }, - { entries: [{ url: "http://example.com#4" }] }, - { entries: [{ url: "http://example.com#5" }] }, - ] }] }; - let state2 = { windows: [{ tabs: [ - { entries: [{ url: "http://example.org#1" }] }, - { entries: [{ url: "http://example.org#2" }] }, - { entries: [{ url: "http://example.org#3" }] }, - { entries: [{ url: "http://example.org#4" }] }, - { entries: [{ url: "http://example.org#5" }] } - ] }] }; - let numTabs = 2 + state2.windows[0].tabs.length; - - let loadCount = 0; - gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { - // When loadCount == 2, we'll also restore state2 into the window - if (++loadCount == 2) { - ss.setWindowState(window, JSON.stringify(state2), true); - } - - if (loadCount < numTabs) { - return; - } - - // We don't actually care about load order in this test, just that they all - // do load. - is(loadCount, numTabs, "all tabs were restored"); - // window.__SS_tabsToRestore isn't decremented until after the progress - // listener is called. Since we get in here before that, we still expect - // the count to be 1. - is(window.__SS_tabsToRestore, 1, "window doesn't think there are more tabs to restore"); - is(aNeedRestore, 0, "there are no tabs left needing restore"); - - gProgressListener.unsetCallback(); - executeSoon(next); - }); - - yield ss.setWindowState(window, JSON.stringify(state1), true); -} diff --git a/browser/components/sessionstore/test/browser_586147.js b/browser/components/sessionstore/test/browser_586147.js deleted file mode 100644 index d70f406b9..000000000 --- a/browser/components/sessionstore/test/browser_586147.js +++ /dev/null @@ -1,52 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function observeOneRestore(callback) { - let topic = "sessionstore-browser-state-restored"; - Services.obs.addObserver(function onRestore() { - Services.obs.removeObserver(onRestore, topic); - callback(); - }, topic, false); -}; - -function test() { - waitForExplicitFinish(); - ignoreAllUncaughtExceptions(); - - // There should be one tab when we start the test - let [origTab] = gBrowser.visibleTabs; - let hiddenTab = gBrowser.addTab(); - - is(gBrowser.visibleTabs.length, 2, "should have 2 tabs before hiding"); - gBrowser.showOnlyTheseTabs([origTab]); - is(gBrowser.visibleTabs.length, 1, "only 1 after hiding"); - ok(hiddenTab.hidden, "sanity check that it's hidden"); - - let extraTab = gBrowser.addTab(); - let state = ss.getBrowserState(); - let stateObj = JSON.parse(state); - let tabs = stateObj.windows[0].tabs; - is(tabs.length, 3, "just checking that browser state is correct"); - ok(!tabs[0].hidden, "first tab is visible"); - ok(tabs[1].hidden, "second is hidden"); - ok(!tabs[2].hidden, "third is visible"); - - // Make the third tab hidden and then restore the modified state object - tabs[2].hidden = true; - - observeOneRestore(function() { - let testWindow = Services.wm.getEnumerator("navigator:browser").getNext(); - is(testWindow.gBrowser.visibleTabs.length, 1, "only restored 1 visible tab"); - let tabs = testWindow.gBrowser.tabs; - ok(!tabs[0].hidden, "first is still visible"); - ok(tabs[1].hidden, "second tab is still hidden"); - ok(tabs[2].hidden, "third tab is now hidden"); - - // Restore the original state and clean up now that we're done - gBrowser.removeTab(hiddenTab); - gBrowser.removeTab(extraTab); - finish(); - }); - ss.setBrowserState(JSON.stringify(stateObj)); -} diff --git a/browser/components/sessionstore/test/browser_588426.js b/browser/components/sessionstore/test/browser_588426.js deleted file mode 100644 index 7a20fd0a6..000000000 --- a/browser/components/sessionstore/test/browser_588426.js +++ /dev/null @@ -1,41 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -function test() { - let state = { windows: [{ tabs: [ - {entries: [{url: "about:mozilla"}], hidden: true}, - {entries: [{url: "about:rights"}], hidden: true} - ] }] }; - - waitForExplicitFinish(); - - newWindowWithState(state, function (win) { - registerCleanupFunction(function () win.close()); - - is(win.gBrowser.tabs.length, 2, "two tabs were restored"); - is(win.gBrowser.visibleTabs.length, 1, "one tab is visible"); - - let tab = win.gBrowser.visibleTabs[0]; - is(tab.linkedBrowser.currentURI.spec, "about:mozilla", "visible tab is about:mozilla"); - - finish(); - }); -} - -function newWindowWithState(state, callback) { - let opts = "chrome,all,dialog=no,height=800,width=800"; - let win = window.openDialog(getBrowserURL(), "_blank", opts); - - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - - executeSoon(function () { - win.addEventListener("SSWindowStateReady", function onReady() { - win.removeEventListener("SSWindowStateReady", onReady, false); - executeSoon(function () callback(win)); - }, false); - - ss.setWindowState(win, JSON.stringify(state), true); - }); - }, false); -} diff --git a/browser/components/sessionstore/test/browser_589246.js b/browser/components/sessionstore/test/browser_589246.js deleted file mode 100644 index 379d038e1..000000000 --- a/browser/components/sessionstore/test/browser_589246.js +++ /dev/null @@ -1,243 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// Mirrors WINDOW_ATTRIBUTES IN nsSessionStore.js -const WINDOW_ATTRIBUTES = ["width", "height", "screenX", "screenY", "sizemode"]; - -let stateBackup = ss.getBrowserState(); - -let originalWarnOnClose = gPrefService.getBoolPref("browser.tabs.warnOnClose"); -let originalStartupPage = gPrefService.getIntPref("browser.startup.page"); -let originalWindowType = document.documentElement.getAttribute("windowtype"); - -let gotLastWindowClosedTopic = false; -let shouldPinTab = false; -let shouldOpenTabs = false; -let shouldCloseTab = false; -let testNum = 0; -let afterTestCallback; - -// Set state so we know the closed windows content -let testState = { - windows: [ - { tabs: [{ entries: [{ url: "http://example.org" }] }] } - ], - _closedWindows: [] -}; - -// We'll push a set of conditions and callbacks into this array -// Ideally we would also test win/linux under a complete set of conditions, but -// the tests for osx mirror the other set of conditions possible on win/linux. -let tests = []; - -// the third & fourth test share a condition check, keep it DRY -function checkOSX34Generator(num) { - return function(aPreviousState, aCurState) { - // In here, we should have restored the pinned tab, so only the unpinned tab - // should be in aCurState. So let's shape our expectations. - let expectedState = JSON.parse(aPreviousState); - expectedState[0].tabs.shift(); - // size attributes are stripped out in _prepDataForDeferredRestore in nsSessionStore. - // This isn't the best approach, but neither is comparing JSON strings - WINDOW_ATTRIBUTES.forEach(function (attr) delete expectedState[0][attr]); - - is(aCurState, JSON.stringify(expectedState), - "test #" + num + ": closedWindowState is as expected"); - }; -} -function checkNoWindowsGenerator(num) { - return function(aPreviousState, aCurState) { - is(aCurState, "[]", "test #" + num + ": there should be no closedWindowsLeft"); - }; -} - -// The first test has 0 pinned tabs and 1 unpinned tab -tests.push({ - pinned: false, - extra: false, - close: false, - checkWinLin: checkNoWindowsGenerator(1), - checkOSX: function(aPreviousState, aCurState) { - is(aCurState, aPreviousState, "test #1: closed window state is unchanged"); - } -}); - -// The second test has 1 pinned tab and 0 unpinned tabs. -tests.push({ - pinned: true, - extra: false, - close: false, - checkWinLin: checkNoWindowsGenerator(2), - checkOSX: checkNoWindowsGenerator(2) -}); - -// The third test has 1 pinned tab and 2 unpinned tabs. -tests.push({ - pinned: true, - extra: true, - close: false, - checkWinLin: checkNoWindowsGenerator(3), - checkOSX: checkOSX34Generator(3) -}); - -// The fourth test has 1 pinned tab, 2 unpinned tabs, and closes one unpinned tab. -tests.push({ - pinned: true, - extra: true, - close: "one", - checkWinLin: checkNoWindowsGenerator(4), - checkOSX: checkOSX34Generator(4) -}); - -// The fifth test has 1 pinned tab, 2 unpinned tabs, and closes both unpinned tabs. -tests.push({ - pinned: true, - extra: true, - close: "both", - checkWinLin: checkNoWindowsGenerator(5), - checkOSX: checkNoWindowsGenerator(5) -}); - - -function test() { - /** Test for Bug 589246 - Closed window state getting corrupted when closing - and reopening last browser window without exiting browser **/ - waitForExplicitFinish(); - // windows opening & closing, so extending the timeout - requestLongerTimeout(2); - - // We don't want the quit dialog pref - gPrefService.setBoolPref("browser.tabs.warnOnClose", false); - // Ensure that we would restore the session (important for Windows) - gPrefService.setIntPref("browser.startup.page", 3); - - runNextTestOrFinish(); -} - -function runNextTestOrFinish() { - if (tests.length) { - setupForTest(tests.shift()) - } - else { - // some state is cleaned up at the end of each test, but not all - ["browser.tabs.warnOnClose", "browser.startup.page"].forEach(function(p) { - if (gPrefService.prefHasUserValue(p)) - gPrefService.clearUserPref(p); - }); - - ss.setBrowserState(stateBackup); - executeSoon(finish); - } -} - -function setupForTest(aConditions) { - // reset some checks - gotLastWindowClosedTopic = false; - shouldPinTab = aConditions.pinned; - shouldOpenTabs = aConditions.extra; - shouldCloseTab = aConditions.close; - testNum++; - - // set our test callback - afterTestCallback = /Mac/.test(navigator.platform) ? aConditions.checkOSX - : aConditions.checkWinLin; - - // Add observers - Services.obs.addObserver(onLastWindowClosed, "browser-lastwindow-close-granted", false); - - // Set the state - Services.obs.addObserver(onStateRestored, "sessionstore-browser-state-restored", false); - ss.setBrowserState(JSON.stringify(testState)); -} - -function onStateRestored(aSubject, aTopic, aData) { - info("test #" + testNum + ": onStateRestored"); - Services.obs.removeObserver(onStateRestored, "sessionstore-browser-state-restored"); - - // change this window's windowtype so that closing a new window will trigger - // browser-lastwindow-close-granted. - document.documentElement.setAttribute("windowtype", "navigator:testrunner"); - - let newWin = openDialog(location, "_blank", "chrome,all,dialog=no", "http://example.com"); - newWin.addEventListener("load", function(aEvent) { - newWin.removeEventListener("load", arguments.callee, false); - - newWin.gBrowser.selectedBrowser.addEventListener("load", function() { - newWin.gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); - - // pin this tab - if (shouldPinTab) - newWin.gBrowser.pinTab(newWin.gBrowser.selectedTab); - - newWin.addEventListener("unload", function () { - newWin.removeEventListener("unload", arguments.callee, false); - onWindowUnloaded(); - }, false); - // Open a new tab as well. On Windows/Linux this will be restored when the - // new window is opened below (in onWindowUnloaded). On OS X we'll just - // restore the pinned tabs, leaving the unpinned tab in the closedWindowsData. - if (shouldOpenTabs) { - let newTab = newWin.gBrowser.addTab("about:config"); - let newTab2 = newWin.gBrowser.addTab("about:buildconfig"); - - newTab.linkedBrowser.addEventListener("load", function() { - newTab.linkedBrowser.removeEventListener("load", arguments.callee, true); - - if (shouldCloseTab == "one") { - newWin.gBrowser.removeTab(newTab2); - } - else if (shouldCloseTab == "both") { - newWin.gBrowser.removeTab(newTab); - newWin.gBrowser.removeTab(newTab2); - } - newWin.BrowserTryToCloseWindow(); - }, true); - } - else { - newWin.BrowserTryToCloseWindow(); - } - }, true); - }, false); -} - -// This will be called before the window is actually closed -function onLastWindowClosed(aSubject, aTopic, aData) { - info("test #" + testNum + ": onLastWindowClosed"); - Services.obs.removeObserver(onLastWindowClosed, "browser-lastwindow-close-granted"); - gotLastWindowClosedTopic = true; -} - -// This is the unload event listener on the new window (from onStateRestored). -// Unload is fired after the window is closed, so sessionstore has already -// updated _closedWindows (which is important). We'll open a new window here -// which should actually trigger the bug. -function onWindowUnloaded() { - info("test #" + testNum + ": onWindowClosed"); - ok(gotLastWindowClosedTopic, "test #" + testNum + ": browser-lastwindow-close-granted was notified prior"); - - let previousClosedWindowData = ss.getClosedWindowData(); - - // Now we want to open a new window - let newWin = openDialog(location, "_blank", "chrome,all,dialog=no", "about:mozilla"); - newWin.addEventListener("load", function(aEvent) { - newWin.removeEventListener("load", arguments.callee, false); - - newWin.gBrowser.selectedBrowser.addEventListener("load", function () { - newWin.gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); - - // Good enough for checking the state - afterTestCallback(previousClosedWindowData, ss.getClosedWindowData()); - afterTestCleanup(newWin); - }, true); - - }, false); -} - -function afterTestCleanup(aNewWin) { - executeSoon(function() { - aNewWin.close(); - document.documentElement.setAttribute("windowtype", originalWindowType); - runNextTestOrFinish(); - }); -} diff --git a/browser/components/sessionstore/test/browser_590268.js b/browser/components/sessionstore/test/browser_590268.js deleted file mode 100644 index 34eef0e0c..000000000 --- a/browser/components/sessionstore/test/browser_590268.js +++ /dev/null @@ -1,136 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const NUM_TABS = 12; - -let stateBackup = ss.getBrowserState(); - -function test() { - /** Test for Bug 590268 - Provide access to sessionstore tab data sooner **/ - waitForExplicitFinish(); - - let startedTest = false; - - // wasLoaded will be used to keep track of tabs that have already had SSTabRestoring - // fired for them. - let wasLoaded = { }; - let restoringTabsCount = 0; - let restoredTabsCount = 0; - let uniq2 = { }; - let uniq2Count = 0; - let state = { windows: [{ tabs: [] }] }; - // We're going to put a bunch of tabs into this state - for (let i = 0; i < NUM_TABS; i++) { - let uniq = r(); - let tabData = { - entries: [{ url: "http://example.com/#" + i }], - extData: { "uniq": uniq, "baz": "qux" } - }; - state.windows[0].tabs.push(tabData); - wasLoaded[uniq] = false; - } - - - function onSSTabRestoring(aEvent) { - restoringTabsCount++; - let uniq = ss.getTabValue(aEvent.originalTarget, "uniq"); - wasLoaded[uniq] = true; - - is(ss.getTabValue(aEvent.originalTarget, "foo"), "", - "There is no value for 'foo'"); - - // On the first SSTabRestoring we're going to run the the real test. - // We'll keep this listener around so we can keep marking tabs as restored. - if (restoringTabsCount == 1) - onFirstSSTabRestoring(); - else if (restoringTabsCount == NUM_TABS) - onLastSSTabRestoring(); - } - - function onSSTabRestored(aEvent) { - if (++restoredTabsCount < NUM_TABS) - return; - cleanup(); - } - - function onTabOpen(aEvent) { - // To test bug 614708, we'll just set a value on the tab here. This value - // would previously cause us to not recognize the values in extData until - // much later. So testing "uniq" failed. - ss.setTabValue(aEvent.originalTarget, "foo", "bar"); - } - - // This does the actual testing. SSTabRestoring should be firing on tabs from - // left to right, so we're going to start with the rightmost tab. - function onFirstSSTabRestoring() { - info("onFirstSSTabRestoring..."); - for (let i = gBrowser.tabs.length - 1; i >= 0; i--) { - let tab = gBrowser.tabs[i]; - let actualUniq = ss.getTabValue(tab, "uniq"); - let expectedUniq = state.windows[0].tabs[i].extData["uniq"]; - - if (wasLoaded[actualUniq]) { - info("tab " + i + ": already restored"); - continue; - } - is(actualUniq, expectedUniq, "tab " + i + ": extData was correct"); - - // Now we're going to set a piece of data back on the tab so it can be read - // to test setting a value "early". - uniq2[actualUniq] = r(); - ss.setTabValue(tab, "uniq2", uniq2[actualUniq]); - - // Delete the value we have for "baz". This tests that deleteTabValue - // will delete "early access" values (c.f. bug 617175). If this doesn't throw - // then the test is successful. - try { - ss.deleteTabValue(tab, "baz"); - } - catch (e) { - ok(false, "no error calling deleteTabValue - " + e); - } - - // This will be used in the final comparison to make sure we checked the - // same number as we set. - uniq2Count++; - } - } - - function onLastSSTabRestoring() { - let checked = 0; - for (let i = 0; i < gBrowser.tabs.length; i++) { - let tab = gBrowser.tabs[i]; - let uniq = ss.getTabValue(tab, "uniq"); - - // Look to see if we set a uniq2 value for this uniq value - if (uniq in uniq2) { - is(ss.getTabValue(tab, "uniq2"), uniq2[uniq], "tab " + i + " has correct uniq2 value"); - checked++; - } - } - ok(uniq2Count > 0, "at least 1 tab properly checked 'early access'"); - is(checked, uniq2Count, "checked the same number of uniq2 as we set"); - } - - function cleanup() { - // remove the event listener and clean up before finishing - gBrowser.tabContainer.removeEventListener("SSTabRestoring", onSSTabRestoring, false); - gBrowser.tabContainer.removeEventListener("SSTabRestored", onSSTabRestored, true); - gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, false); - // Put this in an executeSoon because we still haven't called restoreNextTab - // in sessionstore for the last tab (we'll call it after this). We end up - // trying to restore the tab (since we then add a closed tab to the array). - executeSoon(function() { - ss.setBrowserState(stateBackup); - executeSoon(finish); - }); - } - - // Add the event listeners - gBrowser.tabContainer.addEventListener("SSTabRestoring", onSSTabRestoring, false); - gBrowser.tabContainer.addEventListener("SSTabRestored", onSSTabRestored, true); - gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, false); - // Restore state - ss.setBrowserState(JSON.stringify(state)); -} diff --git a/browser/components/sessionstore/test/browser_590563.js b/browser/components/sessionstore/test/browser_590563.js deleted file mode 100644 index 2ede82323..000000000 --- a/browser/components/sessionstore/test/browser_590563.js +++ /dev/null @@ -1,78 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -function test() { - let oldState = { - windows: [{ - tabs: [ - { entries: [{ url: "about:mozilla" }], hidden: true }, - { entries: [{ url: "about:blank" }], hidden: false } - ] - }] - }; - let pageData = { - url: "about:sessionrestore", - formdata: { id: { "sessionData": oldState } } - }; - let state = { windows: [{ tabs: [{ entries: [pageData] }] }] }; - - waitForExplicitFinish(); - - newWindowWithState(state, function (win) { - registerCleanupFunction(function () win.close()); - - is(gBrowser.tabs.length, 1, "The total number of tabs should be 1"); - is(gBrowser.visibleTabs.length, 1, "The total number of visible tabs should be 1"); - - executeSoon(function () { - waitForFocus(function () { - middleClickTest(win); - finish(); - }, win); - }); - }); -} - -function middleClickTest(win) { - let browser = win.gBrowser.selectedBrowser; - let tree = browser.contentDocument.getElementById("tabList"); - is(tree.view.rowCount, 3, "There should be three items"); - - let x = {}, y = {}, width = {}, height = {}; - - // click on the first tab item - tree.treeBoxObject.getCoordsForCellItem(1, tree.columns[1], "text", x, y, width, height); - EventUtils.synthesizeMouse(tree.body, x.value, y.value, { button: 1 }, - browser.contentWindow); - // click on the second tab item - tree.treeBoxObject.getCoordsForCellItem(2, tree.columns[1], "text", x, y, width, height); - EventUtils.synthesizeMouse(tree.body, x.value, y.value, { button: 1 }, - browser.contentWindow); - - is(win.gBrowser.tabs.length, 3, - "The total number of tabs should be 3 after restoring 2 tabs by middle click."); - is(win.gBrowser.visibleTabs.length, 3, - "The total number of visible tabs should be 3 after restoring 2 tabs by middle click"); -} - -function newWindowWithState(state, callback) { - let opts = "chrome,all,dialog=no,height=800,width=800"; - let win = window.openDialog(getBrowserURL(), "_blank", opts); - - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - - let tab = win.gBrowser.selectedTab; - - // The form data will be restored before SSTabRestored, so we want to listen - // for that on the currently selected tab (it will be reused) - tab.addEventListener("SSTabRestored", function onRestored() { - tab.removeEventListener("SSTabRestored", onRestored, true); - callback(win); - }, true); - - executeSoon(function () { - ss.setWindowState(win, JSON.stringify(state), true); - }); - }, false); -} diff --git a/browser/components/sessionstore/test/browser_595601-restore_hidden.js b/browser/components/sessionstore/test/browser_595601-restore_hidden.js deleted file mode 100644 index cff2d9c5d..000000000 --- a/browser/components/sessionstore/test/browser_595601-restore_hidden.js +++ /dev/null @@ -1,111 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -let state = {windows:[{tabs:[ - {entries:[{url:"http://example.com#1"}]}, - {entries:[{url:"http://example.com#2"}]}, - {entries:[{url:"http://example.com#3"}]}, - {entries:[{url:"http://example.com#4"}]}, - {entries:[{url:"http://example.com#5"}], hidden: true}, - {entries:[{url:"http://example.com#6"}], hidden: true}, - {entries:[{url:"http://example.com#7"}], hidden: true}, - {entries:[{url:"http://example.com#8"}], hidden: true} -]}]}; - -function test() { - waitForExplicitFinish(); - - registerCleanupFunction(function () { - Services.prefs.clearUserPref("browser.sessionstore.restore_hidden_tabs"); - }); - - // First stage: restoreHiddenTabs = true - // Second stage: restoreHiddenTabs = false - test_loadTabs(true, function () { - test_loadTabs(false, finish); - }); -} - -function test_loadTabs(restoreHiddenTabs, callback) { - Services.prefs.setBoolPref("browser.sessionstore.restore_hidden_tabs", restoreHiddenTabs); - - let expectedTabs = restoreHiddenTabs ? 8 : 4; - let firstProgress = true; - - newWindowWithState(state, function (win, needsRestore, isRestoring) { - if (firstProgress) { - firstProgress = false; - is(isRestoring, 3, "restoring 3 tabs concurrently"); - } else { - ok(isRestoring < 4, "restoring max. 3 tabs concurrently"); - } - - // We're explicity checking for (isRestoring == 1) here because the test - // progress listener is called before the session store one. So when we're - // called with one tab left to restore we know that the last tab has - // finished restoring and will soon be handled by the SS listener. - let tabsNeedingRestore = win.gBrowser.tabs.length - needsRestore; - if (isRestoring == 1 && tabsNeedingRestore == expectedTabs) { - is(win.gBrowser.visibleTabs.length, 4, "only 4 visible tabs"); - - TabsProgressListener.uninit(); - executeSoon(callback); - } - }); -} - -let TabsProgressListener = { - init: function (win) { - this.window = win; - - this.window.gBrowser.addTabsProgressListener(this); - }, - - uninit: function () { - this.window.gBrowser.removeTabsProgressListener(this); - - delete this.window; - delete this.callback; - }, - - setCallback: function (callback) { - this.callback = callback; - }, - - onStateChange: function (aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) { - if (this.callback && aBrowser.__SS_restoreState == TAB_STATE_RESTORING && - aStateFlags & Ci.nsIWebProgressListener.STATE_STOP && - aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK && - aStateFlags & Ci.nsIWebProgressListener.STATE_IS_WINDOW) - this.callback.apply(null, [this.window].concat(this.countTabs())); - }, - - countTabs: function () { - let needsRestore = 0, isRestoring = 0; - - for (let i = 0; i < this.window.gBrowser.tabs.length; i++) { - let browser = this.window.gBrowser.tabs[i].linkedBrowser; - if (browser.__SS_restoreState == TAB_STATE_RESTORING) - isRestoring++; - else if (browser.__SS_restoreState == TAB_STATE_NEEDS_RESTORE) - needsRestore++; - } - - return [needsRestore, isRestoring]; - } -} - -// ---------- -function newWindowWithState(state, callback) { - let opts = "chrome,all,dialog=no,height=800,width=800"; - let win = window.openDialog(getBrowserURL(), "_blank", opts); - - registerCleanupFunction(function () win.close()); - - whenWindowLoaded(win, function onWindowLoaded(aWin) { - TabsProgressListener.init(aWin); - TabsProgressListener.setCallback(callback); - - ss.setWindowState(aWin, JSON.stringify(state), true); - }); -} diff --git a/browser/components/sessionstore/test/browser_597071.js b/browser/components/sessionstore/test/browser_597071.js deleted file mode 100644 index bc56718ec..000000000 --- a/browser/components/sessionstore/test/browser_597071.js +++ /dev/null @@ -1,53 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 597071 **/ - - waitForExplicitFinish(); - - // set the pref to 1 greater than it currently is so we have room for an extra - // closed window - let closedWindowCount = ss.getClosedWindowCount(); - Services.prefs.setIntPref("browser.sessionstore.max_windows_undo", - closedWindowCount + 1); - - let currentState = ss.getBrowserState(); - let popupState = { windows:[ - { tabs:[ {entries:[] }], isPopup: true, hidden: "toolbar" } - ] }; - - // set this window to be a popup. - ss.setWindowState(window, JSON.stringify(popupState), true); - - // open a new non-popup window - let newWin = openDialog(location, "", "chrome,all,dialog=no", "http://example.com"); - newWin.addEventListener("load", function(aEvent) { - newWin.removeEventListener("load", arguments.callee, false); - - newWin.gBrowser.addEventListener("load", function(aEvent) { - newWin.gBrowser.removeEventListener("load", arguments.callee, true); - - newWin.gBrowser.addTab().linkedBrowser.stop(); - - // make sure sessionstore sees this window - let state = JSON.parse(ss.getBrowserState()); - is(state.windows.length, 2, "sessionstore knows about this window"); - - newWin.close(); - newWin.addEventListener("unload", function(aEvent) { - newWin.removeEventListener("unload", arguments.callee, false); - - is(ss.getClosedWindowCount(), closedWindowCount + 1, - "increased closed window count"); - - Services.prefs.clearUserPref("browser.sessionstore.max_windows_undo"); - ss.setBrowserState(currentState); - executeSoon(finish); - - }, false); - }, true); - }, false); -} - diff --git a/browser/components/sessionstore/test/browser_597315.js b/browser/components/sessionstore/test/browser_597315.js deleted file mode 100644 index d139e83ae..000000000 --- a/browser/components/sessionstore/test/browser_597315.js +++ /dev/null @@ -1,58 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Test for Bug 597315 - Frameset history does not work properly when restoring a tab **/ - waitForExplicitFinish(); - - let testURL = getRootDirectory(gTestPath) + "browser_597315_index.html"; - let tab = gBrowser.addTab(testURL); - gBrowser.selectedTab = tab; - - waitForLoadsInBrowser(tab.linkedBrowser, 4, function() { - let browser_b = tab.linkedBrowser.contentDocument.getElementsByTagName("frame")[1]; - let document_b = browser_b.contentDocument; - let links = document_b.getElementsByTagName("a"); - - // We're going to click on the first link, so listen for another load event - waitForLoadsInBrowser(tab.linkedBrowser, 1, function() { - waitForLoadsInBrowser(tab.linkedBrowser, 1, function() { - - gBrowser.removeTab(tab); - // wait for 4 loads again... - let newTab = ss.undoCloseTab(window, 0); - - waitForLoadsInBrowser(newTab.linkedBrowser, 4, function() { - gBrowser.goBack(); - waitForLoadsInBrowser(newTab.linkedBrowser, 1, function() { - - let expectedURLEnds = ["a.html", "b.html", "c1.html"]; - let frames = newTab.linkedBrowser.contentDocument.getElementsByTagName("frame"); - for (let i = 0; i < frames.length; i++) { - is(frames[i].contentDocument.location, - getRootDirectory(gTestPath) + "browser_597315_" + expectedURLEnds[i], - "frame " + i + " has the right url"); - } - gBrowser.removeTab(newTab); - executeSoon(finish); - }); - }); - }); - EventUtils.sendMouseEvent({type:"click"}, links[1], browser_b.contentWindow); - }); - EventUtils.sendMouseEvent({type:"click"}, links[0], browser_b.contentWindow); - }); -} - -// helper function -function waitForLoadsInBrowser(aBrowser, aLoadCount, aCallback) { - let loadCount = 0; - aBrowser.addEventListener("load", function(aEvent) { - if (++loadCount < aLoadCount) - return; - - aBrowser.removeEventListener("load", arguments.callee, true); - aCallback(); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_597315_a.html b/browser/components/sessionstore/test/browser_597315_a.html deleted file mode 100644 index 8e7b35d7a..000000000 --- a/browser/components/sessionstore/test/browser_597315_a.html +++ /dev/null @@ -1,5 +0,0 @@ -<html> - <body> - I'm A! - </body> -</html> diff --git a/browser/components/sessionstore/test/browser_597315_b.html b/browser/components/sessionstore/test/browser_597315_b.html deleted file mode 100644 index f8dbfb2a2..000000000 --- a/browser/components/sessionstore/test/browser_597315_b.html +++ /dev/null @@ -1,10 +0,0 @@ -<html> - <body> - I'm B!<br/> - <a target="c" href="browser_597315_c1.html">click me first</a><br/> - <a target="c" href="browser_597315_c2.html">then click me</a><br/> - Close this tab.<br/> - Restore this tab.<br/> - Click back.<br/> - </body> -</html> diff --git a/browser/components/sessionstore/test/browser_597315_c.html b/browser/components/sessionstore/test/browser_597315_c.html deleted file mode 100644 index 0efd7d902..000000000 --- a/browser/components/sessionstore/test/browser_597315_c.html +++ /dev/null @@ -1,5 +0,0 @@ -<html> - <body> - I'm C! - </body> -</html> diff --git a/browser/components/sessionstore/test/browser_597315_c1.html b/browser/components/sessionstore/test/browser_597315_c1.html deleted file mode 100644 index b55c1d45a..000000000 --- a/browser/components/sessionstore/test/browser_597315_c1.html +++ /dev/null @@ -1,5 +0,0 @@ -<html> - <body> - I'm C1! - </body> -</html> diff --git a/browser/components/sessionstore/test/browser_597315_c2.html b/browser/components/sessionstore/test/browser_597315_c2.html deleted file mode 100644 index aec504141..000000000 --- a/browser/components/sessionstore/test/browser_597315_c2.html +++ /dev/null @@ -1,5 +0,0 @@ -<html> - <body> - I'm C2! - </body> -</html> diff --git a/browser/components/sessionstore/test/browser_597315_index.html b/browser/components/sessionstore/test/browser_597315_index.html deleted file mode 100644 index 1465ddf04..000000000 --- a/browser/components/sessionstore/test/browser_597315_index.html +++ /dev/null @@ -1,10 +0,0 @@ -<html> - <frameset cols="20%,80%"> - <frameset rows="30%,70%"> - <frame src="browser_597315_a.html"/> - <frame src="browser_597315_b.html"/> - </frameset> - <frame src="browser_597315_c.html" name="c"/> - </frameset> -</html> - diff --git a/browser/components/sessionstore/test/browser_599909.js b/browser/components/sessionstore/test/browser_599909.js deleted file mode 100644 index 31d190139..000000000 --- a/browser/components/sessionstore/test/browser_599909.js +++ /dev/null @@ -1,113 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -let stateBackup = ss.getBrowserState(); - -function cleanup() { - // Reset the pref - try { - Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand"); - } catch (e) {} - ss.setBrowserState(stateBackup); - executeSoon(finish); -} - -function test() { - /** Bug 599909 - to-be-reloaded tabs don't show up in switch-to-tab **/ - waitForExplicitFinish(); - - // Set the pref to true so we know exactly how many tabs should be restoring at - // any given time. This guarantees that a finishing load won't start another. - Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true); - - let state = { windows: [{ tabs: [ - { entries: [{ url: "http://example.org/#1" }] }, - { entries: [{ url: "http://example.org/#2" }] }, - { entries: [{ url: "http://example.org/#3" }] }, - { entries: [{ url: "http://example.org/#4" }] } - ], selected: 1 }] }; - - let tabsForEnsure = {}; - state.windows[0].tabs.forEach(function(tab) { - tabsForEnsure[tab.entries[0].url] = 1; - }); - - let tabsRestoring = 0; - let tabsRestored = 0; - - function handleEvent(aEvent) { - if (aEvent.type == "SSTabRestoring") - tabsRestoring++; - else - tabsRestored++; - - if (tabsRestoring < state.windows[0].tabs.length || - tabsRestored < 1) - return; - - gBrowser.tabContainer.removeEventListener("SSTabRestoring", handleEvent, true); - gBrowser.tabContainer.removeEventListener("SSTabRestored", handleEvent, true); - executeSoon(function() { - checkAutocompleteResults(tabsForEnsure, cleanup); - }); - } - - // currentURI is set before SSTabRestoring is fired, so we can sucessfully check - // after that has fired for all tabs. Since 1 tab will be restored though, we - // also need to wait for 1 SSTabRestored since currentURI will be set, unset, then set. - gBrowser.tabContainer.addEventListener("SSTabRestoring", handleEvent, true); - gBrowser.tabContainer.addEventListener("SSTabRestored", handleEvent, true); - ss.setBrowserState(JSON.stringify(state)); -} - -// The following was taken from browser/base/content/test/browser_tabMatchesInAwesomebar.js -// so that we could do the same sort of checking. -var gController = Cc["@mozilla.org/autocomplete/controller;1"]. - getService(Ci.nsIAutoCompleteController); - -function checkAutocompleteResults(aExpected, aCallback) { - gController.input = { - timeout: 10, - textValue: "", - searches: ["history"], - searchParam: "enable-actions", - popupOpen: false, - minResultsForPopup: 0, - invalidate: function() {}, - disableAutoComplete: false, - completeDefaultIndex: false, - get popup() { return this; }, - onSearchBegin: function() {}, - onSearchComplete: function () - { - info("Found " + gController.matchCount + " matches."); - // Check to see the expected uris and titles match up (in any order) - for (let i = 0; i < gController.matchCount; i++) { - let uri = gController.getValueAt(i).replace(/^moz-action:[^,]+,/i, ""); - - info("Search for '" + uri + "' in open tabs."); - ok(uri in aExpected, "Registered open page found in autocomplete."); - // Remove the found entry from expected results. - delete aExpected[uri]; - } - - // Make sure there is no reported open page that is not open. - for (let entry in aExpected) { - ok(false, "'" + entry + "' not found in autocomplete."); - } - - executeSoon(aCallback); - }, - setSelectedIndex: function() {}, - get searchCount() { return this.searches.length; }, - getSearchAt: function(aIndex) this.searches[aIndex], - QueryInterface: XPCOMUtils.generateQI([ - Ci.nsIAutoCompleteInput, - Ci.nsIAutoCompletePopup, - ]) - }; - - info("Searching open pages."); - gController.startSearch(Services.prefs.getCharPref("browser.urlbar.restrict.openpage")); -} diff --git a/browser/components/sessionstore/test/browser_600545.js b/browser/components/sessionstore/test/browser_600545.js deleted file mode 100644 index a5a81f5cb..000000000 --- a/browser/components/sessionstore/test/browser_600545.js +++ /dev/null @@ -1,84 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -let stateBackup = ss.getBrowserState(); - -function test() { - /** Test for Bug 600545 **/ - waitForExplicitFinish(); - testBug600545(); -} - -function testBug600545() { - // Set the pref to false to cause non-app tabs to be stripped out on a save - Services.prefs.setBoolPref("browser.sessionstore.resume_from_crash", false); - Services.prefs.setIntPref("browser.sessionstore.interval", 2000); - - registerCleanupFunction(function () { - Services.prefs.clearUserPref("browser.sessionstore.resume_from_crash"); - Services.prefs.clearUserPref("browser.sessionstore.interval"); - }); - - // This tests the following use case: - // When multiple windows are open and browser.sessionstore.resume_from_crash - // preference is false, tab session data for non-active window is stripped for - // non-pinned tabs. This occurs after "sessionstore-state-write" fires which - // will only fire in this case if there is at least one pinned tab. - let state = { windows: [ - { - tabs: [ - { entries: [{ url: "http://example.org#0" }], pinned:true }, - { entries: [{ url: "http://example.com#1" }] }, - { entries: [{ url: "http://example.com#2" }] }, - ], - selected: 2 - }, - { - tabs: [ - { entries: [{ url: "http://example.com#3" }] }, - { entries: [{ url: "http://example.com#4" }] }, - { entries: [{ url: "http://example.com#5" }] }, - { entries: [{ url: "http://example.com#6" }] } - ], - selected: 3 - } - ] }; - - waitForBrowserState(state, function() { - // Need to wait for SessionStore's saveState function to be called - // so that non-pinned tabs will be stripped from non-active window - waitForSaveState(function () { - let expectedNumberOfTabs = getStateTabCount(state); - let retrievedState = JSON.parse(ss.getBrowserState()); - let actualNumberOfTabs = getStateTabCount(retrievedState); - - is(actualNumberOfTabs, expectedNumberOfTabs, - "Number of tabs in retreived session data, matches number of tabs set."); - - done(); - }); - }); -} - -function done() { - // Enumerate windows and close everything but our primary window. We can't - // use waitForFocus() because apparently it's buggy. See bug 599253. - let windowsEnum = Services.wm.getEnumerator("navigator:browser"); - while (windowsEnum.hasMoreElements()) { - let currentWindow = windowsEnum.getNext(); - if (currentWindow != window) - currentWindow.close(); - } - - ss.setBrowserState(stateBackup); - executeSoon(finish); -} - -// Count up the number of tabs in the state data -function getStateTabCount(aState) { - let tabCount = 0; - for (let i in aState.windows) - tabCount += aState.windows[i].tabs.length; - return tabCount; -} diff --git a/browser/components/sessionstore/test/browser_601955.js b/browser/components/sessionstore/test/browser_601955.js deleted file mode 100644 index f1044d459..000000000 --- a/browser/components/sessionstore/test/browser_601955.js +++ /dev/null @@ -1,54 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This tests that pinning/unpinning a tab, on its own, eventually triggers a -// session store. - -function test() { - waitForExplicitFinish(); - // We speed up the interval between session saves to ensure that the test - // runs quickly. - Services.prefs.setIntPref("browser.sessionstore.interval", 2000); - - // Loading a tab causes a save state and this is meant to catch that event. - waitForSaveState(testBug601955_1); - - // Assumption: Only one window is open and it has one tab open. - gBrowser.addTab("about:mozilla"); -} - -function testBug601955_1() { - // Because pinned tabs are at the front of |gBrowser.tabs|, pinning tabs - // re-arranges the |tabs| array. - ok(!gBrowser.tabs[0].pinned, "first tab should not be pinned yet"); - ok(!gBrowser.tabs[1].pinned, "second tab should not be pinned yet"); - - waitForSaveState(testBug601955_2); - gBrowser.pinTab(gBrowser.tabs[0]); -} - -function testBug601955_2() { - let state = JSON.parse(ss.getBrowserState()); - ok(state.windows[0].tabs[0].pinned, "first tab should be pinned by now"); - ok(!state.windows[0].tabs[1].pinned, "second tab should still not be pinned"); - - waitForSaveState(testBug601955_3); - gBrowser.unpinTab(window.gBrowser.tabs[0]); -} - -function testBug601955_3() { - let state = JSON.parse(ss.getBrowserState()); - ok(!state.windows[0].tabs[0].pinned, "first tab should not be pinned"); - ok(!state.windows[0].tabs[1].pinned, "second tab should not be pinned"); - - done(); -} - -function done() { - gBrowser.removeTab(window.gBrowser.tabs[0]); - - Services.prefs.clearUserPref("browser.sessionstore.interval"); - - executeSoon(finish); -} diff --git a/browser/components/sessionstore/test/browser_607016.js b/browser/components/sessionstore/test/browser_607016.js deleted file mode 100644 index 6534b6e45..000000000 --- a/browser/components/sessionstore/test/browser_607016.js +++ /dev/null @@ -1,117 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -let stateBackup = ss.getBrowserState(); - -function cleanup() { - // Reset the pref - try { - Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand"); - } catch (e) {} - ss.setBrowserState(stateBackup); - executeSoon(finish); -} - -function test() { - /** Bug 607016 - If a tab is never restored, attributes (eg. hidden) aren't updated correctly **/ - waitForExplicitFinish(); - ignoreAllUncaughtExceptions(); - - // Set the pref to true so we know exactly how many tabs should be restoring at - // any given time. This guarantees that a finishing load won't start another. - Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true); - - // We have our own progress listener for this test, which we'll attach before our state is set - let progressListener = { - onStateChange: function (aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) { - if (aBrowser.__SS_restoreState == TAB_STATE_RESTORING && - aStateFlags & Ci.nsIWebProgressListener.STATE_STOP && - aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK && - aStateFlags & Ci.nsIWebProgressListener.STATE_IS_WINDOW) - progressCallback(aBrowser); - } - } - - let state = { windows: [{ tabs: [ - { entries: [{ url: "http://example.org#1" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org#2" }], extData: { "uniq": r() } }, // overwriting - { entries: [{ url: "http://example.org#3" }], extData: { "uniq": r() } }, // hiding - { entries: [{ url: "http://example.org#4" }], extData: { "uniq": r() } }, // adding - { entries: [{ url: "http://example.org#5" }], extData: { "uniq": r() } }, // deleting - { entries: [{ url: "http://example.org#6" }] } // creating - ], selected: 1 }] }; - - function progressCallback(aBrowser) { - // We'll remove the progress listener after the first one because we aren't - // loading any other tabs - window.gBrowser.removeTabsProgressListener(progressListener); - - let curState = JSON.parse(ss.getBrowserState()); - for (let i = 0; i < curState.windows[0].tabs.length; i++) { - let tabState = state.windows[0].tabs[i]; - let tabCurState = curState.windows[0].tabs[i]; - if (tabState.extData) { - is(tabCurState.extData["uniq"], tabState.extData["uniq"], - "sanity check that tab has correct extData"); - } - else { - // We aren't expecting there to be any data on extData, but panorama - // may be setting something, so we need to make sure that if we do have - // data, we just don't have anything for "uniq". - ok(!("extData" in tabCurState) || !("uniq" in tabCurState.extData), - "sanity check that tab doesn't have extData or extData doesn't have 'uniq'"); - } - } - - // Now we'll set a new unique value on 1 of the tabs - let newUniq = r(); - ss.setTabValue(gBrowser.tabs[1], "uniq", newUniq); - gBrowser.removeTab(gBrowser.tabs[1]); - let closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0]; - is(closedTabData.state.extData.uniq, newUniq, - "(overwriting) new data is stored in extData"); - - // hide the next tab before closing it - gBrowser.hideTab(gBrowser.tabs[1]); - gBrowser.removeTab(gBrowser.tabs[1]); - closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0]; - ok(closedTabData.state.hidden, "(hiding) tab data has hidden == true"); - - // set data that's not in a conflicting key - let stillUniq = r(); - ss.setTabValue(gBrowser.tabs[1], "stillUniq", stillUniq); - gBrowser.removeTab(gBrowser.tabs[1]); - closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0]; - is(closedTabData.state.extData.stillUniq, stillUniq, - "(adding) new data is stored in extData"); - - // remove the uniq value and make sure it's not there in the closed data - ss.deleteTabValue(gBrowser.tabs[1], "uniq"); - gBrowser.removeTab(gBrowser.tabs[1]); - closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0]; - // Since Panorama might have put data in, first check if there is extData. - // If there is explicitly check that "uniq" isn't in it. Otherwise, we're ok - if ("extData" in closedTabData.state) { - ok(!("uniq" in closedTabData.state.extData), - "(deleting) uniq not in existing extData"); - } - else { - ok(true, "(deleting) no data is stored in extData"); - } - - // set unique data on the tab that never had any set, make sure that's saved - let newUniq2 = r(); - ss.setTabValue(gBrowser.tabs[1], "uniq", newUniq2); - gBrowser.removeTab(gBrowser.tabs[1]); - closedTabData = (JSON.parse(ss.getClosedTabData(window)))[0]; - is(closedTabData.state.extData.uniq, newUniq2, - "(creating) new data is stored in extData where there was none"); - - cleanup(); - } - - window.gBrowser.addTabsProgressListener(progressListener); - ss.setBrowserState(JSON.stringify(state)); -} - diff --git a/browser/components/sessionstore/test/browser_615394-SSWindowState_events.js b/browser/components/sessionstore/test/browser_615394-SSWindowState_events.js deleted file mode 100644 index 26064be22..000000000 --- a/browser/components/sessionstore/test/browser_615394-SSWindowState_events.js +++ /dev/null @@ -1,359 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const stateBackup = JSON.parse(ss.getBrowserState()); -const testState = { - windows: [{ - tabs: [ - { entries: [{ url: "about:blank" }] }, - { entries: [{ url: "about:rights" }] } - ] - }] -}; -const lameMultiWindowState = { windows: [ - { - tabs: [ - { entries: [{ url: "http://example.org#1" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org#2" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org#3" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.org#4" }], extData: { "uniq": r() } } - ], - selected: 1 - }, - { - tabs: [ - { entries: [{ url: "http://example.com#1" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com#2" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com#3" }], extData: { "uniq": r() } }, - { entries: [{ url: "http://example.com#4" }], extData: { "uniq": r() } }, - ], - selected: 3 - } - ] }; - - -function getOuterWindowID(aWindow) { - return aWindow.QueryInterface(Ci.nsIInterfaceRequestor). - getInterface(Ci.nsIDOMWindowUtils).outerWindowID; -} - -function test() { - /** Test for Bug 615394 - Session Restore should notify when it is beginning and ending a restore **/ - waitForExplicitFinish(); - // Preemptively extend the timeout to prevent [orange] - requestLongerTimeout(2); - runNextTest(); -} - - -let tests = [ - test_setTabState, - test_duplicateTab, - test_undoCloseTab, - test_setWindowState, - test_setBrowserState, - test_undoCloseWindow -]; -function runNextTest() { - // set an empty state & run the next test, or finish - if (tests.length) { - // Enumerate windows and close everything but our primary window. We can't - // use waitForFocus() because apparently it's buggy. See bug 599253. - var windowsEnum = Services.wm.getEnumerator("navigator:browser"); - while (windowsEnum.hasMoreElements()) { - var currentWindow = windowsEnum.getNext(); - if (currentWindow != window) { - currentWindow.close(); - } - } - - let currentTest = tests.shift(); - info("prepping for " + currentTest.name); - waitForBrowserState(testState, currentTest); - } - else { - waitForBrowserState(stateBackup, finish); - } -} - -/** ACTUAL TESTS **/ - -function test_setTabState() { - let tab = gBrowser.tabs[1]; - let newTabState = JSON.stringify({ entries: [{ url: "http://example.org" }], extData: { foo: "bar" } }); - let busyEventCount = 0; - let readyEventCount = 0; - - function onSSWindowStateBusy(aEvent) { - busyEventCount++; - } - - function onSSWindowStateReady(aEvent) { - readyEventCount++; - is(ss.getTabValue(tab, "foo"), "bar"); - ss.setTabValue(tab, "baz", "qux"); - } - - function onSSTabRestored(aEvent) { - is(busyEventCount, 1); - is(readyEventCount, 1); - is(ss.getTabValue(tab, "baz"), "qux"); - is(tab.linkedBrowser.currentURI.spec, "http://example.org/"); - - window.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy, false); - window.removeEventListener("SSWindowStateReady", onSSWindowStateReady, false); - gBrowser.tabContainer.removeEventListener("SSTabRestored", onSSTabRestored, false); - - runNextTest(); - } - - window.addEventListener("SSWindowStateBusy", onSSWindowStateBusy, false); - window.addEventListener("SSWindowStateReady", onSSWindowStateReady, false); - gBrowser.tabContainer.addEventListener("SSTabRestored", onSSTabRestored, false); - ss.setTabState(tab, newTabState); -} - - -function test_duplicateTab() { - let tab = gBrowser.tabs[1]; - let busyEventCount = 0; - let readyEventCount = 0; - let newTab; - - // We'll look to make sure this value is on the duplicated tab - ss.setTabValue(tab, "foo", "bar"); - - function onSSWindowStateBusy(aEvent) { - busyEventCount++; - } - - // duplicateTab is "synchronous" in tab creation. Since restoreHistory is called - // via setTimeout, newTab will be assigned before the SSWindowStateReady event - function onSSWindowStateReady(aEvent) { - readyEventCount++; - is(ss.getTabValue(newTab, "foo"), "bar"); - ss.setTabValue(newTab, "baz", "qux"); - } - - function onSSTabRestored(aEvent) { - is(busyEventCount, 1); - is(readyEventCount, 1); - is(ss.getTabValue(newTab, "baz"), "qux"); - is(newTab.linkedBrowser.currentURI.spec, "about:rights"); - - window.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy, false); - window.removeEventListener("SSWindowStateReady", onSSWindowStateReady, false); - gBrowser.tabContainer.removeEventListener("SSTabRestored", onSSTabRestored, false); - - runNextTest(); - } - - window.addEventListener("SSWindowStateBusy", onSSWindowStateBusy, false); - window.addEventListener("SSWindowStateReady", onSSWindowStateReady, false); - gBrowser.tabContainer.addEventListener("SSTabRestored", onSSTabRestored, false); - - newTab = ss.duplicateTab(window, tab); -} - - -function test_undoCloseTab() { - let tab = gBrowser.tabs[1], - busyEventCount = 0, - readyEventCount = 0, - reopenedTab; - - ss.setTabValue(tab, "foo", "bar"); - - function onSSWindowStateBusy(aEvent) { - busyEventCount++; - } - - // undoCloseTab is "synchronous" in tab creation. Since restoreHistory is called - // via setTimeout, reopenedTab will be assigned before the SSWindowStateReady event - function onSSWindowStateReady(aEvent) { - readyEventCount++; - is(ss.getTabValue(reopenedTab, "foo"), "bar"); - ss.setTabValue(reopenedTab, "baz", "qux"); - } - - function onSSTabRestored(aEvent) { - is(busyEventCount, 1); - is(readyEventCount, 1); - is(ss.getTabValue(reopenedTab, "baz"), "qux"); - is(reopenedTab.linkedBrowser.currentURI.spec, "about:rights"); - - window.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy, false); - window.removeEventListener("SSWindowStateReady", onSSWindowStateReady, false); - gBrowser.tabContainer.removeEventListener("SSTabRestored", onSSTabRestored, false); - - runNextTest(); - } - - window.addEventListener("SSWindowStateBusy", onSSWindowStateBusy, false); - window.addEventListener("SSWindowStateReady", onSSWindowStateReady, false); - gBrowser.tabContainer.addEventListener("SSTabRestored", onSSTabRestored, false); - - gBrowser.removeTab(tab); - reopenedTab = ss.undoCloseTab(window, 0); -} - - -function test_setWindowState() { - let testState = { - windows: [{ - tabs: [ - { entries: [{ url: "about:mozilla" }], extData: { "foo": "bar" } }, - { entries: [{ url: "http://example.org" }], extData: { "baz": "qux" } } - ] - }] - }; - - let busyEventCount = 0, - readyEventCount = 0, - tabRestoredCount = 0; - - function onSSWindowStateBusy(aEvent) { - busyEventCount++; - } - - function onSSWindowStateReady(aEvent) { - readyEventCount++; - is(ss.getTabValue(gBrowser.tabs[0], "foo"), "bar"); - is(ss.getTabValue(gBrowser.tabs[1], "baz"), "qux"); - } - - function onSSTabRestored(aEvent) { - if (++tabRestoredCount < 2) - return; - - is(busyEventCount, 1); - is(readyEventCount, 1); - is(gBrowser.tabs[0].linkedBrowser.currentURI.spec, "about:mozilla"); - is(gBrowser.tabs[1].linkedBrowser.currentURI.spec, "http://example.org/"); - - window.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy, false); - window.removeEventListener("SSWindowStateReady", onSSWindowStateReady, false); - gBrowser.tabContainer.removeEventListener("SSTabRestored", onSSTabRestored, false); - - runNextTest(); - } - - window.addEventListener("SSWindowStateBusy", onSSWindowStateBusy, false); - window.addEventListener("SSWindowStateReady", onSSWindowStateReady, false); - gBrowser.tabContainer.addEventListener("SSTabRestored", onSSTabRestored, false); - - ss.setWindowState(window, JSON.stringify(testState), true); -} - - -function test_setBrowserState() { - // We'll track events per window so we are sure that they are each happening once - // pre window. - let windowEvents = {}; - windowEvents[getOuterWindowID(window)] = { busyEventCount: 0, readyEventCount: 0 }; - - // waitForBrowserState does it's own observing for windows, but doesn't attach - // the listeners we want here, so do it ourselves. - let newWindow; - function windowObserver(aSubject, aTopic, aData) { - if (aTopic == "domwindowopened") { - newWindow = aSubject.QueryInterface(Ci.nsIDOMWindow); - newWindow.addEventListener("load", function() { - newWindow.removeEventListener("load", arguments.callee, false); - - Services.ww.unregisterNotification(windowObserver); - - windowEvents[getOuterWindowID(newWindow)] = { busyEventCount: 0, readyEventCount: 0 }; - - newWindow.addEventListener("SSWindowStateBusy", onSSWindowStateBusy, false); - newWindow.addEventListener("SSWindowStateReady", onSSWindowStateReady, false); - }, false); - } - } - - function onSSWindowStateBusy(aEvent) { - windowEvents[getOuterWindowID(aEvent.originalTarget)].busyEventCount++; - } - - function onSSWindowStateReady(aEvent) { - windowEvents[getOuterWindowID(aEvent.originalTarget)].readyEventCount++; - } - - window.addEventListener("SSWindowStateBusy", onSSWindowStateBusy, false); - window.addEventListener("SSWindowStateReady", onSSWindowStateReady, false); - Services.ww.registerNotification(windowObserver); - - waitForBrowserState(lameMultiWindowState, function() { - let checkedWindows = 0; - for each (let [id, winEvents] in Iterator(windowEvents)) { - is(winEvents.busyEventCount, 1, - "[test_setBrowserState] window" + id + " busy event count correct"); - is(winEvents.readyEventCount, 1, - "[test_setBrowserState] window" + id + " ready event count correct"); - checkedWindows++; - } - is(checkedWindows, 2, - "[test_setBrowserState] checked 2 windows"); - window.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy, false); - window.removeEventListener("SSWindowStateReady", onSSWindowStateReady, false); - newWindow.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy, false); - newWindow.removeEventListener("SSWindowStateReady", onSSWindowStateReady, false); - runNextTest(); - }); -} - - -function test_undoCloseWindow() { - let newWindow, reopenedWindow; - - function firstWindowObserver(aSubject, aTopic, aData) { - if (aTopic == "domwindowopened") { - newWindow = aSubject.QueryInterface(Ci.nsIDOMWindow); - Services.ww.unregisterNotification(firstWindowObserver); - } - } - Services.ww.registerNotification(firstWindowObserver); - - waitForBrowserState(lameMultiWindowState, function() { - // Close the window which isn't window - newWindow.close(); - reopenedWindow = ss.undoCloseWindow(0); - reopenedWindow.addEventListener("SSWindowStateBusy", onSSWindowStateBusy, false); - reopenedWindow.addEventListener("SSWindowStateReady", onSSWindowStateReady, false); - - reopenedWindow.addEventListener("load", function() { - reopenedWindow.removeEventListener("load", arguments.callee, false); - - reopenedWindow.gBrowser.tabContainer.addEventListener("SSTabRestored", onSSTabRestored, false); - }, false); - }); - - let busyEventCount = 0, - readyEventCount = 0, - tabRestoredCount = 0; - // These will listen to the reopened closed window... - function onSSWindowStateBusy(aEvent) { - busyEventCount++; - } - - function onSSWindowStateReady(aEvent) { - readyEventCount++; - } - - function onSSTabRestored(aEvent) { - if (++tabRestoredCount < 4) - return; - - is(busyEventCount, 1); - is(readyEventCount, 1); - - reopenedWindow.removeEventListener("SSWindowStateBusy", onSSWindowStateBusy, false); - reopenedWindow.removeEventListener("SSWindowStateReady", onSSWindowStateReady, false); - reopenedWindow.gBrowser.tabContainer.removeEventListener("SSTabRestored", onSSTabRestored, false); - - reopenedWindow.close(); - - runNextTest(); - } -} diff --git a/browser/components/sessionstore/test/browser_618151.js b/browser/components/sessionstore/test/browser_618151.js deleted file mode 100644 index cba2e924a..000000000 --- a/browser/components/sessionstore/test/browser_618151.js +++ /dev/null @@ -1,62 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const stateBackup = ss.getBrowserState(); -const testState = { - windows: [{ - tabs: [ - { entries: [{ url: "about:blank" }] }, - { entries: [{ url: "about:mozilla" }] } - ] - }] -}; - - -function test() { - /** Test for Bug 618151 - Overwriting state can lead to unrestored tabs **/ - waitForExplicitFinish(); - runNextTest(); -} - -// Just a subset of tests from bug 615394 that causes a timeout. -let tests = [test_setup, test_hang]; -function runNextTest() { - // set an empty state & run the next test, or finish - if (tests.length) { - // Enumerate windows and close everything but our primary window. We can't - // use waitForFocus() because apparently it's buggy. See bug 599253. - var windowsEnum = Services.wm.getEnumerator("navigator:browser"); - while (windowsEnum.hasMoreElements()) { - var currentWindow = windowsEnum.getNext(); - if (currentWindow != window) { - currentWindow.close(); - } - } - - let currentTest = tests.shift(); - info("running " + currentTest.name); - waitForBrowserState(testState, currentTest); - } - else { - ss.setBrowserState(stateBackup); - executeSoon(finish); - } -} - -function test_setup() { - function onSSTabRestored(aEvent) { - gBrowser.tabContainer.removeEventListener("SSTabRestored", onSSTabRestored, false); - runNextTest(); - } - - gBrowser.tabContainer.addEventListener("SSTabRestored", onSSTabRestored, false); - ss.setTabState(gBrowser.tabs[1], JSON.stringify({ - entries: [{ url: "http://example.org" }], - extData: { foo: "bar" } })); -} - -function test_hang() { - ok(true, "test didn't time out"); - runNextTest(); -} diff --git a/browser/components/sessionstore/test/browser_623779.js b/browser/components/sessionstore/test/browser_623779.js deleted file mode 100644 index 34a6d7788..000000000 --- a/browser/components/sessionstore/test/browser_623779.js +++ /dev/null @@ -1,7 +0,0 @@ -function test() { - gBrowser.pinTab(gBrowser.selectedTab); - var newTab = gBrowser.duplicateTab(gBrowser.selectedTab); - ok(!newTab.pinned, "duplicating a pinned tab creates unpinned tab"); - gBrowser.removeTab(newTab); - gBrowser.unpinTab(gBrowser.selectedTab); -} diff --git a/browser/components/sessionstore/test/browser_624727.js b/browser/components/sessionstore/test/browser_624727.js deleted file mode 100644 index 9884058f2..000000000 --- a/browser/components/sessionstore/test/browser_624727.js +++ /dev/null @@ -1,39 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -function test() { - waitForExplicitFinish(); - - let assertNumberOfTabs = function (num, msg) { - is(gBrowser.tabs.length, num, msg); - } - - let assertNumberOfPinnedTabs = function (num, msg) { - is(gBrowser._numPinnedTabs, num, msg); - } - - // check prerequisites - assertNumberOfTabs(1, "we start off with one tab"); - assertNumberOfPinnedTabs(0, "no pinned tabs so far"); - - // setup - gBrowser.addTab("about:blank"); - assertNumberOfTabs(2, "there are two tabs, now"); - - let [tab1, tab2] = gBrowser.tabs; - let linkedBrowser = tab1.linkedBrowser; - gBrowser.pinTab(tab1); - gBrowser.pinTab(tab2); - assertNumberOfPinnedTabs(2, "both tabs are now pinned"); - - // run the test - waitForBrowserState( - { windows: [{ tabs: [{ url: "about:blank" }] }] }, - function () { - assertNumberOfTabs(1, "one tab left after setBrowserState()"); - assertNumberOfPinnedTabs(0, "there are no pinned tabs"); - is(gBrowser.tabs[0].linkedBrowser, linkedBrowser, "first tab's browser got re-used"); - finish(); - } - ); -} diff --git a/browser/components/sessionstore/test/browser_625016.js b/browser/components/sessionstore/test/browser_625016.js deleted file mode 100644 index 1f1c2d2b3..000000000 --- a/browser/components/sessionstore/test/browser_625016.js +++ /dev/null @@ -1,125 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -let newWin; -let newTab; - -function test() { - /** Test for Bug 625016 - Restore windows closed in succession to quit (non-OSX only) **/ - - // We'll test this by opening a new window, waiting for the save event, then - // closing that window. We'll observe the "sessionstore-state-write" notification - // and check that the state contains no _closedWindows. We'll then add a new - // tab and make sure that the state following that was reset and the closed - // window is now in _closedWindows. - - waitForExplicitFinish(); - requestLongerTimeout(2); - - // We speed up the interval between session saves to ensure that the test - // runs quickly. - Services.prefs.setIntPref("browser.sessionstore.interval", 4000); - registerCleanupFunction(function () { - Services.prefs.clearUserPref("browser.sessionstore.interval"); - }); - - waitForSaveState(setup); -} - -function setup() { - // We'll clear all closed windows to make sure our state is clean - // forgetClosedWindow doesn't trigger a delayed save - while (ss.getClosedWindowCount()) { - ss.forgetClosedWindow(0); - } - is(ss.getClosedWindowCount(), 0, "starting with no closed windows"); - - // Open a new window, which should trigger a save event soon. - waitForSaveState(onSaveState); - newWin = openDialog(location, "_blank", "chrome,all,dialog=no", "about:rights"); -} - -function onSaveState() { - try { - ss.getWindowValue(newWin, "foobar"); - } catch (e) { - // The window is untracked which means that the saveState() call isn't the - // one we're waiting for. It's most likely been triggered by an async - // collection running in the background. - waitForSaveState(onSaveState); - return; - } - - // Double check that we have no closed windows - is(ss.getClosedWindowCount(), 0, "no closed windows on first save"); - - Services.obs.addObserver(observe1, "sessionstore-state-write", false); - - // Now close the new window, which should trigger another save event - newWin.close(); -} - -function observe1(aSubject, aTopic, aData) { - info("observe1: " + aTopic); - switch (aTopic) { - case "sessionstore-state-write": - aSubject.QueryInterface(Ci.nsISupportsString); - let state = JSON.parse(aSubject.data); - is(state.windows.length, 2, - "observe1: 2 windows in data being writted to disk"); - is(state._closedWindows.length, 0, - "observe1: no closed windows in data being writted to disk"); - - // The API still treats the closed window as closed, so ensure that window is there - is(ss.getClosedWindowCount(), 1, - "observe1: 1 closed window according to API"); - Services.obs.removeObserver(observe1, "sessionstore-state-write"); - Services.obs.addObserver(observe1, "sessionstore-state-write-complete", false); - break; - case "sessionstore-state-write-complete": - Services.obs.removeObserver(observe1, "sessionstore-state-write-complete"); - openTab(); - break; - } -} - -function observe2(aSubject, aTopic, aData) { - info("observe2: " + aTopic); - switch (aTopic) { - case "sessionstore-state-write": - aSubject.QueryInterface(Ci.nsISupportsString); - let state = JSON.parse(aSubject.data); - is(state.windows.length, 1, - "observe2: 1 window in data being writted to disk"); - is(state._closedWindows.length, 1, - "observe2: 1 closed window in data being writted to disk"); - - // The API still treats the closed window as closed, so ensure that window is there - is(ss.getClosedWindowCount(), 1, - "observe2: 1 closed window according to API"); - Services.obs.removeObserver(observe2, "sessionstore-state-write"); - Services.obs.addObserver(observe2, "sessionstore-state-write-complete", false); - break; - case "sessionstore-state-write-complete": - Services.obs.removeObserver(observe2, "sessionstore-state-write-complete"); - done(); - break; - } -} - -// We'll open a tab, which should trigger another state save which would wipe -// the _shouldRestore attribute from the closed window -function openTab() { - Services.obs.addObserver(observe2, "sessionstore-state-write", false); - newTab = gBrowser.addTab("about:mozilla"); -} - -function done() { - gBrowser.removeTab(newTab); - // The API still represents the closed window as closed, so we can clear it - // with the API, but just to make sure... - is(ss.getClosedWindowCount(), 1, "1 closed window according to API"); - ss.forgetClosedWindow(0); - executeSoon(finish); -} - diff --git a/browser/components/sessionstore/test/browser_625257.js b/browser/components/sessionstore/test/browser_625257.js deleted file mode 100644 index 9bd69cf58..000000000 --- a/browser/components/sessionstore/test/browser_625257.js +++ /dev/null @@ -1,85 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This tests that a tab which is closed while loading is not lost. -// Specifically, that session store does not rely on an invalid cache when -// constructing data for a tab which is loading. - -// The newly created tab which we load a URL into and try closing/undoing. -let tab; - -// This test steps through the following parts: -// 1. Tab has been created is loading URI_TO_LOAD. -// 2. Before URI_TO_LOAD finishes loading, browser.currentURI has changed and -// tab is scheduled to be removed. -// 3. After the tab has been closed, undoCloseTab() has been called and the tab -// should fully load. -const URI_TO_LOAD = "about:mozilla"; - -function test() { - waitForExplicitFinish(); - - gBrowser.addTabsProgressListener(tabsListener); - - tab = gBrowser.addTab(); - - tab.linkedBrowser.addEventListener("load", firstOnLoad, true); - - gBrowser.tabContainer.addEventListener("TabClose", onTabClose, true); -} - -function firstOnLoad(aEvent) { - tab.linkedBrowser.removeEventListener("load", firstOnLoad, true); - - let uri = aEvent.target.location; - is(uri, "about:blank", "first load should be for about:blank"); - - // Trigger a save state. - ss.getBrowserState(); - - is(gBrowser.tabs[1], tab, "newly created tab should exist by now"); - ok(tab.linkedBrowser.__SS_data, "newly created tab should be in save state"); - - tab.linkedBrowser.loadURI(URI_TO_LOAD); -} - -let tabsListener = { - onLocationChange: function onLocationChange(aBrowser) { - gBrowser.removeTabsProgressListener(tabsListener); - - is(aBrowser.currentURI.spec, URI_TO_LOAD, - "should occur after about:blank load and be loading next page"); - - // Since we are running in the context of tabs listeners, we do not - // want to disrupt other tabs listeners. - executeSoon(function() { - gBrowser.removeTab(tab); - }); - } -}; - -function onTabClose(aEvent) { - gBrowser.tabContainer.removeEventListener("TabClose", onTabClose, true); - - is(tab.linkedBrowser.currentURI.spec, URI_TO_LOAD, - "should only remove when loading page"); - - executeSoon(function() { - tab = ss.undoCloseTab(window, 0); - tab.linkedBrowser.addEventListener("load", secondOnLoad, true); - }); -} - -function secondOnLoad(aEvent) { - let uri = aEvent.target.location; - is(uri, URI_TO_LOAD, "should load page from undoCloseTab"); - done(); -} - -function done() { - tab.linkedBrowser.removeEventListener("load", secondOnLoad, true); - gBrowser.removeTab(tab); - - executeSoon(finish); -} diff --git a/browser/components/sessionstore/test/browser_628270.js b/browser/components/sessionstore/test/browser_628270.js deleted file mode 100644 index d3dbc95cf..000000000 --- a/browser/components/sessionstore/test/browser_628270.js +++ /dev/null @@ -1,51 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -function test() { - let assertNumberOfTabs = function (num, msg) { - is(gBrowser.tabs.length, num, msg); - } - - let assertNumberOfVisibleTabs = function (num, msg) { - is(gBrowser.visibleTabs.length, num, msg); - } - - let assertNumberOfPinnedTabs = function (num, msg) { - is(gBrowser._numPinnedTabs, num, msg); - } - - waitForExplicitFinish(); - - // check prerequisites - assertNumberOfTabs(1, "we start off with one tab"); - - // setup - let tab = gBrowser.addTab("about:mozilla"); - - whenTabIsLoaded(tab, function () { - // hide the newly created tab - assertNumberOfVisibleTabs(2, "there are two visible tabs"); - gBrowser.showOnlyTheseTabs([gBrowser.tabs[0]]); - assertNumberOfVisibleTabs(1, "there is one visible tab"); - ok(tab.hidden, "newly created tab is now hidden"); - - // close and restore hidden tab - gBrowser.removeTab(tab); - tab = ss.undoCloseTab(window, 0); - - // check that everything was restored correctly, clean up and finish - whenTabIsLoaded(tab, function () { - is(tab.linkedBrowser.currentURI.spec, "about:mozilla", "restored tab has correct url"); - - gBrowser.removeTab(tab); - finish(); - }); - }); -} - -function whenTabIsLoaded(tab, callback) { - tab.linkedBrowser.addEventListener("load", function onLoad() { - tab.linkedBrowser.removeEventListener("load", onLoad, true); - callback(); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_635418.js b/browser/components/sessionstore/test/browser_635418.js deleted file mode 100644 index 461ad1ee8..000000000 --- a/browser/components/sessionstore/test/browser_635418.js +++ /dev/null @@ -1,54 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This tests that hiding/showing a tab, on its own, eventually triggers a -// session store. - -function test() { - waitForExplicitFinish(); - // We speed up the interval between session saves to ensure that the test - // runs quickly. - Services.prefs.setIntPref("browser.sessionstore.interval", 2000); - - // Loading a tab causes a save state and this is meant to catch that event. - waitForSaveState(testBug635418_1); - - // Assumption: Only one window is open and it has one tab open. - gBrowser.addTab("about:mozilla"); -} - -function testBug635418_1() { - ok(!gBrowser.tabs[0].hidden, "first tab should not be hidden"); - ok(!gBrowser.tabs[1].hidden, "second tab should not be hidden"); - - waitForSaveState(testBug635418_2); - - // We can't hide the selected tab, so hide the new one - gBrowser.hideTab(gBrowser.tabs[1]); -} - -function testBug635418_2() { - let state = JSON.parse(ss.getBrowserState()); - ok(!state.windows[0].tabs[0].hidden, "first tab should still not be hidden"); - ok(state.windows[0].tabs[1].hidden, "second tab should be hidden by now"); - - waitForSaveState(testBug635418_3); - gBrowser.showTab(gBrowser.tabs[1]); -} - -function testBug635418_3() { - let state = JSON.parse(ss.getBrowserState()); - ok(!state.windows[0].tabs[0].hidden, "first tab should still still not be hidden"); - ok(!state.windows[0].tabs[1].hidden, "second tab should not be hidden again"); - - done(); -} - -function done() { - gBrowser.removeTab(window.gBrowser.tabs[1]); - - Services.prefs.clearUserPref("browser.sessionstore.interval"); - - executeSoon(finish); -} diff --git a/browser/components/sessionstore/test/browser_636279.js b/browser/components/sessionstore/test/browser_636279.js deleted file mode 100644 index 653199209..000000000 --- a/browser/components/sessionstore/test/browser_636279.js +++ /dev/null @@ -1,99 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -let stateBackup = ss.getBrowserState(); - -let statePinned = {windows:[{tabs:[ - {entries:[{url:"http://example.com#1"}], pinned: true} -]}]}; - -let state = {windows:[{tabs:[ - {entries:[{url:"http://example.com#1"}]}, - {entries:[{url:"http://example.com#2"}]}, - {entries:[{url:"http://example.com#3"}]}, - {entries:[{url:"http://example.com#4"}]}, -]}]}; - -function test() { - waitForExplicitFinish(); - - registerCleanupFunction(function () { - TabsProgressListener.uninit(); - ss.setBrowserState(stateBackup); - }); - - - TabsProgressListener.init(); - - window.addEventListener("SSWindowStateReady", function onReady() { - window.removeEventListener("SSWindowStateReady", onReady, false); - - let firstProgress = true; - - TabsProgressListener.setCallback(function (needsRestore, isRestoring) { - if (firstProgress) { - firstProgress = false; - is(isRestoring, 3, "restoring 3 tabs concurrently"); - } else { - ok(isRestoring <= 3, "restoring max. 2 tabs concurrently"); - } - - if (0 == needsRestore) { - TabsProgressListener.unsetCallback(); - waitForFocus(finish); - } - }); - - ss.setBrowserState(JSON.stringify(state)); - }, false); - - ss.setBrowserState(JSON.stringify(statePinned)); -} - -function countTabs() { - let needsRestore = 0, isRestoring = 0; - let windowsEnum = Services.wm.getEnumerator("navigator:browser"); - - while (windowsEnum.hasMoreElements()) { - let window = windowsEnum.getNext(); - if (window.closed) - continue; - - for (let i = 0; i < window.gBrowser.tabs.length; i++) { - let browser = window.gBrowser.tabs[i].linkedBrowser; - if (browser.__SS_restoreState == TAB_STATE_RESTORING) - isRestoring++; - else if (browser.__SS_restoreState == TAB_STATE_NEEDS_RESTORE) - needsRestore++; - } - } - - return [needsRestore, isRestoring]; -} - -let TabsProgressListener = { - init: function () { - gBrowser.addTabsProgressListener(this); - }, - - uninit: function () { - this.unsetCallback(); - gBrowser.removeTabsProgressListener(this); - }, - - setCallback: function (callback) { - this.callback = callback; - }, - - unsetCallback: function () { - delete this.callback; - }, - - onStateChange: function (aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) { - if (this.callback && aBrowser.__SS_restoreState == TAB_STATE_RESTORING && - aStateFlags & Ci.nsIWebProgressListener.STATE_STOP && - aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK && - aStateFlags & Ci.nsIWebProgressListener.STATE_IS_WINDOW) - this.callback.apply(null, countTabs()); - } -} diff --git a/browser/components/sessionstore/test/browser_637020.js b/browser/components/sessionstore/test/browser_637020.js deleted file mode 100644 index dbe145445..000000000 --- a/browser/components/sessionstore/test/browser_637020.js +++ /dev/null @@ -1,74 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -const TEST_URL = "http://mochi.test:8888/browser/browser/components/" + - "sessionstore/test/browser_637020_slow.sjs"; - -const TEST_STATE = { - windows: [{ - tabs: [ - { entries: [{ url: "about:mozilla" }] }, - { entries: [{ url: "about:robots" }] } - ] - }, { - tabs: [ - { entries: [{ url: TEST_URL }] }, - { entries: [{ url: TEST_URL }] } - ] - }] -}; - -function test() { - TestRunner.run(); -} - -/** - * This test ensures that windows that have just been restored will be marked - * as dirty, otherwise _getCurrentState() might ignore them when collecting - * state for the first time and we'd just save them as empty objects. - * - * The dirty state acts as a cache to not collect data from all windows all the - * time, so at the beginning, each window must be dirty so that we collect - * their state at least once. - */ - -function runTests() { - let win; - - // Wait until the new window has been opened. - Services.obs.addObserver(function onOpened(subject) { - Services.obs.removeObserver(onOpened, "domwindowopened"); - win = subject; - executeSoon(next); - }, "domwindowopened", false); - - // Set the new browser state that will - // restore a window with two slowly loading tabs. - yield SessionStore.setBrowserState(JSON.stringify(TEST_STATE)); - - // The window has now been opened. Check the state that is returned, - // this should come from the cache while the window isn't restored, yet. - info("the window has been opened"); - checkWindows(); - - // The history has now been restored and the tabs are loading. The data must - // now come from the window, if it's correctly been marked as dirty before. - yield whenDelayedStartupFinished(win, next); - info("the delayed startup has finished"); - checkWindows(); -} - -function checkWindows() { - let state = JSON.parse(SessionStore.getBrowserState()); - is(state.windows[0].tabs.length, 2, "first window has two tabs"); - is(state.windows[1].tabs.length, 2, "second window has two tabs"); -} - -function whenDelayedStartupFinished(aWindow, aCallback) { - Services.obs.addObserver(function observer(aSubject, aTopic) { - if (aWindow == aSubject) { - Services.obs.removeObserver(observer, aTopic); - executeSoon(aCallback); - } - }, "browser-delayed-startup-finished", false); -} diff --git a/browser/components/sessionstore/test/browser_637020_slow.sjs b/browser/components/sessionstore/test/browser_637020_slow.sjs deleted file mode 100644 index 41da3c2ad..000000000 --- a/browser/components/sessionstore/test/browser_637020_slow.sjs +++ /dev/null @@ -1,21 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -const Cc = Components.classes; -const Ci = Components.interfaces; - -const DELAY_MS = "2000"; - -let timer; - -function handleRequest(req, resp) { - resp.processAsync(); - resp.setHeader("Cache-Control", "no-cache", false); - resp.setHeader("Content-Type", "text/html;charset=utf-8", false); - - timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); - timer.init(() => { - resp.write("hi"); - resp.finish(); - }, DELAY_MS, Ci.nsITimer.TYPE_ONE_SHOT); -} diff --git a/browser/components/sessionstore/test/browser_644409-scratchpads.js b/browser/components/sessionstore/test/browser_644409-scratchpads.js deleted file mode 100644 index cc79a7b4b..000000000 --- a/browser/components/sessionstore/test/browser_644409-scratchpads.js +++ /dev/null @@ -1,67 +0,0 @@ - /* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -const testState = { - windows: [{ - tabs: [ - { entries: [{ url: "about:blank" }] }, - ] - }], - scratchpads: [ - { text: "text1", executionContext: 1 }, - { text: "", executionContext: 2, filename: "test.js" } - ] -}; - -// only finish() when correct number of windows opened -var restored = []; -function addState(state) { - restored.push(state); - - if (restored.length == testState.scratchpads.length) { - ok(statesMatch(restored, testState.scratchpads), - "Two scratchpad windows restored"); - - Services.ww.unregisterNotification(windowObserver); - finish(); - } -} - -function test() { - waitForExplicitFinish(); - - Services.ww.registerNotification(windowObserver); - - ss.setBrowserState(JSON.stringify(testState)); -} - -function windowObserver(aSubject, aTopic, aData) { - if (aTopic == "domwindowopened") { - let win = aSubject.QueryInterface(Ci.nsIDOMWindow); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - - if (win.Scratchpad) { - win.Scratchpad.addObserver({ - onReady: function() { - win.Scratchpad.removeObserver(this); - - let state = win.Scratchpad.getState(); - win.close(); - addState(state); - }, - }); - } - }, false); - } -} - -function statesMatch(restored, states) { - return states.every(function(state) { - return restored.some(function(restoredState) { - return state.filename == restoredState.filename && - state.text == restoredState.text && - state.executionContext == restoredState.executionContext; - }) - }); -} diff --git a/browser/components/sessionstore/test/browser_645428.js b/browser/components/sessionstore/test/browser_645428.js deleted file mode 100644 index 124a7aea9..000000000 --- a/browser/components/sessionstore/test/browser_645428.js +++ /dev/null @@ -1,22 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -const NOTIFICATION = "sessionstore-browser-state-restored"; - -function test() { - waitForExplicitFinish(); - - function observe(subject, topic, data) { - if (NOTIFICATION == topic) { - finish(); - ok(true, "TOPIC received"); - } - } - - Services.obs.addObserver(observe, NOTIFICATION, false); - registerCleanupFunction(function () { - Services.obs.removeObserver(observe, NOTIFICATION); - }); - - ss.setBrowserState(JSON.stringify({ windows: [] })); -} diff --git a/browser/components/sessionstore/test/browser_659591.js b/browser/components/sessionstore/test/browser_659591.js deleted file mode 100644 index 3608ea793..000000000 --- a/browser/components/sessionstore/test/browser_659591.js +++ /dev/null @@ -1,32 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -function test() { - waitForExplicitFinish(); - - let eventReceived = false; - - registerCleanupFunction(function () { - ok(eventReceived, "SSWindowClosing event received"); - }); - - newWindow(function (win) { - win.addEventListener("SSWindowClosing", function onWindowClosing() { - win.removeEventListener("SSWindowClosing", onWindowClosing, false); - eventReceived = true; - waitForFocus(finish); - }, false); - - win.close(); - }); -} - -function newWindow(callback) { - let opts = "chrome,all,dialog=no,height=800,width=800"; - let win = window.openDialog(getBrowserURL(), "_blank", opts); - - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - executeSoon(function () callback(win)); - }, false); -} diff --git a/browser/components/sessionstore/test/browser_662743.js b/browser/components/sessionstore/test/browser_662743.js deleted file mode 100644 index 6d49a2fec..000000000 --- a/browser/components/sessionstore/test/browser_662743.js +++ /dev/null @@ -1,128 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -// This tests that session restore component does restore the right <select> option. -// Session store should not rely only on previous user's selectedIndex, it should -// check its value as well. - -function test() { - /** Tests selected options **/ - waitForExplicitFinish(); - - let testTabCount = 0; - let formData = [ - // default case - { }, - // old format - { "#select_id" : 0 }, - { "#select_id" : 2 }, - // invalid index - { "#select_id" : 8 }, - { "/xhtml:html/xhtml:body/xhtml:select" : 5}, - { "/xhtml:html/xhtml:body/xhtml:select[@name='select_name']" : 6}, - - // new format - // index doesn't match value (testing an option in between (two)) - { id:{ "select_id": {"selectedIndex":0,"value":"val2"} } }, - // index doesn't match value (testing an invalid value) - { id:{ "select_id": {"selectedIndex":4,"value":"val8"} } }, - // index doesn't match value (testing an invalid index) - { id:{ "select_id": {"selectedIndex":8,"value":"val5"} } }, - // index and value match position zero - { id:{ "select_id": {"selectedIndex":0,"value":"val0"} }, xpath: {} }, - // index doesn't match value (testing the last option (seven)) - { id:{},"xpath":{ "/xhtml:html/xhtml:body/xhtml:select[@name='select_name']": {"selectedIndex":1,"value":"val7"} } }, - // index and value match the default option "selectedIndex":3,"value":"val3" - { xpath: { "/xhtml:html/xhtml:body/xhtml:select[@name='select_name']" : {"selectedIndex":3,"value":"val3"} } }, - // index matches default option however it doesn't match value - { id:{ "select_id": {"selectedIndex":3,"value":"val4"} } }, - - // combinations - { "#select_id" : 3, id:{ "select_id": {"selectedIndex":1,"value":"val1"} } }, - { "#select_id" : 5, xpath: { "/xhtml:html/xhtml:body/xhtml:select[@name='select_name']" : {"selectedIndex":4,"value":"val4"} } }, - { "/xhtml:html/xhtml:body/xhtml:select" : 5, id:{ "select_id": {"selectedIndex":1,"value":"val1"} }}, - { "/xhtml:html/xhtml:body/xhtml:select[@name='select_name']" : 2, xpath: { "/xhtml:html/xhtml:body/xhtml:select[@name='select_name']" : {"selectedIndex":7,"value":"val7"} } } - ]; - - let expectedValues = [ - [ "val3"], // default value - [ "val0"], - [ "val2"], - [ "val3"], // default value (invalid index) - [ "val5"], - [ "val6"], - [ "val2"], - [ "val3"], // default value (invalid value) - [ "val5"], // value is still valid (even it has an invalid index) - [ "val0"], - [ "val7"], - [ "val3"], - [ "val4"], - [ "val1"], - [ "val4"], - [ "val1"], - [ "val7"] - ]; - let callback = function() { - testTabCount--; - if (testTabCount == 0) { - finish(); - } - }; - - for (let i = 0; i < formData.length; i++) { - testTabCount++; - testTabRestoreData(formData[i], expectedValues[i], callback); - } -} - -function testTabRestoreData(aFormData, aExpectedValues, aCallback) { - let testURL = - getRootDirectory(gTestPath) + "browser_662743_sample.html"; - let tab = gBrowser.addTab(testURL); - let tabState = { entries: [{ url: testURL, formdata: aFormData}] }; - - tab.linkedBrowser.addEventListener("load", function(aEvent) { - tab.linkedBrowser.removeEventListener("load", arguments.callee, true); - ss.setTabState(tab, JSON.stringify(tabState)); - - tab.addEventListener("SSTabRestored", function(aEvent) { - tab.removeEventListener("SSTabRestored", arguments.callee); - let doc = tab.linkedBrowser.contentDocument; - let select = doc.getElementById("select_id"); - let value = select.options[select.selectedIndex].value; - - // test select options values - is(value, aExpectedValues[0], - "Select Option by selectedIndex &/or value has been restored correctly"); - - // clean up - gBrowser.removeTab(tab); - aCallback(); - }); - - tab.addEventListener("TabClose", function(aEvent) { - tab.removeEventListener("TabClose", arguments.callee); - let restoredTabState = JSON.parse(ss.getTabState(tab)); - let restoredFormData = restoredTabState.entries[0].formdata; - let selectIdFormData = restoredFormData.id.select_id; - let value = restoredFormData.id.select_id.value; - - // test format - ok("id" in restoredFormData && "xpath" in restoredFormData, - "FormData format is valid"); - // validate that there are no old keys - is(Object.keys(restoredFormData).length, 2, - "FormData key length is valid"); - // test format - ok("selectedIndex" in selectIdFormData && "value" in selectIdFormData, - "select format is valid"); - // validate that there are no old keys - is(Object.keys(selectIdFormData).length, 2, - "select_id length is valid"); - // test set collection values - is(value, aExpectedValues[0], - "Collection has been saved correctly"); - }); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_662743_sample.html b/browser/components/sessionstore/test/browser_662743_sample.html deleted file mode 100644 index de48fa0c9..000000000 --- a/browser/components/sessionstore/test/browser_662743_sample.html +++ /dev/null @@ -1,15 +0,0 @@ -<!DOCTYPE html> -<title>Test 662743</title> - -<!-- Select events --> -<h3>Select options</h3> -<select id="select_id" name="select_name"> - <option value="val0">Zero</option> - <option value="val1">One</option> - <option value="val2">Two</option> - <option value="val3" selected="selected">Three</option> - <option value="val4">Four</option> - <option value="val5">Five</option> - <option value="val6">Six</option> - <option value="val7">Seven</option> -</select>
\ No newline at end of file diff --git a/browser/components/sessionstore/test/browser_662812.js b/browser/components/sessionstore/test/browser_662812.js deleted file mode 100644 index 44cfe7ba3..000000000 --- a/browser/components/sessionstore/test/browser_662812.js +++ /dev/null @@ -1,34 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -function test() { - waitForExplicitFinish(); - - window.addEventListener("SSWindowStateBusy", function onBusy() { - window.removeEventListener("SSWindowStateBusy", onBusy, false); - - let state = JSON.parse(ss.getWindowState(window)); - ok(state.windows[0].busy, "window is busy"); - - window.addEventListener("SSWindowStateReady", function onReady() { - window.removeEventListener("SSWindowStateReady", onReady, false); - - let state = JSON.parse(ss.getWindowState(window)); - ok(!state.windows[0].busy, "window is not busy"); - - gBrowser.removeTab(gBrowser.tabs[1]); - executeSoon(finish); - }, false); - }, false); - - // create a new tab - let tab = gBrowser.addTab("about:mozilla"); - let browser = tab.linkedBrowser; - - // close and restore it - browser.addEventListener("load", function onLoad() { - browser.removeEventListener("load", onLoad, true); - gBrowser.removeTab(tab); - ss.undoCloseTab(window, 0); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_665702-state_session.js b/browser/components/sessionstore/test/browser_665702-state_session.js deleted file mode 100644 index aee0f2554..000000000 --- a/browser/components/sessionstore/test/browser_665702-state_session.js +++ /dev/null @@ -1,24 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -function compareArray(a, b) { - if (a.length !== b.length) { - return false; - } - for (let i = 0; i < a.length; i++) { - if (a[i] !== b[i]) { - return false; - } - } - return true; -} - -function test() { - let currentState = JSON.parse(ss.getBrowserState()); - ok(currentState.session, "session data returned by getBrowserState"); - - let keys = Object.keys(currentState.session); - let expectedKeys = ["state", "lastUpdate", "startTime", "recentCrashes"]; - ok(compareArray(keys.sort(), expectedKeys.sort()), - "session object from getBrowserState has correct keys"); -} diff --git a/browser/components/sessionstore/test/browser_682507.js b/browser/components/sessionstore/test/browser_682507.js deleted file mode 100644 index 52b95341b..000000000 --- a/browser/components/sessionstore/test/browser_682507.js +++ /dev/null @@ -1,16 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -function test() { - Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true); - gBrowser.addTab("about:mozilla"); - - ss.setTabState(gBrowser.tabs[1], ss.getTabState(gBrowser.tabs[1])); - ok(gBrowser.tabs[1].hasAttribute("pending"), "second tab should have 'pending' attribute"); - - gBrowser.selectedTab = gBrowser.tabs[1]; - ok(!gBrowser.tabs[1].hasAttribute("pending"), "second tab should have not 'pending' attribute"); - - gBrowser.removeTab(gBrowser.tabs[1]); - Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand"); -} diff --git a/browser/components/sessionstore/test/browser_687710.js b/browser/components/sessionstore/test/browser_687710.js deleted file mode 100644 index be8d9cec1..000000000 --- a/browser/components/sessionstore/test/browser_687710.js +++ /dev/null @@ -1,44 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -// Test that sessionrestore handles cycles in the shentry graph properly. -// -// These cycles shouldn't be there in the first place, but they cause hangs -// when they mysteriously appear (bug 687710). Docshell code assumes this -// graph is a tree and tires to walk to the root. But if there's a cycle, -// there is no root, and we loop forever. - -let stateBackup = ss.getBrowserState(); - -let state = {windows:[{tabs:[{entries:[ - { - docIdentifier: 1, - url: "http://example.com", - children: [ - { - docIdentifier: 2, - url: "http://example.com" - } - ] - }, - { - docIdentifier: 2, - url: "http://example.com", - children: [ - { - docIdentifier: 1, - url: "http://example.com" - } - ] - } -]}]}]} - -function test() { - registerCleanupFunction(function () { - ss.setBrowserState(stateBackup); - }); - - /* This test fails by hanging. */ - ss.setBrowserState(JSON.stringify(state)); - ok(true, "Didn't hang!"); -} diff --git a/browser/components/sessionstore/test/browser_687710_2.js b/browser/components/sessionstore/test/browser_687710_2.js deleted file mode 100644 index 6b36fdc35..000000000 --- a/browser/components/sessionstore/test/browser_687710_2.js +++ /dev/null @@ -1,64 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -// Test that the fix for bug 687710 isn't too aggressive -- shentries which are -// cousins should be able to share bfcache entries. - -let stateBackup = ss.getBrowserState(); - -let state = {entries:[ - { - docIdentifier: 1, - url: "http://example.com?1", - children: [{ docIdentifier: 10, - url: "http://example.com?10" }] - }, - { - docIdentifier: 1, - url: "http://example.com?1#a", - children: [{ docIdentifier: 10, - url: "http://example.com?10#aa" }] - } -]}; - -function test() -{ - registerCleanupFunction(function () { - ss.setBrowserState(stateBackup); - }); - - let tab = gBrowser.addTab("about:blank"); - ss.setTabState(tab, JSON.stringify(state)); - let history = tab.linkedBrowser.webNavigation.sessionHistory; - - is(history.count, 2, "history.count"); - for (let i = 0; i < history.count; i++) { - for (let j = 0; j < history.count; j++) { - compareEntries(i, j, history); - } - } -} - -function compareEntries(i, j, history) -{ - let e1 = history.getEntryAtIndex(i, false) - .QueryInterface(Ci.nsISHEntry) - .QueryInterface(Ci.nsISHContainer); - - let e2 = history.getEntryAtIndex(j, false) - .QueryInterface(Ci.nsISHEntry) - .QueryInterface(Ci.nsISHContainer); - - ok(e1.sharesDocumentWith(e2), - i + ' should share doc with ' + j); - is(e1.childCount, e2.childCount, - 'Child count mismatch (' + i + ', ' + j + ')'); - - for (let c = 0; c < e1.childCount; c++) { - let c1 = e1.GetChildAt(c); - let c2 = e2.GetChildAt(c); - - ok(c1.sharesDocumentWith(c2), - 'Cousins should share documents. (' + i + ', ' + j + ', ' + c + ')'); - } -} diff --git a/browser/components/sessionstore/test/browser_694378.js b/browser/components/sessionstore/test/browser_694378.js deleted file mode 100644 index 8578428d8..000000000 --- a/browser/components/sessionstore/test/browser_694378.js +++ /dev/null @@ -1,33 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -// Test Summary: -// 1. call ss.setWindowState with a broken state -// 1a. ensure that it doesn't throw. - -function test() { - waitForExplicitFinish(); - - let brokenState = { - windows: [ - { tabs: [{ entries: [{ url: "about:mozilla" }] }] } - ], - selectedWindow: 2 - }; - let brokenStateString = JSON.stringify(brokenState); - - let gotError = false; - try { - ss.setWindowState(window, brokenStateString, true); - } - catch (ex) { - gotError = true; - info(ex); - } - - ok(!gotError, "ss.setWindowState did not throw an error"); - - // Make sure that we reset the state. Use a full state just in case things get crazy. - let blankState = { windows: [{ tabs: [{ entries: [{ url: "about:blank" }] }]}]}; - waitForBrowserState(blankState, finish); -} diff --git a/browser/components/sessionstore/test/browser_701377.js b/browser/components/sessionstore/test/browser_701377.js deleted file mode 100644 index e526b7eb7..000000000 --- a/browser/components/sessionstore/test/browser_701377.js +++ /dev/null @@ -1,41 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -let state = {windows:[{tabs:[ - {entries:[{url:"http://example.com#1"}]}, - {entries:[{url:"http://example.com#2"}], hidden: true} -]}]}; - -function test() { - waitForExplicitFinish(); - - newWindowWithState(state, function (aWindow) { - let tab = aWindow.gBrowser.tabs[1]; - ok(tab.hidden, "the second tab is hidden"); - - let tabShown = false; - let tabShowCallback = function () tabShown = true; - tab.addEventListener("TabShow", tabShowCallback, false); - - let tabState = ss.getTabState(tab); - ss.setTabState(tab, tabState); - - tab.removeEventListener("TabShow", tabShowCallback, false); - ok(tab.hidden && !tabShown, "tab remains hidden"); - - finish(); - }); -} - -// ---------- -function newWindowWithState(aState, aCallback) { - let opts = "chrome,all,dialog=no,height=800,width=800"; - let win = window.openDialog(getBrowserURL(), "_blank", opts); - - registerCleanupFunction(function () win.close()); - - whenWindowLoaded(win, function onWindowLoaded(aWin) { - ss.setWindowState(aWin, JSON.stringify(aState), true); - executeSoon(function () aCallback(aWin)); - }); -} diff --git a/browser/components/sessionstore/test/browser_705597.js b/browser/components/sessionstore/test/browser_705597.js deleted file mode 100644 index 8810c88e6..000000000 --- a/browser/components/sessionstore/test/browser_705597.js +++ /dev/null @@ -1,57 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -let tabState = { - entries: [{url: "about:robots", children: [{url: "about:mozilla"}]}] -}; - -function test() { - waitForExplicitFinish(); - requestLongerTimeout(2); - - Services.prefs.setIntPref("browser.sessionstore.interval", 4000); - registerCleanupFunction(function () { - Services.prefs.clearUserPref("browser.sessionstore.interval"); - }); - - let tab = gBrowser.addTab("about:blank"); - - let browser = tab.linkedBrowser; - - waitForTabState(tab, tabState, function () { - - let sessionHistory = browser.sessionHistory; - let entry = sessionHistory.getEntryAtIndex(0, false); - entry.QueryInterface(Ci.nsISHContainer); - - whenChildCount(entry, 1, function () { - whenChildCount(entry, 2, function () { - whenBrowserLoaded(browser, function () { - let {entries} = JSON.parse(ss.getTabState(tab)); - is(entries.length, 1, "tab has one history entry"); - ok(!entries[0].children, "history entry has no subframes"); - - // Make sure that we reset the state. - let blankState = { windows: [{ tabs: [{ entries: [{ url: "about:blank" }] }]}]}; - waitForBrowserState(blankState, finish); - }); - - // reload the browser to deprecate the subframes - browser.reload(); - }); - - // create a dynamic subframe - let doc = browser.contentDocument; - let iframe = doc.createElement("iframe"); - doc.body.appendChild(iframe); - iframe.setAttribute("src", "about:mozilla"); - }); - }); -} - -function whenChildCount(aEntry, aChildCount, aCallback) { - if (aEntry.childCount == aChildCount) - aCallback(); - else - setTimeout(function () whenChildCount(aEntry, aChildCount, aCallback), 100); -} diff --git a/browser/components/sessionstore/test/browser_707862.js b/browser/components/sessionstore/test/browser_707862.js deleted file mode 100644 index db09e0d05..000000000 --- a/browser/components/sessionstore/test/browser_707862.js +++ /dev/null @@ -1,58 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -let tabState = { - entries: [{url: "about:robots", children: [{url: "about:mozilla"}]}] -}; - -function test() { - waitForExplicitFinish(); - requestLongerTimeout(2); - - Services.prefs.setIntPref("browser.sessionstore.interval", 4000); - registerCleanupFunction(function () { - Services.prefs.clearUserPref("browser.sessionstore.interval"); - }); - - let tab = gBrowser.addTab("about:blank"); - - let browser = tab.linkedBrowser; - - waitForTabState(tab, tabState, function() { - - let sessionHistory = browser.sessionHistory; - let entry = sessionHistory.getEntryAtIndex(0, false); - entry.QueryInterface(Ci.nsISHContainer); - - whenChildCount(entry, 1, function () { - whenChildCount(entry, 2, function () { - whenBrowserLoaded(browser, function () { - let sessionHistory = browser.sessionHistory; - let entry = sessionHistory.getEntryAtIndex(0, false); - - whenChildCount(entry, 0, function () { - // Make sure that we reset the state. - let blankState = { windows: [{ tabs: [{ entries: [{ url: "about:blank" }] }]}]}; - waitForBrowserState(blankState, finish); - }); - }); - - // reload the browser to deprecate the subframes - browser.reload(); - }); - - // create a dynamic subframe - let doc = browser.contentDocument; - let iframe = doc.createElement("iframe"); - doc.body.appendChild(iframe); - iframe.setAttribute("src", "about:mozilla"); - }); - }); -} - -function whenChildCount(aEntry, aChildCount, aCallback) { - if (aEntry.childCount == aChildCount) - aCallback(); - else - setTimeout(function () whenChildCount(aEntry, aChildCount, aCallback), 100); -} diff --git a/browser/components/sessionstore/test/browser_739531.js b/browser/components/sessionstore/test/browser_739531.js deleted file mode 100644 index e5927caf6..000000000 --- a/browser/components/sessionstore/test/browser_739531.js +++ /dev/null @@ -1,47 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -// This test ensures that attempts made to save/restore ("duplicate") pages -// using designmode AND make changes to document structure (remove body) -// don't result in uncaught errors and a broken browser state. - -function test() { - waitForExplicitFinish(); - - let testURL = "http://mochi.test:8888/browser/" + - "browser/components/sessionstore/test/browser_739531_sample.html"; - - let loadCount = 0; - let tab = gBrowser.addTab(testURL); - tab.linkedBrowser.addEventListener("load", function onLoad(aEvent) { - // make sure both the page and the frame are loaded - if (++loadCount < 2) - return; - tab.linkedBrowser.removeEventListener("load", onLoad, true); - - // executeSoon to allow the JS to execute on the page - executeSoon(function() { - - let tab2; - let caughtError = false; - try { - tab2 = ss.duplicateTab(window, tab); - } - catch (e) { - caughtError = true; - info(e); - } - - is(gBrowser.tabs.length, 3, "there should be 3 tabs") - - ok(!caughtError, "duplicateTab didn't throw"); - - // if the test fails, we don't want to try to close a tab that doesn't exist - if (tab2) - gBrowser.removeTab(tab2); - gBrowser.removeTab(tab); - - finish(); - }); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_739531_sample.html b/browser/components/sessionstore/test/browser_739531_sample.html deleted file mode 100644 index ad317ab0c..000000000 --- a/browser/components/sessionstore/test/browser_739531_sample.html +++ /dev/null @@ -1,25 +0,0 @@ -<!-- originally a crash test for bug 713417 - https://bug713417.bugzilla.mozilla.org/attachment.cgi?id=584240 --> -<!DOCTYPE html> -<html> -<head> -<meta charset="utf-8"> -<script> - -function boom() -{ - var w = document.getElementById("f").contentWindow; - var d = w.document; - d.designMode = 'on'; - var r = d.documentElement; - d.removeChild(r); - document.adoptNode(r); -} - -</script> -</head> -<body onload="boom();"> -<iframe src="data:text/html;charset=utf-8,1" id="f"></iframe> -</body> -</html> - diff --git a/browser/components/sessionstore/test/browser_739805.js b/browser/components/sessionstore/test/browser_739805.js deleted file mode 100644 index 077916456..000000000 --- a/browser/components/sessionstore/test/browser_739805.js +++ /dev/null @@ -1,54 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -let tabState = { - entries: [{url: "data:text/html;charset=utf-8,<input%20id='foo'>", formdata: { id: { "foo": "bar" } } }] -}; - -function test() { - waitForExplicitFinish(); - Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true); - - registerCleanupFunction(function () { - if (gBrowser.tabs.length > 1) - gBrowser.removeTab(gBrowser.tabs[1]); - Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand"); - }); - - let tab = gBrowser.addTab("about:blank"); - let browser = tab.linkedBrowser; - - whenBrowserLoaded(browser, function () { - isnot(gBrowser.selectedTab, tab, "newly created tab is not selected"); - - ss.setTabState(tab, JSON.stringify(tabState)); - is(browser.__SS_restoreState, TAB_STATE_NEEDS_RESTORE, "tab needs restoring"); - - let state = JSON.parse(ss.getTabState(tab)); - let formdata = state.entries[0].formdata; - is(formdata && formdata.id["foo"], "bar", "tab state's formdata is valid"); - - whenTabRestored(tab, function () { - let input = browser.contentDocument.getElementById("foo"); - is(input.value, "bar", "formdata has been restored correctly"); - finish(); - }); - - // Restore the tab by selecting it. - gBrowser.selectedTab = tab; - }); -} - -function whenBrowserLoaded(aBrowser, aCallback) { - aBrowser.addEventListener("load", function onLoad() { - aBrowser.removeEventListener("load", onLoad, true); - executeSoon(aCallback); - }, true); -} - -function whenTabRestored(aTab, aCallback) { - aTab.addEventListener("SSTabRestored", function onRestored() { - aTab.removeEventListener("SSTabRestored", onRestored); - executeSoon(aCallback); - }); -} diff --git a/browser/components/sessionstore/test/browser_819510_perwindowpb.js b/browser/components/sessionstore/test/browser_819510_perwindowpb.js deleted file mode 100644 index 291e8aa50..000000000 --- a/browser/components/sessionstore/test/browser_819510_perwindowpb.js +++ /dev/null @@ -1,189 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -const originalState = ss.getBrowserState(); - -/** Private Browsing Test for Bug 819510 **/ -function test() { - waitForExplicitFinish(); - - registerCleanupFunction(function() { - ss.setBrowserState(originalState); - }); - - runNextTest(); -} - -let tests = [test_1, test_2, test_3 ]; - -const testState = { - windows: [{ - tabs: [ - { entries: [{ url: "about:blank" }] }, - ] - }] -}; - -function runNextTest() { - // Set an empty state - closeAllButPrimaryWindow(); - - // Run the next test, or finish - if (tests.length) { - let currentTest = tests.shift(); - waitForBrowserState(testState, currentTest); - } else { - finish(); - } -} - -// Test opening default mochitest-normal-private-normal-private windows -// (saving the state with last window being private) -function test_1() { - testOnWindow(false, function(aWindow) { - aWindow.gBrowser.addTab("http://www.example.com/1"); - testOnWindow(true, function(aWindow) { - aWindow.gBrowser.addTab("http://www.example.com/2"); - testOnWindow(false, function(aWindow) { - aWindow.gBrowser.addTab("http://www.example.com/3"); - testOnWindow(true, function(aWindow) { - aWindow.gBrowser.addTab("http://www.example.com/4"); - - let curState = JSON.parse(ss.getBrowserState()); - is (curState.windows.length, 5, "Browser has opened 5 windows"); - is (curState.windows[2].isPrivate, true, "Window is private"); - is (curState.windows[4].isPrivate, true, "Last window is private"); - is (curState.selectedWindow, 5, "Last window opened is the one selected"); - - forceWriteState(function(state) { - is(state.windows.length, 3, - "sessionstore state: 3 windows in data being written to disk"); - is (state.selectedWindow, 3, - "Selected window is updated to match one of the saved windows"); - state.windows.forEach(function(win) { - is(!win.isPrivate, true, "Saved window is not private"); - }); - is(state._closedWindows.length, 0, - "sessionstore state: no closed windows in data being written to disk"); - runNextTest(); - }); - }); - }); - }); - }); -} - -// Test opening default mochitest window + 2 private windows -function test_2() { - testOnWindow(true, function(aWindow) { - aWindow.gBrowser.addTab("http://www.example.com/1"); - testOnWindow(true, function(aWindow) { - aWindow.gBrowser.addTab("http://www.example.com/2"); - - let curState = JSON.parse(ss.getBrowserState()); - is (curState.windows.length, 3, "Browser has opened 3 windows"); - is (curState.windows[1].isPrivate, true, "Window 1 is private"); - is (curState.windows[2].isPrivate, true, "Window 2 is private"); - is (curState.selectedWindow, 3, "Last window opened is the one selected"); - - forceWriteState(function(state) { - is(state.windows.length, 1, - "sessionstore state: 1 windows in data being written to disk"); - is (state.selectedWindow, 1, - "Selected window is updated to match one of the saved windows"); - is(state._closedWindows.length, 0, - "sessionstore state: no closed windows in data being written to disk"); - runNextTest(); - }); - }); - }); -} - -// Test opening default-normal-private-normal windows and closing a normal window -function test_3() { - testOnWindow(false, function(normalWindow) { - waitForTabLoad(normalWindow, "http://www.example.com/", function() { - testOnWindow(true, function(aWindow) { - waitForTabLoad(aWindow, "http://www.example.com/", function() { - testOnWindow(false, function(aWindow) { - waitForTabLoad(aWindow, "http://www.example.com/", function() { - - let curState = JSON.parse(ss.getBrowserState()); - is(curState.windows.length, 4, "Browser has opened 4 windows"); - is(curState.windows[2].isPrivate, true, "Window 2 is private"); - is(curState.selectedWindow, 4, "Last window opened is the one selected"); - - waitForWindowClose(normalWindow, function() { - // Load another tab before checking the written state so that - // the list of restoring windows gets cleared. Otherwise the - // window we just closed would be marked as not closed. - waitForTabLoad(aWindow, "http://www.example.com/", function() { - forceWriteState(function(state) { - is(state.windows.length, 2, - "sessionstore state: 2 windows in data being written to disk"); - is(state.selectedWindow, 2, - "Selected window is updated to match one of the saved windows"); - state.windows.forEach(function(win) { - is(!win.isPrivate, true, "Saved window is not private"); - }); - is(state._closedWindows.length, 1, - "sessionstore state: 1 closed window in data being written to disk"); - state._closedWindows.forEach(function(win) { - is(!win.isPrivate, true, "Closed window is not private"); - }); - runNextTest(); - }); - }); - }); - }); - }); - }); - }); - }); - }); -} - -function waitForWindowClose(aWin, aCallback) { - let winCount = JSON.parse(ss.getBrowserState()).windows.length; - aWin.addEventListener("SSWindowClosing", function onWindowClosing() { - aWin.removeEventListener("SSWindowClosing", onWindowClosing, false); - function checkCount() { - let state = JSON.parse(ss.getBrowserState()); - if (state.windows.length == (winCount - 1)) { - aCallback(); - } else { - executeSoon(checkCount); - } - } - executeSoon(checkCount); - }, false); - aWin.close(); -} - -function forceWriteState(aCallback) { - Services.obs.addObserver(function observe(aSubject, aTopic, aData) { - if (aTopic == "sessionstore-state-write") { - Services.obs.removeObserver(observe, aTopic); - Services.prefs.clearUserPref("browser.sessionstore.interval"); - aSubject.QueryInterface(Ci.nsISupportsString); - aCallback(JSON.parse(aSubject.data)); - } - }, "sessionstore-state-write", false); - Services.prefs.setIntPref("browser.sessionstore.interval", 0); -} - -function testOnWindow(aIsPrivate, aCallback) { - let win = OpenBrowserWindow({private: aIsPrivate}); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - executeSoon(function() { aCallback(win); }); - }, false); -} - -function waitForTabLoad(aWin, aURL, aCallback) { - aWin.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { - aWin.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); - executeSoon(aCallback); - }, true); - aWin.gBrowser.selectedBrowser.loadURI(aURL); -} diff --git a/browser/components/sessionstore/test/browser_833286_atomic_backup.js b/browser/components/sessionstore/test/browser_833286_atomic_backup.js deleted file mode 100644 index bc21ae399..000000000 --- a/browser/components/sessionstore/test/browser_833286_atomic_backup.js +++ /dev/null @@ -1,143 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -// This tests are for a sessionstore.js atomic backup. - -let tmp = {}; -Cu.import("resource://gre/modules/osfile.jsm", tmp); -Cu.import("resource://gre/modules/Task.jsm", tmp); -Cu.import("resource:///modules/sessionstore/_SessionFile.jsm", tmp); - -const {OS, Task, _SessionFile} = tmp; - -const PREF_SS_INTERVAL = "browser.sessionstore.interval"; -// Full paths for sessionstore.js and sessionstore.bak. -const path = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.js"); -const backupPath = OS.Path.join(OS.Constants.Path.profileDir, - "sessionstore.bak"); - -// A text decoder. -let gDecoder = new TextDecoder(); -// Global variables that contain sessionstore.js and sessionstore.bak data for -// comparison between tests. -let gSSData; -let gSSBakData; - -// waitForSaveStateComplete waits for a state write completion. -function waitForSaveStateComplete(aSaveStateCallback) { - let topic = "sessionstore-state-write-complete"; - - function observer() { - Services.prefs.clearUserPref(PREF_SS_INTERVAL); - Services.obs.removeObserver(observer, topic); - executeSoon(function taskCallback() { - Task.spawn(aSaveStateCallback); - }); - } - - Services.obs.addObserver(observer, topic, false); -} - -// Register next test callback and trigger state saving change. -function nextTest(testFunc) { - waitForSaveStateComplete(testFunc); - Services.prefs.setIntPref(PREF_SS_INTERVAL, 0); -} - -registerCleanupFunction(function() { - // Cleaning up after the test: removing the sessionstore.bak file. - Task.spawn(function cleanupTask() { - yield OS.File.remove(backupPath); - }); -}); - -function test() { - waitForExplicitFinish(); - nextTest(testInitialWriteNoBackup); -} - -function testInitialWriteNoBackup() { - // Ensure that sessionstore.js is created, but not sessionstore.bak. - let ssExists = yield OS.File.exists(path); - let ssBackupExists = yield OS.File.exists(backupPath); - ok(ssExists, "sessionstore.js should be created."); - ok(!ssBackupExists, "sessionstore.bak should not have been created, yet."); - - nextTest(testWriteNoBackup); -} - -function testWriteNoBackup() { - // Ensure sessionstore.bak is not created. - let ssExists = yield OS.File.exists(path); - let ssBackupExists = yield OS.File.exists(backupPath); - ok(ssExists, "sessionstore.js should exist."); - ok(!ssBackupExists, "sessionstore.bak should not have been created, yet"); - - // Save sessionstore.js data to compare to the sessionstore.bak data in the - // next test. - let array = yield OS.File.read(path); - gSSData = gDecoder.decode(array); - - // Manually trigger _SessionFile.createBackupCopy since the backup once - // promise is already resolved and backup would not be triggered again. - yield _SessionFile.createBackupCopy(); - - nextTest(testWriteBackup); -} - -function testWriteBackup() { - // Ensure sessionstore.bak is finally created. - let ssExists = yield OS.File.exists(path); - let ssBackupExists = yield OS.File.exists(backupPath); - ok(ssExists, "sessionstore.js exists."); - ok(ssBackupExists, "sessionstore.bak should now be created."); - - // Read sessionstore.bak data. - let array = yield OS.File.read(backupPath); - gSSBakData = gDecoder.decode(array); - - // Make sure that the sessionstore.bak is identical to the last - // sessionstore.js. - is(gSSBakData, gSSData, "sessionstore.js is backed up correctly."); - - // Read latest sessionstore.js. - array = yield OS.File.read(path); - gSSData = gDecoder.decode(array); - - // Read sessionstore.js with _SessionFile.read. - let ssDataRead = yield _SessionFile.read(); - is(ssDataRead, gSSData, "_SessionFile.read read sessionstore.js correctly."); - - // Read sessionstore.js with _SessionFile.syncRead. - ssDataRead = _SessionFile.syncRead(); - is(ssDataRead, gSSData, - "_SessionFile.syncRead read sessionstore.js correctly."); - - // Remove sessionstore.js to test fallback onto sessionstore.bak. - yield OS.File.remove(path); - ssExists = yield OS.File.exists(path); - ok(!ssExists, "sessionstore.js should be removed now."); - - // Read sessionstore.bak with _SessionFile.read. - ssDataRead = yield _SessionFile.read(); - is(ssDataRead, gSSBakData, - "_SessionFile.read read sessionstore.bak correctly."); - - // Read sessionstore.bak with _SessionFile.syncRead. - ssDataRead = _SessionFile.syncRead(); - is(ssDataRead, gSSBakData, - "_SessionFile.syncRead read sessionstore.bak correctly."); - nextTest(testNoWriteBackup); -} - -function testNoWriteBackup() { - // Ensure sessionstore.bak is backed up only once. - - // Read sessionstore.bak data. - let array = yield OS.File.read(backupPath); - let ssBakData = gDecoder.decode(array); - // Ensure the sessionstore.bak did not change. - is(ssBakData, gSSBakData, "sessionstore.bak is unchanged."); - - executeSoon(finish); -}
\ No newline at end of file diff --git a/browser/components/sessionstore/test/browser_attributes.js b/browser/components/sessionstore/test/browser_attributes.js deleted file mode 100644 index 29b748b85..000000000 --- a/browser/components/sessionstore/test/browser_attributes.js +++ /dev/null @@ -1,72 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -function test() { - TestRunner.run(); -} - -/** - * This test makes sure that we correctly preserve tab attributes when storing - * and restoring tabs. It also ensures that we skip special attributes like - * 'image' and 'pending' that need to be handled differently or internally. - */ - -const PREF = "browser.sessionstore.restore_on_demand"; - -function runTests() { - Services.prefs.setBoolPref(PREF, true) - registerCleanupFunction(() => Services.prefs.clearUserPref(PREF)); - - // Add a new tab with a nice icon. - let tab = gBrowser.addTab("about:robots"); - yield whenBrowserLoaded(tab.linkedBrowser); - - // Check that the tab has an 'image' attribute. - ok(tab.hasAttribute("image"), "tab.image exists"); - - // Make sure we do not persist 'image' attributes. - ss.persistTabAttribute("image"); - let {attributes} = JSON.parse(ss.getTabState(tab)); - ok(!("image" in attributes), "'image' attribute not saved"); - ok(!("custom" in attributes), "'custom' attribute not saved"); - - // Test persisting a custom attribute. - tab.setAttribute("custom", "foobar"); - ss.persistTabAttribute("custom"); - - let {attributes} = JSON.parse(ss.getTabState(tab)); - is(attributes.custom, "foobar", "'custom' attribute is correct"); - - // Make sure we're backwards compatible and restore old 'image' attributes. - let state = { - entries: [{url: "about:mozilla"}], - attributes: {custom: "foobaz", image: gBrowser.getIcon(tab)} - }; - - // Prepare a pending tab waiting to be restored. - whenTabRestoring(tab); - yield ss.setTabState(tab, JSON.stringify(state)); - - ok(tab.hasAttribute("pending"), "tab is pending"); - is(gBrowser.getIcon(tab), state.attributes.image, "tab has correct icon"); - - // Let the pending tab load. - gBrowser.selectedTab = tab; - yield whenBrowserLoaded(tab.linkedBrowser); - - // Ensure no 'image' or 'pending' attributes are stored. - let {attributes} = JSON.parse(ss.getTabState(tab)); - ok(!("image" in attributes), "'image' attribute not saved"); - ok(!("pending" in attributes), "'pending' attribute not saved"); - is(attributes.custom, "foobaz", "'custom' attribute is correct"); - - // Clean up. - gBrowser.removeTab(tab); -} - -function whenTabRestoring(tab) { - tab.addEventListener("SSTabRestoring", function onRestoring() { - tab.removeEventListener("SSTabRestoring", onRestoring); - executeSoon(next); - }); -} diff --git a/browser/components/sessionstore/test/browser_capabilities.js b/browser/components/sessionstore/test/browser_capabilities.js deleted file mode 100644 index 349d4ecfa..000000000 --- a/browser/components/sessionstore/test/browser_capabilities.js +++ /dev/null @@ -1,73 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -function test() { - TestRunner.run(); -} - -/** - * This test ensures that disabling features by flipping nsIDocShell.allow* - * properties are (re)stored as disabled. Disallowed features must be - * re-enabled when the tab is re-used by another tab restoration. - */ - -function runTests() { - // Create a tab that we're going to use for our tests. - let tab = gBrowser.selectedTab = gBrowser.addTab("about:mozilla"); - let browser = tab.linkedBrowser; - let docShell = browser.docShell; - yield waitForLoad(browser); - - // Get the list of capabilities for docShells. - let flags = Object.keys(docShell).filter(k => k.startsWith("allow")); - - // Check that everything is allowed by default for new tabs. - let state = JSON.parse(ss.getTabState(tab)); - ok(!("disallow" in state), "everything allowed by default"); - ok(flags.every(f => docShell[f]), "all flags set to true"); - - // Flip a couple of allow* flags. - docShell.allowImages = false; - docShell.allowMetaRedirects = false; - - // Check that we correctly save disallowed features. - let disallowedState = JSON.parse(ss.getTabState(tab)); - let disallow = new Set(disallowedState.disallow.split(",")); - ok(disallow.has("Images"), "images not allowed"); - ok(disallow.has("MetaRedirects"), "meta redirects not allowed"); - is(disallow.size, 2, "two capabilities disallowed"); - - // Reuse the tab to restore a new, clean state into it. - ss.setTabState(tab, JSON.stringify({ entries: [{url: "about:robots"}] })); - yield waitForLoad(browser); - - // After restoring disallowed features must be available again. - state = JSON.parse(ss.getTabState(tab)); - ok(!("disallow" in state), "everything allowed again"); - ok(flags.every(f => docShell[f]), "all flags set to true"); - - // Restore the state with disallowed features. - ss.setTabState(tab, JSON.stringify(disallowedState)); - yield waitForLoad(browser); - - // Check that docShell flags are set. - ok(!docShell.allowImages, "images not allowed"); - ok(!docShell.allowMetaRedirects, "meta redirects not allowed") - - // Check that we correctly restored features as disabled. - state = JSON.parse(ss.getTabState(tab)); - disallow = new Set(state.disallow.split(",")); - ok(disallow.has("Images"), "images not allowed anymore"); - ok(disallow.has("MetaRedirects"), "meta redirects not allowed anymore"); - is(disallow.size, 2, "two capabilities disallowed"); - - // Clean up after ourselves. - gBrowser.removeTab(tab); -} - -function waitForLoad(aElement) { - aElement.addEventListener("load", function onLoad() { - aElement.removeEventListener("load", onLoad, true); - executeSoon(next); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_dying_cache.js b/browser/components/sessionstore/test/browser_dying_cache.js deleted file mode 100644 index 41e22d864..000000000 --- a/browser/components/sessionstore/test/browser_dying_cache.js +++ /dev/null @@ -1,78 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -function test() { - TestRunner.run(); -} - -/** - * This test ensures that after closing a window we keep its state data around - * as long as something keeps a reference to it. It should only be possible to - * read data after closing - writing should fail. - */ - -function runTests() { - // Open a new window. - let win = OpenBrowserWindow(); - yield whenWindowLoaded(win); - - // Load some URL in the current tab. - win.gBrowser.selectedBrowser.loadURI("about:robots"); - yield whenBrowserLoaded(win.gBrowser.selectedBrowser); - - // Open a second tab and close the first one. - let tab = win.gBrowser.addTab("about:mozilla"); - yield whenBrowserLoaded(tab.linkedBrowser); - win.gBrowser.removeTab(win.gBrowser.tabs[0]); - - // Make sure our window is still tracked by sessionstore - // and the window state is as expected. - ok("__SSi" in win, "window is being tracked by sessionstore"); - ss.setWindowValue(win, "foo", "bar"); - checkWindowState(win); - - let state = ss.getWindowState(win); - let closedTabData = ss.getClosedTabData(win); - - // Close our window and wait a tick. - whenWindowClosed(win); - yield win.close(); - - // SessionStore should no longer track our window - // but it should still report the same state. - ok(!("__SSi" in win), "sessionstore does no longer track our window"); - checkWindowState(win); - - // Make sure we're not allowed to modify state data. - ok(shouldThrow(() => ss.setWindowState(win, {})), - "we're not allowed to modify state data anymore"); - ok(shouldThrow(() => ss.setWindowValue(win, "foo", "baz")), - "we're not allowed to modify state data anymore"); -} - -function checkWindowState(window) { - let {windows: [{tabs}]} = JSON.parse(ss.getWindowState(window)); - is(tabs.length, 1, "the window has a single tab"); - is(tabs[0].entries[0].url, "about:mozilla", "the tab is about:mozilla"); - - is(ss.getClosedTabCount(window), 1, "the window has one closed tab"); - let [{state: {entries: [{url}]}}] = JSON.parse(ss.getClosedTabData(window)); - is(url, "about:robots", "the closed tab is about:robots"); - - is(ss.getWindowValue(window, "foo"), "bar", "correct extData value"); -} - -function shouldThrow(f) { - try { - f(); - } catch (e) { - return true; - } -} - -function whenWindowClosed(window) { - window.addEventListener("SSWindowClosing", function onClosing() { - window.removeEventListener("SSWindowClosing", onClosing); - executeSoon(next); - }); -} diff --git a/browser/components/sessionstore/test/browser_form_restore_events.js b/browser/components/sessionstore/test/browser_form_restore_events.js deleted file mode 100644 index f673d85ec..000000000 --- a/browser/components/sessionstore/test/browser_form_restore_events.js +++ /dev/null @@ -1,67 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function test() { - /** Originally a test for Bug 476161, but then expanded to include all input types in bug 640136 **/ - - waitForExplicitFinish(); - - let file = Components.classes["@mozilla.org/file/directory_service;1"] - .getService(Components.interfaces.nsIProperties) - .get("TmpD", Components.interfaces.nsIFile); - - let testURL = "http://mochi.test:8888/browser/" + - "browser/components/sessionstore/test/browser_form_restore_events_sample.html"; - let tab = gBrowser.addTab(testURL); - tab.linkedBrowser.addEventListener("load", function(aEvent) { - tab.linkedBrowser.removeEventListener("load", arguments.callee, true); - let doc = tab.linkedBrowser.contentDocument; - - // text fields - doc.getElementById("modify01").value += Math.random(); - doc.getElementById("modify02").value += " " + Date.now(); - - // textareas - doc.getElementById("modify03").value += Math.random(); - doc.getElementById("modify04").value += " " + Date.now(); - - // file - doc.getElementById("modify05").value = file.path; - - // select - doc.getElementById("modify06").selectedIndex = 1; - var multipleChange = doc.getElementById("modify07"); - Array.forEach(multipleChange.options, function(option) option.selected = true); - - // checkbox - doc.getElementById("modify08").checked = true; - doc.getElementById("modify09").checked = false; - - // radio - // select one then another in the same group - only last one should get event on restore - doc.getElementById("modify10").checked = true; - doc.getElementById("modify11").checked = true; - - - let tab2 = gBrowser.duplicateTab(tab); - tab2.linkedBrowser.addEventListener("load", function(aEvent) { - tab2.linkedBrowser.removeEventListener("load", arguments.callee, true); - let doc = tab2.linkedBrowser.contentDocument; - let inputFired = doc.getElementById("inputFired").textContent.trim().split(); - let changeFired = doc.getElementById("changeFired").textContent.trim().split(); - - is(inputFired.sort().join(" "), "modify01 modify02 modify03 modify04 modify05", - "input events were only dispatched for modified input, textarea fields"); - - is(changeFired.sort().join(" "), "modify06 modify07 modify08 modify09 modify11", - "change events were only dispatched for modified select, checkbox, radio fields"); - - // clean up - gBrowser.removeTab(tab2); - gBrowser.removeTab(tab); - - finish(); - }, true); - }, true); -} diff --git a/browser/components/sessionstore/test/browser_form_restore_events_sample.html b/browser/components/sessionstore/test/browser_form_restore_events_sample.html deleted file mode 100644 index 1d46d4040..000000000 --- a/browser/components/sessionstore/test/browser_form_restore_events_sample.html +++ /dev/null @@ -1,99 +0,0 @@ -<!DOCTYPE html> -<meta charset="utf-8"> -<title>Test for form restore events (originally bug 476161)</title> - -<script> - -document.addEventListener("input", function(aEvent) { - var inputEl = aEvent.originalTarget; - var changedEl = document.getElementById("inputFired"); - changedEl.textContent += " " + inputEl.id; -}, false); - -document.addEventListener("change", function(aEvent) { - var inputEl = aEvent.originalTarget; - var changedEl = document.getElementById("changeFired"); - changedEl.textContent += " " + inputEl.id; -}, false); - -</script> - -<!-- input events --> -<h3>Text fields with changed text</h3> -<input type="text" id="modify1"> -<input type="text" id="modify2" value="preset value"> -<input type="text" id="modify01"> -<input type="text" id="modify02" value="preset value"> - -<h3>Text fields with unchanged text</h3> -<input type="text" id="unchanged1"> -<input type="text" id="unchanged2" value="preset value"> -<input type="text" id="unchanged01"> -<input type="text" id="unchanged02" value="preset value"> - -<h3>Textarea with changed text</h3> -<textarea id="modify03"></textarea> -<textarea id="modify04">preset value</textarea> - -<h3>Textarea with unchanged text</h3> -<textarea id="unchanged03"></textarea> -<textarea id="unchanged04">preset value</textarea> - -<h3>file field with changed value</h3> -<input type="file" id="modify05"> - -<h3>file field with unchanged value</h3> -<input type="file" id="unchanged05"> - -<!-- change events --> - -<h3>Select menu with changed selection</h3> -<select id="modify06"> - <option value="one">one</option> - <option value="two">two</option> - <option value="three">three</option> -</select> - -<h3>Select menu with unchanged selection (change event still fires)</h3> -<select id="unchanged06"> - <option value="one">one</option> - <option value="two" selected>two</option> - <option value="three">three</option> -</select> - -<h3>Multiple Select menu with changed selection</h3> -<select id="modify07" multiple> - <option value="one">one</option> - <option value="two" selected>two</option> - <option value="three">three</option> -</select> - -<h3>Select menu with unchanged selection</h3> -<select id="unchanged07" multiple> - <option value="one">one</option> - <option value="two" selected>two</option> - <option value="three" selected>three</option> -</select> - -<h3>checkbox with changed value</h3> -<input type="checkbox" id="modify08"> -<input type="checkbox" id="modify09" checked> - -<h3>checkbox with unchanged value</h3> -<input type="checkbox" id="unchanged08"> -<input type="checkbox" id="unchanged09" checked> - -<h3>radio with changed value</h3> -<input type="radio" id="modify10" name="group">Radio 1</input> -<input type="radio" id="modify11" name="group">Radio 2</input> -<input type="radio" id="modify12" name="group" checked>Radio 3</input> - -<h3>radio with unchanged value</h3> -<input type="radio" id="unchanged10" name="group2">Radio 4</input> -<input type="radio" id="unchanged11" name="group2">Radio 5</input> -<input type="radio" id="unchanged12" name="group2" checked>Radio 6</input> - -<h3>Changed field IDs</h3> -<div id="changed"></div> -<div id="inputFired"></div> -<div id="changeFired"></div> diff --git a/browser/components/sessionstore/test/browser_formdata_format.js b/browser/components/sessionstore/test/browser_formdata_format.js deleted file mode 100644 index 52d165a1c..000000000 --- a/browser/components/sessionstore/test/browser_formdata_format.js +++ /dev/null @@ -1,115 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -function test() { - /** Tests formdata format **/ - waitForExplicitFinish(); - - let formData = [ - { }, - // old format - { "#input1" : "value0" }, - { "#input1" : "value1", "/xhtml:html/xhtml:body/xhtml:input[@name='input2']" : "value2" }, - { "/xhtml:html/xhtml:body/xhtml:input[@name='input2']" : "value3" }, - // new format - { id: { "input1" : "value4" } }, - { id: { "input1" : "value5" }, xpath: {} }, - { id: { "input1" : "value6" }, xpath: { "/xhtml:html/xhtml:body/xhtml:input[@name='input2']" : "value7" } }, - { id: {}, xpath: { "/xhtml:html/xhtml:body/xhtml:input[@name='input2']" : "value8" } }, - { xpath: { "/xhtml:html/xhtml:body/xhtml:input[@name='input2']" : "value9" } }, - // combinations - { "#input1" : "value10", id: { "input1" : "value11" } }, - { "#input1" : "value12", id: { "input1" : "value13" }, xpath: { "/xhtml:html/xhtml:body/xhtml:input[@name='input2']" : "value14" } }, - { "#input1" : "value15", xpath: { "/xhtml:html/xhtml:body/xhtml:input[@name='input2']" : "value16" } }, - { "/xhtml:html/xhtml:body/xhtml:input[@name='input2']" : "value17", id: { "input1" : "value18" } }, - { "/xhtml:html/xhtml:body/xhtml:input[@name='input2']" : "value19", id: { "input1" : "value20" }, xpath: { "/xhtml:html/xhtml:body/xhtml:input[@name='input2']" : "value21" } }, - { "/xhtml:html/xhtml:body/xhtml:input[@name='input2']" : "value22", xpath: { "/xhtml:html/xhtml:body/xhtml:input[@name='input2']" : "value23" } }, - { "#input1" : "value24", "/xhtml:html/xhtml:body/xhtml:input[@name='input2']" : "value25", id: { "input1" : "value26" } }, - { "#input1" : "value27", "/xhtml:html/xhtml:body/xhtml:input[@name='input2']" : "value28", id: { "input1" : "value29" }, xpath: { "/xhtml:html/xhtml:body/xhtml:input[@name='input2']" : "value30" } }, - { "#input1" : "value31", "/xhtml:html/xhtml:body/xhtml:input[@name='input2']" : "value32", xpath: { "/xhtml:html/xhtml:body/xhtml:input[@name='input2']" : "value33" } } - ] - let expectedValues = [ - [ "" , "" ], - // old format - [ "value0", "" ], - [ "value1", "value2" ], - [ "", "value3" ], - // new format - [ "value4", "" ], - [ "value5", "" ], - [ "value6", "value7" ], - [ "", "value8" ], - [ "", "value9" ], - // combinations - [ "value11", "" ], - [ "value13", "value14" ], - [ "", "value16" ], - [ "value18", "" ], - [ "value20", "value21" ], - [ "", "value23" ], - [ "value26", "" ], - [ "value29", "value30" ], - [ "", "value33" ] - ]; - let testTabCount = 0; - let callback = function() { - testTabCount--; - if (testTabCount == 0) { - finish(); - } - }; - - for (let i = 0; i < formData.length; i++) { - testTabCount++; - testTabRestoreData(formData[i], expectedValues[i], callback); - } -} - -function testTabRestoreData(aFormData, aExpectedValue, aCallback) { - let testURL = - getRootDirectory(gTestPath) + "browser_formdata_format_sample.html"; - let tab = gBrowser.addTab(testURL); - let tabState = { entries: [{ url: testURL, formdata: aFormData}] }; - - let browserLoadedCallback = function(aEvent) { - let tabStateCallback = function(aEvent) { - let doc = tab.linkedBrowser.contentDocument; - let input1 = doc.getElementById("input1"); - let input2 = doc.querySelector("input[name=input2]"); - let saveStateCallback = function(aEvent) { - let restoredTabState = JSON.parse(ss.getTabState(tab)); - let restoredFormData = restoredTabState.entries[0].formdata; - - if (restoredFormData) { - // test format - ok("id" in restoredFormData && "xpath" in restoredFormData, - "FormData format is valid: " + restoredFormData); - // validate that there are no old keys - is(Object.keys(restoredFormData).length, 2, - "FormData key length is valid"); - // test id - is(input1.value, aExpectedValue[0], - "FormData by 'id' has been restored correctly"); - // test xpath - is(input2.value, aExpectedValue[1], - "FormData by 'xpath' has been restored correctly"); - } - - // clean up - gBrowser.removeTab(tab); - aCallback(); - }; - - waitForSaveState(saveStateCallback); - - // force a change event to recollect the formdata - let changeEvent = document.createEvent("Events"); - changeEvent.initEvent("change", true, true); - input.dispatchEvent(changeEvent); - }; - - waitForTabState(tab, tabState, tabStateCallback); - }; - - whenBrowserLoaded(tab.linkedBrowser, browserLoadedCallback); -} diff --git a/browser/components/sessionstore/test/browser_formdata_format_sample.html b/browser/components/sessionstore/test/browser_formdata_format_sample.html deleted file mode 100644 index f991e3657..000000000 --- a/browser/components/sessionstore/test/browser_formdata_format_sample.html +++ /dev/null @@ -1,7 +0,0 @@ -<!DOCTYPE html> -<title>Test formdata format</title> - -<!-- input events --> -<h3>Input fields</h3> -<input type="text" id="input1"> -<input type="text" name="input2">
\ No newline at end of file diff --git a/browser/components/sessionstore/test/browser_input.js b/browser/components/sessionstore/test/browser_input.js deleted file mode 100644 index 56681ca4f..000000000 --- a/browser/components/sessionstore/test/browser_input.js +++ /dev/null @@ -1,121 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -const URL = "http://mochi.test:8888/browser/" + - "browser/components/sessionstore/test/browser_input_sample.html"; - -function test() { - TestRunner.run(); -} - -/** - * This test ensures that modifying form input fields on a web page marks the - * window as dirty and causes the corresponding form data of the tab that - * changed to be re-collected. - */ - -function runTests() { - // Create a dummy window that is regarded as active. We need to do this - // because we always collect data for tabs of active windows no matter if - // the window is dirty or not. - let win = OpenBrowserWindow(); - yield waitForLoad(win); - - // Create a tab with some form fields. - let tab = gBrowser.selectedTab = gBrowser.addTab(URL); - let browser = gBrowser.selectedBrowser; - yield waitForLoad(browser); - - // All windows currently marked as dirty will be written to disk - // and thus marked clean afterwards. - yield forceWriteState(); - - // Modify the checkbox field's state. - let chk = browser.contentDocument.getElementById("chk"); - EventUtils.sendMouseEvent({type: "click"}, chk); - yield waitForInput(); - - // Check that we'll save the form data state correctly. - let state = JSON.parse(ss.getBrowserState()); - let {formdata} = state.windows[0].tabs[1].entries[0]; - is(formdata.id.chk, true, "chk's value is correct"); - - // Clear dirty state of all windows again. - yield forceWriteState(); - - // Modify the text input field's state. - browser.contentDocument.getElementById("txt").focus(); - EventUtils.synthesizeKey("m", {}); - yield waitForInput(); - - // Check that we'll save the form data state correctly. - let state = JSON.parse(ss.getBrowserState()); - let {formdata} = state.windows[0].tabs[1].entries[0]; - is(formdata.id.chk, true, "chk's value is correct"); - is(formdata.id.txt, "m", "txt's value is correct"); - - // Clear dirty state of all windows again. - yield forceWriteState(); - - // Modify the state of the checkbox contained in the iframe. - let cdoc = browser.contentDocument.getElementById("ifr").contentDocument; - EventUtils.sendMouseEvent({type: "click"}, cdoc.getElementById("chk")); - yield waitForInput(); - - // Modify the state of text field contained in the iframe. - cdoc.getElementById("txt").focus(); - EventUtils.synthesizeKey("m", {}); - yield waitForInput(); - - // Check that we'll save the iframe's form data correctly. - let state = JSON.parse(ss.getBrowserState()); - let {formdata} = state.windows[0].tabs[1].entries[0].children[0]; - is(formdata.id.chk, true, "iframe chk's value is correct"); - is(formdata.id.txt, "m", "iframe txt's value is correct"); - - // Clear dirty state of all windows again. - yield forceWriteState(); - - // Modify the content editable's state. - browser.contentDocument.getElementById("ced").focus(); - EventUtils.synthesizeKey("m", {}); - yield waitForInput(); - - // Check the we'll correctly save the content editable's state. - let state = JSON.parse(ss.getBrowserState()); - let {innerHTML} = state.windows[0].tabs[1].entries[0].children[1]; - is(innerHTML, "m", "content editable's value is correct"); - - // Clean up after ourselves. - gBrowser.removeTab(tab); - win.close(); -} - -function forceWriteState() { - const PREF = "browser.sessionstore.interval"; - const TOPIC = "sessionstore-state-write"; - - Services.obs.addObserver(function observe() { - Services.obs.removeObserver(observe, TOPIC); - Services.prefs.clearUserPref(PREF); - executeSoon(next); - }, TOPIC, false); - - Services.prefs.setIntPref(PREF, 0); -} - -function waitForLoad(aElement) { - aElement.addEventListener("load", function onLoad() { - aElement.removeEventListener("load", onLoad, true); - executeSoon(next); - }, true); -} - -function waitForInput() { - let mm = gBrowser.selectedBrowser.messageManager; - - mm.addMessageListener("SessionStore:input", function onPageShow() { - mm.removeMessageListener("SessionStore:input", onPageShow); - executeSoon(next); - }); -} diff --git a/browser/components/sessionstore/test/browser_input_sample.html b/browser/components/sessionstore/test/browser_input_sample.html deleted file mode 100644 index bbcac79c0..000000000 --- a/browser/components/sessionstore/test/browser_input_sample.html +++ /dev/null @@ -1,18 +0,0 @@ -<!DOCTYPE HTML> -<html dir="ltr" xml:lang="en-US" lang="en-US"> - <head> - <meta charset="utf-8"> - <title>sessionstore input test</title> - </head> - <body> - <input id="chk" type="checkbox" /><input id="txt" /> - <iframe id="ifr" src="data:text/html;charset=utf-8,<input id=chk type=checkbox /><input id=txt />"></iframe> - <iframe id="ced"></iframe> - - <script type="text/javascript"> - addEventListener("load", () => { - document.getElementById("ced").contentDocument.designMode = "on"; - }); - </script> - </body> -</html> diff --git a/browser/components/sessionstore/test/browser_pageshow.js b/browser/components/sessionstore/test/browser_pageshow.js deleted file mode 100644 index 0130288e3..000000000 --- a/browser/components/sessionstore/test/browser_pageshow.js +++ /dev/null @@ -1,87 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -function test() { - TestRunner.run(); -} - -/** - * This test ensures that loading a page from bfcache (by going back or forward - * in history) marks the window as dirty and causes data about the tab that - * changed to be re-collected. - * - * We will do this by creating a tab with two history entries and going back - * to the first. When we now request the current browser state from the - * session store service the first history entry must be selected. - */ - -const URL = "data:text/html,<h1>first</h1>"; -const URL2 = "data:text/html,<h1>second</h1>"; - -function runTests() { - // Create a dummy window that is regarded as active. We need to do this - // because we always collect data for tabs of active windows no matter if - // the window is dirty or not. - let win = OpenBrowserWindow(); - yield waitForLoad(win); - - // Create a tab with two history entries. - let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank"); - yield loadURI(URL); - yield loadURI(URL2); - - // All windows currently marked as dirty will be written to disk - // and thus marked clean afterwards. - yield forceWriteState(); - - // Go back to 'about:robots' - which is loaded from the bfcache and thus - // will not fire a 'load' event but a 'pageshow' event with persisted=true. - waitForPageShow(); - yield gBrowser.selectedBrowser.goBack(); - is(tab.linkedBrowser.currentURI.spec, URL, "correct url after going back"); - - // If by receiving the 'pageshow' event the first window has correctly - // been marked as dirty, getBrowserState() should return the tab we created - // with the right history entry (about:robots) selected. - let state = JSON.parse(ss.getBrowserState()); - is(state.windows[0].tabs[1].index, 1, "first history entry is selected"); - - // Clean up after ourselves. - gBrowser.removeTab(tab); - win.close(); -} - -function forceWriteState() { - const PREF = "browser.sessionstore.interval"; - const TOPIC = "sessionstore-state-write"; - - Services.obs.addObserver(function observe() { - Services.obs.removeObserver(observe, TOPIC); - Services.prefs.clearUserPref(PREF); - executeSoon(next); - }, TOPIC, false); - - Services.prefs.setIntPref(PREF, 0); -} - -function loadURI(aURI) { - let browser = gBrowser.selectedBrowser; - waitForLoad(browser); - browser.loadURI(aURI); -} - -function waitForLoad(aElement) { - aElement.addEventListener("load", function onLoad() { - aElement.removeEventListener("load", onLoad, true); - executeSoon(next); - }, true); -} - -function waitForPageShow() { - let mm = gBrowser.selectedBrowser.messageManager; - - mm.addMessageListener("SessionStore:pageshow", function onPageShow() { - mm.removeMessageListener("SessionStore:pageshow", onPageShow); - executeSoon(next); - }); -} diff --git a/browser/components/sessionstore/test/browser_windowRestore_perwindowpb.js b/browser/components/sessionstore/test/browser_windowRestore_perwindowpb.js deleted file mode 100644 index 3ee345138..000000000 --- a/browser/components/sessionstore/test/browser_windowRestore_perwindowpb.js +++ /dev/null @@ -1,30 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public -* License, v. 2.0. If a copy of the MPL was not distributed with this -* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// This test checks that closed private windows can't be restored - -function test() { - waitForExplicitFinish(); - - // Purging the list of closed windows - while(ss.getClosedWindowCount() > 0) - ss.forgetClosedWindow(0); - - // Load a private window, then close it - // and verify it doesn't get remembered for restoring - var win = OpenBrowserWindow({private: true}); - - whenWindowLoaded(win, function onload() { - info("The private window got loaded"); - win.addEventListener("SSWindowClosing", function onclosing() { - win.removeEventListener("SSWindowClosing", onclosing, false); - executeSoon(function () { - is (ss.getClosedWindowCount(), 0, - "The private window should not have been stored"); - finish(); - }); - }, false); - win.close(); - }); -} diff --git a/browser/components/sessionstore/test/head.js b/browser/components/sessionstore/test/head.js deleted file mode 100644 index 86d741d2d..000000000 --- a/browser/components/sessionstore/test/head.js +++ /dev/null @@ -1,342 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const TAB_STATE_NEEDS_RESTORE = 1; -const TAB_STATE_RESTORING = 2; - -let tmp = {}; -Cu.import("resource:///modules/sessionstore/SessionStore.jsm", tmp); -let SessionStore = tmp.SessionStore; - -let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore); - -// Some tests here assume that all restored tabs are loaded without waiting for -// the user to bring them to the foreground. We ensure this by resetting the -// related preference (see the "firefox.js" defaults file for details). -Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", false); -registerCleanupFunction(function () { - Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand"); -}); - -// This kicks off the search service used on about:home and allows the -// session restore tests to be run standalone without triggering errors. -Cc["@mozilla.org/browser/clh;1"].getService(Ci.nsIBrowserHandler).defaultArgs; - -function provideWindow(aCallback, aURL, aFeatures) { - function callbackSoon(aWindow) { - executeSoon(function executeCallbackSoon() { - aCallback(aWindow); - }); - } - - let win = openDialog(getBrowserURL(), "", aFeatures || "chrome,all,dialog=no", aURL); - whenWindowLoaded(win, function onWindowLoaded(aWin) { - if (!aURL) { - info("Loaded a blank window."); - callbackSoon(aWin); - return; - } - - aWin.gBrowser.selectedBrowser.addEventListener("load", function selectedBrowserLoadListener() { - aWin.gBrowser.selectedBrowser.removeEventListener("load", selectedBrowserLoadListener, true); - callbackSoon(aWin); - }, true); - }); -} - -// This assumes that tests will at least have some state/entries -function waitForBrowserState(aState, aSetStateCallback) { - let windows = [window]; - let tabsRestored = 0; - let expectedTabsRestored = 0; - let expectedWindows = aState.windows.length; - let windowsOpen = 1; - let listening = false; - let windowObserving = false; - let restoreHiddenTabs = Services.prefs.getBoolPref( - "browser.sessionstore.restore_hidden_tabs"); - - aState.windows.forEach(function (winState) { - winState.tabs.forEach(function (tabState) { - if (restoreHiddenTabs || !tabState.hidden) - expectedTabsRestored++; - }); - }); - - // There must be only hidden tabs and restoreHiddenTabs = false. We still - // expect one of them to be restored because it gets shown automatically. - if (!expectedTabsRestored) - expectedTabsRestored = 1; - - function onSSTabRestored(aEvent) { - if (++tabsRestored == expectedTabsRestored) { - // Remove the event listener from each window - windows.forEach(function(win) { - win.gBrowser.tabContainer.removeEventListener("SSTabRestored", onSSTabRestored, true); - }); - listening = false; - info("running " + aSetStateCallback.name); - executeSoon(aSetStateCallback); - } - } - - // Used to add our listener to further windows so we can catch SSTabRestored - // coming from them when creating a multi-window state. - function windowObserver(aSubject, aTopic, aData) { - if (aTopic == "domwindowopened") { - let newWindow = aSubject.QueryInterface(Ci.nsIDOMWindow); - newWindow.addEventListener("load", function() { - newWindow.removeEventListener("load", arguments.callee, false); - - if (++windowsOpen == expectedWindows) { - Services.ww.unregisterNotification(windowObserver); - windowObserving = false; - } - - // Track this window so we can remove the progress listener later - windows.push(newWindow); - // Add the progress listener - newWindow.gBrowser.tabContainer.addEventListener("SSTabRestored", onSSTabRestored, true); - }, false); - } - } - - // We only want to register the notification if we expect more than 1 window - if (expectedWindows > 1) { - registerCleanupFunction(function() { - if (windowObserving) { - Services.ww.unregisterNotification(windowObserver); - } - }); - windowObserving = true; - Services.ww.registerNotification(windowObserver); - } - - registerCleanupFunction(function() { - if (listening) { - windows.forEach(function(win) { - win.gBrowser.tabContainer.removeEventListener("SSTabRestored", onSSTabRestored, true); - }); - } - }); - // Add the event listener for this window as well. - listening = true; - gBrowser.tabContainer.addEventListener("SSTabRestored", onSSTabRestored, true); - - // Finally, call setBrowserState - ss.setBrowserState(JSON.stringify(aState)); -} - -// Doesn't assume that the tab needs to be closed in a cleanup function. -// If that's the case, the test author should handle that in the test. -function waitForTabState(aTab, aState, aCallback) { - let listening = true; - - function onSSTabRestored() { - aTab.removeEventListener("SSTabRestored", onSSTabRestored, false); - listening = false; - aCallback(); - } - - aTab.addEventListener("SSTabRestored", onSSTabRestored, false); - - registerCleanupFunction(function() { - if (listening) { - aTab.removeEventListener("SSTabRestored", onSSTabRestored, false); - } - }); - ss.setTabState(aTab, JSON.stringify(aState)); -} - -// waitForSaveState waits for a state write but not necessarily for the state to -// turn dirty. -function waitForSaveState(aSaveStateCallback) { - let observing = false; - let topic = "sessionstore-state-write"; - - let sessionSaveTimeout = 1000 + - Services.prefs.getIntPref("browser.sessionstore.interval"); - - function removeObserver() { - if (!observing) - return; - Services.obs.removeObserver(observer, topic); - observing = false; - } - - let timeout = setTimeout(function () { - removeObserver(); - aSaveStateCallback(); - }, sessionSaveTimeout); - - function observer(aSubject, aTopic, aData) { - removeObserver(); - timeout = clearTimeout(timeout); - executeSoon(aSaveStateCallback); - } - - registerCleanupFunction(function() { - removeObserver(); - if (timeout) { - clearTimeout(timeout); - } - }); - - observing = true; - Services.obs.addObserver(observer, topic, false); -}; - -function whenBrowserLoaded(aBrowser, aCallback = next) { - aBrowser.addEventListener("load", function onLoad() { - aBrowser.removeEventListener("load", onLoad, true); - executeSoon(aCallback); - }, true); -} - -function whenWindowLoaded(aWindow, aCallback = next) { - aWindow.addEventListener("load", function windowLoadListener() { - aWindow.removeEventListener("load", windowLoadListener, false); - executeSoon(function executeWhenWindowLoaded() { - aCallback(aWindow); - }); - }, false); -} - -var gUniqueCounter = 0; -function r() { - return Date.now() + "-" + (++gUniqueCounter); -} - -function BrowserWindowIterator() { - let windowsEnum = Services.wm.getEnumerator("navigator:browser"); - while (windowsEnum.hasMoreElements()) { - let currentWindow = windowsEnum.getNext(); - if (!currentWindow.closed) { - yield currentWindow; - } - } -} - -let gProgressListener = { - _callback: null, - _checkRestoreState: true, - - setCallback: function gProgressListener_setCallback(aCallback, aCheckRestoreState = true) { - if (!this._callback) { - window.gBrowser.addTabsProgressListener(this); - } - this._callback = aCallback; - this._checkRestoreState = aCheckRestoreState; - }, - - unsetCallback: function gProgressListener_unsetCallback() { - if (this._callback) { - this._callback = null; - window.gBrowser.removeTabsProgressListener(this); - } - }, - - onStateChange: - function gProgressListener_onStateChange(aBrowser, aWebProgress, aRequest, - aStateFlags, aStatus) { - if ((!this._checkRestoreState || - aBrowser.__SS_restoreState == TAB_STATE_RESTORING) && - aStateFlags & Ci.nsIWebProgressListener.STATE_STOP && - aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK && - aStateFlags & Ci.nsIWebProgressListener.STATE_IS_WINDOW) { - let args = [aBrowser].concat(this._countTabs()); - this._callback.apply(this, args); - } - }, - - _countTabs: function gProgressListener_countTabs() { - let needsRestore = 0, isRestoring = 0, wasRestored = 0; - - for (let win in BrowserWindowIterator()) { - for (let i = 0; i < win.gBrowser.tabs.length; i++) { - let browser = win.gBrowser.tabs[i].linkedBrowser; - if (browser.__SS_restoreState == TAB_STATE_RESTORING) - isRestoring++; - else if (browser.__SS_restoreState == TAB_STATE_NEEDS_RESTORE) - needsRestore++; - else - wasRestored++; - } - } - return [needsRestore, isRestoring, wasRestored]; - } -}; - -registerCleanupFunction(function () { - gProgressListener.unsetCallback(); -}); - -// Close everything but our primary window. We can't use waitForFocus() -// because apparently it's buggy. See bug 599253. -function closeAllButPrimaryWindow() { - for (let win in BrowserWindowIterator()) { - if (win != window) { - win.close(); - } - } -} - -function whenNewWindowLoaded(aIsPrivate, aCallback) { - let win = OpenBrowserWindow({private: aIsPrivate}); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - aCallback(win); - }, false); -} - -/** - * The test runner that controls the execution flow of our tests. - */ -let TestRunner = { - _iter: null, - - /** - * Holds the browser state from before we started so - * that we can restore it after all tests ran. - */ - backupState: {}, - - /** - * Starts the test runner. - */ - run: function () { - waitForExplicitFinish(); - - SessionStore.promiseInitialized.then(function () { - executeSoon(function () { - this.backupState = JSON.parse(ss.getBrowserState()); - this._iter = runTests(); - this.next(); - }.bind(this)); - }.bind(this)); - }, - - /** - * Runs the next available test or finishes if there's no test left. - */ - next: function () { - try { - TestRunner._iter.next(); - } catch (e if e instanceof StopIteration) { - TestRunner.finish(); - } - }, - - /** - * Finishes all tests and cleans up. - */ - finish: function () { - closeAllButPrimaryWindow(); - waitForBrowserState(this.backupState, finish); - } -}; - -function next() { - TestRunner.next(); -} diff --git a/browser/components/sessionstore/test/moz.build b/browser/components/sessionstore/test/moz.build deleted file mode 100644 index 191c90f0b..000000000 --- a/browser/components/sessionstore/test/moz.build +++ /dev/null @@ -1,7 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini'] diff --git a/browser/components/sessionstore/test/unit/data/sessionstore_valid.js b/browser/components/sessionstore/test/unit/data/sessionstore_valid.js deleted file mode 100644 index f9511f29f..000000000 --- a/browser/components/sessionstore/test/unit/data/sessionstore_valid.js +++ /dev/null @@ -1,3 +0,0 @@ -{ - "windows": [] -}
\ No newline at end of file diff --git a/browser/components/sessionstore/test/unit/head.js b/browser/components/sessionstore/test/unit/head.js deleted file mode 100644 index ff599ec3b..000000000 --- a/browser/components/sessionstore/test/unit/head.js +++ /dev/null @@ -1,26 +0,0 @@ -let Cu = Components.utils; -let Cc = Components.classes; -let Ci = Components.interfaces; - -Components.utils.import("resource://gre/modules/Services.jsm"); - -// Call a function once initialization of SessionStartup is complete -let afterSessionStartupInitialization = - function afterSessionStartupInitialization(cb) { - do_print("Waiting for session startup initialization"); - let observer = function() { - try { - do_print("Session startup initialization observed"); - Services.obs.removeObserver(observer, "sessionstore-state-finalized"); - cb(); - } catch (ex) { - do_throw(ex); - } - }; - let startup = Cc["@mozilla.org/browser/sessionstartup;1"]. - getService(Ci.nsIObserver); - Services.obs.addObserver(startup, "final-ui-startup", false); - Services.obs.addObserver(startup, "quit-application", false); - Services.obs.notifyObservers(null, "final-ui-startup", ""); - Services.obs.addObserver(observer, "sessionstore-state-finalized", false); -};
\ No newline at end of file diff --git a/browser/components/sessionstore/test/unit/test_startup_nosession_async.js b/browser/components/sessionstore/test/unit/test_startup_nosession_async.js deleted file mode 100644 index 5185b02d6..000000000 --- a/browser/components/sessionstore/test/unit/test_startup_nosession_async.js +++ /dev/null @@ -1,22 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - - -// Test nsISessionStartup.sessionType in the following scenario: -// - no sessionstore.js; -// - the session store has been loaded, so no need to go -// through the synchronous fallback - -function run_test() { - do_get_profile(); - // Initialize the profile (the session startup uses it) - - do_test_pending(); - let startup = Cc["@mozilla.org/browser/sessionstartup;1"]. - getService(Ci.nsISessionStartup); - - afterSessionStartupInitialization(function cb() { - do_check_eq(startup.sessionType, Ci.nsISessionStartup.NO_SESSION); - do_test_finished(); - }); -}
\ No newline at end of file diff --git a/browser/components/sessionstore/test/unit/test_startup_nosession_sync.js b/browser/components/sessionstore/test/unit/test_startup_nosession_sync.js deleted file mode 100644 index a06770a39..000000000 --- a/browser/components/sessionstore/test/unit/test_startup_nosession_sync.js +++ /dev/null @@ -1,15 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - - -// Test nsISessionStartup.sessionType in the following scenario: -// - no sessionstore.js; -// - the session store has not been loaded yet, so we have to trigger -// synchronous fallback - -function run_test() { - do_get_profile(); - let startup = Cc["@mozilla.org/browser/sessionstartup;1"]. - getService(Ci.nsISessionStartup); - do_check_eq(startup.sessionType, Ci.nsISessionStartup.NO_SESSION); -}
\ No newline at end of file diff --git a/browser/components/sessionstore/test/unit/test_startup_session_async.js b/browser/components/sessionstore/test/unit/test_startup_session_async.js deleted file mode 100644 index ce8c6f90d..000000000 --- a/browser/components/sessionstore/test/unit/test_startup_session_async.js +++ /dev/null @@ -1,23 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - - -// Test nsISessionStartup.sessionType in the following scenario: -// - valid sessionstore.js; -// - the session store has been loaded, so no need to go -// through the synchronous fallback - -function run_test() { - let profd = do_get_profile(); - let source = do_get_file("data/sessionstore_valid.js"); - source.copyTo(profd, "sessionstore.js"); - - do_test_pending(); - let startup = Cc["@mozilla.org/browser/sessionstartup;1"]. - getService(Ci.nsISessionStartup); - - afterSessionStartupInitialization(function cb() { - do_check_eq(startup.sessionType, Ci.nsISessionStartup.DEFER_SESSION); - do_test_finished(); - }); -}
\ No newline at end of file diff --git a/browser/components/sessionstore/test/unit/test_startup_session_sync.js b/browser/components/sessionstore/test/unit/test_startup_session_sync.js deleted file mode 100644 index f8e56d3e9..000000000 --- a/browser/components/sessionstore/test/unit/test_startup_session_sync.js +++ /dev/null @@ -1,17 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - - -// Test nsISessionStartup.sessionType in the following scenario: -// - valid sessionstore.js; -// - the session store has not been loaded yet, so we have to trigger -// synchronous fallback - -function run_test() { - let profd = do_get_profile(); - let source = do_get_file("data/sessionstore_valid.js"); - source.copyTo(profd, "sessionstore.js"); - let startup = Cc["@mozilla.org/browser/sessionstartup;1"]. - getService(Ci.nsISessionStartup); - do_check_eq(startup.sessionType, Ci.nsISessionStartup.DEFER_SESSION); -}
\ No newline at end of file diff --git a/browser/components/sessionstore/test/unit/xpcshell.ini b/browser/components/sessionstore/test/unit/xpcshell.ini deleted file mode 100644 index 661c5d705..000000000 --- a/browser/components/sessionstore/test/unit/xpcshell.ini +++ /dev/null @@ -1,9 +0,0 @@ -[DEFAULT] -head = head.js -tail = -firefox-appdir = browser - -[test_startup_nosession_sync.js] -[test_startup_nosession_async.js] -[test_startup_session_sync.js] -[test_startup_session_async.js] diff --git a/browser/components/shell/moz.build b/browser/components/shell/moz.build index 92950f537..76218104c 100644 --- a/browser/components/shell/moz.build +++ b/browser/components/shell/moz.build @@ -5,4 +5,4 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DIRS += ['public', 'src'] -TEST_DIRS += ['test'] + diff --git a/browser/components/shell/test/Makefile.in b/browser/components/shell/test/Makefile.in deleted file mode 100644 index b9624ac6e..000000000 --- a/browser/components/shell/test/Makefile.in +++ /dev/null @@ -1,18 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -DEPTH = @DEPTH@ -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ -relativesrcdir = @relativesrcdir@ - -include $(DEPTH)/config/autoconf.mk - -MOCHITEST_BROWSER_FILES = \ - browser_420786.js \ - browser_633221.js \ - $(NULL) - -include $(topsrcdir)/config/rules.mk diff --git a/browser/components/shell/test/browser_420786.js b/browser/components/shell/test/browser_420786.js deleted file mode 100644 index 8824fd637..000000000 --- a/browser/components/shell/test/browser_420786.js +++ /dev/null @@ -1,95 +0,0 @@ -const DG_BACKGROUND = "/desktop/gnome/background" -const DG_IMAGE_KEY = DG_BACKGROUND + "/picture_filename"; -const DG_OPTION_KEY = DG_BACKGROUND + "/picture_options"; -const DG_DRAW_BG_KEY = DG_BACKGROUND + "/draw_background"; - -function onPageLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onPageLoad, true); - - var bs = Cc["@mozilla.org/intl/stringbundle;1"]. - getService(Ci.nsIStringBundleService); - var brandName = bs.createBundle("chrome://branding/locale/brand.properties"). - GetStringFromName("brandShortName"); - - var dirSvc = Cc["@mozilla.org/file/directory_service;1"]. - getService(Ci.nsIDirectoryServiceProvider); - var homeDir = dirSvc.getFile("Home", {}); - - var wpFile = homeDir.clone(); - wpFile.append(brandName + "_wallpaper.png"); - - // Backup the existing wallpaper so that this test doesn't change the user's - // settings. - var wpFileBackup = homeDir.clone() - wpFileBackup.append(brandName + "_wallpaper.png.backup"); - - if (wpFileBackup.exists()) - wpFileBackup.remove(false); - - if (wpFile.exists()) - wpFile.copyTo(null, wpFileBackup.leafName); - - var shell = Cc["@mozilla.org/browser/shell-service;1"]. - getService(Ci.nsIShellService); - var gconf = Cc["@mozilla.org/gnome-gconf-service;1"]. - getService(Ci.nsIGConfService); - - var prevImageKey = gconf.getString(DG_IMAGE_KEY); - var prevOptionKey = gconf.getString(DG_OPTION_KEY); - var prevDrawBgKey = gconf.getBool(DG_DRAW_BG_KEY); - - var image = content.document.images[0]; - - function checkWallpaper(position, expectedGConfPosition) { - shell.setDesktopBackground(image, position); - ok(wpFile.exists(), "Wallpaper was written to disk"); - is(gconf.getString(DG_IMAGE_KEY), wpFile.path, - "Wallpaper file GConf key is correct"); - is(gconf.getString(DG_OPTION_KEY), expectedGConfPosition, - "Wallpaper position GConf key is correct"); - } - - checkWallpaper(Ci.nsIShellService.BACKGROUND_TILE, "wallpaper"); - checkWallpaper(Ci.nsIShellService.BACKGROUND_STRETCH, "stretched"); - checkWallpaper(Ci.nsIShellService.BACKGROUND_CENTER, "centered"); - checkWallpaper(Ci.nsIShellService.BACKGROUND_FILL, "zoom"); - checkWallpaper(Ci.nsIShellService.BACKGROUND_FIT, "scaled"); - - // Restore GConf and wallpaper - - gconf.setString(DG_IMAGE_KEY, prevImageKey); - gconf.setString(DG_OPTION_KEY, prevOptionKey); - gconf.setBool(DG_DRAW_BG_KEY, prevDrawBgKey); - - wpFile.remove(false); - if (wpFileBackup.exists()) - wpFileBackup.moveTo(null, wpFile.leafName); - - gBrowser.removeCurrentTab(); - finish(); -} - -function test() { - var osString = Cc["@mozilla.org/xre/app-info;1"]. - getService(Ci.nsIXULRuntime).OS; - if (osString != "Linux") { - todo(false, "This test is Linux specific for now."); - return; - } - - try { - // If GSettings is available, then the GConf tests - // will fail - var gsettings = Cc["@mozilla.org/gsettings-service;1"]. - getService(Ci.nsIGSettingsService). - getCollectionForSchema("org.gnome.desktop.background"); - todo(false, "This test doesn't work when GSettings is available"); - return; - } catch(e) { } - - gBrowser.selectedTab = gBrowser.addTab(); - gBrowser.selectedBrowser.addEventListener("load", onPageLoad, true); - content.location = "about:logo"; - - waitForExplicitFinish(); -} diff --git a/browser/components/shell/test/browser_633221.js b/browser/components/shell/test/browser_633221.js deleted file mode 100644 index 840394dea..000000000 --- a/browser/components/shell/test/browser_633221.js +++ /dev/null @@ -1,15 +0,0 @@ -function test() { - let osString = Cc["@mozilla.org/xre/app-info;1"]. - getService(Ci.nsIXULRuntime).OS; - - // this test is Linux-specific - if (osString != "Linux") - return; - - let shell = Cc["@mozilla.org/browser/shell-service;1"]. - getService(Ci.nsIShellService); - - shell.setDefaultBrowser(true, false); - ok(shell.isDefaultBrowser(true, false), "we got here and are the default browser"); - ok(shell.isDefaultBrowser(true, true), "we got here and are the default browser"); -} diff --git a/browser/components/shell/test/moz.build b/browser/components/shell/test/moz.build deleted file mode 100644 index e68a73ba4..000000000 --- a/browser/components/shell/test/moz.build +++ /dev/null @@ -1,9 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -MODULE = 'test_browser_shell' - -XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini'] diff --git a/browser/components/shell/test/unit/test_421977.js b/browser/components/shell/test/unit/test_421977.js deleted file mode 100644 index f787301d6..000000000 --- a/browser/components/shell/test/unit/test_421977.js +++ /dev/null @@ -1,123 +0,0 @@ -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cr = Components.results; - -const GCONF_BG_COLOR_KEY = "/desktop/gnome/background/primary_color"; - -var gShell; -var gGConf; - -/** - * Converts from a rgb numerical color valule (r << 16 | g << 8 | b) - * into a hex string in #RRGGBB format. - */ -function colorToHex(aColor) { - const rMask = 4294901760; - const gMask = 65280; - const bMask = 255; - - var r = (aColor & rMask) >> 16; - var g = (aColor & gMask) >> 8; - var b = (aColor & bMask); - - return "#" + [r, g, b].map(function(aInt) - aInt.toString(16).replace(/^(.)$/, "0$1")) - .join("").toUpperCase(); -} - -/** - * Converts a color string in #RRGGBB format to a rgb numerical color value - * (r << 16 | g << 8 | b). - */ -function hexToColor(aString) { - return parseInt(aString.substring(1,3), 16) << 16 | - parseInt(aString.substring(3,5), 16) << 8 | - parseInt(aString.substring(5,7), 16); -} - -/** - * Checks that setting the GConf background key to aGConfColor will - * result in the Shell component returning a background color equals - * to aExpectedShellColor in #RRGGBB format. - */ -function checkGConfToShellColor(aGConfColor, aExpectedShellColor) { - - gGConf.setString(GCONF_BG_COLOR_KEY, aGConfColor); - var shellColor = colorToHex(gShell.desktopBackgroundColor); - - do_check_eq(shellColor, aExpectedShellColor); -} - -/** - * Checks that setting the background color (in #RRGGBB format) using the Shell - * component will result in having a GConf key for the background color set to - * aExpectedGConfColor. - */ -function checkShellToGConfColor(aShellColor, aExpectedGConfColor) { - - gShell.desktopBackgroundColor = hexToColor(aShellColor); - var gconfColor = gGConf.getString(GCONF_BG_COLOR_KEY); - - do_check_eq(gconfColor, aExpectedGConfColor); -} - -function run_test() { - - // This test is Linux specific for now - if (!("@mozilla.org/gnome-gconf-service;1" in Cc)) - return; - - try { - // If GSettings is available, then the GConf tests - // will fail - var gsettings = Cc["@mozilla.org/gsettings-service;1"]. - getService(Ci.nsIGSettingsService). - getCollectionForSchema("org.gnome.desktop.background"); - return; - } catch(e) { } - - gGConf = Cc["@mozilla.org/gnome-gconf-service;1"]. - getService(Ci.nsIGConfService); - - gShell = Cc["@mozilla.org/browser/shell-service;1"]. - getService(Ci.nsIShellService); - - // Save the original background color so that we can restore it - // after the test. - var origGConfColor = gGConf.getString(GCONF_BG_COLOR_KEY); - - try { - - checkGConfToShellColor("#000", "#000000"); - checkGConfToShellColor("#00f", "#0000FF"); - checkGConfToShellColor("#b2f", "#BB22FF"); - checkGConfToShellColor("#fff", "#FFFFFF"); - - checkGConfToShellColor("#000000", "#000000"); - checkGConfToShellColor("#0000ff", "#0000FF"); - checkGConfToShellColor("#b002f0", "#B002F0"); - checkGConfToShellColor("#ffffff", "#FFFFFF"); - - checkGConfToShellColor("#000000000", "#000000"); - checkGConfToShellColor("#00f00f00f", "#000000"); - checkGConfToShellColor("#aaabbbccc", "#AABBCC"); - checkGConfToShellColor("#fffffffff", "#FFFFFF"); - - checkGConfToShellColor("#000000000000", "#000000"); - checkGConfToShellColor("#000f000f000f", "#000000"); - checkGConfToShellColor("#00ff00ff00ff", "#000000"); - checkGConfToShellColor("#aaaabbbbcccc", "#AABBCC"); - checkGConfToShellColor("#111122223333", "#112233"); - checkGConfToShellColor("#ffffffffffff", "#FFFFFF"); - - checkShellToGConfColor("#000000", "#000000000000"); - checkShellToGConfColor("#0000FF", "#00000000ffff"); - checkShellToGConfColor("#FFFFFF", "#ffffffffffff"); - checkShellToGConfColor("#0A0B0C", "#0a0a0b0b0c0c"); - checkShellToGConfColor("#A0B0C0", "#a0a0b0b0c0c0"); - checkShellToGConfColor("#AABBCC", "#aaaabbbbcccc"); - - } finally { - gGConf.setString(GCONF_BG_COLOR_KEY, origGConfColor); - } -} diff --git a/browser/components/shell/test/unit/xpcshell.ini b/browser/components/shell/test/unit/xpcshell.ini deleted file mode 100644 index 33804fd42..000000000 --- a/browser/components/shell/test/unit/xpcshell.ini +++ /dev/null @@ -1,6 +0,0 @@ -[DEFAULT] -head = -tail = -firefox-appdir = browser - -[test_421977.js] diff --git a/browser/components/test/Makefile.in b/browser/components/test/Makefile.in deleted file mode 100644 index b2e2e479d..000000000 --- a/browser/components/test/Makefile.in +++ /dev/null @@ -1,17 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -DEPTH = @DEPTH@ -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ -relativesrcdir = @relativesrcdir@ - -include $(DEPTH)/config/autoconf.mk - -MOCHITEST_BROWSER_FILES = \ - browser_bug538331.js \ - $(NULL) - -include $(topsrcdir)/config/rules.mk diff --git a/browser/components/test/browser_bug538331.js b/browser/components/test/browser_bug538331.js deleted file mode 100644 index d559795db..000000000 --- a/browser/components/test/browser_bug538331.js +++ /dev/null @@ -1,427 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=2 et sw=2 tw=80: */ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -const PREF_POSTUPDATE = "app.update.postupdate"; -const PREF_MSTONE = "browser.startup.homepage_override.mstone"; -const PREF_OVERRIDE_URL = "startup.homepage_override_url"; - -const DEFAULT_PREF_URL = "http://pref.example.com/"; -const DEFAULT_UPDATE_URL = "http://example.com/"; - -const XML_EMPTY = "<?xml version=\"1.0\"?><updates xmlns=" + - "\"http://www.mozilla.org/2005/app-update\"></updates>"; - -const XML_PREFIX = "<updates xmlns=\"http://www.mozilla.org/2005/app-update\"" + - "><update appVersion=\"1.0\" buildID=\"20080811053724\" " + - "channel=\"nightly\" displayVersion=\"Version 1.0\" " + - "extensionVersion=\"1.0\" installDate=\"1238441400314\" " + - "isCompleteUpdate=\"true\" name=\"Update Test 1.0\" " + - "serviceURL=\"https://example.com/\" showNeverForVersion=" + - "\"false\" showPrompt=\"false\" type=" + - "\"minor\" version=\"version 1.0\" detailsURL=" + - "\"http://example.com/\" previousAppVersion=\"1.0\" " + - "statusText=\"The Update was successfully installed\" " + - "foregroundDownload=\"true\""; - -const XML_SUFFIX = "><patch type=\"complete\" URL=\"http://example.com/\" " + - "hashFunction=\"MD5\" hashValue=" + - "\"6232cd43a1c77e30191c53a329a3f99d\" size=\"775\" " + - "selected=\"true\" state=\"succeeded\"/></update></updates>"; - -// nsBrowserContentHandler.js defaultArgs tests -const BCH_TESTS = [ - { - description: "no mstone change and no update", - noPostUpdatePref: true, - noMstoneChange: true - }, { - description: "mstone changed and no update", - noPostUpdatePref: true, - prefURL: DEFAULT_PREF_URL - }, { - description: "no mstone change and update with 'showURL' for actions", - actions: "showURL", - noMstoneChange: true - }, { - description: "update without actions", - prefURL: DEFAULT_PREF_URL - }, { - description: "update with 'showURL' for actions", - actions: "showURL", - prefURL: DEFAULT_PREF_URL - }, { - description: "update with 'showURL' for actions and openURL", - actions: "showURL", - openURL: DEFAULT_UPDATE_URL - }, { - description: "update with 'showURL showAlert' for actions", - actions: "showAlert showURL", - prefURL: DEFAULT_PREF_URL - }, { - description: "update with 'showAlert showURL' for actions and openURL", - actions: "showAlert showURL", - openURL: DEFAULT_UPDATE_URL - }, { - description: "update with 'showURL showNotification' for actions", - actions: "showURL showNotification", - prefURL: DEFAULT_PREF_URL - }, { - description: "update with 'showNotification showURL' for actions and " + - "openURL", - actions: "showNotification showURL", - openURL: DEFAULT_UPDATE_URL - }, { - description: "update with 'showAlert showURL showNotification' for actions", - actions: "showAlert showURL showNotification", - prefURL: DEFAULT_PREF_URL - }, { - description: "update with 'showNotification showURL showAlert' for " + - "actions and openURL", - actions: "showNotification showURL showAlert", - openURL: DEFAULT_UPDATE_URL - }, { - description: "update with 'showAlert' for actions", - actions: "showAlert" - }, { - description: "update with 'showAlert showNotification' for actions", - actions: "showAlert showNotification" - }, { - description: "update with 'showNotification' for actions", - actions: "showNotification" - }, { - description: "update with 'showNotification showAlert' for actions", - actions: "showNotification showAlert" - }, { - description: "update with 'silent' for actions", - actions: "silent" - }, { - description: "update with 'silent showURL showAlert showNotification' " + - "for actions and openURL", - actions: "silent showURL showAlert showNotification" - } -]; - -var gOriginalMStone; -var gOriginalOverrideURL; - -this.__defineGetter__("gBG", function() { - delete this.gBG; - return this.gBG = Cc["@mozilla.org/browser/browserglue;1"]. - getService(Ci.nsIBrowserGlue). - QueryInterface(Ci.nsIObserver); -}); - -function test() -{ - waitForExplicitFinish(); - - if (gPrefService.prefHasUserValue(PREF_MSTONE)) { - gOriginalMStone = gPrefService.getCharPref(PREF_MSTONE); - } - - if (gPrefService.prefHasUserValue(PREF_OVERRIDE_URL)) { - gOriginalOverrideURL = gPrefService.getCharPref(PREF_OVERRIDE_URL); - } - - testDefaultArgs(); -} - -var gWindowCatcher = { - windowsOpen: 0, - finishCalled: false, - start: function() { - Services.ww.registerNotification(this); - }, - - finish: function(aFunc) { - Services.ww.unregisterNotification(this); - this.finishFunc = aFunc; - if (this.windowsOpen > 0) - return; - - this.finishFunc(); - }, - - closeWindow: function (win) { - info("window catcher closing window: " + win.document.documentURI); - win.close(); - this.windowsOpen--; - if (this.finishFunc) { - this.finish(this.finishFunc); - } - }, - - windowLoad: function (win) { - executeSoon(this.closeWindow.bind(this, win)); - }, - - observe: function(subject, topic, data) { - if (topic != "domwindowopened") - return; - - this.windowsOpen++; - let win = subject.QueryInterface(Ci.nsIDOMWindow); - info("window catcher caught window opening: " + win.document.documentURI); - win.addEventListener("load", function () { - win.removeEventListener("load", arguments.callee, false); - gWindowCatcher.windowLoad(win); - }, false); - } -}; - -function finish_test() -{ - // Reset browser.startup.homepage_override.mstone to the original value or - // clear it if it didn't exist. - if (gOriginalMStone) { - gPrefService.setCharPref(PREF_MSTONE, gOriginalMStone); - } else if (gPrefService.prefHasUserValue(PREF_MSTONE)) { - gPrefService.clearUserPref(PREF_MSTONE); - } - - // Reset startup.homepage_override_url to the original value or clear it if - // it didn't exist. - if (gOriginalOverrideURL) { - gPrefService.setCharPref(PREF_OVERRIDE_URL, gOriginalOverrideURL); - } else if (gPrefService.prefHasUserValue(PREF_OVERRIDE_URL)) { - gPrefService.clearUserPref(PREF_OVERRIDE_URL); - } - - writeUpdatesToXMLFile(XML_EMPTY); - reloadUpdateManagerData(); - - finish(); -} - -// Test the defaultArgs returned by nsBrowserContentHandler after an update -function testDefaultArgs() -{ - // Clear any pre-existing override in defaultArgs that are hanging around. - // This will also set the browser.startup.homepage_override.mstone preference - // if it isn't already set. - Cc["@mozilla.org/browser/clh;1"].getService(Ci.nsIBrowserHandler).defaultArgs; - - let originalMstone = gPrefService.getCharPref(PREF_MSTONE); - - gPrefService.setCharPref(PREF_OVERRIDE_URL, DEFAULT_PREF_URL); - - writeUpdatesToXMLFile(XML_EMPTY); - reloadUpdateManagerData(); - - for (let i = 0; i < BCH_TESTS.length; i++) { - let test = BCH_TESTS[i]; - ok(true, "Test nsBrowserContentHandler " + (i + 1) + ": " + test.description); - - if (test.actions) { - let actionsXML = " actions=\"" + test.actions + "\""; - if (test.openURL) { - actionsXML += " openURL=\"" + test.openURL + "\""; - } - writeUpdatesToXMLFile(XML_PREFIX + actionsXML + XML_SUFFIX); - } else { - writeUpdatesToXMLFile(XML_EMPTY); - } - - reloadUpdateManagerData(); - - let noOverrideArgs = Cc["@mozilla.org/browser/clh;1"]. - getService(Ci.nsIBrowserHandler).defaultArgs; - - let overrideArgs = ""; - if (test.prefURL) { - overrideArgs = test.prefURL; - } else if (test.openURL) { - overrideArgs = test.openURL; - } - - if (overrideArgs == "" && noOverrideArgs) { - overrideArgs = noOverrideArgs; - } else if (noOverrideArgs) { - overrideArgs += "|" + noOverrideArgs; - } - - if (test.noMstoneChange === undefined) { - gPrefService.setCharPref(PREF_MSTONE, "PreviousMilestone"); - } - - if (test.noPostUpdatePref == undefined) { - gPrefService.setBoolPref(PREF_POSTUPDATE, true); - } - - let defaultArgs = Cc["@mozilla.org/browser/clh;1"]. - getService(Ci.nsIBrowserHandler).defaultArgs; - is(defaultArgs, overrideArgs, "correct value returned by defaultArgs"); - - if (test.noMstoneChange === undefined || test.noMstoneChange != true) { - let newMstone = gPrefService.getCharPref(PREF_MSTONE); - is(originalMstone, newMstone, "preference " + PREF_MSTONE + - " should have been updated"); - } - - if (gPrefService.prefHasUserValue(PREF_POSTUPDATE)) { - gPrefService.clearUserPref(PREF_POSTUPDATE); - } - } - - testShowNotification(); -} - -// nsBrowserGlue.js _showUpdateNotification notification tests -const BG_NOTIFY_TESTS = [ - { - description: "'silent showNotification' actions should not display a notification", - actions: "silent showNotification" - }, { - description: "'showNotification' for actions should display a notification", - actions: "showNotification" - }, { - description: "no actions and empty updates.xml", - }, { - description: "'showAlert' for actions should not display a notification", - actions: "showAlert" - }, { - // This test MUST be the last test in the array to test opening the url - // provided by the updates.xml. - description: "'showNotification' for actions with custom notification " + - "attributes should display a notification", - actions: "showNotification", - notificationText: "notification text", - notificationURL: DEFAULT_UPDATE_URL, - notificationButtonLabel: "button label", - notificationButtonAccessKey: "b" - } -]; - -// Test showing a notification after an update -// _showUpdateNotification in nsBrowserGlue.js -function testShowNotification() -{ - let gTestBrowser = gBrowser.selectedBrowser; - let notifyBox = gBrowser.getNotificationBox(gTestBrowser); - - // Catches any windows opened by these tests (e.g. alert windows) and closes - // them - gWindowCatcher.start(); - - for (let i = 0; i < BG_NOTIFY_TESTS.length; i++) { - let test = BG_NOTIFY_TESTS[i]; - ok(true, "Test showNotification " + (i + 1) + ": " + test.description); - - if (test.actions) { - let actionsXML = " actions=\"" + test.actions + "\""; - if (test.notificationText) { - actionsXML += " notificationText=\"" + test.notificationText + "\""; - } - if (test.notificationURL) { - actionsXML += " notificationURL=\"" + test.notificationURL + "\""; - } - if (test.notificationButtonLabel) { - actionsXML += " notificationButtonLabel=\"" + test.notificationButtonLabel + "\""; - } - if (test.notificationButtonAccessKey) { - actionsXML += " notificationButtonAccessKey=\"" + test.notificationButtonAccessKey + "\""; - } - writeUpdatesToXMLFile(XML_PREFIX + actionsXML + XML_SUFFIX); - } else { - writeUpdatesToXMLFile(XML_EMPTY); - } - - reloadUpdateManagerData(); - gPrefService.setBoolPref(PREF_POSTUPDATE, true); - - gBG.observe(null, "browser-glue-test", "post-update-notification"); - - let updateBox = notifyBox.getNotificationWithValue("post-update-notification"); - if (test.actions && test.actions.indexOf("showNotification") != -1 && - test.actions.indexOf("silent") == -1) { - ok(updateBox, "Update notification box should have been displayed"); - if (updateBox) { - if (test.notificationText) { - is(updateBox.label, test.notificationText, "Update notification box " + - "should have the label provided by the update"); - } - if (test.notificationButtonLabel) { - var button = updateBox.getElementsByTagName("button").item(0); - is(button.label, test.notificationButtonLabel, "Update notification " + - "box button should have the label provided by the update"); - if (test.notificationButtonAccessKey) { - let accessKey = button.getAttribute("accesskey"); - is(accessKey, test.notificationButtonAccessKey, "Update " + - "notification box button should have the accesskey " + - "provided by the update"); - } - } - // The last test opens an url and verifies the url from the updates.xml - // is correct. - if (i == (BG_NOTIFY_TESTS.length - 1)) { - // Wait for any windows caught by the windowcatcher to close - gWindowCatcher.finish(function () { - button.click(); - gBrowser.selectedBrowser.addEventListener("load", function () { - gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); - testNotificationURL(); - }, true); - }); - } else { - notifyBox.removeAllNotifications(true); - } - } else if (i == (BG_NOTIFY_TESTS.length - 1)) { - // If updateBox is null the test has already reported errors so bail - finish_test(); - } - } else { - ok(!updateBox, "Update notification box should not have been displayed"); - } - - let prefHasUserValue = gPrefService.prefHasUserValue(PREF_POSTUPDATE); - is(prefHasUserValue, false, "preference " + PREF_POSTUPDATE + - " shouldn't have a user value"); - } -} - -// Test opening the url provided by the updates.xml in the last test -function testNotificationURL() -{ - ok(true, "Test testNotificationURL: clicking the notification button " + - "opened the url specified by the update"); - let href = gBrowser.selectedBrowser.contentWindow.location.href; - let expectedURL = BG_NOTIFY_TESTS[BG_NOTIFY_TESTS.length - 1].notificationURL; - is(href, expectedURL, "The url opened from the notification should be the " + - "url provided by the update"); - gBrowser.removeCurrentTab(); - window.focus(); - finish_test(); -} - -/* Reloads the update metadata from disk */ -function reloadUpdateManagerData() -{ - Cc["@mozilla.org/updates/update-manager;1"].getService(Ci.nsIUpdateManager). - QueryInterface(Ci.nsIObserver).observe(null, "um-reload-update-data", ""); -} - - -function writeUpdatesToXMLFile(aText) -{ - const PERMS_FILE = 0644; - - const MODE_WRONLY = 0x02; - const MODE_CREATE = 0x08; - const MODE_TRUNCATE = 0x20; - - let file = Cc["@mozilla.org/file/directory_service;1"]. - getService(Ci.nsIProperties). - get("UpdRootD", Ci.nsIFile); - file.append("updates.xml"); - let fos = Cc["@mozilla.org/network/file-output-stream;1"]. - createInstance(Ci.nsIFileOutputStream); - if (!file.exists()) { - file.create(Ci.nsILocalFile.NORMAL_FILE_TYPE, PERMS_FILE); - } - fos.init(file, MODE_WRONLY | MODE_CREATE | MODE_TRUNCATE, PERMS_FILE, 0); - fos.write(aText, aText.length); - fos.close(); -} diff --git a/browser/components/test/moz.build b/browser/components/test/moz.build deleted file mode 100644 index 895d11993..000000000 --- a/browser/components/test/moz.build +++ /dev/null @@ -1,6 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - |