Skip to content

Commit

Permalink
✅ Fix tests broken by changes from https://twitter.com/ to https://x.…
Browse files Browse the repository at this point in the history
  • Loading branch information
danielrozenberg authored May 20, 2024
1 parent 33b82c3 commit d15fbae
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describes.endtoend(
await controller.switchToWindow(windows[1]);

await expect(controller.getCurrentUrl()).to.have.string(
'https://twitter.com/'
'https://x.com/'
);
});

Expand Down
28 changes: 13 additions & 15 deletions test/unit/test-document-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ describes.sandboxed('document-info', {}, (env) => {
}

it('should provide the canonicalUrl', () => {
return getWin({'canonical': ['https://twitter.com/']}).then((win) => {
return getWin({'canonical': ['https://x.com/']}).then((win) => {
expect(Services.documentInfoForDoc(win.document).canonicalUrl).to.equal(
'https://twitter.com/'
'https://x.com/'
);
});
});
Expand Down Expand Up @@ -133,7 +133,7 @@ describes.sandboxed('document-info', {}, (env) => {
});

it('should provide the pageViewId', () => {
return getWin({'canonical': ['https://twitter.com/']}).then((win) => {
return getWin({'canonical': ['https://x.com/']}).then((win) => {
expect(Services.documentInfoForDoc(win.document).pageViewId).to.equal(
'1234'
);
Expand All @@ -144,7 +144,7 @@ describes.sandboxed('document-info', {}, (env) => {
});

it('should provide the pageViewId64', () => {
return getWin({'canonical': ['https://twitter.com/']}).then((win) => {
return getWin({'canonical': ['https://x.com/']}).then((win) => {
expect(Services.documentInfoForDoc(win.document).pageViewId64).to.equal(
'abcdef'
);
Expand All @@ -164,12 +164,12 @@ describes.sandboxed('document-info', {}, (env) => {

it('should provide the linkRels containing link tag rels', () => {
return getWin({
'canonical': ['https://twitter.com/'],
'canonical': ['https://x.com/'],
'icon': ['https://foo.html/bar.gif'],
}).then((win) => {
expect(
Services.documentInfoForDoc(win.document).linkRels['canonical']
).to.equal('https://twitter.com/');
).to.equal('https://x.com/');
expect(
Services.documentInfoForDoc(win.document).linkRels['icon']
).to.equal('https://foo.html/bar.gif');
Expand Down Expand Up @@ -201,15 +201,15 @@ describes.sandboxed('document-info', {}, (env) => {
'space in rel',
() => {
return getWin({
'sharelink canonical': ['https://twitter.com/'],
'sharelink canonical': ['https://x.com/'],
'icon': ['https://foo.html/bar.gif'],
}).then((win) => {
expect(
Services.documentInfoForDoc(win.document).linkRels['sharelink']
).to.equal('https://twitter.com/');
).to.equal('https://x.com/');
expect(
Services.documentInfoForDoc(win.document).linkRels['canonical']
).to.equal('https://twitter.com/');
).to.equal('https://x.com/');
expect(
Services.documentInfoForDoc(win.document).linkRels['icon']
).to.equal('https://foo.html/bar.gif');
Expand All @@ -222,17 +222,15 @@ describes.sandboxed('document-info', {}, (env) => {
'hrefs',
() => {
return getWin({
'canonical': ['https://twitter.com/'],
'canonical': ['https://x.com/'],
'icon': ['https://foo.html/bar.gif'],
'stylesheet': [
'https://foo.html/style1.css',
'https://foo.html/style2.css',
],
}).then((win) => {
const documentInfo = Services.documentInfoForDoc(win.document);
expect(documentInfo.linkRels['canonical']).to.equal(
'https://twitter.com/'
);
expect(documentInfo.linkRels['canonical']).to.equal('https://x.com/');
expect(documentInfo.linkRels['icon']).to.equal(
'https://foo.html/bar.gif'
);
Expand All @@ -252,15 +250,15 @@ describes.sandboxed('document-info', {}, (env) => {
'prefetch/preload/preconnect rels',
() => {
return getWin({
'canonical': ['https://twitter.com/'],
'canonical': ['https://x.com/'],
'icon': ['https://foo.html/bar.gif'],
'prefetch': ['https://foo1.com'],
'preload': ['https://foo2.com'],
'preconnect': ['https://foo3.com'],
}).then((win) => {
expect(
Services.documentInfoForDoc(win.document).linkRels['canonical']
).to.equal('https://twitter.com/');
).to.equal('https://x.com/');
expect(
Services.documentInfoForDoc(win.document).linkRels['icon']
).to.equal('https://foo.html/bar.gif');
Expand Down
88 changes: 40 additions & 48 deletions test/unit/test-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ describes.sandboxed('parseUrlDeprecated', {}, () => {
origin: 'http://foo.com:123',
});
});
it('should parse origin https://twitter.com/path#abc', () => {
expect(parseUrlDeprecated('https://twitter.com/path#abc').origin).to.equal(
'https://twitter.com'
it('should parse origin https://x.com/path#abc', () => {
expect(parseUrlDeprecated('https://x.com/path#abc').origin).to.equal(
'https://x.com'
);
});

Expand Down Expand Up @@ -285,13 +285,13 @@ describes.sandboxed('assertHttpsUrl/isSecureUrl', {}, () => {
assertHttpsUrl('', referenceElement);
});
it('should allow https', () => {
assertHttpsUrl('https://twitter.com', referenceElement);
expect(isSecureUrlDeprecated('https://twitter.com')).to.be.true;
assertHttpsUrl('https://x.com', referenceElement);
expect(isSecureUrlDeprecated('https://x.com')).to.be.true;
});
it('should allow protocol relative', () => {
assertHttpsUrl('//twitter.com', referenceElement);
assertHttpsUrl('//x.com', referenceElement);
// `isSecureUrl` always resolves relative URLs.
expect(isSecureUrlDeprecated('//twitter.com')).to.be.equal(
expect(isSecureUrlDeprecated('//x.com')).to.be.equal(
window.location.protocol == 'https:'
);
});
Expand All @@ -308,10 +308,10 @@ describes.sandboxed('assertHttpsUrl/isSecureUrl', {}, () => {
it('should fail on http', () => {
allowConsoleError(() => {
expect(() => {
assertHttpsUrl('http://twitter.com', referenceElement);
assertHttpsUrl('http://x.com', referenceElement);
}).to.throw(/source must start with/);
});
expect(isSecureUrlDeprecated('http://twitter.com')).to.be.false;
expect(isSecureUrlDeprecated('http://x.com')).to.be.false;
});
it('should fail on http with localhost in the name', () => {
allowConsoleError(() => {
Expand All @@ -325,25 +325,25 @@ describes.sandboxed('assertHttpsUrl/isSecureUrl', {}, () => {

describes.sandboxed('assertAbsoluteHttpOrHttpsUrl', {}, () => {
it('should allow http', () => {
expect(assertAbsoluteHttpOrHttpsUrl('http://twitter.com/')).to.equal(
'http://twitter.com/'
expect(assertAbsoluteHttpOrHttpsUrl('http://x.com/')).to.equal(
'http://x.com/'
);
expect(assertAbsoluteHttpOrHttpsUrl('HTTP://twitter.com/')).to.equal(
'http://twitter.com/'
expect(assertAbsoluteHttpOrHttpsUrl('HTTP://x.com/')).to.equal(
'http://x.com/'
);
});
it('should allow https', () => {
expect(assertAbsoluteHttpOrHttpsUrl('https://twitter.com/')).to.equal(
'https://twitter.com/'
expect(assertAbsoluteHttpOrHttpsUrl('https://x.com/')).to.equal(
'https://x.com/'
);
expect(assertAbsoluteHttpOrHttpsUrl('HTTPS://twitter.com/')).to.equal(
'https://twitter.com/'
expect(assertAbsoluteHttpOrHttpsUrl('HTTPS://x.com/')).to.equal(
'https://x.com/'
);
});
it('should fail on relative protocol', () => {
allowConsoleError(() => {
expect(() => {
assertAbsoluteHttpOrHttpsUrl('//twitter.com/');
assertAbsoluteHttpOrHttpsUrl('//x.com/');
}).to.throw(/URL must start with/);
});
});
Expand All @@ -367,69 +367,61 @@ describes.sandboxed('assertAbsoluteHttpOrHttpsUrl', {}, () => {

describes.sandboxed('removeFragment', {}, () => {
it('should remove fragment', () => {
expect(removeFragment('https://twitter.com/path#abc')).to.equal(
'https://twitter.com/path'
expect(removeFragment('https://x.com/path#abc')).to.equal(
'https://x.com/path'
);
});
it('should remove empty fragment', () => {
expect(removeFragment('https://twitter.com/path#')).to.equal(
'https://twitter.com/path'
expect(removeFragment('https://x.com/path#')).to.equal(
'https://x.com/path'
);
});
it('should ignore when no fragment', () => {
expect(removeFragment('https://twitter.com/path')).to.equal(
'https://twitter.com/path'
);
expect(removeFragment('https://x.com/path')).to.equal('https://x.com/path');
});
});

describes.sandboxed('removeSearch', {}, () => {
it('should remove search', () => {
expect(removeSearch('https://twitter.com/path?abc')).to.equal(
'https://twitter.com/path'
expect(removeSearch('https://x.com/path?abc')).to.equal(
'https://x.com/path'
);
});
it('should remove search with value', () => {
expect(removeSearch('https://twitter.com/path?abc=123')).to.equal(
'https://twitter.com/path'
expect(removeSearch('https://x.com/path?abc=123')).to.equal(
'https://x.com/path'
);
});
it('should remove multiple params', () => {
expect(removeSearch('https://twitter.com/path?abc=123&d&e=4')).to.equal(
'https://twitter.com/path'
expect(removeSearch('https://x.com/path?abc=123&d&e=4')).to.equal(
'https://x.com/path'
);
});
it('should remove empty search', () => {
expect(removeSearch('https://twitter.com/path?')).to.equal(
'https://twitter.com/path'
);
expect(removeSearch('https://x.com/path?')).to.equal('https://x.com/path');
});
it('should ignore when no search', () => {
expect(removeSearch('https://twitter.com/path')).to.equal(
'https://twitter.com/path'
);
expect(removeSearch('https://x.com/path')).to.equal('https://x.com/path');
});
it('should preserve fragment', () => {
expect(removeSearch('https://twitter.com/path?abc#f')).to.equal(
'https://twitter.com/path#f'
expect(removeSearch('https://x.com/path?abc#f')).to.equal(
'https://x.com/path#f'
);
});
it('should preserve fragment with multiple params', () => {
expect(removeSearch('https://twitter.com/path?a&d=1&e=5#f=x')).to.equal(
'https://twitter.com/path#f=x'
expect(removeSearch('https://x.com/path?a&d=1&e=5#f=x')).to.equal(
'https://x.com/path#f=x'
);
});
it('should preserve fragment when no search', () => {
expect(removeSearch('https://twitter.com/path#f')).to.equal(
'https://twitter.com/path#f'
expect(removeSearch('https://x.com/path#f')).to.equal(
'https://x.com/path#f'
);
});
it('should handle empty fragment', () => {
expect(removeSearch('https://twitter.com/path#')).to.equal(
'https://twitter.com/path#'
);
expect(removeSearch('https://twitter.com/path?#')).to.equal(
'https://twitter.com/path#'
expect(removeSearch('https://x.com/path#')).to.equal('https://x.com/path#');
expect(removeSearch('https://x.com/path?#')).to.equal(
'https://x.com/path#'
);
});
});
Expand Down

0 comments on commit d15fbae

Please sign in to comment.