]>
git.proxmox.com Git - mirror_novnc.git/blob - tests/test.util.js
1 /* jshint expr: true */
3 var assert
= chai
.assert
;
4 var expect
= chai
.expect
;
6 import * as Log
from '../core/util/logging.js';
7 import l10nGet
, { l10n
} from '../core/util/localization.js';
9 import sinon
from '../vendor/sinon.js';
11 describe('Utils', function() {
14 describe('logging functions', function () {
15 beforeEach(function () {
16 sinon
.spy(console
, 'log');
17 sinon
.spy(console
, 'debug');
18 sinon
.spy(console
, 'warn');
19 sinon
.spy(console
, 'error');
20 sinon
.spy(console
, 'info');
23 afterEach(function () {
24 console
.log
.restore();
25 console
.debug
.restore();
26 console
.warn
.restore();
27 console
.error
.restore();
28 console
.info
.restore();
32 it('should use noop for levels lower than the min level', function () {
33 Log
.init_logging('warn');
36 expect(console
.log
).to
.not
.have
.been
.called
;
39 it('should use console.debug for Debug', function () {
40 Log
.init_logging('debug');
42 expect(console
.debug
).to
.have
.been
.calledWith('dbg');
45 it('should use console.info for Info', function () {
46 Log
.init_logging('debug');
48 expect(console
.info
).to
.have
.been
.calledWith('inf');
51 it('should use console.warn for Warn', function () {
52 Log
.init_logging('warn');
54 expect(console
.warn
).to
.have
.been
.called
;
55 expect(console
.warn
).to
.have
.been
.calledWith('wrn');
58 it('should use console.error for Error', function () {
59 Log
.init_logging('error');
61 expect(console
.error
).to
.have
.been
.called
;
62 expect(console
.error
).to
.have
.been
.calledWith('err');
66 describe('language selection', function () {
68 beforeEach(function () {
69 // window.navigator is a protected read-only property in many
70 // environments, so we need to redefine it whilst running these
72 origNavigator
= Object
.getOwnPropertyDescriptor(window
, "navigator");
73 if (origNavigator
=== undefined) {
74 // Object.getOwnPropertyDescriptor() doesn't work
75 // properly in any version of IE
79 Object
.defineProperty(window
, "navigator", {value
: {}});
80 if (window
.navigator
.languages
!== undefined) {
81 // Object.defineProperty() doesn't work properly in old
86 window
.navigator
.languages
= [];
88 afterEach(function () {
89 Object
.defineProperty(window
, "navigator", origNavigator
);
92 it('should use English by default', function() {
93 expect(l10n
.language
).to
.equal('en');
95 it('should use English if no user language matches', function() {
96 window
.navigator
.languages
= ["nl", "de"];
97 l10n
.setup(["es", "fr"]);
98 expect(l10n
.language
).to
.equal('en');
100 it('should use the most preferred user language', function() {
101 window
.navigator
.languages
= ["nl", "de", "fr"];
102 l10n
.setup(["es", "fr", "de"]);
103 expect(l10n
.language
).to
.equal('de');
105 it('should prefer sub-languages languages', function() {
106 window
.navigator
.languages
= ["pt-BR"];
107 l10n
.setup(["pt", "pt-BR"]);
108 expect(l10n
.language
).to
.equal('pt-BR');
110 it('should fall back to language "parents"', function() {
111 window
.navigator
.languages
= ["pt-BR"];
112 l10n
.setup(["fr", "pt", "de"]);
113 expect(l10n
.language
).to
.equal('pt');
115 it('should not use specific language when user asks for a generic language', function() {
116 window
.navigator
.languages
= ["pt", "de"];
117 l10n
.setup(["fr", "pt-BR", "de"]);
118 expect(l10n
.language
).to
.equal('de');
120 it('should handle underscore as a separator', function() {
121 window
.navigator
.languages
= ["pt-BR"];
122 l10n
.setup(["pt_BR"]);
123 expect(l10n
.language
).to
.equal('pt_BR');
125 it('should handle difference in case', function() {
126 window
.navigator
.languages
= ["pt-br"];
127 l10n
.setup(["pt-BR"]);
128 expect(l10n
.language
).to
.equal('pt-BR');
132 // TODO(directxman12): test the conf_default and conf_defaults methods
133 // TODO(directxman12): test decodeUTF8
134 // TODO(directxman12): test the event methods (addEvent, removeEvent, stopEvent)
135 // TODO(directxman12): figure out a good way to test getPosition and getEventPosition
136 // TODO(directxman12): figure out how to test the browser detection functions properly
137 // (we can't really test them against the browsers, except for Gecko
138 // via PhantomJS, the default test driver)