Bug 684327 - Generalize test_readwriteattributes.js into test_attributes.js. r=khuey
authorBobby Holley <bobbyholley@gmail.com>
Sun, 25 Sep 2011 15:38:00 +0100
changeset 77523 ca6bb27d3527ef30ec3277c684e1176d0aed268f
parent 77522 614b6c0627b9182b696db8311a6c36e06e81b648
child 77524 3d4cbdd72c036e2492adf32013a1332cac2212d8
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewerskhuey
bugs684327
milestone9.0a1
Bug 684327 - Generalize test_readwriteattributes.js into test_attributes.js. r=khuey
js/src/xpconnect/tests/components/js/xpctest.manifest
js/src/xpconnect/tests/components/js/xpctest_attributes.js
js/src/xpconnect/tests/unit/test_attributes.js
js/src/xpconnect/tests/unit/test_readwriteattributes.js
js/src/xpconnect/tests/unit/xpcshell.ini
--- a/js/src/xpconnect/tests/components/js/xpctest.manifest
+++ b/js/src/xpconnect/tests/components/js/xpctest.manifest
@@ -1,2 +1,5 @@
 component {8ff41d9c-66e9-4453-924a-7d8de0a5e966} xpctest_attributes.js
 contract @mozilla.org/js/xpc/test/js/ObjectReadWrite;1 {8ff41d9c-66e9-4453-924a-7d8de0a5e966}
+
+component {916c4247-253d-4ed0-a425-adfedf53ecc8} xpctest_attributes.js
+contract @mozilla.org/js/xpc/test/js/ObjectReadOnly;1 {916c4247-253d-4ed0-a425-adfedf53ecc8}
--- a/js/src/xpconnect/tests/components/js/xpctest_attributes.js
+++ b/js/src/xpconnect/tests/components/js/xpctest_attributes.js
@@ -47,9 +47,28 @@ TestObjectReadWrite.prototype = {
   stringProperty: "XPConnect Read-Writable String",
   booleanProperty: true,
   shortProperty: 32767,
   longProperty: 2147483647,
   floatProperty: 5.5,
   charProperty: "X"
 };
 
-var NSGetFactory = XPCOMUtils.generateNSGetFactory([TestObjectReadWrite]);
+
+function TestObjectReadOnly() {}
+TestObjectReadOnly.prototype = {
+
+  /* Boilerplate */
+  QueryInterface: XPCOMUtils.generateQI([Components.interfaces["nsIXPCTestObjectReadOnly"]]),
+  contractID: "@mozilla.org/js/xpc/test/js/ObjectReadOnly;1",
+  classID: Components.ID("{916c4247-253d-4ed0-a425-adfedf53ecc8}"),
+
+  /* nsIXPCTestObjectReadOnly */
+  strReadOnly: "XPConnect Read-Only String",
+  boolReadOnly: true,
+  shortReadOnly: 32767,
+  longReadOnly: 2147483647,
+  floatReadOnly: 5.5,
+  charReadOnly: "X"
+};
+
+
+var NSGetFactory = XPCOMUtils.generateNSGetFactory([TestObjectReadWrite, TestObjectReadOnly]);
rename from js/src/xpconnect/tests/unit/test_readwriteattributes.js
rename to js/src/xpconnect/tests/unit/test_attributes.js
--- a/js/src/xpconnect/tests/unit/test_readwriteattributes.js
+++ b/js/src/xpconnect/tests/unit/test_attributes.js
@@ -29,35 +29,36 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-// Globals
-var gInterface = Components.interfaces["nsIXPCTestObjectReadWrite"];
+const Cc = Components.classes;
+const Ci = Components.interfaces;
 
 function run_test() {
 
   // Load the component manifests.
   Components.manager.autoRegister(do_get_file('../components/native/xpctest.manifest'));
   Components.manager.autoRegister(do_get_file('../components/js/xpctest.manifest'));
 
   // Test for each component.
-  test_component("@mozilla.org/js/xpc/test/native/ObjectReadWrite;1");
-  test_component("@mozilla.org/js/xpc/test/js/ObjectReadWrite;1");
-
+  test_component_readwrite("@mozilla.org/js/xpc/test/native/ObjectReadWrite;1");
+  test_component_readwrite("@mozilla.org/js/xpc/test/js/ObjectReadWrite;1");
+  test_component_readonly("@mozilla.org/js/xpc/test/native/ObjectReadOnly;1");
+  test_component_readonly("@mozilla.org/js/xpc/test/js/ObjectReadOnly;1");
 }
 
-function test_component(contractid) {
+function test_component_readwrite(contractid) {
 
   // Instantiate the object.
-  var o = Components.classes[contractid].createInstance(gInterface);
+  var o = Cc[contractid].createInstance(Ci["nsIXPCTestObjectReadWrite"]);
 
   // Test the initial values.
   do_check_eq("XPConnect Read-Writable String", o.stringProperty);
   do_check_eq(true, o.booleanProperty);
   do_check_eq(32767, o.shortProperty);
   do_check_eq(2147483647, o.longProperty);
   do_check_true(5.25 < o.floatProperty && 5.75 > o.floatProperty);
   do_check_eq("X", o.charProperty);
@@ -88,8 +89,21 @@ function test_component(contractid) {
   SetAndTestBooleanProperty(1, true);
   SetAndTestBooleanProperty(null, false);
   SetAndTestBooleanProperty("A", true);
   SetAndTestBooleanProperty(undefined, false);
   SetAndTestBooleanProperty([], true);
   SetAndTestBooleanProperty({}, true);
 }
 
+function test_component_readonly(contractid) {
+
+  // Instantiate the object.
+  var o = Cc[contractid].createInstance(Ci["nsIXPCTestObjectReadOnly"]);
+
+  // Test the initial values.
+  do_check_eq("XPConnect Read-Only String", o.strReadOnly);
+  do_check_eq(true, o.boolReadOnly);
+  do_check_eq(32767, o.shortReadOnly);
+  do_check_eq(2147483647, o.longReadOnly);
+  do_check_true(5.25 < o.floatReadOnly && 5.75 > o.floatReadOnly);
+  do_check_eq("X", o.charReadOnly);
+}
--- a/js/src/xpconnect/tests/unit/xpcshell.ini
+++ b/js/src/xpconnect/tests/unit/xpcshell.ini
@@ -16,9 +16,9 @@ tail =
 [test_js_weak_references.js]
 [test_reflect_parse.js]
 [test_localeCompare.js]
 # Bug 676965: test fails consistently on Android
 fail-if = os == "android"
 [test_recursive_import.js]
 [test_xpcomutils.js]
 [test_unload.js]
-[test_readwriteattributes.js]
+[test_attributes.js]