Skip to content

Commit

Permalink
Fix JS test failures due to browser discrepancies
Browse files Browse the repository at this point in the history
Firefox and Chromium return different values when evaluating
"background-image", absolute URL vs relative URL.

This fix adjusts the TestUtil to normalize the URL to absolute because
the purpose of the test is just to check that the correct target image
was set.
  • Loading branch information
Vincent Petry committed Oct 25, 2018
1 parent 067b826 commit b1fcd2e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions core/js/tests/specHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ window.isPhantom = /phantom/i.test(navigator.userAgent);
/**
* Returns the image URL set on the given element
* @param $el element
* @return {String} image URL
* @return {String} absolute image URL
*/
getImageUrl: function($el) {
// might be slightly different cross-browser
Expand All @@ -136,7 +136,13 @@ window.isPhantom = /phantom/i.test(navigator.userAgent);
if (!r) {
return url;
}
return r[1];
url = r[1];

// some browsers return this as relative URL, others as absolute
if (!url.startsWith(OC.getProtocol() + '://')) {
return this.buildAbsoluteUrl(url);
}
return url;
},
buildAbsoluteUrl: function(relativeUrl) {
return window.location.protocol + '//' + window.location.host + relativeUrl;
Expand Down
2 changes: 1 addition & 1 deletion core/js/tests/specs/shareSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('OC.Share tests', function() {
describe('displaying the folder icon', function() {
function checkIcon(expectedImage) {
var imageUrl = OC.TestUtil.getImageUrl($file.find('.filename .thumbnail'));
expectedIcon = OC.TestUtil.buildAbsoluteUrl(OC.imagePath('core', expectedImage));
var expectedIcon = OC.TestUtil.buildAbsoluteUrl(OC.imagePath('core', expectedImage));
expect(imageUrl).toEqual(expectedIcon);
}

Expand Down

0 comments on commit b1fcd2e

Please sign in to comment.