Source code
Revision control
Copy as Markdown
Other Tools
import { classifySite } from "lib/SiteClassifier.sys.mjs";
const FAKE_CLASSIFIER_DATA = [
{
type: "hostname-and-params-match",
criteria: [
{
hostname: "hostnameandparams.com",
params: [
{
key: "param1",
value: "val1",
},
],
},
],
weight: 300,
},
{
type: "url-match",
weight: 400,
},
{
type: "params-match",
criteria: [
{
params: [
{
key: "param1",
value: "val1",
},
{
key: "param2",
value: "val2",
},
],
},
],
weight: 200,
},
{
type: "params-prefix-match",
criteria: [
{
params: [
{
key: "client",
prefix: "fir",
},
],
},
],
weight: 200,
},
{
type: "has-params",
criteria: [
{
params: [{ key: "has-param1" }, { key: "has-param2" }],
},
],
weight: 100,
},
{
type: "search-engine",
criteria: [
{ sld: "google" },
{ hostname: "bing.com" },
{ hostname: "duckduckgo.com" },
],
weight: 1,
},
{
type: "news-portal",
criteria: [
{ hostname: "yahoo.com" },
{ hostname: "aol.com" },
{ hostname: "msn.com" },
],
weight: 1,
},
{
type: "social-media",
criteria: [{ hostname: "facebook.com" }, { hostname: "twitter.com" }],
weight: 1,
},
{
type: "ecommerce",
criteria: [{ sld: "amazon" }, { hostname: "ebay.com" }],
weight: 1,
},
];
describe("SiteClassifier", () => {
function RemoteSettings() {
return {
get() {
return Promise.resolve(FAKE_CLASSIFIER_DATA);
},
};
}
it("should return the right category", async () => {
assert.equal(
"hostname-and-params-match",
await classifySite(
RemoteSettings
)
);
assert.equal(
"other",
await classifySite(
RemoteSettings
)
);
assert.equal(
"other",
await classifySite(
RemoteSettings
)
);
assert.equal(
"other",
);
assert.equal(
"other",
);
assert.equal(
"url-match",
);
assert.equal(
"other",
);
assert.equal(
"params-match",
await classifySite(
RemoteSettings
)
);
assert.equal(
"params-match",
await classifySite(
RemoteSettings
)
);
assert.equal(
"other",
await classifySite(
RemoteSettings
)
);
assert.equal(
"other",
);
assert.equal(
"params-prefix-match",
);
assert.equal(
"params-prefix-match",
);
assert.equal(
"other",
await classifySite(
RemoteSettings
)
);
assert.equal(
"has-params",
await classifySite(
RemoteSettings
)
);
assert.equal(
"has-params",
await classifySite(
RemoteSettings
)
);
assert.equal(
"has-params",
await classifySite(
RemoteSettings
)
);
assert.equal(
"other",
);
assert.equal(
"other",
);
assert.equal(
"search-engine",
);
assert.equal(
"search-engine",
);
assert.equal(
"search-engine",
);
assert.equal(
"news-portal",
);
assert.equal(
"social-media",
);
assert.equal(
"ecommerce",
);
assert.equal(
"ecommerce",
);
assert.equal(
"ecommerce",
);
});
});