Skip to content

Commit cb014cc

Browse files
committed
Merge branch 't/13566'
2 parents 41775af + f2e16c7 commit cb014cc

File tree

8 files changed

+158
-8
lines changed

8 files changed

+158
-8
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Fixed Issues:
2929
* [#13554](http://dev.ckeditor.com/ticket/13554): [Edge] Fixed: Paste dialog's iframe does not receive focus on show.
3030
* [#13574](http://dev.ckeditor.com/ticket/13574): [Edge] Fixed: Permission denied thrown while opening editor dialogs.
3131
* [#13440](http://dev.ckeditor.com/ticket/13440): [Edge] Fixed: Unable to paste a widget.
32+
* [#13566](http://dev.ckeditor.com/ticket/13566): Fixed: Suppressed notifications in [Media Embed Base](http://ckeditor.com/addon/embedbase) plugin.
3233

3334
Other Changes:
3435

plugins/embedbase/plugin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,17 +349,17 @@
349349
* was canceled or the default listener could not convert oEmbed response into embeddable HTML.
350350
*/
351351
_handleResponse: function( request ) {
352-
if ( request.task ) {
353-
request.task.done();
354-
}
355-
356352
var evtData = {
357353
url: request.url,
358354
html: '',
359355
response: request.response
360356
};
361357

362358
if ( this.fire( 'handleResponse', evtData ) !== false ) {
359+
if ( request.task ) {
360+
request.task.done();
361+
}
362+
363363
this._setContent( request.url, evtData.html );
364364
return true;
365365
} else {

plugins/notificationaggregator/plugin.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,14 @@
414414
* @property {Number}
415415
*/
416416
this._doneWeight = 0;
417+
418+
/**
419+
* Indicates when the task is canceled.
420+
*
421+
* @private
422+
* @property {Boolean}
423+
*/
424+
this._isCanceled = false;
417425
}
418426

419427
Task.prototype = {
@@ -430,9 +438,9 @@
430438
* @param {Number} weight Number indicating how much of the total task {@link #_weight} is done.
431439
*/
432440
update: function( weight ) {
433-
// If task is already done there is no need to update it, and we don't expect
441+
// If task is already done or canceled there is no need to update it, and we don't expect
434442
// progress to be reversed.
435-
if ( this.isDone() ) {
443+
if ( this.isDone() || this.isCanceled() ) {
436444
return;
437445
}
438446

@@ -455,6 +463,14 @@
455463
* Cancels the task (the task will be removed from the aggregator).
456464
*/
457465
cancel: function() {
466+
// If task is already done or canceled.
467+
if ( this.isDone() || this.isCanceled() ) {
468+
return;
469+
}
470+
471+
// Mark task as canceled.
472+
this._isCanceled = true;
473+
458474
// We'll fire cancel event it's up to aggregator to listen for this event,
459475
// and remove the task.
460476
this.fire( 'canceled' );
@@ -467,6 +483,15 @@
467483
*/
468484
isDone: function() {
469485
return this._weight === this._doneWeight;
486+
},
487+
488+
/**
489+
* Checks if the task is canceled.
490+
*
491+
* @returns {Boolean}
492+
*/
493+
isCanceled: function() {
494+
return this._isCanceled;
470495
}
471496
};
472497

tests/plugins/autoembed/autoembed.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,5 +334,46 @@ bender.test( {
334334
assert.areSame( finalizeCreationSpy.called, false, 'finalize creation was not called' );
335335
}, 200 );
336336
} );
337+
},
338+
339+
'check if notifications are showed after unsuccessful embedding': function() {
340+
var bot = this.editorBot,
341+
editor = bot.editor,
342+
firstRequest = true,
343+
notificationShowSpy = sinon.spy( CKEDITOR.plugins.notification.prototype, 'show' );
344+
345+
// JSONP callback for embed request.
346+
jsonpCallback = function( urlTemplate, urlParams, callback, errorCallback ) {
347+
348+
// First request will return error - so two notifications should be showed.
349+
// First informing about embedding process, second about embedding error.
350+
if ( firstRequest ) {
351+
errorCallback();
352+
firstRequest = false;
353+
editor.execCommand( 'paste', 'https://foo.bar/g/notification/test/2' );
354+
} else {
355+
resume( function() {
356+
357+
// Second request returns success - one notification should be showed.
358+
callback( {
359+
'url': decodeURIComponent( urlParams.url ),
360+
'type': 'rich',
361+
'version': '1.0',
362+
'html': '<img src="' + decodeURIComponent( urlParams.url ) + '">'
363+
} );
364+
365+
notificationShowSpy.restore();
366+
367+
// Check if notification was showed three times.
368+
assert.isTrue( notificationShowSpy.calledThrice, 'Notification should be showed three times.' );
369+
} );
370+
}
371+
};
372+
373+
bot.setData( '', function() {
374+
editor.focus();
375+
editor.execCommand( 'paste', 'https://foo.bar/g/notification/test/1' );
376+
wait();
377+
} );
337378
}
338379
} );
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<p>Non-embeddable URLs</p>
2+
3+
<ul>
4+
<li><input type="text" value="http://ckeditor.com/"></li>
5+
<li><input type="text" value="http://foo/bar/"></li>
6+
</ul>
7+
8+
<p>Embeddable URLs</p>
9+
10+
<ul>
11+
<li><input type="text" value="https://placekitten.com/g/200/300"></li>
12+
<li><input type="text" value="https://twitter.com/reinmarpl/status/573118615274315776"></li>
13+
</ul>
14+
15+
<textarea id="editor1" cols="10" rows="10"></textarea>
16+
17+
<script>
18+
embedTools.delayJsonp();
19+
CKEDITOR.replace( 'editor1', {
20+
extraPlugins: 'embed',
21+
height: 500,
22+
width: 600
23+
} );
24+
</script>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@bender-tags: tc, 4.5.2, 13566
2+
@bender-ui: collapsed
3+
@bender-include: ../../embedbase/_helpers/tools.js
4+
@bender-ckeditor-plugins: wysiwygarea,sourcearea,htmlwriter,entities,toolbar,elementspath,undo,clipboard,autolink,autoembed,link
5+
6+
1. Paste one of non-embeddable links.
7+
1. Wait until two notifications are showed. First informing about embedding process in progress, second informing about embedding failure.
8+
1. Paste one of embeddable links.
9+
1. Check if notifications are showed and embedding is finished correctly.

tests/plugins/embedbase/definition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ bender.test( {
458458
assert.areSame( 'foo', widget.data.url, 'widget\'s url has not been changed' );
459459
assert.areSame( dataWithWidget, editor.getData() );
460460

461-
assert.isTrue( task.isDone(), 'task is done' );
461+
assert.isTrue( task.isCanceled(), 'task is canceled' );
462462

463463
assert.isTrue( handleResponseSpy.calledOnce, '_handleResponse was called once' );
464464
assert.isFalse( handleResponseSpy.returnValues[ 0 ], '_handleResponse returned false' );

tests/plugins/notificationaggregator/task.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,57 @@
158158

159159
assert.areSame( 1, instance.fire.callCount, 'instance.fire call count' );
160160
sinon.assert.calledWithExactly( instance.fire, 'canceled' );
161+
},
162+
163+
'test task cannot be finished twice': function() {
164+
var instance = new Task( 300 ),
165+
doneEventSpy = sinon.spy();
166+
167+
instance.on( 'done', doneEventSpy );
168+
instance.update( 300 );
169+
instance.update( 300 );
170+
171+
assert.isTrue( doneEventSpy.calledOnce, 'Done event should be fired once.' );
172+
},
173+
174+
'test task cannot be cancelled twice': function() {
175+
var instance = new Task( 300 ),
176+
cancelEventSpy = sinon.spy();
177+
178+
instance.on( 'canceled', cancelEventSpy );
179+
instance.cancel();
180+
instance.cancel();
181+
182+
assert.isTrue( cancelEventSpy.calledOnce, 'Cancel event should be fired once.' );
183+
},
184+
185+
'test task cannot be cancelled after being finished': function() {
186+
var instance = new Task( 300 ),
187+
doneEventSpy = sinon.spy(),
188+
cancelEventSpy = sinon.spy();
189+
190+
instance.on( 'canceled', cancelEventSpy );
191+
instance.on( 'done', doneEventSpy );
192+
instance.update( 300 );
193+
instance.cancel();
194+
195+
assert.isTrue( doneEventSpy.calledOnce, 'Done event should be fired once.' );
196+
assert.isFalse( cancelEventSpy.called, 'Cancel event should not be fired.' );
197+
},
198+
199+
'test task cannot be finished after being cancelled': function() {
200+
var instance = new Task( 300 ),
201+
doneEventSpy = sinon.spy(),
202+
cancelEventSpy = sinon.spy();
203+
204+
instance.on( 'canceled', cancelEventSpy );
205+
instance.on( 'done', doneEventSpy );
206+
instance.cancel();
207+
instance.update( 300 );
208+
209+
assert.isTrue( cancelEventSpy.calledOnce, 'Cancel event should be fired once.' );
210+
assert.isFalse( doneEventSpy.called, 'Done event should not be fired.' );
161211
}
162212
} );
163213

164-
} )();
214+
} )();

0 commit comments

Comments
 (0)