Commit fb92d31a authored by Xiaowu Zhang's avatar Xiaowu Zhang

gadget initialization should not be cancellable

parent 2c8228c5
...@@ -94,7 +94,8 @@ module.exports = function (grunt) { ...@@ -94,7 +94,8 @@ module.exports = function (grunt) {
'__RenderJSEmbeddedGadget', '__RenderJSEmbeddedGadget',
'FileReader', 'FileReader',
'Blob', 'Blob',
'Event' 'Event',
'MutationObserver'
] ]
} }
} }
......
...@@ -955,7 +955,14 @@ ...@@ -955,7 +955,14 @@
gadget_loading_klass = undefined; gadget_loading_klass = undefined;
throw e; throw e;
}); });
local_loading_klass_promise = loading_klass_promise; //gadget loading should not be interrupted
//if not, gadget's definition will not be complete
//.then will return another promise
//so loading_klass_promise can't be cancel
local_loading_klass_promise = loading_klass_promise
.then(function (gadget_instance) {
return gadget_instance;
});
queue = new RSVP.Queue() queue = new RSVP.Queue()
.push(function () { .push(function () {
......
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Embedded page for renderJS test</title>
<meta name="viewport" content="width=device-width, height=device-height"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="./cancel_gadget.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
This source diff could not be displayed because it is too large. You can view the blob instead.
/*jslint nomen: true*/ /*jslint nomen: true*/
(function (document, renderJS, QUnit, sinon, URI, URL, Event) { (function (document, renderJS, QUnit, sinon, URI, URL, Event,
MutationObserver) {
"use strict"; "use strict";
var test = QUnit.test, var test = QUnit.test,
stop = QUnit.stop, stop = QUnit.stop,
...@@ -337,6 +338,61 @@ ...@@ -337,6 +338,61 @@
["http://example.org/lib/qunit/qunit.js"]); ["http://example.org/lib/qunit/qunit.js"]);
}); });
/////////////////////////////////////////////////////////////////
//cancel when declare gadget
/////////////////////////////////////////////////////////////////
module("cancel when declare gadget", {
setup: function () {
renderJS.clearGadgetKlassList();
}
});
test('cancel gadget initialization', function () {
var gadget = new RenderJSGadget(),
url = renderJS.getAbsoluteURL('./cancel_gadget.html',
window.location.href),
cancel_queue,
observer = new MutationObserver(function (mutations) {
if (mutations[0].addedNodes[0].src.indexOf('cancel_gadget.js')
!== -1) {
//cancel when load cancel_gadget.js
cancel_queue.cancel();
observer.disconnect();
}
});
observer.observe(document.head, {
attributes: true,
childList: true,
characterData: true
});
stop();
gadget.__sub_gadget_dict = {};
cancel_queue = gadget.declareGadget(url);
return new RSVP.Queue()
.push(function () {
return cancel_queue;
})
.push(undefined, function (err) {
ok(err instanceof RSVP.CancellationError);
//let cancel_gadget.js load
return RSVP.delay(100);
})
.push(function () {
return gadget.declareGadget(url);
})
.push(function (instance) {
ok(instance.render !== undefined);
})
.always(function () {
start();
});
});
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// declareGadgetKlass // declareGadgetKlass
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -5315,5 +5371,6 @@ ...@@ -5315,5 +5371,6 @@
}); });
}); });
}(document, renderJS, QUnit, sinon, URI, URL, Event)); }(document, renderJS, QUnit, sinon, URI, URL, Event,
MutationObserver));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment