Commit bd13f81e authored by Thomas Greiner's avatar Thomas Greiner

Issue 7144 - Fixed: Issue reporter mock was broken

parent 8d4eb230
Pipeline #38353944 failed with stages
in 2 minutes and 30 seconds
......@@ -242,5 +242,10 @@ parameters:
* `platform=chromium`: shows the opt-out for the developer tools panel
* `showNotificationUI=true`: simulates user having opted-out of notifications
issue-reporter.html?1
---------------------
This is the implementation of the Adblock Plus issue reporter which collects
data for reporting an issue to adblockplus.org.
[crowdin]: https://crowdin.com
......@@ -68,4 +68,11 @@
});
}
window.browser.runtime.onConnect = {addListener: onConnect};
if (!("tabs" in browser))
browser.tabs = {};
browser.tabs.onRemoved = {
addListener() {}
};
}());
......@@ -19,6 +19,12 @@
(function()
{
function log(...args)
{
// eslint-disable-next-line no-console
console.log("MOCK", ...args);
}
if (typeof ext == "undefined")
window.ext = {};
......@@ -113,14 +119,128 @@
}
browser.runtime.connect = connect;
const getTab = (url) => ({id: ++tabCounter, url});
let tabCounter = 0;
let activeTab = getTab("https://example.com/");
const tabs = new Map([
[activeTab.id, activeTab]
]);
if (!("tabs" in browser))
browser.tabs = new Map([[0, {url: "example.com"}]]);
browser.tabs = {};
browser.tabs.captureVisibleTab = (tabId, options, callback) =>
{
log(`Take screenshot of tab with ID ${tabId || activeTab.id}`);
return fetch("../tests/image.base64.txt")
.then(body => body.text())
.then(callback);
};
browser.tabs.create = (options) =>
{
const tab = getTab(options.url);
tabs.set(tab.id, tab);
log(`Created tab '${tab.url}' with ID ${tab.id}`);
if (options.active)
{
activeTab = tab;
log(`Focused tab with ID ${activeTab.id}`);
}
return Promise.resolve(tab);
};
browser.tabs.get = (tabId) =>
{
const tab = tabs.get(tabId);
if (!tab)
return Promise.reject(new Error(`Tab with ID ${tabId} cannot be found`));
return Promise.resolve(tab);
};
browser.tabs.getCurrent = (callback) =>
{
return Promise.resolve(activeTab).then(callback);
};
browser.tabs.onUpdated = {
addListener() {}
};
browser.tabs.remove = (tabId) =>
{
log(`Closed tab: ${tabs.get(tabId).url}`);
tabs.delete(tabId);
return Promise.resolve();
};
browser.tabs.get = (...args) =>
browser.tabs.update = (tabId, options, callback) =>
{
// Extend browser.tabs.get()
const result = Map.prototype.get.apply(browser.tabs, args);
return (result ? Promise.resolve(result) :
Promise.reject(new Error("Tab cannot be found")));
if (options.active)
{
activeTab = tabs.get(tabId);
log(`Focused tab with ID ${activeTab.id}`);
}
return Promise.resolve().then(callback);
};
class MockXmlHttpRequest extends XMLHttpRequest
{
get responseText()
{
if (typeof this._responseText === "undefined")
return super.responseText;
return this._responseText;
}
get status()
{
if (typeof this._status === "undefined")
return super.status;
return this._status;
}
open(method, url, ...args)
{
super.open(method, url, ...args);
this._method = method.toLowerCase();
this._url = url;
}
send(body)
{
// We're only intercepting data that is sent to the server
if (this._method !== "post")
{
super.send(body);
return;
}
try
{
log("Sent request", this._url);
this._status = 200;
this._responseText = `
<a download href="data:text/xml;utf-8,${encodeURIComponent(body)}">
Download issue report as XML
</a>
`;
const event = new CustomEvent("load");
this.dispatchEvent(event);
}
catch (ex)
{
console.error(ex);
}
}
}
window.XMLHttpRequest = MockXmlHttpRequest;
}());
......@@ -90,7 +90,7 @@ module.exports = {
{
const tabId = parseInt(location.search.replace(/^\?/, ""), 10);
if (!tabId)
if (!tabId && tabId !== 0)
return Promise.reject(new Error("invalid tab id"));
return Promise.all([
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment