michael@0: // Copyright 2012 Mozilla Corporation. All rights reserved. michael@0: // This code is governed by the BSD license found in the LICENSE file. michael@0: michael@0: /** michael@0: * @description Tests that invalid time zone names are not accepted. michael@0: * @author Norbert Lindenberg michael@0: */ michael@0: michael@0: var invalidTimeZoneNames = [ michael@0: "", michael@0: "MEZ", // localized abbreviation michael@0: "Pacific Time", // localized long form michael@0: "cnsha", // BCP 47 time zone code michael@0: "invalid", // as the name says michael@0: "Europe/İstanbul", // non-ASCII letter michael@0: "asıa/baku", // non-ASCII letter michael@0: "europe/brußels" // non-ASCII letter michael@0: ]; michael@0: michael@0: invalidTimeZoneNames.forEach(function (name) { michael@0: var error; michael@0: try { michael@0: // this must throw an exception for an invalid time zone name michael@0: var format = new Intl.DateTimeFormat(["de-de"], {timeZone: name}); michael@0: } catch (e) { michael@0: error = e; michael@0: } michael@0: if (error === undefined) { michael@0: $ERROR("Invalid time zone name " + name + " was not rejected."); michael@0: } else if (error.name !== "RangeError") { michael@0: $ERROR("Invalid time zone name " + name + " was rejected with wrong error " + error.name + "."); michael@0: } michael@0: }); michael@0: