-
Notifications
You must be signed in to change notification settings - Fork 162
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
Conversation
❌ 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 () { |
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.
'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; |
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.
timeoutId
src/client/sandbox/xhr.js
Outdated
const xmlHttpRequestProto = window.XMLHttpRequest.prototype; | ||
const xhrSandbox = this; | ||
const xmlHttpRequestProto = window.XMLHttpRequest.prototype; | ||
const xhrConstructorString = nativeMethods.XMLHttpRequest.toString(); |
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.
Move to the nativeMethods
and rename to the xmlHttpRequestToString
.
Same as https://github.com/DevExpress/testcafe-hammerhead/blob/master/src/client/sandbox/native-methods.js#L212
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.
But it is string, it is not a function.
And it is used only in this place.
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.
Ok. Don't move it. But rename.
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.
xmlHttpRequestString
?
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.
xmlHttpRequestToString
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.
sounds like a 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.
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
src/client/sandbox/xhr.js
Outdated
@@ -73,6 +81,20 @@ export default class XhrSandbox extends SandboxBase { | |||
nativeMethods.xhrRemoveEventListener.call(this, 'readystatechange', syncCookieWithClient); | |||
}; | |||
|
|||
const xhrConstructorWrapper = 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.
xmlHttpRequestWrapper
|
||
xhr.open('GET', '/xhr-test/', true); | ||
xhr.send(); | ||
}); |
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.
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()
src/client/sandbox/xhr.js
Outdated
|
||
if (xhrSandbox.corsSupported) | ||
nativeMethods.xhrSetRequestHeader.call(this, XHR_HEADERS.corsSupported, 'true'); | ||
nativeMethods.xhrSetRequestHeader.call(xhr, XHR_HEADERS.corsSupported, '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.
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(); |
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.
add ok(false, 'outer handler is called before XHR_COMPLETED_EVENT');
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.
this handler will be called in all 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.
Ok
❌ Tests for the commit d60e74c have failed. See details: |
✅ Tests for the commit b4b835f have passed. See details: |
FPR |
src/client/sandbox/xhr.js
Outdated
value: xmlHttpRequestWrapper | ||
}); | ||
|
||
const defineConstructorConst = (name, value) => { |
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.
defineProperty(obj, name, value)
src/client/sandbox/xhr.js
Outdated
}); | ||
}; | ||
|
||
defineConstructorConst('UNSENT', 0); |
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.
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 () { |
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.
toString, instanceof, constructor and static properties
or simple properties
src/client/sandbox/xhr.js
Outdated
return xhr; | ||
}; | ||
|
||
for (const prop of ['UNSENT', 'OPENED', 'HEADERS_RECEIVED', 'LOADING', 'DONE']) { |
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.
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)...
❌ Tests for the commit 0a4d37c have failed. See details: |
@testcafe-build-bot \retest |
❌ Tests for the commit 0a4d37c have failed. See details: |
@testcafe-build-bot \retest |
✅ Tests for the commit 0a4d37c have passed. See details: |
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; |
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.
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 () { |
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.
'XHR_COMPLETED_EVENT' should be raised when xhr is prevented
✅ Tests for the commit 2045e6b have passed. See details: |
❌ Tests for the commit acb6938 have failed. See details: |
@testcafe-build-bot \retest |
❌ Tests for the commit acb6938 have failed. See details: |
@testcafe-build-bot \retest |
✅ Tests for the commit acb6938 have passed. See details: |
…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
/cc @miherlosev @churkin @AlexanderMoskovkin