Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: remoting/webapp/crd/js/l10n_unittest.js

Issue 1133913002: [Chromoting] Move shared webapp JS files from crd/js -> base/js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/webapp/crd/js/l10n.js ('k') | remoting/webapp/crd/js/log_to_server.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 (function() {
6
7 'use strict';
8
9 QUnit.module('l10n', {
10 beforeEach: function() {
11 sinon.stub(chrome.i18n, 'getMessage');
12 },
13 afterEach: function() {
14 $testStub(chrome.i18n.getMessage).restore();
15 }
16 });
17
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 });
23
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>');
29
30 l10n.localizeElementFromTag(element, 'tag');
31
32 assert.equal(element.innerHTML, '&lt;b&gt;Hello World&lt;/b&gt;');
33 });
34
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>');
40
41 l10n.localizeElementFromTag(element, 'tag', null, true);
42
43 assert.equal(element.innerHTML, '<b>Hello World</b>');
44 });
45
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>');
54
55 l10n.localizeElement(element);
56
57 assert.equal(element.innerHTML, '&lt;b&gt;Hello World&lt;/b&gt;');
58 });
59
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');
69
70 l10n.localize();
71
72 var target = document.querySelector('.target');
73 assert.equal(target.title, 'localized title');
74 });
75
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>';
84
85 $testStub(chrome.i18n.getMessage).withArgs('tag', ['param1', 'param2'])
86 .returns('localized');
87
88 l10n.localize();
89
90 var target = document.querySelector('.target');
91 assert.equal(target.innerText, 'localized');
92 });
93
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>';
99
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');
105
106 l10n.localize();
107
108 var target = document.querySelector('.target');
109 assert.equal(target.innerText, 'localized');
110 });
111
112 })();
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/l10n.js ('k') | remoting/webapp/crd/js/log_to_server.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698