diff --git a/lighthouse-cli/test/fixtures/dobetterweb/dbw_tester.html b/lighthouse-cli/test/fixtures/dobetterweb/dbw_tester.html
index a79165794080..73349895337a 100644
--- a/lighthouse-cli/test/fixtures/dobetterweb/dbw_tester.html
+++ b/lighthouse-cli/test/fixtures/dobetterweb/dbw_tester.html
@@ -106,10 +106,18 @@
Do better web tester page
external link
-
+
+ external link
+
external link that uses rel noopener and another unrelated rel attribute
-
+
+ external link that uses rel noopener
+
internal link is ok
+
+
+
+
diff --git a/lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js b/lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js
index 29afcc778c3c..fdab95f1538d 100644
--- a/lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js
+++ b/lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js
@@ -53,12 +53,12 @@ module.exports = [
'If they are not used as hyperlinks, consider removing the _blank target.',
extendedInfo: {
value: {
- length: 2,
+ length: 3,
},
},
details: {
items: {
- length: 2,
+ length: 3,
},
},
},
diff --git a/lighthouse-core/audits/dobetterweb/external-anchors-use-rel-noopener.js b/lighthouse-core/audits/dobetterweb/external-anchors-use-rel-noopener.js
index 296f94dc9647..1e47810887ca 100644
--- a/lighthouse-core/audits/dobetterweb/external-anchors-use-rel-noopener.js
+++ b/lighthouse-core/audits/dobetterweb/external-anchors-use-rel-noopener.js
@@ -47,8 +47,7 @@ class ExternalAnchorsUseRelNoopenerAudit extends Audit {
}
})
.filter(anchor => {
- // Ignore href's that are not real links
- return !anchor.href || !anchor.href.toLowerCase().startsWith('javascript:');
+ return !anchor.href || anchor.href.toLowerCase().startsWith('http');
})
.map(anchor => {
return {
diff --git a/lighthouse-core/test/audits/dobetterweb/external-anchors-use-rel-noopener-test.js b/lighthouse-core/test/audits/dobetterweb/external-anchors-use-rel-noopener-test.js
index c89aab41e7c9..fb3bf5a36981 100644
--- a/lighthouse-core/test/audits/dobetterweb/external-anchors-use-rel-noopener-test.js
+++ b/lighthouse-core/test/audits/dobetterweb/external-anchors-use-rel-noopener-test.js
@@ -27,6 +27,30 @@ describe('External anchors use rel="noopener"', () => {
assert.equal(auditResult.details.items.length, 0);
});
+ it('passes when links have javascript in href attribute', () => {
+ const auditResult = ExternalAnchorsAudit.audit({
+ AnchorsWithNoRelNoopener: [
+ {href: 'javascript:void(0)'},
+ {href: 'JAVASCRIPT:void(0)'},
+ ],
+ URL: {finalUrl: URL},
+ });
+ assert.equal(auditResult.rawValue, true);
+ assert.equal(auditResult.details.items.length, 0);
+ });
+
+ it('passes when links have mailto in href attribute', () => {
+ const auditResult = ExternalAnchorsAudit.audit({
+ AnchorsWithNoRelNoopener: [
+ {href: 'mailto:inbox@email.com'},
+ {href: 'MAILTO:INBOX@EMAIL.COM'},
+ ],
+ URL: {finalUrl: URL},
+ });
+ assert.equal(auditResult.rawValue, true);
+ assert.equal(auditResult.details.items.length, 0);
+ });
+
it('fails when links are from different hosts than the page host', () => {
const auditResult = ExternalAnchorsAudit.audit({
AnchorsWithNoRelNoopener: [
@@ -40,30 +64,32 @@ describe('External anchors use rel="noopener"', () => {
assert.equal(auditResult.details.items.length, 2);
});
- it('handles links with no href attribute', () => {
+ it('fails when links have no href attribute', () => {
const auditResult = ExternalAnchorsAudit.audit({
AnchorsWithNoRelNoopener: [
{href: ''},
- {href: 'http://'},
- {href: 'http:'},
],
URL: {finalUrl: URL},
});
assert.equal(auditResult.rawValue, false);
- assert.equal(auditResult.details.items.length, 3);
- assert.equal(auditResult.details.items.length, 3);
+ assert.equal(auditResult.details.items.length, 1);
+ assert.equal(auditResult.details.items.length, 1);
assert.ok(auditResult.debugString, 'includes debugString');
});
- it('does not fail for links with javascript in href attribute', () => {
+ it('fails when links have href attribute starting with a protocol', () => {
const auditResult = ExternalAnchorsAudit.audit({
AnchorsWithNoRelNoopener: [
- {href: 'javascript:void(0)'},
- {href: 'JAVASCRIPT:void(0)'},
+ {href: 'http://'},
+ {href: 'http:'},
+ {href: 'https://'},
+ {href: 'https:'},
],
URL: {finalUrl: URL},
});
- assert.equal(auditResult.rawValue, true);
- assert.equal(auditResult.details.items.length, 0);
+ assert.equal(auditResult.rawValue, false);
+ assert.equal(auditResult.details.items.length, 4);
+ assert.equal(auditResult.details.items.length, 4);
+ assert.ok(auditResult.debugString, 'includes debugString');
});
});