4 <script src=
"../resources/testharness.js"></script>
5 <script src=
"../resources/testharnessreport.js"></script>
9 assert_true('language' in window
.navigator
);
10 assert_true('languages' in window
.navigator
);
11 assert_true('onlanguagechange' in window
);
12 }, "Test that NavigatorLanguage API is present in window");
16 window
.onlanguagechange = function() {
20 window
.testRunner
.setAcceptLanguages('klingon');
21 assert_true(received
);
22 }, "Test that the languagechange event fires on window.onlanguagechange");
26 window
.addEventListener('languagechange', function() {
30 window
.testRunner
.setAcceptLanguages('klingon-FR');
31 assert_true(received
);
32 }, "Test that the languagechange event fires on window.addEventListener('languagechange')");
35 window
.received
= false; // We need a global variable here.
36 document
.body
.setAttribute('onlanguagechange', 'window.received = true;');
38 window
.testRunner
.setAcceptLanguages('klingon-US');
39 assert_true(window
.received
);
40 }, "Test that the languagechange event fires on body onlanguagechange attribute");
43 window
.received
= 0; // We need a global variable here.
44 var fromWindowHandler
= false;
45 document
.body
.setAttribute('onlanguagechange', 'window.received++;');
46 window
.onlanguagechange = function() {
48 fromWindowHandler
= true;
51 window
.testRunner
.setAcceptLanguages('klingon');
52 assert_equals(window
.received
, 1);
53 assert_true(fromWindowHandler
);
56 fromWindowHandler
= false;
57 window
.onlanguagechange = function() {
59 fromWindowHandler
= true;
61 document
.body
.setAttribute('onlanguagechange', 'window.received++;');
63 window
.testRunner
.setAcceptLanguages('klingon-FR');
64 assert_equals(window
.received
, 1);
65 assert_false(fromWindowHandler
);
66 }, "Test that the languagechange event fires on body onlanguagechange attribute XOR window.onlanguagechange");
70 window
.onlanguagechange = function() {
74 window
.testRunner
.setAcceptLanguages('klingon-US');
75 window
.testRunner
.setAcceptLanguages('klingon-US');
77 assert_equals(eventsCount
, 1);
78 }, "Test that changing the language to the same value doesn't fire an event.")
81 window
.addEventListener('languagechange', function(e
) {
82 assert_false(e
.cancelable
);
83 assert_false(e
.bubbles
);
86 window
.testRunner
.setAcceptLanguages('klingon');
87 }, "Test properties of the fired event.");
91 { accept_languages
: 'foo', language
: 'foo', languages
: ['foo'] },
92 { accept_languages
: '', language
: '', languages
: [] },
93 { accept_languages
: 'foo,bar', language
: 'foo', languages
: [ 'foo', 'bar' ] },
94 { accept_languages
: ' foo , bar ', language
: 'foo', languages
: [ 'foo', 'bar' ] },
95 { accept_languages
: ' foo ; bar ', language
: 'foo ; bar', languages
: [ 'foo ; bar' ] },
96 { accept_languages
: '_foo_', language
: '_foo_', languages
: ['_foo_'] },
97 { accept_languages
: 'en_', language
: 'en-', languages
: ['en-'] },
98 { accept_languages
: 'en__', language
: 'en-_', languages
: ['en-_'] },
99 { accept_languages
: 'en_US, fr_FR', language
: 'en-US', languages
: ['en-US', 'fr-FR'] },
100 { accept_languages
: 'en_US_CA', language
: 'en-US_CA', languages
: ['en-US_CA'] },
104 window
.onlanguagechange = function() {
108 for (var i
= 0; i
< testValues
.length
; ++i
) {
109 var data
= testValues
[i
];
111 window
.testRunner
.setAcceptLanguages(data
.accept_languages
);
112 assert_equals(eventsCount
, i
+ 1);
114 assert_equals(navigator
.languages
.length
, data
.languages
.length
);
115 // FIXME: test navigator.language
116 for (var j
= 0; j
< navigator
.languages
.length
; ++j
) {
117 assert_equals(navigator
.languages
[j
], data
.languages
[j
]);
120 }, "Test that navigator.languages reflects the accept languages value.");
123 var previous
= navigator
.languages
;
124 assert_equals(navigator
.languages
, navigator
.languages
);
125 assert_equals(navigator
.languages
, previous
);
127 window
.testRunner
.setAcceptLanguages('fr-FR');
128 assert_not_equals(navigator
.languages
, previous
);
129 }, "Test that navigator.languages caching behaviour.");
132 // The region code should be uppercase.
133 assert_equals(navigator
.language
, 'en-US');
134 }, 'Test that the default navigator.language in the test environment.');