Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Farfurix committed Mar 5, 2018
1 parent dc0699e commit 5b17b49
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 22 deletions.
67 changes: 46 additions & 21 deletions test/client/fixtures/sandbox/code-instrumentation/location-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@ var Promise = hammerhead.Promise;
var nativeMethods = hammerhead.nativeMethods;
var browserUtils = hammerhead.utils.browser;
var domUtils = hammerhead.utils.dom;
var navigateTo = hammerhead.navigateTo;

const SHOULD_ADD_TRAILING_SLASH = [
'http://example.com',
'https://example.com',
'http://localhost',
'https://localhost',
'http://localhost:8080',
'https://localhost:8080',
'http://127.0.0.1',
'https://127.0.0.1',
'http://127.0.0.1:8080',
'https://127.0.0.1:8080'
];

const SHOULD_NOT_ADD_TRAILING_SLASH = [
'about:blank',
'about:error',
'http://example.com/page.html',
'https://example.com/page.html'
];

test('iframe with empty src', function () {
function assert (iframe) {
Expand Down Expand Up @@ -157,29 +178,9 @@ test('special pages (GH-339)', function () {
destLocation.forceLocation(storedForcedLocation);
});

test('should add the trailing slash to location.href if url consist of origin', function () {
test('should add the trailing slash to location.href if url consist of origin (GH-1426)', function () {
var storedForcedLocation = destLocation.getLocation();

const SHOULD_ADD_TRAILING_SLASH = [
'http://example.com',
'https://example.com',
'http://localhost',
'https://localhost',
'http://localhost:8080',
'https://localhost:8080',
'http://127.0.0.1',
'https://127.0.0.1',
'http://127.0.0.1:8080',
'https://127.0.0.1:8080'
];

const SHOULD_NOT_ADD_TRAILING_SLASH = [
'about:blank',
'about:error',
'http://example.com/page.html',
'https://example.com/page.html'
];

function checkTrailingSlash (urls, trailingSlashIsNeeded) {
urls.forEach(function (url) {
destLocation.forceLocation(urlUtils.getProxyUrl(url));
Expand All @@ -201,6 +202,30 @@ test('should add the trailing slash to location.href if url consist of origin',
destLocation.forceLocation(storedForcedLocation);
});

test('should add the trailing slash to location when navigateTo() is called (GH-1426)', function () {
var getWindowMock = function () {
return {
navigateToUrl: navigateTo,

win: {
location: ''
},
};
};

var windowMock = getWindowMock();

function checkTrailingSlash (urls, trailingSlashIsNeeded) {
urls.forEach(function (url) {
windowMock.navigateToUrl(url);
strictEqual(urlUtils.parseProxyUrl(windowMock.win.location).destUrl, url + (trailingSlashIsNeeded ? '/' : ''));
});
}

checkTrailingSlash(SHOULD_ADD_TRAILING_SLASH, true);
checkTrailingSlash(SHOULD_NOT_ADD_TRAILING_SLASH, false);
});

module('regression');

if (browserUtils.compareVersions([browserUtils.webkitVersion, '603.1.30']) === -1) {
Expand Down
10 changes: 9 additions & 1 deletion test/server/proxy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,14 @@ describe('Proxy', () => {
});

describe('Session', () => {
it('Should add the trailing slash to the proxied url if it consist of origin (GH-1426)', () => {
const shouldAddTralingSlash = proxy.openSession('http://example.com', session);
const shouldNotAddTralingSlash = proxy.openSession('http://example.com/index', session);

expect(urlUtils.parseProxyUrl(shouldAddTralingSlash).destUrl).eql('http://example.com/');
expect(urlUtils.parseProxyUrl(shouldNotAddTralingSlash).destUrl).eql('http://example.com/index');
});

it('Should pass DNS errors to session', done => {
session.handlePageError = (ctx, err) => {
expect(err).eql('Failed to find a DNS-record for the resource at <a href="http://www.some-unresolvable.url/">http://www.some-unresolvable.url/</a>.');
Expand Down Expand Up @@ -2615,7 +2623,7 @@ describe('Proxy', () => {
]);
});

it('Should add the trailing slash to location header if url consist of origin', () => {
it('Should add the trailing slash to location header if url consist of origin (GH-1426)', () => {
proxy.openSession('http://127.0.0.1:2000/', session);

function testRedirectRequest (redirectLocation, trailingSlashIsNeeded) {
Expand Down

0 comments on commit 5b17b49

Please sign in to comment.