diff --git a/toolkit/components/downloads/test/unit/test_download_samename.js b/toolkit/components/downloads/test/unit/test_download_samename.js index c76c9153c9f0..c609e22447a9 100644 --- a/toolkit/components/downloads/test/unit/test_download_samename.js +++ b/toolkit/components/downloads/test/unit/test_download_samename.js @@ -57,21 +57,20 @@ let DownloadListener = { do_check_neq(file.leafName, prevFile.leafName); } this.prevFiles.push(file); - + // get the contents of the file let fis = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream); fis.init(file, -1, -1, 0); var cstream = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance(Ci.nsIConverterInputStream); cstream.init(fis, "UTF-8", 0, 0); - + let val = ""; - let (str = {}) { - let read = 0; - do { - read = cstream.readString(0xffffffff, str); - val += str.value; - } while (read != 0); - } + let str = {}; + let read = 0; + do { + read = cstream.readString(0xffffffff, str); + val += str.value; + } while (read != 0); cstream.close(); // check if the file contents match the expected ones diff --git a/toolkit/components/places/tests/autocomplete/head_autocomplete.js b/toolkit/components/places/tests/autocomplete/head_autocomplete.js index 9510086df4ea..70d03a886dad 100644 --- a/toolkit/components/places/tests/autocomplete/head_autocomplete.js +++ b/toolkit/components/places/tests/autocomplete/head_autocomplete.js @@ -10,7 +10,8 @@ const Cu = Components.utils; Cu.import("resource://gre/modules/Services.jsm"); // Import common head. -let (commonFile = do_get_file("../head_common.js", false)) { +{ + let commonFile = do_get_file("../head_common.js", false); let uri = Services.io.newFileURI(commonFile); Services.scriptloader.loadSubScript(uri.spec, this); } diff --git a/toolkit/components/places/tests/bookmarks/head_bookmarks.js b/toolkit/components/places/tests/bookmarks/head_bookmarks.js index 67582d03b508..2ae00c14aa1e 100644 --- a/toolkit/components/places/tests/bookmarks/head_bookmarks.js +++ b/toolkit/components/places/tests/bookmarks/head_bookmarks.js @@ -11,7 +11,8 @@ const Cu = Components.utils; Cu.import("resource://gre/modules/Services.jsm"); // Import common head. -let (commonFile = do_get_file("../head_common.js", false)) { +{ + let commonFile = do_get_file("../head_common.js", false); let uri = Services.io.newFileURI(commonFile); Services.scriptloader.loadSubScript(uri.spec, this); } diff --git a/toolkit/components/places/tests/expiration/head_expiration.js b/toolkit/components/places/tests/expiration/head_expiration.js index bbcd5dd5e021..f7f262e70fde 100644 --- a/toolkit/components/places/tests/expiration/head_expiration.js +++ b/toolkit/components/places/tests/expiration/head_expiration.js @@ -12,7 +12,8 @@ const Cu = Components.utils; Cu.import("resource://gre/modules/Services.jsm"); // Import common head. -let (commonFile = do_get_file("../head_common.js", false)) { +{ + let commonFile = do_get_file("../head_common.js", false); let uri = Services.io.newFileURI(commonFile); Services.scriptloader.loadSubScript(uri.spec, this); } diff --git a/toolkit/components/places/tests/favicons/head_favicons.js b/toolkit/components/places/tests/favicons/head_favicons.js index b3a911239243..0b973e9ce018 100644 --- a/toolkit/components/places/tests/favicons/head_favicons.js +++ b/toolkit/components/places/tests/favicons/head_favicons.js @@ -11,7 +11,8 @@ const Cu = Components.utils; Cu.import("resource://gre/modules/Services.jsm"); // Import common head. -let (commonFile = do_get_file("../head_common.js", false)) { +{ + let commonFile = do_get_file("../head_common.js", false); let uri = Services.io.newFileURI(commonFile); Services.scriptloader.loadSubScript(uri.spec, this); } diff --git a/toolkit/components/places/tests/favicons/test_moz-anno_favicon_mime_type.js b/toolkit/components/places/tests/favicons/test_moz-anno_favicon_mime_type.js index 334fd7ebb4e1..26e20f1329ed 100644 --- a/toolkit/components/places/tests/favicons/test_moz-anno_favicon_mime_type.js +++ b/toolkit/components/places/tests/favicons/test_moz-anno_favicon_mime_type.js @@ -58,46 +58,43 @@ function run_test() getService(Ci.nsIIOService); // Test that the default icon has the content type of image/png. - let (channel = ios.newChannelFromURI2(fs.defaultFavicon, + let channel = ios.newChannelFromURI2(fs.defaultFavicon, null, // aLoadingNode Services.scriptSecurityManager.getSystemPrincipal(), null, // aTriggeringPrincipal Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_IMAGE)) { - channel.asyncOpen(new streamListener("image/png"), null); - do_test_pending(); - } + Ci.nsIContentPolicy.TYPE_IMAGE); + channel.asyncOpen(new streamListener("image/png"), null); + do_test_pending(); // Test URI that we don't know anything about. Will end up being the default // icon, so expect image/png. - let (channel = ios.newChannel2(moz_anno_favicon_prefix + "http://mozilla.org", - null, - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_IMAGE)) { - channel.asyncOpen(new streamListener("image/png"), null); - do_test_pending(); - } + channel = ios.newChannel2(moz_anno_favicon_prefix + "http://mozilla.org", + null, + null, + null, // aLoadingNode + Services.scriptSecurityManager.getSystemPrincipal(), + null, // aTriggeringPrincipal + Ci.nsILoadInfo.SEC_NORMAL, + Ci.nsIContentPolicy.TYPE_IMAGE); + channel.asyncOpen(new streamListener("image/png"), null); + do_test_pending(); // Test that the content type of a favicon we add ends up being image/png. - let (testURI = uri("http://mozilla.org/")) { - // Add the data before opening - fs.replaceFaviconDataFromDataURL(testURI, testFaviconData, - (Date.now() + 60 * 60 * 24 * 1000) * 1000); + let testURI = uri("http://mozilla.org/"); + // Add the data before opening + fs.replaceFaviconDataFromDataURL(testURI, testFaviconData, + (Date.now() + 60 * 60 * 24 * 1000) * 1000); - // Open the channel - let channel = ios.newChannel2(moz_anno_favicon_prefix + testURI.spec, - null, - null, - null, // aLoadingNode - Services.scriptSecurityManager.getSystemPrincipal(), - null, // aTriggeringPrincipal - Ci.nsILoadInfo.SEC_NORMAL, - Ci.nsIContentPolicy.TYPE_IMAGE); - channel.asyncOpen(new streamListener("image/png"), null); - do_test_pending(); - } + // Open the channel + channel = ios.newChannel2(moz_anno_favicon_prefix + testURI.spec, + null, + null, + null, // aLoadingNode + Services.scriptSecurityManager.getSystemPrincipal(), + null, // aTriggeringPrincipal + Ci.nsILoadInfo.SEC_NORMAL, + Ci.nsIContentPolicy.TYPE_IMAGE); + channel.asyncOpen(new streamListener("image/png"), null); + do_test_pending(); } diff --git a/toolkit/components/places/tests/history/head_history.js b/toolkit/components/places/tests/history/head_history.js index c47f8d506b02..2632aabcf276 100644 --- a/toolkit/components/places/tests/history/head_history.js +++ b/toolkit/components/places/tests/history/head_history.js @@ -12,8 +12,8 @@ const Cu = Components.utils; Cu.import("resource://gre/modules/Services.jsm"); // Import common head. -let (commonFile = do_get_file("../head_common.js", false)) { +{ + let commonFile = do_get_file("../head_common.js", false); let uri = Services.io.newFileURI(commonFile); Services.scriptloader.loadSubScript(uri.spec, this); -}; - +} diff --git a/toolkit/components/places/tests/inline/head_autocomplete.js b/toolkit/components/places/tests/inline/head_autocomplete.js index 09463a0a2622..7ed53d72a808 100644 --- a/toolkit/components/places/tests/inline/head_autocomplete.js +++ b/toolkit/components/places/tests/inline/head_autocomplete.js @@ -10,7 +10,8 @@ const Cu = Components.utils; Cu.import("resource://gre/modules/Services.jsm"); // Import common head. -let (commonFile = do_get_file("../head_common.js", false)) { +{ + let commonFile = do_get_file("../head_common.js", false); let uri = Services.io.newFileURI(commonFile); Services.scriptloader.loadSubScript(uri.spec, this); } diff --git a/toolkit/components/places/tests/migration/head_migration.js b/toolkit/components/places/tests/migration/head_migration.js index d43a1cf2b445..f4b5abfb2be2 100644 --- a/toolkit/components/places/tests/migration/head_migration.js +++ b/toolkit/components/places/tests/migration/head_migration.js @@ -8,7 +8,8 @@ const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components; Cu.import("resource://gre/modules/Services.jsm"); // Import common head. -let (commonFile = do_get_file("../head_common.js", false)) { +{ + let commonFile = do_get_file("../head_common.js", false); let uri = Services.io.newFileURI(commonFile); Services.scriptloader.loadSubScript(uri.spec, this); } diff --git a/toolkit/components/places/tests/network/head_network.js b/toolkit/components/places/tests/network/head_network.js index 3f72dbea8385..d6988c06fa73 100644 --- a/toolkit/components/places/tests/network/head_network.js +++ b/toolkit/components/places/tests/network/head_network.js @@ -12,7 +12,8 @@ Cu.import("resource://testing-common/httpd.js"); Cu.import("resource://gre/modules/Services.jsm"); // Import common head. -let (commonFile = do_get_file("../head_common.js", false)) { +{ + let commonFile = do_get_file("../head_common.js", false); let uri = Services.io.newFileURI(commonFile); Services.scriptloader.loadSubScript(uri.spec, this); } diff --git a/toolkit/components/places/tests/queries/head_queries.js b/toolkit/components/places/tests/queries/head_queries.js index bf0e33604fc0..4740703a7302 100644 --- a/toolkit/components/places/tests/queries/head_queries.js +++ b/toolkit/components/places/tests/queries/head_queries.js @@ -12,7 +12,8 @@ const Cu = Components.utils; Cu.import("resource://gre/modules/Services.jsm"); // Import common head. -let (commonFile = do_get_file("../head_common.js", false)) { +{ + let commonFile = do_get_file("../head_common.js", false); let uri = Services.io.newFileURI(commonFile); Services.scriptloader.loadSubScript(uri.spec, this); } diff --git a/toolkit/components/places/tests/queries/test_async.js b/toolkit/components/places/tests/queries/test_async.js index 72c64ba39243..b3eeba1a790d 100644 --- a/toolkit/components/places/tests/queries/test_async.js +++ b/toolkit/components/places/tests/queries/test_async.js @@ -186,7 +186,8 @@ Test.prototype = { openContainer: function () { // Set up the result observer. It delegates to this object's callbacks and // wraps them in a try-catch so that errors don't get eaten. - this.observer = let (self = this) { + let self = this; + this.observer = { containerStateChanged: function (container, oldState, newState) { print("New state passed to containerStateChanged() should equal the " + "container's current state"); @@ -230,7 +231,7 @@ Test.prototype = { * This must be called before run(). It adds a bookmark and sets up the * test's result. Override if need be. */ - setup: function () { + setup: function*() { // Populate the database with different types of bookmark items. this.data = DataHelper.makeDataArray([ { type: "bookmark" }, @@ -290,7 +291,8 @@ let DataHelper = { * @return An array of objects suitable for passing to populateDB(). */ makeDataArray: function DH_makeDataArray(aData) { - return let (self = this) aData.map(function (dat) { + let self = this; + return aData.map(function (dat) { let type = dat.type; dat = self._makeDataWithDefaults(dat, self.defaults[type]); switch (type) { @@ -348,7 +350,7 @@ function run_test() run_next_test(); } -add_task(function test_async() +add_task(function* test_async() { for (let [, test] in Iterator(tests)) { remove_all_bookmarks(); diff --git a/toolkit/components/places/tests/unifiedcomplete/head_autocomplete.js b/toolkit/components/places/tests/unifiedcomplete/head_autocomplete.js index fd3892b50772..3b192a4d89d5 100644 --- a/toolkit/components/places/tests/unifiedcomplete/head_autocomplete.js +++ b/toolkit/components/places/tests/unifiedcomplete/head_autocomplete.js @@ -10,7 +10,8 @@ const Cu = Components.utils; Cu.import("resource://gre/modules/Services.jsm"); // Import common head. -let (commonFile = do_get_file("../head_common.js", false)) { +{ + let commonFile = do_get_file("../head_common.js", false); let uri = Services.io.newFileURI(commonFile); Services.scriptloader.loadSubScript(uri.spec, this); } diff --git a/toolkit/components/places/tests/unit/head_bookmarks.js b/toolkit/components/places/tests/unit/head_bookmarks.js index 67582d03b508..2ae00c14aa1e 100644 --- a/toolkit/components/places/tests/unit/head_bookmarks.js +++ b/toolkit/components/places/tests/unit/head_bookmarks.js @@ -11,7 +11,8 @@ const Cu = Components.utils; Cu.import("resource://gre/modules/Services.jsm"); // Import common head. -let (commonFile = do_get_file("../head_common.js", false)) { +{ + let commonFile = do_get_file("../head_common.js", false); let uri = Services.io.newFileURI(commonFile); Services.scriptloader.loadSubScript(uri.spec, this); } diff --git a/toolkit/components/places/tests/unit/test_bookmarks_html.js b/toolkit/components/places/tests/unit/test_bookmarks_html.js index caa304c2b2b1..d0a2a8382de9 100644 --- a/toolkit/components/places/tests/unit/test_bookmarks_html.js +++ b/toolkit/components/places/tests/unit/test_bookmarks_html.js @@ -311,17 +311,16 @@ function* checkItem(aExpected, aNode) do_check_eq(aNode.uri, aExpected.url) break; case "icon": - let (deferred = Promise.defer(), data) { - PlacesUtils.favicons.getFaviconDataForPage( - NetUtil.newURI(aExpected.url), - function (aURI, aDataLen, aData, aMimeType) { - deferred.resolve(aData); - }); - data = yield deferred.promise; - let base64Icon = "data:image/png;base64," + - base64EncodeString(String.fromCharCode.apply(String, data)); - do_check_true(base64Icon == aExpected.icon); - } + let deferred = Promise.defer(); + PlacesUtils.favicons.getFaviconDataForPage( + NetUtil.newURI(aExpected.url), + function (aURI, aDataLen, aData, aMimeType) { + deferred.resolve(aData); + }); + let data = yield deferred.promise; + let base64Icon = "data:image/png;base64," + + base64EncodeString(String.fromCharCode.apply(String, data)); + do_check_true(base64Icon == aExpected.icon); break; case "keyword": break; diff --git a/toolkit/components/places/tests/unit/test_bookmarks_json.js b/toolkit/components/places/tests/unit/test_bookmarks_json.js index e0c3538311bf..f756c38e710c 100644 --- a/toolkit/components/places/tests/unit/test_bookmarks_json.js +++ b/toolkit/components/places/tests/unit/test_bookmarks_json.js @@ -171,17 +171,16 @@ function checkItem(aExpected, aNode) { do_check_eq(aNode.uri, aExpected.url); break; case "icon": - let (deferred = Promise.defer(), data) { - PlacesUtils.favicons.getFaviconDataForPage( - NetUtil.newURI(aExpected.url), - function (aURI, aDataLen, aData, aMimeType) { - deferred.resolve(aData); - }); - data = yield deferred.promise; - let base64Icon = "data:image/png;base64," + - base64EncodeString(String.fromCharCode.apply(String, data)); - do_check_true(base64Icon == aExpected.icon); - } + let deferred = Promise.defer(); + PlacesUtils.favicons.getFaviconDataForPage( + NetUtil.newURI(aExpected.url), + function (aURI, aDataLen, aData, aMimeType) { + deferred.resolve(aData); + }); + let data = yield deferred.promise; + let base64Icon = "data:image/png;base64," + + base64EncodeString(String.fromCharCode.apply(String, data)); + do_check_true(base64Icon == aExpected.icon); break; case "keyword": break; diff --git a/toolkit/components/places/tests/unit/test_database_replaceOnStartup.js b/toolkit/components/places/tests/unit/test_database_replaceOnStartup.js index 1b9e258a77ec..655e19340aff 100644 --- a/toolkit/components/places/tests/unit/test_database_replaceOnStartup.js +++ b/toolkit/components/places/tests/unit/test_database_replaceOnStartup.js @@ -6,14 +6,13 @@ function run_test() { // Ensure that our database doesn't already exist. - let (dbFile = gProfD.clone()) { - dbFile.append("places.sqlite"); - do_check_false(dbFile.exists()); - } - let (dbFile = gProfD.clone()) { - dbFile.append("places.sqlite.corrupt"); - do_check_false(dbFile.exists()); - } + let dbFile = gProfD.clone(); + dbFile.append("places.sqlite"); + do_check_false(dbFile.exists()); + + dbFile = gProfD.clone(); + dbFile.append("places.sqlite.corrupt"); + do_check_false(dbFile.exists()); let file = do_get_file("default.sqlite"); file.copyToFollowingLinks(gProfD, "places.sqlite"); @@ -29,20 +28,19 @@ function run_test() { do_check_eq(PlacesUtils.history.databaseStatus, PlacesUtils.history.DATABASE_STATUS_CORRUPT); - let (dbFile = gProfD.clone()) { - dbFile.append("places.sqlite"); - do_check_true(dbFile.exists()); + dbFile = gProfD.clone(); + dbFile.append("places.sqlite"); + do_check_true(dbFile.exists()); - // Check the new database is really a new one. - let db = Services.storage.openUnsharedDatabase(file); - try { - db.executeSimpleSQL("DELETE * FROM test"); - do_throw("The new database should not have our unique content"); - } catch(ex) {} - db.close(); - } - let (dbFile = gProfD.clone()) { - dbFile.append("places.sqlite.corrupt"); - do_check_true(dbFile.exists()); - } -}; + // Check the new database is really a new one. + db = Services.storage.openUnsharedDatabase(file); + try { + db.executeSimpleSQL("DELETE * FROM test"); + do_throw("The new database should not have our unique content"); + } catch(ex) {} + db.close(); + + dbFile = gProfD.clone(); + dbFile.append("places.sqlite.corrupt"); + do_check_true(dbFile.exists()); +} diff --git a/toolkit/components/places/tests/unit/test_getPlacesInfo.js b/toolkit/components/places/tests/unit/test_getPlacesInfo.js index 1ae564d729bb..52ed1057765c 100644 --- a/toolkit/components/places/tests/unit/test_getPlacesInfo.js +++ b/toolkit/components/places/tests/unit/test_getPlacesInfo.js @@ -28,7 +28,7 @@ function ensurePlacesInfoObjectsAreEqual(a, b) { do_check_eq(a.placeId, b.placeId); } -function test_getPlacesInfoExistentPlace() { +function* test_getPlacesInfoExistentPlace() { let testURI = NetUtil.newURI("http://www.example.tld"); yield PlacesTestUtils.addVisits(testURI); @@ -46,7 +46,7 @@ function test_getPlacesInfoExistentPlace() { } add_task(test_getPlacesInfoExistentPlace); -function test_getPlacesInfoNonExistentPlace() { +function* test_getPlacesInfoNonExistentPlace() { let testURI = NetUtil.newURI("http://www.example_non_existent.tld"); let getPlacesInfoResult = yield promiseGetPlacesInfo(testURI); do_check_eq(getPlacesInfoResult.results.length, 0); @@ -54,24 +54,22 @@ function test_getPlacesInfoNonExistentPlace() { } add_task(test_getPlacesInfoNonExistentPlace); -function test_promisedHelper() { - let (uri = NetUtil.newURI("http://www.helper_existent_example.tld")) { - yield PlacesTestUtils.addVisits(uri); - let placeInfo = yield PlacesUtils.promisePlaceInfo(uri); - do_check_true(placeInfo instanceof Ci.mozIPlaceInfo); - }; +function* test_promisedHelper() { + let uri = NetUtil.newURI("http://www.helper_existent_example.tld"); + yield PlacesTestUtils.addVisits(uri); + let placeInfo = yield PlacesUtils.promisePlaceInfo(uri); + do_check_true(placeInfo instanceof Ci.mozIPlaceInfo); - let (uri = NetUtil.newURI("http://www.helper_non_existent_example.tld")) { - try { - let placeInfo = yield PlacesUtils.promisePlaceInfo(uri); - do_throw("PlacesUtils.promisePlaceInfo should have rejected the promise"); - } - catch(ex) { } - }; + uri = NetUtil.newURI("http://www.helper_non_existent_example.tld"); + try { + let placeInfo = yield PlacesUtils.promisePlaceInfo(uri); + do_throw("PlacesUtils.promisePlaceInfo should have rejected the promise"); + } + catch(ex) { } } add_task(test_promisedHelper); -function test_infoByGUID() { +function* test_infoByGUID() { let testURI = NetUtil.newURI("http://www.guid_example.tld"); yield PlacesTestUtils.addVisits(testURI); @@ -81,7 +79,7 @@ function test_infoByGUID() { } add_task(test_infoByGUID); -function test_invalid_guid() { +function* test_invalid_guid() { try { let placeInfoByGUID = yield PlacesUtils.promisePlaceInfo("###"); do_throw("getPlacesInfo should fail for invalid guids") @@ -90,17 +88,15 @@ function test_invalid_guid() { } add_task(test_invalid_guid); -function test_mixed_selection() { +function* test_mixed_selection() { let placeInfo1, placeInfo2; - let (uri = NetUtil.newURI("http://www.mixed_selection_test_1.tld")) { - yield PlacesTestUtils.addVisits(uri); - placeInfo1 = yield PlacesUtils.promisePlaceInfo(uri); - }; + let uri = NetUtil.newURI("http://www.mixed_selection_test_1.tld"); + yield PlacesTestUtils.addVisits(uri); + placeInfo1 = yield PlacesUtils.promisePlaceInfo(uri); - let (uri = NetUtil.newURI("http://www.mixed_selection_test_2.tld")) { - yield PlacesTestUtils.addVisits(uri); - placeInfo2 = yield PlacesUtils.promisePlaceInfo(uri); - }; + uri = NetUtil.newURI("http://www.mixed_selection_test_2.tld"); + yield PlacesTestUtils.addVisits(uri); + placeInfo2 = yield PlacesUtils.promisePlaceInfo(uri); let getPlacesInfoResult = yield promiseGetPlacesInfo([placeInfo1.uri, placeInfo2.guid]); do_check_eq(getPlacesInfoResult.results.length, 2); diff --git a/toolkit/components/places/tests/unit/test_tagging.js b/toolkit/components/places/tests/unit/test_tagging.js index bd6bd7f876df..77a5c63d041d 100644 --- a/toolkit/components/places/tests/unit/test_tagging.js +++ b/toolkit/components/places/tests/unit/test_tagging.js @@ -117,61 +117,60 @@ function run_test() { do_check_true(uri4Tags.indexOf("456") != -1); // Test sparse arrays. - let (curChildCount = tagRoot.childCount) { - try { - tagssvc.tagURI(uri1, [, "tagSparse"]); - do_check_eq(tagRoot.childCount, curChildCount + 1); - } catch (ex) { - do_throw("Passing a sparse array should not throw"); - } - try { - tagssvc.untagURI(uri1, [, "tagSparse"]); - do_check_eq(tagRoot.childCount, curChildCount); - } catch (ex) { - do_throw("Passing a sparse array should not throw"); - } + let curChildCount = tagRoot.childCount; - // Test that the API throws for bad arguments. - try { - tagssvc.tagURI(uri1, ["", "test"]); - do_throw("Passing a bad tags array should throw"); - } catch (ex) { - do_check_eq(ex.name, "NS_ERROR_ILLEGAL_VALUE"); - } - try { - tagssvc.untagURI(uri1, ["", "test"]); - do_throw("Passing a bad tags array should throw"); - } catch (ex) { - do_check_eq(ex.name, "NS_ERROR_ILLEGAL_VALUE"); - } - try { - tagssvc.tagURI(uri1, [0, "test"]); - do_throw("Passing a bad tags array should throw"); - } catch (ex) { - do_check_eq(ex.name, "NS_ERROR_ILLEGAL_VALUE"); - } - try { - tagssvc.tagURI(uri1, [0, "test"]); - do_throw("Passing a bad tags array should throw"); - } catch (ex) { - do_check_eq(ex.name, "NS_ERROR_ILLEGAL_VALUE"); - } - - // Tag name length should be limited to nsITaggingService.MAX_TAG_LENGTH (bug407821) - try { - - // generate a long tag name. i.e. looooo...oong_tag - var n = Ci.nsITaggingService.MAX_TAG_LENGTH; - var someOos = new Array(n).join('o'); - var longTagName = "l" + someOos + "ng_tag"; - - tagssvc.tagURI(uri1, ["short_tag", longTagName]); - do_throw("Passing a bad tags array should throw"); - - } catch (ex) { - do_check_eq(ex.name, "NS_ERROR_ILLEGAL_VALUE"); - } - + try { + tagssvc.tagURI(uri1, [, "tagSparse"]); + do_check_eq(tagRoot.childCount, curChildCount + 1); + } catch (ex) { + do_throw("Passing a sparse array should not throw"); + } + try { + tagssvc.untagURI(uri1, [, "tagSparse"]); + do_check_eq(tagRoot.childCount, curChildCount); + } catch (ex) { + do_throw("Passing a sparse array should not throw"); + } + + // Test that the API throws for bad arguments. + try { + tagssvc.tagURI(uri1, ["", "test"]); + do_throw("Passing a bad tags array should throw"); + } catch (ex) { + do_check_eq(ex.name, "NS_ERROR_ILLEGAL_VALUE"); + } + try { + tagssvc.untagURI(uri1, ["", "test"]); + do_throw("Passing a bad tags array should throw"); + } catch (ex) { + do_check_eq(ex.name, "NS_ERROR_ILLEGAL_VALUE"); + } + try { + tagssvc.tagURI(uri1, [0, "test"]); + do_throw("Passing a bad tags array should throw"); + } catch (ex) { + do_check_eq(ex.name, "NS_ERROR_ILLEGAL_VALUE"); + } + try { + tagssvc.tagURI(uri1, [0, "test"]); + do_throw("Passing a bad tags array should throw"); + } catch (ex) { + do_check_eq(ex.name, "NS_ERROR_ILLEGAL_VALUE"); + } + + // Tag name length should be limited to nsITaggingService.MAX_TAG_LENGTH (bug407821) + try { + + // generate a long tag name. i.e. looooo...oong_tag + var n = Ci.nsITaggingService.MAX_TAG_LENGTH; + var someOos = new Array(n).join('o'); + var longTagName = "l" + someOos + "ng_tag"; + + tagssvc.tagURI(uri1, ["short_tag", longTagName]); + do_throw("Passing a bad tags array should throw"); + + } catch (ex) { + do_check_eq(ex.name, "NS_ERROR_ILLEGAL_VALUE"); } // cleanup diff --git a/toolkit/modules/tests/xpcshell/test_dict.js b/toolkit/modules/tests/xpcshell/test_dict.js index c07fb5395a70..66f49aef2640 100644 --- a/toolkit/modules/tests/xpcshell/test_dict.js +++ b/toolkit/modules/tests/xpcshell/test_dict.js @@ -189,67 +189,62 @@ function test_set_property_lazy_getter() { }); }; - let (dict = new Dict()) { - setThunk(dict); + let dict = new Dict(); + setThunk(dict); - // Test that checking for the key existence does not invoke - // the getter function. - do_check_true(dict.has("foo")); - do_check_false(thunkCalled); - do_check_true(dict.isLazyGetter("foo")); + // Test that checking for the key existence does not invoke + // the getter function. + do_check_true(dict.has("foo")); + do_check_false(thunkCalled); + do_check_true(dict.isLazyGetter("foo")); - // Calling get the first time should invoke the getter function - // and unmark the key as a lazy getter. - do_check_eq(dict.get("foo"), "bar"); - do_check_true(thunkCalled); - do_check_false(dict.isLazyGetter("foo")); + // Calling get the first time should invoke the getter function + // and unmark the key as a lazy getter. + do_check_eq(dict.get("foo"), "bar"); + do_check_true(thunkCalled); + do_check_false(dict.isLazyGetter("foo")); - // Calling get again should not invoke the getter function - thunkCalled = false; - do_check_eq(dict.get("foo"), "bar"); - do_check_false(thunkCalled); - do_check_false(dict.isLazyGetter("foo")); - } + // Calling get again should not invoke the getter function + thunkCalled = false; + do_check_eq(dict.get("foo"), "bar"); + do_check_false(thunkCalled); + do_check_false(dict.isLazyGetter("foo")); // Test that listvalues works for lazy keys. - let (dict = new Dict()) { - setThunk(dict); - do_check_true(dict.isLazyGetter("foo")); + dict = new Dict(); + setThunk(dict); + do_check_true(dict.isLazyGetter("foo")); - let (listvalues = dict.listvalues()) { - do_check_false(dict.isLazyGetter("foo")); - do_check_true(thunkCalled); - do_check_true(listvalues.length, 1); - do_check_eq(listvalues[0], "bar"); - } + let listvalues = dict.listvalues(); + do_check_false(dict.isLazyGetter("foo")); + do_check_true(thunkCalled); + do_check_true(listvalues.length, 1); + do_check_eq(listvalues[0], "bar"); - thunkCalled = false; + thunkCalled = false; - // Retrieving the list again shouldn't invoke our getter. - let (listvalues = dict.listvalues()) { - do_check_false(dict.isLazyGetter("foo")); - do_check_false(thunkCalled); - do_check_true(listvalues.length, 1); - do_check_eq(listvalues[0], "bar"); - } - } + // Retrieving the list again shouldn't invoke our getter. + listvalues = dict.listvalues(); + do_check_false(dict.isLazyGetter("foo")); + do_check_false(thunkCalled); + do_check_true(listvalues.length, 1); + do_check_eq(listvalues[0], "bar"); // Test that the values iterator also works as expected. - let (dict = new Dict()) { - setThunk(dict); - let values = dict.values; + dict = new Dict(); + setThunk(dict); + let values = dict.values; - // Our getter shouldn't be called before the iterator reaches it. - do_check_true(dict.isLazyGetter("foo")); - do_check_false(thunkCalled); - do_check_eq(values.next(), "bar"); - do_check_true(thunkCalled); + // Our getter shouldn't be called before the iterator reaches it. + do_check_true(dict.isLazyGetter("foo")); + do_check_false(thunkCalled); + do_check_eq(values.next(), "bar"); + do_check_true(thunkCalled); - thunkCalled = false; - do_check_false(dict.isLazyGetter("foo")); - do_check_eq(dict.get("foo"), "bar"); - do_check_false(thunkCalled); - } + thunkCalled = false; + do_check_false(dict.isLazyGetter("foo")); + do_check_eq(dict.get("foo"), "bar"); + do_check_false(thunkCalled); } // This is used by both test_construct_dict_from_json_string and test_serialize_dict_to_json_string diff --git a/toolkit/modules/tests/xpcshell/test_propertyListsUtils.js b/toolkit/modules/tests/xpcshell/test_propertyListsUtils.js index 0787e1e171fe..6db28ae240e0 100644 --- a/toolkit/modules/tests/xpcshell/test_propertyListsUtils.js +++ b/toolkit/modules/tests/xpcshell/test_propertyListsUtils.js @@ -36,47 +36,45 @@ function checkMainPropertyList(aPropertyListRoot) { checkValue(aPropertyListRoot, PropertyListUtils.TYPE_DICTIONARY); checkValue(aPropertyListRoot.get("Boolean"), PRIMITIVE, false); - let (array = aPropertyListRoot.get("Array")) { - checkValue(array, PropertyListUtils.TYPE_ARRAY); - do_check_eq(array.length, 8); + let array = aPropertyListRoot.get("Array"); + checkValue(array, PropertyListUtils.TYPE_ARRAY); + do_check_eq(array.length, 8); - // Test both long and short values, since binary property lists store - // long values a little bit differently (see readDataLengthAndOffset). + // Test both long and short values, since binary property lists store + // long values a little bit differently (see readDataLengthAndOffset). - // Short ASCII string - checkLazyGetterValue(array, 0, PRIMITIVE, "abc"); - // Long ASCII string - checkLazyGetterValue(array, 1, PRIMITIVE, new Array(1001).join("a")); - // Short unicode string - checkLazyGetterValue(array, 2, PRIMITIVE, "\u05D0\u05D0\u05D0"); - // Long unicode string - checkLazyGetterValue(array, 3, PRIMITIVE, new Array(1001).join("\u05D0")); - // Unicode surrogate pair - checkLazyGetterValue(array, 4, PRIMITIVE, - "\uD800\uDC00\uD800\uDC00\uD800\uDC00"); + // Short ASCII string + checkLazyGetterValue(array, 0, PRIMITIVE, "abc"); + // Long ASCII string + checkLazyGetterValue(array, 1, PRIMITIVE, new Array(1001).join("a")); + // Short unicode string + checkLazyGetterValue(array, 2, PRIMITIVE, "\u05D0\u05D0\u05D0"); + // Long unicode string + checkLazyGetterValue(array, 3, PRIMITIVE, new Array(1001).join("\u05D0")); + // Unicode surrogate pair + checkLazyGetterValue(array, 4, PRIMITIVE, + "\uD800\uDC00\uD800\uDC00\uD800\uDC00"); - // Date - checkLazyGetterValue(array, 5, PropertyListUtils.TYPE_DATE, - new Date("2011-12-31T11:15:23Z")); + // Date + checkLazyGetterValue(array, 5, PropertyListUtils.TYPE_DATE, + new Date("2011-12-31T11:15:23Z")); - // Data - checkLazyGetterValue(array, 6, PropertyListUtils.TYPE_UINT8_ARRAY); - let dataAsString = [String.fromCharCode(b) for each (b in array[6])].join(""); - do_check_eq(dataAsString, "2011-12-31T11:15:33Z"); + // Data + checkLazyGetterValue(array, 6, PropertyListUtils.TYPE_UINT8_ARRAY); + let dataAsString = [String.fromCharCode(b) for each (b in array[6])].join(""); + do_check_eq(dataAsString, "2011-12-31T11:15:33Z"); - // Dict - let (dict = array[7]) { - checkValue(dict, PropertyListUtils.TYPE_DICTIONARY); - checkValue(dict.get("Negative Number"), PRIMITIVE, -400); - checkValue(dict.get("Real Number"), PRIMITIVE, 2.71828183); - checkValue(dict.get("Big Int"), - PropertyListUtils.TYPE_INT64, - "9007199254740993"); - checkValue(dict.get("Negative Big Int"), - PropertyListUtils.TYPE_INT64, - "-9007199254740993"); - } - } + // Dict + let dict = array[7]; + checkValue(dict, PropertyListUtils.TYPE_DICTIONARY); + checkValue(dict.get("Negative Number"), PRIMITIVE, -400); + checkValue(dict.get("Real Number"), PRIMITIVE, 2.71828183); + checkValue(dict.get("Big Int"), + PropertyListUtils.TYPE_INT64, + "9007199254740993"); + checkValue(dict.get("Negative Big Int"), + PropertyListUtils.TYPE_INT64, + "-9007199254740993"); } function readPropertyList(aFile, aCallback) {