aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--content/noscript.js1
-rw-r--r--test/resources/index.html1
-rw-r--r--test/spec/LibreJSSpec.js24
3 files changed, 22 insertions, 4 deletions
diff --git a/content/noscript.js b/content/noscript.js
index 9cf1ac1..58445c5 100644
--- a/content/noscript.js
+++ b/content/noscript.js
@@ -24,6 +24,7 @@
for (const noscript of document.querySelectorAll(
'noscript:not([data-librejs-nodisplay])')) {
const replacement = document.createElement('span');
+ replacement.setAttribute('data-librejs-show-noscript', true);
replacement.innerHTML = noscript.innerHTML;
noscript.replaceWith(replacement);
}
diff --git a/test/resources/index.html b/test/resources/index.html
index 791a673..0cbb219 100644
--- a/test/resources/index.html
+++ b/test/resources/index.html
@@ -39,6 +39,7 @@
<a href="bar">About Us</a>
<a href="foo">Contact Us</a><span> at lib@re.js.</span>
<a href="quux">Website Feedback</a>
+ <noscript>inside a noscript tag</noscript>
</div>
</body>
</html>
diff --git a/test/spec/LibreJSSpec.js b/test/spec/LibreJSSpec.js
index 70ec339..459c8b4 100644
--- a/test/spec/LibreJSSpec.js
+++ b/test/spec/LibreJSSpec.js
@@ -50,7 +50,6 @@ describe('LibreJS\' components', () => {
let url = browser.extension.getURL('/test/resources/index.html');
tab = (await browser.tabs.query({ url }))[0] || (await browser.tabs.create({ url }));
documentUrl = url;
-
});
describe('The whitelist/blacklist manager', () => {
@@ -257,15 +256,32 @@ describe('LibreJS\' components', () => {
});
});
- describe('FIXME: dummy test to get noscript.js displayed in the console debugger', () => {
+ describe('User forces noscript element content', () => {
beforeAll(async () => {
await browser.tabs.executeScript(tab.id, {
file: '/content/noscript.js'
});
});
- it('IGNORE ME', () => {
- expect(1).toBe(1);
+ it('forces noscript element content from content script', async () => {
+ const [numNsBefore] = await browser.tabs.executeScript(tab.id, {
+ code: 'document.querySelectorAll("noscript").length'
+ });
+ expect(numNsBefore).toBe(1);
+ const contentBefore = await browser.tabs.executeScript(tab.id, {
+ code: 'document.querySelectorAll("noscript")[0].innerHTML'
+ });
+ await browser.tabs.sendMessage(tab.id, {
+ action: 'forceNoscript'
+ });
+ const [numNsAfter] = await browser.tabs.executeScript(tab.id, {
+ code: 'document.querySelectorAll("noscript").length'
+ });
+ expect(numNsAfter).toBe(0);
+ const contentAfter = await browser.tabs.executeScript(tab.id, {
+ code: 'document.querySelectorAll("span[data-librejs-show-noscript]")[0].innerHTML'
+ });
+ expect(contentBefore).toEqual(contentAfter);
});
});