Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

test(*): fix tests involving submit on Chrome 60 #16141

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions karma-shared.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ module.exports = function(config, specificOptions) {
'SL_Chrome': {
base: 'SauceLabs',
browserName: 'chrome',
version: '51'
version: '59'
},
'SL_Firefox': {
base: 'SauceLabs',
browserName: 'firefox',
version: '47'
version: '54'
},
'SL_Safari_8': {
base: 'SauceLabs',
Expand Down
16 changes: 14 additions & 2 deletions test/ng/directive/formSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ describe('form', function() {
doc = jqLite('<form ng-submit="submitMe()">' +
'<input type="submit" value="submit">' +
'</form>');
// Support: Chrome 60+ (on Windows)
// We need to add the form to the DOM in order for `submit` events to be properly fired.
window.document.body.appendChild(doc[0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Aren't all of these memory leaks? Or is there some global cleanup between tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

We empty body before each test.


var assertPreventDefaultListener = function(e) {
reloadPrevented = e.defaultPrevented || (e.returnValue === false);
Expand Down Expand Up @@ -420,15 +423,18 @@ describe('form', function() {
inject(function($timeout) {
doc = jqLite('<div>' +
'<form ng-submit="submitMe()">' +
'<button ng-click="destroy()"></button>' +
'<button type="submit" ng-click="destroy()"></button>' +
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this necessary? I think if there's no other button, then the first button is the submit button

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it is not necessary. Just making it more explicit for people that might not know.

'</form>' +
'</div>');
// Support: Chrome 60+ (on Windows)
// We need to add the form to the DOM in order for `submit` events to be properly fired.
window.document.body.appendChild(doc[0]);

var form = doc.find('form'),
destroyed = false,
nextTurn = false,
submitted = false,
reloadPrevented;
reloadPrevented = 'never called';

scope.destroy = function() {
// yes, I know, scope methods should not do direct DOM manipulation, but I wanted to keep
Expand Down Expand Up @@ -466,6 +472,12 @@ describe('form', function() {
// the issue in the wild, I'm not going to bother to do it
// now. (i)

// Support: Chrome 60+ (on Windows)
// Chrome 60+ on Windows does not fire `submit` events when the form is not attached to
// the DOM. Verify that the `submit` listener was either never fired or (if fired) the
// reload was prevented.
expect(reloadPrevented).not.toBe(false);

// prevent mem leak in test
form[0].removeEventListener('submit', assertPreventDefaultListener);
})
Expand Down
22 changes: 16 additions & 6 deletions test/ng/directive/ngEventDirsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@ describe('event directives', function() {
describe('ngSubmit', function() {

it('should get called on form submit', inject(function($rootScope, $compile) {
element = $compile('<form action="/foo" ng-submit="submitted = true">' +
'<input type="submit"/>' +
element = $compile(
'<form action="/foo" ng-submit="submitted = true">' +
'<input type="submit" />' +
'</form>')($rootScope);
$rootScope.$digest();

// Support: Chrome 60+
// We need to add the form to the DOM in order for `submit` events to be properly fired.
window.document.body.appendChild(element[0]);

// prevent submit within the test harness
element.on('submit', function(e) { e.preventDefault(); });

expect($rootScope.submitted).not.toBeDefined();
expect($rootScope.submitted).toBeUndefined();

browserTrigger(element.children()[0]);
expect($rootScope.submitted).toEqual(true);
Expand All @@ -33,15 +38,20 @@ describe('event directives', function() {
}
};

element = $compile('<form action="/foo" ng-submit="formSubmission($event)">' +
'<input type="submit"/>' +
element = $compile(
'<form action="/foo" ng-submit="formSubmission($event)">' +
'<input type="submit" />' +
'</form>')($rootScope);
$rootScope.$digest();

// Support: Chrome 60+ (on Windows)
// We need to add the form to the DOM in order for `submit` events to be properly fired.
window.document.body.appendChild(element[0]);

// prevent submit within the test harness
element.on('submit', function(e) { e.preventDefault(); });

expect($rootScope.formSubmitted).not.toBeDefined();
expect($rootScope.formSubmitted).toBeUndefined();

browserTrigger(element.children()[0]);
expect($rootScope.formSubmitted).toEqual('foo');
Expand Down