]>
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';
10 import sinonChai
from '../node_modules/sinon-chai/lib/sinon-chai.js';
13 describe('Utils', function() {
16 describe('logging functions', function () {
17 beforeEach(function () {
18 sinon
.spy(console
, 'log');
19 sinon
.spy(console
, 'debug');
20 sinon
.spy(console
, 'warn');
21 sinon
.spy(console
, 'error');
22 sinon
.spy(console
, 'info');
25 afterEach(function () {
26 console
.log
.restore();
27 console
.debug
.restore();
28 console
.warn
.restore();
29 console
.error
.restore();
30 console
.info
.restore();
33 it('should use noop for levels lower than the min level', function () {
34 Log
.init_logging('warn');
37 expect(console
.log
).to
.not
.have
.been
.called
;
40 it('should use console.debug for Debug', function () {
41 Log
.init_logging('debug');
43 expect(console
.debug
).to
.have
.been
.calledWith('dbg');
46 it('should use console.info for Info', function () {
47 Log
.init_logging('debug');
49 expect(console
.info
).to
.have
.been
.calledWith('inf');
52 it('should use console.warn for Warn', function () {
53 Log
.init_logging('warn');
55 expect(console
.warn
).to
.have
.been
.called
;
56 expect(console
.warn
).to
.have
.been
.calledWith('wrn');
59 it('should use console.error for Error', function () {
60 Log
.init_logging('error');
62 expect(console
.error
).to
.have
.been
.called
;
63 expect(console
.error
).to
.have
.been
.calledWith('err');
67 describe('language selection', function () {
69 beforeEach(function () {
70 // window.navigator is a protected read-only property in many
71 // environments, so we need to redefine it whilst running these
73 origNavigator
= Object
.getOwnPropertyDescriptor(window
, "navigator");
74 if (origNavigator
=== undefined) {
75 // Object.getOwnPropertyDescriptor() doesn't work
76 // properly in any version of IE
80 Object
.defineProperty(window
, "navigator", {value
: {}});
81 if (window
.navigator
.languages
!== undefined) {
82 // Object.defineProperty() doesn't work properly in old
87 window
.navigator
.languages
= [];
89 afterEach(function () {
90 Object
.defineProperty(window
, "navigator", origNavigator
);
93 it('should use English by default', function() {
94 expect(l10n
.language
).to
.equal('en');
96 it('should use English if no user language matches', function() {
97 window
.navigator
.languages
= ["nl", "de"];
98 l10n
.setup(["es", "fr"]);
99 expect(l10n
.language
).to
.equal('en');
101 it('should use the most preferred user language', function() {
102 window
.navigator
.languages
= ["nl", "de", "fr"];
103 l10n
.setup(["es", "fr", "de"]);
104 expect(l10n
.language
).to
.equal('de');
106 it('should prefer sub-languages languages', function() {
107 window
.navigator
.languages
= ["pt-BR"];
108 l10n
.setup(["pt", "pt-BR"]);
109 expect(l10n
.language
).to
.equal('pt-BR');
111 it('should fall back to language "parents"', function() {
112 window
.navigator
.languages
= ["pt-BR"];
113 l10n
.setup(["fr", "pt", "de"]);
114 expect(l10n
.language
).to
.equal('pt');
116 it('should not use specific language when user asks for a generic language', function() {
117 window
.navigator
.languages
= ["pt", "de"];
118 l10n
.setup(["fr", "pt-BR", "de"]);
119 expect(l10n
.language
).to
.equal('de');
121 it('should handle underscore as a separator', function() {
122 window
.navigator
.languages
= ["pt-BR"];
123 l10n
.setup(["pt_BR"]);
124 expect(l10n
.language
).to
.equal('pt_BR');
126 it('should handle difference in case', function() {
127 window
.navigator
.languages
= ["pt-br"];
128 l10n
.setup(["pt-BR"]);
129 expect(l10n
.language
).to
.equal('pt-BR');
133 // TODO(directxman12): test the conf_default and conf_defaults methods
134 // TODO(directxman12): test decodeUTF8
135 // TODO(directxman12): test the event methods (addEvent, removeEvent, stopEvent)
136 // TODO(directxman12): figure out a good way to test getPosition and getEventPosition
137 // TODO(directxman12): figure out how to test the browser detection functions properly
138 // (we can't really test them against the browsers, except for Gecko
139 // via PhantomJS, the default test driver)