Skip to content
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

Merged
merged 12 commits into from
Mar 13, 2018

Conversation

Farfurix
Copy link
Contributor

@Farfurix Farfurix commented Feb 27, 2018

Reference: DevExpress/testcafe#2005

Example test is passed (DevExpress/testcafe#2005)

return;

this.win.location = urlUtils.getProxyUrl(url);
const proxyUrl = urlUtils.getProxyUrl(ensureHostEndedTrailingSlash(url));
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit 80f4359 have failed. See details:

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit e73c9b1 have failed. See details:

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit 7da06bd have failed. See details:

@testcafe-build-bot
Copy link
Collaborator

✅ Tests for the commit 09f8e24 have passed. See details:

@testcafe-build-bot
Copy link
Collaborator

✅ Tests for the commit f324dd6 have passed. See details:

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit e1696c9 have failed. See details:

@Farfurix
Copy link
Contributor Author

Farfurix commented Mar 1, 2018

@testcafe-build-bot \retest

@testcafe-build-bot
Copy link
Collaborator

✅ Tests for the commit e1696c9 have passed. See details:

@Farfurix Farfurix changed the title [WIP] fix 'Page without slash after location's host reloads if we set only hash' (close #1426) fix 'Page without slash after location's host reloads if we set only hash' (close #1426) Mar 5, 2018
@Farfurix
Copy link
Contributor Author

Farfurix commented Mar 5, 2018

@testcafe-build-bot \retest

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit 5b17b49 have failed. See details:

@testcafe-build-bot
Copy link
Collaborator

✅ 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'
];
Copy link
Contributor

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
];

Copy link
Contributor Author

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 ? '/' : ''));
Copy link
Contributor

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.

Copy link
Contributor Author

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();
Copy link
Contributor

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;

Copy link
Contributor Author

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 = [
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -296,6 +296,13 @@ describe('Proxy', () => {
.end();
});

app.get('/location-header-with-trailing-slash/:url', (req, res) => {
Copy link
Contributor

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

app.get('/redirect/:url', (req, res) => {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}

return Promise.all([
testRedirectRequest('http://example.com', true),
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit f28b840 have failed. See details:

@Farfurix
Copy link
Contributor Author

Farfurix commented Mar 7, 2018

@testcafe-build-bot \retest

@testcafe-build-bot
Copy link
Collaborator

✅ 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 () {
Copy link
Contributor

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) {
Copy link
Contributor

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);
Copy link
Contributor

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,
Copy link
Contributor

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 = [
Copy link
Contributor

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 () {
Copy link
Contributor

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) {
Copy link
Contributor

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.

Copy link
Contributor

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.

@testcafe-build-bot
Copy link
Collaborator

✅ 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.
Copy link
Contributor

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) {
Copy link
Contributor

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();
Copy link
Contributor

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 () {
Copy link
Contributor

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.

});
};

return Promise.all(proxyUrls.map(testPageRequest));
Copy link
Contributor

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))

@testcafe-build-bot
Copy link
Collaborator

✅ Tests for the commit 2b45e72 have passed. See details:

@miherlosev
Copy link
Contributor

@LavrovArtem review too

@miherlosev miherlosev merged commit 7639504 into DevExpress:master Mar 13, 2018
@Farfurix Farfurix deleted the i1426 branch April 10, 2018 05:35
AndreyBelym pushed a commit to AndreyBelym/testcafe-hammerhead that referenced this pull request Feb 28, 2019
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants