fune/browser/components/urlbar/tests/unit/test_providerOpenTabs.js
Dão Gottwald 9e40dea2a8 Bug 1522426 - Rename MATCH_TYPE to RESULT_TYPE. r=mak
Differential Revision: https://phabricator.services.mozilla.com/D17628

--HG--
extra : moz-landing-system : lando
2019-01-25 16:14:21 +00:00

34 lines
1.4 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function test_openTabs() {
const userContextId = 5;
const url = "http://foo.mozilla.org/";
UrlbarProviderOpenTabs.registerOpenTab(url, userContextId);
UrlbarProviderOpenTabs.registerOpenTab(url, userContextId);
Assert.equal(UrlbarProviderOpenTabs.openTabs.get(userContextId).length, 2,
"Found all the expected tabs");
UrlbarProviderOpenTabs.unregisterOpenTab(url, userContextId);
Assert.equal(UrlbarProviderOpenTabs.openTabs.get(userContextId).length, 1,
"Found all the expected tabs");
let context = createContext();
let matchCount = 0;
let callback = function(provider, match) {
matchCount++;
Assert.equal(provider, UrlbarProviderOpenTabs, "Got the expected provider");
Assert.equal(match.type, UrlbarUtils.RESULT_TYPE.TAB_SWITCH,
"Got the expected result type");
Assert.equal(match.payload.url, url, "Got the expected url");
Assert.equal(match.payload.title, undefined, "Got the expected title");
};
await UrlbarProviderOpenTabs.startQuery(context, callback);
Assert.equal(matchCount, 1, "Found the expected number of matches");
// Sanity check that this doesn't throw.
UrlbarProviderOpenTabs.cancelQuery(context);
Assert.equal(UrlbarProviderOpenTabs.queries.size, 0,
"All the queries have been removed");
});