Convert cacheinvalidation_unittests to run exclusively on Swarming
[chromium-blink-merge.git] / remoting / webapp / base / js / l10n_unittest.js
blobbbb1425e1779a6de20912f191bb8fb1dd975b605
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 (function() {
7 'use strict';
9 QUnit.module('l10n', {
10 beforeEach: function() {
11 sinon.stub(chrome.i18n, 'getMessage');
13 afterEach: function() {
14 $testStub(chrome.i18n.getMessage).restore();
16 });
18 QUnit.test('getTranslationOrError(tag) should return tag on error',
19 function(assert) {
20 var translation = l10n.getTranslationOrError('non_existent_tag');
21 assert.equal(translation, 'non_existent_tag');
22 });
24 QUnit.test('localizeElementFromTag() should replace innerText by default',
25 function(assert) {
26 var element = document.createElement('div');
27 $testStub(chrome.i18n.getMessage).withArgs('tag')
28 .returns('<b>Hello World</b>');
30 l10n.localizeElementFromTag(element, 'tag');
32 assert.equal(element.innerHTML, '&lt;b&gt;Hello World&lt;/b&gt;');
33 });
35 QUnit.test('localizeElementFromTag() should replace innerHTML if flag is set',
36 function(assert) {
37 var element = document.createElement('div');
38 $testStub(chrome.i18n.getMessage).withArgs('tag')
39 .returns('<b>Hello World</b>');
41 l10n.localizeElementFromTag(element, 'tag', null, true);
43 assert.equal(element.innerHTML, '<b>Hello World</b>');
44 });
46 QUnit.test(
47 'localizeElement() should replace innerText using the "i18n-content" ' +
48 'attribute as the tag',
49 function(assert) {
50 var element = document.createElement('div');
51 element.setAttribute('i18n-content', 'tag');
52 $testStub(chrome.i18n.getMessage).withArgs('tag')
53 .returns('<b>Hello World</b>');
55 l10n.localizeElement(element);
57 assert.equal(element.innerHTML, '&lt;b&gt;Hello World&lt;/b&gt;');
58 });
60 QUnit.test(
61 'localize() should replace element title using the "i18n-title" ' +
62 'attribute as the tag',
63 function(assert) {
64 var fixture = document.getElementById('qunit-fixture');
65 fixture.innerHTML = '<div class="target" i18n-title="tag"></div>';
66 $testStub(chrome.i18n.getMessage)
67 .withArgs('tag')
68 .returns('localized title');
70 l10n.localize();
72 var target = document.querySelector('.target');
73 assert.equal(target.title, 'localized title');
74 });
76 QUnit.test('localize() should support string substitutions', function(assert) {
77 var fixture = document.getElementById('qunit-fixture');
78 fixture.innerHTML =
79 '<div class="target" ' +
80 'i18n-content="tag" ' +
81 'i18n-value-1="param1" ' +
82 'i18n-value-2="param2">' +
83 '</div>';
85 $testStub(chrome.i18n.getMessage).withArgs('tag', ['param1', 'param2'])
86 .returns('localized');
88 l10n.localize();
90 var target = document.querySelector('.target');
91 assert.equal(target.innerText, 'localized');
92 });
94 QUnit.test('localize() should support tag substitutions', function(assert) {
95 var fixture = document.getElementById('qunit-fixture');
96 fixture.innerHTML =
97 '<div class="target" i18n-content="tag"' +
98 ' i18n-value-name-1="tag1" i18n-value-name-2="tag2"></div>';
100 $testStub(chrome.i18n.getMessage).withArgs('tag1').returns('param1');
101 $testStub(chrome.i18n.getMessage).withArgs('tag2').returns('param2');
102 $testStub(chrome.i18n.getMessage)
103 .withArgs('tag', ['param1', 'param2'])
104 .returns('localized');
106 l10n.localize();
108 var target = document.querySelector('.target');
109 assert.equal(target.innerText, 'localized');
112 })();