Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

Commit

Permalink
Fix Bug 1478218: add Places cleanup to browser_asrouter_targeting.js (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamHillier committed Jul 25, 2018
1 parent 79ad977 commit 42106b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 8 additions & 1 deletion lib/ASRouterTargeting.jsm
Expand Up @@ -40,6 +40,11 @@ const TopFrecentSitesCache = {
}
resolve(this._topFrecentSites);
});
},
// For testing
expire() {
this._lastUpdated = 0;
this._topFrecentSites = null;
}
};

Expand Down Expand Up @@ -215,4 +220,6 @@ this.ASRouterTargeting = {
}
};

this.EXPORTED_SYMBOLS = ["ASRouterTargeting", "removeRandomItemFromArray"];
// Export for testing
this.TopFrecentSitesCache = TopFrecentSitesCache;
this.EXPORTED_SYMBOLS = ["ASRouterTargeting", "TopFrecentSitesCache"];
12 changes: 8 additions & 4 deletions test/functional/mochitest/browser_asrouter_targeting.js
@@ -1,5 +1,7 @@
ChromeUtils.defineModuleGetter(this, "ASRouterTargeting",
"resource://activity-stream/lib/ASRouterTargeting.jsm");
const {ASRouterTargeting, TopFrecentSitesCache} =
ChromeUtils.import("resource://activity-stream/lib/ASRouterTargeting.jsm", {});
const {AddonTestUtils} =
ChromeUtils.import("resource://testing-common/AddonTestUtils.jsm", {});
ChromeUtils.defineModuleGetter(this, "ProfileAge",
"resource://gre/modules/ProfileAge.jsm");
ChromeUtils.defineModuleGetter(this, "AddonManager",
Expand All @@ -11,8 +13,6 @@ ChromeUtils.defineModuleGetter(this, "NewTabUtils",
ChromeUtils.defineModuleGetter(this, "PlacesTestUtils",
"resource://testing-common/PlacesTestUtils.jsm");

const {AddonTestUtils} = ChromeUtils.import("resource://testing-common/AddonTestUtils.jsm", {});

// ASRouterTargeting.isMatch
add_task(async function should_do_correct_targeting() {
is(await ASRouterTargeting.isMatch("FOO", {}, {FOO: true}), true, "should return true for a matching value");
Expand Down Expand Up @@ -226,4 +226,8 @@ add_task(async function checkFrecentSites() {
message = {id: "foo", targeting: `(topFrecentSites[.frecency >= 900 && .lastVisitDate >= ${timeDaysAgo(1) - 1}]|mapToProperty('host') intersect ['mozilla3.com', 'mozilla2.com', 'mozilla1.com'])|length > 0`};
is(await ASRouterTargeting.findMatchingMessage({messages: [message], target: {}}), message,
"should select correct item when filtering by frecency and lastVisitDate with multiple candidate domains");

// Cleanup
await clearHistoryAndBookmarks();
TopFrecentSitesCache.expire();
});

0 comments on commit 42106b2

Please sign in to comment.