Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / js / src / jsapi-tests / testDateToLocaleString.cpp
blob3a425ab7a69b6b8dc911f8912e020e2b11d2528a
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "js/LocaleSensitive.h"
9 #include "jsapi-tests/tests.h"
11 BEGIN_TEST(testDateToLocaleString) {
12 JSRuntime* rt = JS_GetRuntime(cx);
14 // This test should only attempt to run if we have Intl support: necessary
15 // to properly assume that changes to the default locale will predictably
16 // affect the behavior of the locale-sensitive Date methods tested here.
17 JS::Rooted<JS::Value> haveIntl(cx);
18 EVAL("typeof Intl !== 'undefined'", &haveIntl);
19 if (!haveIntl.toBoolean()) {
20 return true;
23 // Pervasive assumption: our Intl support includes "de" (German) and
24 // "en" (English) and treats them differently for purposes of
25 // Date.prototype.toLocale{,Date,Time}String behavior.
27 // Start with German.
28 CHECK(JS_SetDefaultLocale(rt, "de"));
30 // The (constrained) Date object we'll use to test behavior.
31 EXEC("var d = new Date(Date.UTC(2015, 9 - 1, 17));");
33 // Test that toLocaleString behavior changes with default locale changes.
34 EXEC("var deAll = d.toLocaleString();");
36 CHECK(JS_SetDefaultLocale(rt, "en"));
37 EXEC(
38 "if (d.toLocaleString() === deAll) \n"
39 " throw 'toLocaleString results should have changed with system locale "
40 "change';");
42 // Test that toLocaleDateString behavior changes with default locale changes.
43 EXEC("var enDate = d.toLocaleDateString();");
45 CHECK(JS_SetDefaultLocale(rt, "de"));
46 EXEC(
47 "if (d.toLocaleDateString() === enDate) \n"
48 " throw 'toLocaleDateString results should have changed with system "
49 "locale change';");
51 // Test that toLocaleTimeString behavior changes with default locale changes.
52 EXEC("var deTime = d.toLocaleTimeString();");
54 CHECK(JS_SetDefaultLocale(rt, "en"));
55 EXEC(
56 "if (d.toLocaleTimeString() === deTime) \n"
57 " throw 'toLocaleTimeString results should have changed with system "
58 "locale change';");
60 JS_ResetDefaultLocale(rt);
61 return true;
63 END_TEST(testDateToLocaleString)