michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // Test the cancellable doing/done/cancelAll API in XPIProvider michael@0: michael@0: let scope = Components.utils.import("resource://gre/modules/addons/XPIProvider.jsm"); michael@0: let XPIProvider = scope.XPIProvider; michael@0: michael@0: function run_test() { michael@0: // Check that cancelling with nothing in progress doesn't blow up michael@0: XPIProvider.cancelAll(); michael@0: michael@0: // Check that a basic object gets cancelled michael@0: let getsCancelled = { michael@0: isCancelled: false, michael@0: cancel: function () { michael@0: if (this.isCancelled) michael@0: do_throw("Already cancelled"); michael@0: this.isCancelled = true; michael@0: } michael@0: }; michael@0: XPIProvider.doing(getsCancelled); michael@0: XPIProvider.cancelAll(); michael@0: do_check_true(getsCancelled.isCancelled); michael@0: michael@0: // Check that if we complete a cancellable, it doesn't get cancelled michael@0: let doesntGetCancelled = { michael@0: cancel: () => do_throw("This should not have been cancelled") michael@0: }; michael@0: XPIProvider.doing(doesntGetCancelled); michael@0: do_check_true(XPIProvider.done(doesntGetCancelled)); michael@0: XPIProvider.cancelAll(); michael@0: michael@0: // A cancellable that adds a cancellable michael@0: getsCancelled.isCancelled = false; michael@0: let addsAnother = { michael@0: isCancelled: false, michael@0: cancel: function () { michael@0: if (this.isCancelled) michael@0: do_throw("Already cancelled"); michael@0: this.isCancelled = true; michael@0: XPIProvider.doing(getsCancelled); michael@0: } michael@0: } michael@0: XPIProvider.doing(addsAnother); michael@0: XPIProvider.cancelAll(); michael@0: do_check_true(addsAnother.isCancelled); michael@0: do_check_true(getsCancelled.isCancelled); michael@0: michael@0: // A cancellable that removes another. This assumes that Set() iterates in the michael@0: // order that members were added michael@0: let removesAnother = { michael@0: isCancelled: false, michael@0: cancel: function () { michael@0: if (this.isCancelled) michael@0: do_throw("Already cancelled"); michael@0: this.isCancelled = true; michael@0: XPIProvider.done(doesntGetCancelled); michael@0: } michael@0: } michael@0: XPIProvider.doing(removesAnother); michael@0: XPIProvider.doing(doesntGetCancelled); michael@0: XPIProvider.cancelAll(); michael@0: do_check_true(removesAnother.isCancelled); michael@0: }