Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion chromium/background-scripts/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ async function applyStoredRulesets(rulesets_obj) {
}

if(!replaces) {
rulesets_obj.addFromJson(util.loadExtensionFile('rules/default.rulesets', 'json'));
const url = chrome.runtime.getURL('rules/default.rulesets');
const response = await fetch(url);
rulesets_obj.addFromJson(await response.json());
}
}

Expand Down
25 changes: 0 additions & 25 deletions chromium/background-scripts/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,6 @@ function getDefaultLogLevel() {
return DEFAULT_LOG_LEVEL;
}

/**
* Load a file packaged with the extension
*
* @param url: a relative URL to local file
*/
function loadExtensionFile(url, returnType) {
var xhr = new XMLHttpRequest();
// Use blocking XHR to ensure everything is loaded by the time
// we return.
xhr.open("GET", chrome.runtime.getURL(url), false);
xhr.send(null);
// Get file contents
if (xhr.readyState !== 4) {
return;
}
if (returnType === 'xml') {
return xhr.responseXML;
}
if (returnType === 'json') {
return JSON.parse(xhr.responseText);
}
return xhr.responseText;
}

/**
* Convert an ArrayBuffer to string
*
Expand All @@ -86,7 +62,6 @@ Object.assign(exports, {
log,
setDefaultLogLevel,
getDefaultLogLevel,
loadExtensionFile,
ArrayBufferToString
});

Expand Down
3 changes: 2 additions & 1 deletion chromium/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"nyc": "^11.6.0",
"sinon": "^4.4.8",
"sinon-chrome": "^2.3.1",
"text-encoding": "^0.6.4"
"text-encoding": "^0.6.4",
"node-fetch": "^2.3.0"
},
"scripts": {
"test": "mocha",
Expand Down
5 changes: 3 additions & 2 deletions chromium/test/update_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const assert = require('chai').assert,
util = require('../background-scripts/util'),
atob = require("atob"),
TextDecoder = require('text-encoding').TextDecoder,
sinon = require('sinon');
fetchMock = require('fetch-mock');

const fs = require('fs'),
{ update_channels } = require('../background-scripts/update_channels'),
Expand All @@ -20,6 +20,7 @@ describe('update.js', function() {
describe('applyStoredRulesets', function() {
beforeEach(() => {
chrome.flush();

if(util.loadExtensionFile.restore) {
util.loadExtensionFile.restore();
}
Expand Down Expand Up @@ -57,7 +58,7 @@ describe('update.js', function() {
const example_rulesets = new TextDecoder("utf-8").decode(example_rulesets_byte_array);
const example_rulesets_json = JSON.parse(example_rulesets);

sinon.stub(util, "loadExtensionFile").returns(example_rulesets_json.rulesets);
fetchMock.get('*', example_rulesets_json.rulesets);

update.applyStoredRulesets({addFromJson: response => {
assert.isArray(response);
Expand Down