Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / navigator_language / navigator_language.html
blobdb014cc6767c6c934d71d5f40590a937044fd684
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <script src="../resources/testharness.js"></script>
5 <script src="../resources/testharnessreport.js"></script>
6 <script>
8 test(function() {
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");
14 test(function() {
15 var received = false;
16 window.onlanguagechange = function() {
17 received = true;
20 window.testRunner.setAcceptLanguages('klingon');
21 assert_true(received);
22 }, "Test that the languagechange event fires on window.onlanguagechange");
24 test(function() {
25 var received = false;
26 window.addEventListener('languagechange', function() {
27 received = true;
28 });
30 window.testRunner.setAcceptLanguages('klingon-FR');
31 assert_true(received);
32 }, "Test that the languagechange event fires on window.addEventListener('languagechange')");
34 test(function() {
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");
42 test(function() {
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() {
47 received++;
48 fromWindowHandler = true;
51 window.testRunner.setAcceptLanguages('klingon');
52 assert_equals(window.received, 1);
53 assert_true(fromWindowHandler);
55 window.received = 0;
56 fromWindowHandler = false;
57 window.onlanguagechange = function() {
58 received++;
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");
68 test(function() {
69 var eventsCount = 0;
70 window.onlanguagechange = function() {
71 eventsCount++;
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.")
80 test(function() {
81 window.addEventListener('languagechange', function(e) {
82 assert_false(e.cancelable);
83 assert_false(e.bubbles);
84 });
86 window.testRunner.setAcceptLanguages('klingon');
87 }, "Test properties of the fired event.");
89 test(function() {
90 var testValues = [
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'] },
103 var eventsCount = 0;
104 window.onlanguagechange = function() {
105 eventsCount++;
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.");
122 test(function() {
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.");
131 test(function() {
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.');
136 </script>
137 </body>
138 </html>