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 The onreadystatechange property of XMLHttpRequest.prototype redefined by Angular (close #1283) #1287

Merged
merged 8 commits into from
Sep 4, 2017

Conversation

LavrovArtem
Copy link
Contributor

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit 46d6244 have failed. See details:

@@ -201,3 +205,26 @@ asyncTest('authorization headers by client should be processed (GH-1016)', funct
});
xhr.send();
});

asyncTest('our internal the onreadystatechange handler must be first (GH-1283)', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

'XHR_COMPLETED_EVENT' for completed requests should be raised before calling outer handlers (GH-1283)


asyncTest('our internal the onreadystatechange handler must be first (GH-1283)', function () {
var xhr = new XMLHttpRequest();
var timeout = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

timeoutId

const xmlHttpRequestProto = window.XMLHttpRequest.prototype;
const xhrSandbox = this;
const xmlHttpRequestProto = window.XMLHttpRequest.prototype;
const xhrConstructorString = nativeMethods.XMLHttpRequest.toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@LavrovArtem LavrovArtem Aug 31, 2017

Choose a reason for hiding this comment

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

But it is string, it is not a function.
And it is used only in this place.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. Don't move it. But rename.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

xmlHttpRequestString ?

Copy link
Contributor

Choose a reason for hiding this comment

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

xmlHttpRequestToString

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds like a function

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe.
You can use any notation.
xmlHttpRequestString of xmlHttpRequestToString
We already using ToString notation:
https://github.com/DevExpress/testcafe-hammerhead/blob/master/src/client/sandbox/node/window.js#L18

@@ -73,6 +81,20 @@ export default class XhrSandbox extends SandboxBase {
nativeMethods.xhrRemoveEventListener.call(this, 'readystatechange', syncCookieWithClient);
};

const xhrConstructorWrapper = function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

xmlHttpRequestWrapper


xhr.open('GET', '/xhr-test/', true);
xhr.send();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

You change prototype chain for XMLHttpRequest and override ToString method.
Let's add test code to the following cases:

  • var xhr = new XMLHttpRequest(); xhr instanceof XMLHttpRequest;
  • xhr.toString() === nativeXhr.ToString()


if (xhrSandbox.corsSupported)
nativeMethods.xhrSetRequestHeader.call(this, XHR_HEADERS.corsSupported, 'true');
nativeMethods.xhrSetRequestHeader.call(xhr, XHR_HEADERS.corsSupported, 'true');
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need the additional variable xhr.
Another methods (abort, open) don't declare an additional variable.
So, drop const xhr = this; line and change xhr to this for places in send method.


var readyStateChangeHandler = function (e) {
if (this.readyState === this.DONE)
e.stopImmediatePropagation();
Copy link
Contributor

Choose a reason for hiding this comment

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

add ok(false, 'outer handler is called before XHR_COMPLETED_EVENT');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this handler will be called in all cases

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok

@testcafe-build-bot
Copy link
Collaborator

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

@testcafe-build-bot
Copy link
Collaborator

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

@LavrovArtem
Copy link
Contributor Author

FPR

value: xmlHttpRequestWrapper
});

const defineConstructorConst = (name, value) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

defineProperty(obj, name, value)

});
};

defineConstructorConst('UNSENT', 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

defineProperty(xmlHttpRequestWrapper, 'UNSENT', XMLHttpRequest.UNSENT)
and etc.

I propose this variant because it is more readable.

Also XMLHttpRequest has another static properties such as name, valueOf and etc.
But I think we can skip it.

@@ -69,10 +73,23 @@ test('createNativeXHR', function () {
}
});

test('constructor', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

toString, instanceof, constructor and static properties
or simple properties

return xhr;
};

for (const prop of ['UNSENT', 'OPENED', 'HEADERS_RECEIVED', 'LOADING', 'DONE']) {
Copy link
Contributor

@miherlosev miherlosev Aug 31, 2017

Choose a reason for hiding this comment

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

Store as `const XHR_READY_STATES = ['UNSENT', 'OPENED', 'HEADERS_RECEIVED', 'LOADING', 'DONE'] outside of module

and rewrite as

for (const readyState of XML_HTTP_REQUEST_READY_STATES)...

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit 0a4d37c have failed. See details:

@miherlosev
Copy link
Contributor

@testcafe-build-bot \retest

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit 0a4d37c have failed. See details:

@LavrovArtem
Copy link
Contributor Author

@testcafe-build-bot \retest

@testcafe-build-bot
Copy link
Collaborator

✅ Tests for the commit 0a4d37c have passed. See details:

@LavrovArtem
Copy link
Contributor Author

FPR

module('regression');

asyncTest('unexpected text modifying during typing text in the search input on the http://www.google.co.uk (B238528)', function () {
var timeout = 100;
var timeoutId = 100;
Copy link
Contributor

Choose a reason for hiding this comment

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

Revert back timeoutId to timeout for this test.

@@ -201,3 +218,27 @@ asyncTest('authorization headers by client should be processed (GH-1016)', funct
});
xhr.send();
});

asyncTest('"XHR_COMPLETED_EVENT" for completed requests should be raised before calling outer handlers (GH-1283)', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

'XHR_COMPLETED_EVENT' should be raised when xhr is prevented

@testcafe-build-bot
Copy link
Collaborator

✅ Tests for the commit 2045e6b have passed. See details:

@testcafe-build-bot
Copy link
Collaborator

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

@LavrovArtem
Copy link
Contributor Author

@testcafe-build-bot \retest

@testcafe-build-bot
Copy link
Collaborator

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

@LavrovArtem
Copy link
Contributor Author

@testcafe-build-bot \retest

@testcafe-build-bot
Copy link
Collaborator

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

@miherlosev miherlosev merged commit 397a0d4 into DevExpress:master Sep 4, 2017
@LavrovArtem LavrovArtem deleted the i1283 branch September 4, 2017 12:56
AndreyBelym pushed a commit to AndreyBelym/testcafe-hammerhead that referenced this pull request Feb 28, 2019
…fined by Angular` (close DevExpress#1283) (DevExpress#1287)

* fix `The onreadystatechange property of XMLHttpRequest.prototype redefined by Angular` (close DevExpress#1283)

* fix

* fix review's issues

* some fix

* refactoring

* refactoring

* fix review's issues

* refactoring
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.

5 participants