]>
git.proxmox.com Git - mirror_novnc.git/blob - tests/test.util.js
4ab2944f62e1b440822f001218d931ec5557427a
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();
31 it('should use noop for levels lower than the min level', function () {
32 Log
.init_logging('warn');
35 expect(console
.log
).to
.not
.have
.been
.called
;
38 it('should use console.debug for Debug', function () {
39 Log
.init_logging('debug');
41 expect(console
.debug
).to
.have
.been
.calledWith('dbg');
44 it('should use console.info for Info', function () {
45 Log
.init_logging('debug');
47 expect(console
.info
).to
.have
.been
.calledWith('inf');
50 it('should use console.warn for Warn', function () {
51 Log
.init_logging('warn');
53 expect(console
.warn
).to
.have
.been
.called
;
54 expect(console
.warn
).to
.have
.been
.calledWith('wrn');
57 it('should use console.error for Error', function () {
58 Log
.init_logging('error');
60 expect(console
.error
).to
.have
.been
.called
;
61 expect(console
.error
).to
.have
.been
.calledWith('err');
65 describe('language selection', function () {
67 beforeEach(function () {
68 // window.navigator is a protected read-only property in many
69 // environments, so we need to redefine it whilst running these
71 origNavigator
= Object
.getOwnPropertyDescriptor(window
, "navigator");
72 if (origNavigator
=== undefined) {
73 // Object.getOwnPropertyDescriptor() doesn't work
74 // properly in any version of IE
78 Object
.defineProperty(window
, "navigator", {value
: {}});
79 if (window
.navigator
.languages
!== undefined) {
80 // Object.defineProperty() doesn't work properly in old
85 window
.navigator
.languages
= [];
87 afterEach(function () {
88 Object
.defineProperty(window
, "navigator", origNavigator
);
91 it('should use English by default', function() {
92 expect(l10n
.language
).to
.equal('en');
94 it('should use English if no user language matches', function() {
95 window
.navigator
.languages
= ["nl", "de"];
96 l10n
.setup(["es", "fr"]);
97 expect(l10n
.language
).to
.equal('en');
99 it('should use the most preferred user language', function() {
100 window
.navigator
.languages
= ["nl", "de", "fr"];
101 l10n
.setup(["es", "fr", "de"]);
102 expect(l10n
.language
).to
.equal('de');
104 it('should prefer sub-languages languages', function() {
105 window
.navigator
.languages
= ["pt-BR"];
106 l10n
.setup(["pt", "pt-BR"]);
107 expect(l10n
.language
).to
.equal('pt-BR');
109 it('should fall back to language "parents"', function() {
110 window
.navigator
.languages
= ["pt-BR"];
111 l10n
.setup(["fr", "pt", "de"]);
112 expect(l10n
.language
).to
.equal('pt');
114 it('should not use specific language when user asks for a generic language', function() {
115 window
.navigator
.languages
= ["pt", "de"];
116 l10n
.setup(["fr", "pt-BR", "de"]);
117 expect(l10n
.language
).to
.equal('de');
119 it('should handle underscore as a separator', function() {
120 window
.navigator
.languages
= ["pt-BR"];
121 l10n
.setup(["pt_BR"]);
122 expect(l10n
.language
).to
.equal('pt_BR');
124 it('should handle difference in case', function() {
125 window
.navigator
.languages
= ["pt-br"];
126 l10n
.setup(["pt-BR"]);
127 expect(l10n
.language
).to
.equal('pt-BR');
131 // TODO(directxman12): test the conf_default and conf_defaults methods
132 // TODO(directxman12): test decodeUTF8
133 // TODO(directxman12): test the event methods (addEvent, removeEvent, stopEvent)
134 // TODO(directxman12): figure out a good way to test getPosition and getEventPosition
135 // TODO(directxman12): figure out how to test the browser detection functions properly
136 // (we can't really test them against the browsers, except for Gecko
137 // via PhantomJS, the default test driver)