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

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

Issue 1017613002: Migrate Remoting Webapp Unittests to use QUnit 2.0 syntax. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Async test migration Created 5 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function() { 5 (function() {
6 6
7 'use strict'; 7 'use strict';
8 8
9 module('l10n', { 9 QUnit.module('l10n', {
10 setup: function() { 10 beforeEach: function() {
11 sinon.stub(chrome.i18n, 'getMessage'); 11 sinon.stub(chrome.i18n, 'getMessage');
12 }, 12 },
13 teardown: function() { 13 afterEach: function() {
14 $testStub(chrome.i18n.getMessage).restore(); 14 $testStub(chrome.i18n.getMessage).restore();
15 } 15 }
16 }); 16 });
17 17
18 test('getTranslationOrError(tag) should return tag on error', function() { 18 QUnit.test('getTranslationOrError(tag) should return tag on error', function() {
19 var translation = l10n.getTranslationOrError('non_existent_tag'); 19 var translation = l10n.getTranslationOrError('non_existent_tag');
20 equal(translation, 'non_existent_tag'); 20 QUnit.equal(translation, 'non_existent_tag');
21 }); 21 });
22 22
23 test('localizeElementFromTag() should replace innerText by default', 23 QUnit.test('localizeElementFromTag() should replace innerText by default',
24 function() { 24 function() {
25 var element = document.createElement('div'); 25 var element = document.createElement('div');
26 $testStub(chrome.i18n.getMessage).withArgs('tag') 26 $testStub(chrome.i18n.getMessage).withArgs('tag')
27 .returns('<b>Hello World</b>'); 27 .returns('<b>Hello World</b>');
28 28
29 l10n.localizeElementFromTag(element, 'tag'); 29 l10n.localizeElementFromTag(element, 'tag');
30 30
31 equal(element.innerHTML, '&lt;b&gt;Hello World&lt;/b&gt;'); 31 QUnit.equal(element.innerHTML, '&lt;b&gt;Hello World&lt;/b&gt;');
32 }); 32 });
33 33
34 test('localizeElementFromTag() should replace innerHTML if flag is set', 34 QUnit.test('localizeElementFromTag() should replace innerHTML if flag is set',
35 function() { 35 function() {
36 var element = document.createElement('div'); 36 var element = document.createElement('div');
37 $testStub(chrome.i18n.getMessage).withArgs('tag') 37 $testStub(chrome.i18n.getMessage).withArgs('tag')
38 .returns('<b>Hello World</b>'); 38 .returns('<b>Hello World</b>');
39 39
40 l10n.localizeElementFromTag(element, 'tag', null, true); 40 l10n.localizeElementFromTag(element, 'tag', null, true);
41 41
42 equal(element.innerHTML, '<b>Hello World</b>'); 42 QUnit.equal(element.innerHTML, '<b>Hello World</b>');
43 }); 43 });
44 44
45 test( 45 QUnit.test(
46 'localizeElement() should replace innerText using the "i18n-content" ' + 46 'localizeElement() should replace innerText using the "i18n-content" ' +
47 'attribute as the tag', 47 'attribute as the tag',
48 function() { 48 function() {
49 var element = document.createElement('div'); 49 var element = document.createElement('div');
50 element.setAttribute('i18n-content', 'tag'); 50 element.setAttribute('i18n-content', 'tag');
51 $testStub(chrome.i18n.getMessage).withArgs('tag') 51 $testStub(chrome.i18n.getMessage).withArgs('tag')
52 .returns('<b>Hello World</b>'); 52 .returns('<b>Hello World</b>');
53 53
54 l10n.localizeElement(element); 54 l10n.localizeElement(element);
55 55
56 equal(element.innerHTML, '&lt;b&gt;Hello World&lt;/b&gt;'); 56 QUnit.equal(element.innerHTML, '&lt;b&gt;Hello World&lt;/b&gt;');
57 }); 57 });
58 58
59 test( 59 QUnit.test(
60 'localize() should replace element title using the "i18n-title" ' + 60 'localize() should replace element title using the "i18n-title" ' +
61 'attribute as the tag', 61 'attribute as the tag',
62 function() { 62 function() {
63 var fixture = document.getElementById('qunit-fixture'); 63 var fixture = document.getElementById('qunit-fixture');
64 fixture.innerHTML = '<div class="target" i18n-title="tag"></div>'; 64 fixture.innerHTML = '<div class="target" i18n-title="tag"></div>';
65 $testStub(chrome.i18n.getMessage) 65 $testStub(chrome.i18n.getMessage)
66 .withArgs('tag') 66 .withArgs('tag')
67 .returns('localized title'); 67 .returns('localized title');
68 68
69 l10n.localize(); 69 l10n.localize();
70 70
71 var target = document.querySelector('.target'); 71 var target = document.querySelector('.target');
72 equal(target.title, 'localized title'); 72 QUnit.equal(target.title, 'localized title');
73 }); 73 });
74 74
75 test('localize() should support string substitutions', function() { 75 QUnit.test('localize() should support string substitutions', function() {
76 var fixture = document.getElementById('qunit-fixture'); 76 var fixture = document.getElementById('qunit-fixture');
77 fixture.innerHTML = 77 fixture.innerHTML =
78 '<div class="target" ' + 78 '<div class="target" ' +
79 'i18n-content="tag" ' + 79 'i18n-content="tag" ' +
80 'i18n-value-1="param1" ' + 80 'i18n-value-1="param1" ' +
81 'i18n-value-2="param2">' + 81 'i18n-value-2="param2">' +
82 '</div>'; 82 '</div>';
83 83
84 $testStub(chrome.i18n.getMessage).withArgs('tag', ['param1', 'param2']) 84 $testStub(chrome.i18n.getMessage).withArgs('tag', ['param1', 'param2'])
85 .returns('localized'); 85 .returns('localized');
86 86
87 l10n.localize(); 87 l10n.localize();
88 88
89 var target = document.querySelector('.target'); 89 var target = document.querySelector('.target');
90 equal(target.innerText, 'localized'); 90 QUnit.equal(target.innerText, 'localized');
91 }); 91 });
92 92
93 test('localize() should support tag substitutions', function() { 93 QUnit.test('localize() should support tag substitutions', function() {
94 var fixture = document.getElementById('qunit-fixture'); 94 var fixture = document.getElementById('qunit-fixture');
95 fixture.innerHTML = 95 fixture.innerHTML =
96 '<div class="target" i18n-content="tag"' + 96 '<div class="target" i18n-content="tag"' +
97 ' i18n-value-name-1="tag1" i18n-value-name-2="tag2"></div>'; 97 ' i18n-value-name-1="tag1" i18n-value-name-2="tag2"></div>';
98 98
99 $testStub(chrome.i18n.getMessage).withArgs('tag1').returns('param1'); 99 $testStub(chrome.i18n.getMessage).withArgs('tag1').returns('param1');
100 $testStub(chrome.i18n.getMessage).withArgs('tag2').returns('param2'); 100 $testStub(chrome.i18n.getMessage).withArgs('tag2').returns('param2');
101 $testStub(chrome.i18n.getMessage) 101 $testStub(chrome.i18n.getMessage)
102 .withArgs('tag', ['param1', 'param2']) 102 .withArgs('tag', ['param1', 'param2'])
103 .returns('localized'); 103 .returns('localized');
104 104
105 l10n.localize(); 105 l10n.localize();
106 106
107 var target = document.querySelector('.target'); 107 var target = document.querySelector('.target');
108 equal(target.innerText, 'localized'); 108 QUnit.equal(target.innerText, 'localized');
109 }); 109 });
110 110
111 })(); 111 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698