gecko-dev/browser/extensions/webcompat/test/browser_overrider.js
Dennis Schubert 98c6569650 Bug 1337905 - Update WebCompat Go Faster addon to version 1.1. r=Felipe
MozReview-Commit-ID: FMgf5E9Obzk

--HG--
extra : rebase_source : 99b8bbcb6660e2ad899b7e295b468ec505fa5fdc
2017-02-10 11:15:56 +01:00

40 lines
1.3 KiB
JavaScript

/* 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/. */
/* globals XPCOMUtils, UAOverrider, IOService */
"use strict";
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "UAOverrider", "chrome://webcompat/content/lib/ua_overrider.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "IOService", "@mozilla.org/network/io-service;1", "nsIIOService");
function getnsIURI(uri) {
return IOService.newURI(uri, "utf-8");
}
add_task(function test() {
let overrider = new UAOverrider([
{
baseDomain: "example.org",
uaTransformer: () => "Test UA"
}
]);
let finalUA = overrider.lookupUAOverride(getnsIURI("http://www.example.org/foobar/"));
is(finalUA, "Test UA", "Overrides the UA without a matcher function");
});
add_task(function test() {
let overrider = new UAOverrider([
{
baseDomain: "example.org",
uriMatcher: () => false,
uaTransformer: () => "Test UA"
}
]);
let finalUA = overrider.lookupUAOverride(getnsIURI("http://www.example.org/foobar/"));
isnot(finalUA, "Test UA", "Does not override the UA with the matcher returning false");
});