toolkit/mozapps/extensions/test/xpcshell/test_XPIcancel.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 3 */
michael@0 4
michael@0 5 // Test the cancellable doing/done/cancelAll API in XPIProvider
michael@0 6
michael@0 7 let scope = Components.utils.import("resource://gre/modules/addons/XPIProvider.jsm");
michael@0 8 let XPIProvider = scope.XPIProvider;
michael@0 9
michael@0 10 function run_test() {
michael@0 11 // Check that cancelling with nothing in progress doesn't blow up
michael@0 12 XPIProvider.cancelAll();
michael@0 13
michael@0 14 // Check that a basic object gets cancelled
michael@0 15 let getsCancelled = {
michael@0 16 isCancelled: false,
michael@0 17 cancel: function () {
michael@0 18 if (this.isCancelled)
michael@0 19 do_throw("Already cancelled");
michael@0 20 this.isCancelled = true;
michael@0 21 }
michael@0 22 };
michael@0 23 XPIProvider.doing(getsCancelled);
michael@0 24 XPIProvider.cancelAll();
michael@0 25 do_check_true(getsCancelled.isCancelled);
michael@0 26
michael@0 27 // Check that if we complete a cancellable, it doesn't get cancelled
michael@0 28 let doesntGetCancelled = {
michael@0 29 cancel: () => do_throw("This should not have been cancelled")
michael@0 30 };
michael@0 31 XPIProvider.doing(doesntGetCancelled);
michael@0 32 do_check_true(XPIProvider.done(doesntGetCancelled));
michael@0 33 XPIProvider.cancelAll();
michael@0 34
michael@0 35 // A cancellable that adds a cancellable
michael@0 36 getsCancelled.isCancelled = false;
michael@0 37 let addsAnother = {
michael@0 38 isCancelled: false,
michael@0 39 cancel: function () {
michael@0 40 if (this.isCancelled)
michael@0 41 do_throw("Already cancelled");
michael@0 42 this.isCancelled = true;
michael@0 43 XPIProvider.doing(getsCancelled);
michael@0 44 }
michael@0 45 }
michael@0 46 XPIProvider.doing(addsAnother);
michael@0 47 XPIProvider.cancelAll();
michael@0 48 do_check_true(addsAnother.isCancelled);
michael@0 49 do_check_true(getsCancelled.isCancelled);
michael@0 50
michael@0 51 // A cancellable that removes another. This assumes that Set() iterates in the
michael@0 52 // order that members were added
michael@0 53 let removesAnother = {
michael@0 54 isCancelled: false,
michael@0 55 cancel: function () {
michael@0 56 if (this.isCancelled)
michael@0 57 do_throw("Already cancelled");
michael@0 58 this.isCancelled = true;
michael@0 59 XPIProvider.done(doesntGetCancelled);
michael@0 60 }
michael@0 61 }
michael@0 62 XPIProvider.doing(removesAnother);
michael@0 63 XPIProvider.doing(doesntGetCancelled);
michael@0 64 XPIProvider.cancelAll();
michael@0 65 do_check_true(removesAnother.isCancelled);
michael@0 66 }

mercurial