js/xpconnect/tests/unit/test_attributes.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 const Cc = Components.classes;
     6 const Ci = Components.interfaces;
     8 function run_test() {
    10   // Load the component manifests.
    11   Components.manager.autoRegister(do_get_file('../components/native/xpctest.manifest'));
    12   Components.manager.autoRegister(do_get_file('../components/js/xpctest.manifest'));
    14   // Test for each component.
    15   test_component_readwrite("@mozilla.org/js/xpc/test/native/ObjectReadWrite;1");
    16   test_component_readwrite("@mozilla.org/js/xpc/test/js/ObjectReadWrite;1");
    17   test_component_readonly("@mozilla.org/js/xpc/test/native/ObjectReadOnly;1");
    18   test_component_readonly("@mozilla.org/js/xpc/test/js/ObjectReadOnly;1");
    19 }
    21 function test_component_readwrite(contractid) {
    23   // Instantiate the object.
    24   var o = Cc[contractid].createInstance(Ci["nsIXPCTestObjectReadWrite"]);
    26   // Test the initial values.
    27   do_check_eq("XPConnect Read-Writable String", o.stringProperty);
    28   do_check_eq(true, o.booleanProperty);
    29   do_check_eq(32767, o.shortProperty);
    30   do_check_eq(2147483647, o.longProperty);
    31   do_check_true(5.25 < o.floatProperty && 5.75 > o.floatProperty);
    32   do_check_eq("X", o.charProperty);
    33   do_check_eq(-1, o.timeProperty);
    35   // Write new values.
    36   o.stringProperty = "another string";
    37   o.booleanProperty = false;
    38   o.shortProperty = -12345;
    39   o.longProperty = 1234567890;
    40   o.floatProperty = 10.2;
    41   o.charProperty = "Z";
    42   o.timeProperty = 1;
    44   // Test the new values.
    45   do_check_eq("another string", o.stringProperty);
    46   do_check_eq(false, o.booleanProperty);
    47   do_check_eq(-12345, o.shortProperty);
    48   do_check_eq(1234567890, o.longProperty);
    49   do_check_true(10.15 < o.floatProperty && 10.25 > o.floatProperty);
    50   do_check_eq("Z", o.charProperty);
    51   do_check_eq(1, o.timeProperty);
    53   // Assign values that differ from the expected type to verify conversion.
    55   function SetAndTestBooleanProperty(newValue, expectedValue) {
    56     o.booleanProperty = newValue;
    57     do_check_eq(expectedValue, o.booleanProperty);
    58   };
    59   SetAndTestBooleanProperty(false, false);
    60   SetAndTestBooleanProperty(1, true);
    61   SetAndTestBooleanProperty(null, false);
    62   SetAndTestBooleanProperty("A", true);
    63   SetAndTestBooleanProperty(undefined, false);
    64   SetAndTestBooleanProperty([], true);
    65   SetAndTestBooleanProperty({}, true);
    66 }
    68 function test_component_readonly(contractid) {
    70   // Instantiate the object.
    71   var o = Cc[contractid].createInstance(Ci["nsIXPCTestObjectReadOnly"]);
    73   // Test the initial values.
    74   do_check_eq("XPConnect Read-Only String", o.strReadOnly);
    75   do_check_eq(true, o.boolReadOnly);
    76   do_check_eq(32767, o.shortReadOnly);
    77   do_check_eq(2147483647, o.longReadOnly);
    78   do_check_true(5.25 < o.floatReadOnly && 5.75 > o.floatReadOnly);
    79   do_check_eq("X", o.charReadOnly);
    80   do_check_eq(-1, o.timeReadOnly);
    81 }

mercurial