js/xpconnect/tests/unit/test_unload.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/xpconnect/tests/unit/test_unload.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,28 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 + 
     1.8 +function run_test() {
     1.9 +  var scope1 = {};
    1.10 +  var global1 = Components.utils.import("resource://gre/modules/NetUtil.jsm", scope1);
    1.11 +
    1.12 +  var scope2 = {};
    1.13 +  var global2 = Components.utils.import("resource://gre/modules/NetUtil.jsm", scope2);
    1.14 +
    1.15 +  do_check_true(global1 === global2);
    1.16 +  do_check_true(scope1.NetUtil === scope2.NetUtil);
    1.17 +
    1.18 +  Components.utils.unload("resource://gre/modules/NetUtil.jsm");
    1.19 +
    1.20 +  var scope3 = {};
    1.21 +  var global3 = Components.utils.import("resource://gre/modules/NetUtil.jsm", scope3);
    1.22 +
    1.23 +  do_check_false(global1 === global3);
    1.24 +  do_check_false(scope1.NetUtil === scope3.NetUtil);
    1.25 +
    1.26 +  // When the jsm was unloaded, the value of all its global's properties were
    1.27 +  // set to undefined. While it must be safe (not crash) to call into the
    1.28 +  // module, we expect it to throw an error (e.g., when trying to use Ci).
    1.29 +  try { scope1.NetUtil.newURI("http://www.example.com"); } catch (e) {}
    1.30 +  try { scope3.NetUtil.newURI("http://www.example.com"); } catch (e) {}
    1.31 +}

mercurial