-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix 'Page without slash after location's host reloads if we set only hash' (close #1426) #1514
Conversation
src/client/index.js
Outdated
return; | ||
|
||
this.win.location = urlUtils.getProxyUrl(url); | ||
const proxyUrl = urlUtils.getProxyUrl(ensureHostEndedTrailingSlash(url)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1)Rewrite in two lines of code:
url = ensureHostEndedTrailingSlash(url);
const proxyUrl = urlUtils.getProxyUrl(url);
2)Host, port and protocol is named as 'origin'. See https://developer.mozilla.org/ru/docs/Web/API/Location.
So, let's rename function to ensureOriginTrailingSlash(url)
.
Add this comment in function body
If you request an url containing only port, host and protocol
then browser adds the trailing slash itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. May be add window.location.href in comment?
// NOTE: If you request an url containing only port, host and protocol
// then browser adds the trailing slash to window.location.href.
❌ Tests for the commit 80f4359 have failed. See details: |
❌ Tests for the commit e73c9b1 have failed. See details: |
❌ Tests for the commit 7da06bd have failed. See details: |
✅ Tests for the commit 09f8e24 have passed. See details: |
✅ Tests for the commit f324dd6 have passed. See details: |
❌ Tests for the commit e1696c9 have failed. See details: |
@testcafe-build-bot \retest |
✅ Tests for the commit e1696c9 have passed. See details: |
@testcafe-build-bot \retest |
❌ Tests for the commit 5b17b49 have failed. See details: |
✅ Tests for the commit 5b17b49 have passed. See details: |
'https://127.0.0.1', | ||
'http://127.0.0.1:8080', | ||
'https://127.0.0.1:8080' | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's reduce testcases and combine them to the single contant:
var testcases = [
{
url: 'http://example.com' /*protocol + host*/
shoudAddTrailingSlash: true
},
{
url: https://localhost:8080 /*protocol + host + port*/,
shoudAddTrailingSlash: true
},
{
url: about:blank /*special page*/,
shoudAddTrailingSlash: false
},
{
url: http://example.com/page.html, /*url with path*/
shoudAddTrailingSlash: false
},
linux file protocol url,
window file protocol url
];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
var locationWrapper = new LocationWrapper(windowMock); | ||
|
||
strictEqual(locationWrapper.href, url + (trailingSlashIsNeeded ? '/' : '')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a wrong test because we add a trailing slash on href
property setter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, new test: 'should add the trailing slash to location.href using href.set(), assign() and replace() functions if url consist of origin (GH-1426)'
}; | ||
}; | ||
|
||
var windowMock = getWindowMock(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad test algorithm.
window
does not contain the navigateTo
method.
Rewrite as:
var storedWindow = hammerhead.win;
hammerhead.win = windowMock;
test action with hammerhead.navigateTo()
restore hammerhead.win = storedWindow;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -105,6 +105,41 @@ test('isRelativeUrl', function () { | |||
ok(sharedUrlUtils.isRelativeUrl('C:\\index.htm')); | |||
}); | |||
|
|||
test('ensureOriginTrailingSlash', function () { | |||
const SHOULD_ADD_TRAILING_SLASH = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use testcases from the comment above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
test/server/proxy-test.js
Outdated
@@ -296,6 +296,13 @@ describe('Proxy', () => { | |||
.end(); | |||
}); | |||
|
|||
app.get('/location-header-with-trailing-slash/:url', (req, res) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't dublicate routes without necessary.
See
testcafe-hammerhead/test/server/proxy-test.js
Line 292 in 8b63395
app.get('/redirect/:url', (req, res) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
test/server/proxy-test.js
Outdated
} | ||
|
||
return Promise.all([ | ||
testRedirectRequest('http://example.com', true), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reduce testcases count according the comment above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
…ginTrailingSlash(); rewrite urlUtils.getProxyUrl(ensureOriginTrailingSlash(url))
…export TRAILING_SLASH_RE needed in this test, fix client location test
… header test, add location href test (wrapper)
❌ Tests for the commit f28b840 have failed. See details: |
@testcafe-build-bot \retest |
✅ Tests for the commit f28b840 have passed. See details: |
@@ -157,6 +192,83 @@ test('special pages (GH-339)', function () { | |||
destLocation.forceLocation(storedForcedLocation); | |||
}); | |||
|
|||
test('should add the trailing slash to location.href using href.set(), assign() and replace() functions if url consist of origin (GH-1426)', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should ensure a trailing slash on page navigation using href setter, assign and replace methods (GH-1426)
urlUtils.getProxyUrl(url); | ||
} | ||
|
||
function proxyUrlTrailingSlash (urlCase) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function getExpectedProxyUrl(testCase)
replace: setHref, | ||
assign: setHref, | ||
toString: function () { | ||
return proxyUrl(this.location.href); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use inplace declaration urlUtils.getProxyUrl(url)
var windowMock = { | ||
location: { | ||
href: '', | ||
replace: setHref, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use inplace declaration this.href = url;
in two places
@@ -11,6 +11,41 @@ var nativeMethods = hammerhead.nativeMethods; | |||
var browserUtils = hammerhead.utils.browser; | |||
var domUtils = hammerhead.utils.dom; | |||
|
|||
var URL_TEST_CASES = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var ENSURE_URL_TRAILING_SLASH_TEST_CASES = ...
checkTrailingSlash(URL_TEST_CASES); | ||
}); | ||
|
||
test('should add the trailing slash to location when navigateTo() is called (GH-1426)', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should ensure a trailing slash on page navigation using hammerhead.navigateTo
method (GH-1426)
test('should add the trailing slash to location when navigateTo() is called (GH-1426)', function () { | ||
var storedWindow = hammerhead.win; | ||
|
||
function proxyUrlTrailingSlash (urlCase) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename according the comment above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also need to investigate a necessary of ensureTrailingSlash
function. As I understand, we can remove it in this PR.
✅ Tests for the commit 9b4fc9f have passed. See details: |
src/utils/url.js
Outdated
|
||
export function ensureOriginTrailingSlash (url) { | ||
// NOTE: If you request an url containing only port, host and protocol | ||
// then browser adds the trailing slash to window.location.href. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change
...then browser adds the trailing slash to window.location.href
.
to
...then browser adds the trailing slash itself
|
||
var locationWrapper = new LocationWrapper(windowMock); | ||
|
||
function checkTrailingSlash (testCases) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function testAddingTrailingSlash (testCases) {
here and below
}; | ||
}; | ||
|
||
var windowMock = getWindowMock(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getWindowMock
function is necessary.
Rewrite as
var windowMock = {
location: '';
};
@@ -105,6 +105,53 @@ test('isRelativeUrl', function () { | |||
ok(sharedUrlUtils.isRelativeUrl('C:\\index.htm')); | |||
}); | |||
|
|||
test('ensureOriginTrailingSlash', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this test.
test/server/proxy-test.js
Outdated
}); | ||
}; | ||
|
||
return Promise.all(proxyUrls.map(testPageRequest)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename testPageRequest
to testLocationHeaderValue
.
Combine proxyUrls
with testPageRequest
.
Returned Promise should looks like return Promise.all(ENSURE_URL_TRAILING_SLASH_TEST_CASES.map(testLocationHeaderValue))
✅ Tests for the commit 2b45e72 have passed. See details: |
@LavrovArtem review too |
…hash' (close DevExpress#1426) (DevExpress#1514) * i1426 * i1426 * Requested changes: rename ensureHostEndedTrailingSlash() to ensureOriginTrailingSlash(); rewrite urlUtils.getProxyUrl(ensureOriginTrailingSlash(url)) * Fix server test (Should procees "x-frame-options" header (DevExpressGH-1017)), export TRAILING_SLASH_RE needed in this test, fix client location test * Fix navigateTo(): leading slashes case * Fix ensureOriginTrailingSlash(), code cleanup * Add ensureOriginTrailingSlash test * Fix location header, fix ensureOriginTrailingSlash test, add location header test, add location href test (wrapper) * Add tests * Requested changes * Requested changes * Requested changes
Reference: DevExpress/testcafe#2005
Example test is passed (DevExpress/testcafe#2005)