summaryrefslogtreecommitdiffstats
path: root/toolkit/components/webextensions/test/xpcshell/test_ext_topSites.js
diff options
context:
space:
mode:
authorMoonchild <mcwerewolf@wolfbeast.com>2019-03-13 07:49:07 +0100
committerGitHub <noreply@github.com>2019-03-13 07:49:07 +0100
commitbf0413359245579e9509146d42cd5547e35da695 (patch)
tree8218d4f60d9eccacbf42df8cb88094a082d401b4 /toolkit/components/webextensions/test/xpcshell/test_ext_topSites.js
parent51b821b3fdc5a7eab2369cb6a6680598a6264b08 (diff)
parent709bc24e9110eba12f94cfcb8db00a8338ac4098 (diff)
downloadUXP-bf0413359245579e9509146d42cd5547e35da695.tar
UXP-bf0413359245579e9509146d42cd5547e35da695.tar.gz
UXP-bf0413359245579e9509146d42cd5547e35da695.tar.lz
UXP-bf0413359245579e9509146d42cd5547e35da695.tar.xz
UXP-bf0413359245579e9509146d42cd5547e35da695.zip
Merge pull request #998 from MoonchildProductions/master
Merge master into Sync-weave
Diffstat (limited to 'toolkit/components/webextensions/test/xpcshell/test_ext_topSites.js')
-rw-r--r--toolkit/components/webextensions/test/xpcshell/test_ext_topSites.js85
1 files changed, 0 insertions, 85 deletions
diff --git a/toolkit/components/webextensions/test/xpcshell/test_ext_topSites.js b/toolkit/components/webextensions/test/xpcshell/test_ext_topSites.js
deleted file mode 100644
index eb3f552ed..000000000
--- a/toolkit/components/webextensions/test/xpcshell/test_ext_topSites.js
+++ /dev/null
@@ -1,85 +0,0 @@
-"use strict";
-
-Cu.import("resource://gre/modules/NewTabUtils.jsm");
-
-
-function TestProvider(getLinksFn) {
- this.getLinks = getLinksFn;
- this._observers = new Set();
-}
-
-TestProvider.prototype = {
- addObserver: function(observer) {
- this._observers.add(observer);
- },
- notifyLinkChanged: function(link, index = -1, deleted = false) {
- this._notifyObservers("onLinkChanged", link, index, deleted);
- },
- notifyManyLinksChanged: function() {
- this._notifyObservers("onManyLinksChanged");
- },
- _notifyObservers: function(observerMethodName, ...args) {
- args.unshift(this);
- for (let obs of this._observers) {
- if (obs[observerMethodName]) {
- obs[observerMethodName].apply(NewTabUtils.links, args);
- }
- }
- },
-};
-
-function makeLinks(links) {
- // Important: To avoid test failures due to clock jitter on Windows XP, call
- // Date.now() once here, not each time through the loop.
- let frecency = 0;
- let now = Date.now() * 1000;
- let places = [];
- links.map((link, i) => {
- places.push({
- url: link.url,
- title: link.title,
- lastVisitDate: now - i,
- frecency: frecency++,
- });
- });
- return places;
-}
-
-add_task(function* test_topSites() {
- let expect = [{url: "http://example.com/", title: "site#-1"},
- {url: "http://example0.com/", title: "site#0"},
- {url: "http://example1.com/", title: "site#1"},
- {url: "http://example2.com/", title: "site#2"},
- {url: "http://example3.com/", title: "site#3"}];
-
- let extension = ExtensionTestUtils.loadExtension({
- manifest: {
- "permissions": [
- "topSites",
- ],
- },
- background() {
- browser.topSites.get(result => {
- browser.test.sendMessage("done", result);
- });
- },
- });
-
-
- let expectedLinks = makeLinks(expect);
- let provider = new TestProvider(done => done(expectedLinks));
-
- NewTabUtils.initWithoutProviders();
- NewTabUtils.links.addProvider(provider);
-
- yield NewTabUtils.links.populateCache();
-
- yield extension.startup();
-
- let result = yield extension.awaitMessage("done");
- Assert.deepEqual(expect, result, "got topSites");
-
- yield extension.unload();
-
- NewTabUtils.links.removeProvider(provider);
-});