2010-03-26 14:59:02 -07:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim:set ts=2 sw=2 sts=2 et:
|
2012-05-21 04:12:37 -07:00
|
|
|
* 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/. */
|
2010-03-26 14:59:02 -07:00
|
|
|
|
|
|
|
const TEST_URL_BASES = [
|
|
|
|
"http://example.org/browser/browser/base/content/test/dummy_page.html#tabmatch",
|
|
|
|
"http://example.org/browser/browser/base/content/test/moz.png#tabmatch"
|
|
|
|
];
|
|
|
|
|
|
|
|
var gPrivateBrowsing = Cc["@mozilla.org/privatebrowsing;1"].
|
|
|
|
getService(Ci.nsIPrivateBrowsingService);
|
2010-11-19 16:39:55 -08:00
|
|
|
var gController = Cc["@mozilla.org/autocomplete/controller;1"].
|
|
|
|
getService(Ci.nsIAutoCompleteController);
|
2010-03-26 14:59:02 -07:00
|
|
|
|
|
|
|
var gTabWaitCount = 0;
|
|
|
|
var gTabCounter = 0;
|
|
|
|
|
|
|
|
var gTestSteps = [
|
|
|
|
function() {
|
|
|
|
info("Running step 1");
|
|
|
|
for (let i = 0; i < 10; i++) {
|
|
|
|
let tab = gBrowser.addTab();
|
|
|
|
loadTab(tab, TEST_URL_BASES[0] + (++gTabCounter));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
info("Running step 2");
|
|
|
|
gBrowser.selectTabAtIndex(1);
|
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
gBrowser.selectTabAtIndex(1);
|
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
for (let i = 1; i < gBrowser.tabs.length; i++)
|
|
|
|
loadTab(gBrowser.tabs[i], TEST_URL_BASES[1] + (++gTabCounter));
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
info("Running step 3");
|
|
|
|
for (let i = 1; i < gBrowser.tabs.length; i++)
|
|
|
|
loadTab(gBrowser.tabs[i], TEST_URL_BASES[0] + gTabCounter);
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
info("Running step 4");
|
|
|
|
let ps = Services.prefs;
|
|
|
|
ps.setBoolPref("browser.privatebrowsing.keep_current_session", true);
|
|
|
|
ps.setBoolPref("browser.tabs.warnOnClose", false);
|
|
|
|
|
2012-02-23 02:30:23 -08:00
|
|
|
// Make sure 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).
|
|
|
|
ps.setBoolPref("browser.sessionstore.restore_on_demand", false);
|
|
|
|
|
2010-03-26 14:59:02 -07:00
|
|
|
gPrivateBrowsing.privateBrowsingEnabled = true;
|
|
|
|
|
|
|
|
executeSoon(function() {
|
2010-11-19 16:39:55 -08:00
|
|
|
ensure_opentabs_match_db(nextStep);
|
2010-03-26 14:59:02 -07:00
|
|
|
});
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
info("Running step 5");
|
|
|
|
gPrivateBrowsing.privateBrowsingEnabled = false;
|
|
|
|
|
|
|
|
executeSoon(function() {
|
|
|
|
let ps = Services.prefs;
|
2012-02-23 02:30:23 -08:00
|
|
|
ps.clearUserPref("browser.privatebrowsing.keep_current_session");
|
|
|
|
ps.clearUserPref("browser.tabs.warnOnClose");
|
2010-03-26 14:59:02 -07:00
|
|
|
|
2010-11-19 16:39:55 -08:00
|
|
|
ensure_opentabs_match_db(nextStep);
|
2010-03-26 14:59:02 -07:00
|
|
|
});
|
2010-08-09 08:59:31 -07:00
|
|
|
},
|
|
|
|
function() {
|
|
|
|
info("Running step 6 - ensure we don't register subframes as open pages");
|
|
|
|
let tab = gBrowser.addTab();
|
|
|
|
tab.linkedBrowser.addEventListener("load", function () {
|
|
|
|
tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
|
|
|
|
// Start the sub-document load.
|
|
|
|
executeSoon(function () {
|
|
|
|
tab.linkedBrowser.addEventListener("load", function (e) {
|
|
|
|
tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
|
2010-11-19 16:39:55 -08:00
|
|
|
ensure_opentabs_match_db(nextStep);
|
2010-08-09 08:59:31 -07:00
|
|
|
}, true);
|
|
|
|
tab.linkedBrowser.contentDocument.querySelector("iframe").src = "http://test2.example.org/";
|
|
|
|
});
|
|
|
|
}, true);
|
|
|
|
tab.linkedBrowser.loadURI('data:text/html,<body><iframe src=""></iframe></body>');
|
2010-08-13 18:52:30 -07:00
|
|
|
},
|
|
|
|
function() {
|
|
|
|
info("Running step 7 - remove tab immediately");
|
2010-11-07 06:04:59 -08:00
|
|
|
let tab = gBrowser.addTab("about:logo");
|
2010-08-13 18:52:30 -07:00
|
|
|
gBrowser.removeTab(tab);
|
2010-11-19 16:39:55 -08:00
|
|
|
ensure_opentabs_match_db(nextStep);
|
2010-08-13 18:52:30 -07:00
|
|
|
},
|
2010-09-06 07:27:29 -07:00
|
|
|
function() {
|
|
|
|
info("Running step 8 - check swapBrowsersAndCloseOther preserves registered switch-to-tab result");
|
|
|
|
let tabToKeep = gBrowser.addTab();
|
|
|
|
let tab = gBrowser.addTab();
|
|
|
|
tab.linkedBrowser.addEventListener("load", function () {
|
|
|
|
tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
|
|
|
|
gBrowser.swapBrowsersAndCloseOther(tabToKeep, tab);
|
2010-11-19 16:39:55 -08:00
|
|
|
ensure_opentabs_match_db(function () {
|
|
|
|
gBrowser.removeTab(tabToKeep);
|
|
|
|
ensure_opentabs_match_db(nextStep);
|
|
|
|
});
|
2010-09-06 07:27:29 -07:00
|
|
|
}, true);
|
2012-05-21 18:25:49 -07:00
|
|
|
tab.linkedBrowser.loadURI("about:mozilla");
|
2010-09-06 07:27:29 -07:00
|
|
|
},
|
2011-01-11 16:40:36 -08:00
|
|
|
function() {
|
|
|
|
info("Running step 9 - enter private browsing mode, without keeping session");
|
|
|
|
let ps = Services.prefs;
|
|
|
|
ps.setBoolPref("browser.privatebrowsing.keep_current_session", false);
|
|
|
|
ps.setBoolPref("browser.tabs.warnOnClose", false);
|
|
|
|
|
|
|
|
Services.obs.addObserver(function(aSubject, aTopic, aData) {
|
|
|
|
Services.obs.removeObserver(arguments.callee, "private-browsing-transition-complete");
|
|
|
|
|
|
|
|
for (let i = 0; i < gBrowser.tabs.length; i++)
|
|
|
|
waitForRestoredTab(gBrowser.tabs[i]);
|
|
|
|
}, "private-browsing-transition-complete", false);
|
|
|
|
|
|
|
|
gPrivateBrowsing.privateBrowsingEnabled = true;
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
info("Running step 10 - open tabs in private browsing mode");
|
|
|
|
for (let i = 0; i < 3; i++) {
|
|
|
|
let tab = gBrowser.addTab();
|
|
|
|
loadTab(tab, TEST_URL_BASES[0] + (++gTabCounter));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
info("Running step 11 - close tabs in private browsing mode");
|
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
ensure_opentabs_match_db(nextStep);
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
info("Running step 12 - leave private browsing mode");
|
|
|
|
|
|
|
|
Services.obs.addObserver(function(aSubject, aTopic, aData) {
|
|
|
|
Services.obs.removeObserver(arguments.callee, "private-browsing-transition-complete");
|
|
|
|
|
|
|
|
let ps = Services.prefs;
|
2012-02-23 02:30:23 -08:00
|
|
|
ps.clearUserPref("browser.privatebrowsing.keep_current_session");
|
|
|
|
ps.clearUserPref("browser.tabs.warnOnClose");
|
2011-01-11 16:40:36 -08:00
|
|
|
|
|
|
|
for (let i = 1; i < gBrowser.tabs.length; i++)
|
|
|
|
waitForRestoredTab(gBrowser.tabs[i]);
|
|
|
|
|
|
|
|
}, "private-browsing-transition-complete", false);
|
|
|
|
|
|
|
|
gPrivateBrowsing.privateBrowsingEnabled = false;
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
info("Running step 13 - close all tabs");
|
2012-02-23 02:30:23 -08:00
|
|
|
|
|
|
|
Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand");
|
|
|
|
|
2011-01-11 16:40:36 -08:00
|
|
|
gBrowser.addTab("about:blank", {skipAnimation: true});
|
|
|
|
while (gBrowser.tabs.length > 1) {
|
|
|
|
info("Removing tab: " + gBrowser.tabs[0].linkedBrowser.currentURI.spec);
|
|
|
|
gBrowser.selectTabAtIndex(0);
|
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
}
|
|
|
|
ensure_opentabs_match_db(nextStep);
|
|
|
|
}
|
2010-03-26 14:59:02 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
waitForExplicitFinish();
|
|
|
|
nextStep();
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadTab(tab, url) {
|
2010-08-13 18:52:30 -07:00
|
|
|
// Because adding visits is async, we will not be notified immediately.
|
2011-01-11 16:40:36 -08:00
|
|
|
let visited = gPrivateBrowsing.privateBrowsingEnabled;
|
2010-11-19 16:39:55 -08:00
|
|
|
let loaded = false;
|
|
|
|
|
|
|
|
function maybeCheckResults() {
|
|
|
|
if (visited && loaded && --gTabWaitCount == 0) {
|
|
|
|
ensure_opentabs_match_db(nextStep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tab.linkedBrowser.addEventListener("load", function () {
|
|
|
|
tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
|
|
|
|
loaded = true;
|
|
|
|
maybeCheckResults();
|
|
|
|
}, true);
|
2010-08-13 18:52:30 -07:00
|
|
|
|
2011-01-11 16:40:36 -08:00
|
|
|
if (!visited) {
|
|
|
|
Services.obs.addObserver(
|
|
|
|
function (aSubject, aTopic, aData) {
|
|
|
|
if (url != aSubject.QueryInterface(Ci.nsIURI).spec)
|
|
|
|
return;
|
|
|
|
Services.obs.removeObserver(arguments.callee, aTopic);
|
|
|
|
visited = true;
|
|
|
|
maybeCheckResults();
|
|
|
|
},
|
|
|
|
"uri-visit-saved",
|
|
|
|
false
|
|
|
|
);
|
|
|
|
}
|
2010-08-13 18:52:30 -07:00
|
|
|
|
2010-03-26 14:59:02 -07:00
|
|
|
gTabWaitCount++;
|
2011-01-11 16:40:36 -08:00
|
|
|
info("Loading page: " + url);
|
2010-03-26 14:59:02 -07:00
|
|
|
tab.linkedBrowser.loadURI(url);
|
|
|
|
}
|
|
|
|
|
2011-01-11 16:40:36 -08:00
|
|
|
function waitForRestoredTab(tab) {
|
|
|
|
gTabWaitCount++;
|
|
|
|
|
|
|
|
tab.linkedBrowser.addEventListener("load", function () {
|
|
|
|
tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
|
|
|
|
if (--gTabWaitCount == 0) {
|
|
|
|
ensure_opentabs_match_db(nextStep);
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-26 14:59:02 -07:00
|
|
|
function nextStep() {
|
|
|
|
if (gTestSteps.length == 0) {
|
|
|
|
while (gBrowser.tabs.length > 1) {
|
|
|
|
gBrowser.selectTabAtIndex(1);
|
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
}
|
|
|
|
|
|
|
|
waitForClearHistory(finish);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var stepFunc = gTestSteps.shift();
|
|
|
|
stepFunc();
|
|
|
|
}
|
|
|
|
|
2010-11-19 16:39:55 -08:00
|
|
|
function ensure_opentabs_match_db(aCallback) {
|
2010-03-26 14:59:02 -07:00
|
|
|
var tabs = {};
|
|
|
|
|
|
|
|
var winEnum = Services.wm.getEnumerator("navigator:browser");
|
|
|
|
while (winEnum.hasMoreElements()) {
|
|
|
|
let browserWin = winEnum.getNext();
|
|
|
|
// skip closed-but-not-destroyed windows
|
|
|
|
if (browserWin.closed)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (let i = 0; i < browserWin.gBrowser.tabContainer.childElementCount; i++) {
|
|
|
|
let browser = browserWin.gBrowser.getBrowserAtIndex(i);
|
|
|
|
let url = browser.currentURI.spec;
|
2012-06-20 14:43:19 -07:00
|
|
|
if (browserWin.isBlankPageURL(url))
|
2010-11-07 06:04:59 -08:00
|
|
|
continue;
|
2010-03-26 14:59:02 -07:00
|
|
|
if (!(url in tabs))
|
|
|
|
tabs[url] = 1;
|
|
|
|
else
|
|
|
|
tabs[url]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-19 16:39:55 -08:00
|
|
|
checkAutocompleteResults(tabs, aCallback);
|
2010-03-26 14:59:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2010-11-19 16:39:55 -08:00
|
|
|
PlacesUtils.bhistory.removeAllPages();
|
|
|
|
}
|
|
|
|
|
|
|
|
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"));
|
2010-03-26 14:59:02 -07:00
|
|
|
}
|