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

Side by Side Diff: chrome/test/data/webui/i18n_behavior_test.html

Issue 2927213002: [MD settings] I18nBehavior return textContent from i18n() (Closed)
Patch Set: merge with master Created 3 years, 6 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 <!doctype html> 1 <!doctype html>
2 <html> 2 <html>
3 <body> 3 <body>
4 <script> 4 <script>
5 5
6 /* Execute these tests with the browser_tests executable. */
7
8 var allowedByDefault = '<a href="https://google.com">Google!</a>'; 6 var allowedByDefault = '<a href="https://google.com">Google!</a>';
9 var text = 'I\'m just text, nobody should have a problem with me!'; 7 var text = 'I\'m just text, nobody should have a problem with me!';
10 var nonBreakingSpace = 'A\u00a0B\u00a0C'; // \u00a0 is a unicode nbsp. 8 var nonBreakingSpace = 'A\u00a0B\u00a0C'; // \u00a0 is a unicode nbsp.
11 9
12 function setUpPage() { 10 function setUpPage() {
13 loadTimeData.data = { 11 loadTimeData.data = {
14 'allowedByDefault': allowedByDefault, 12 'allowedByDefault': allowedByDefault,
15 'customAttr': '<a is="action-link">Take action!</a>', 13 'customAttr': '<a is="action-link">Take action!</a>',
16 'customTag': "<x-foo>I'm an X, foo!</x-foo>", 14 'customTag': "<x-foo>I'm an X, foo!</x-foo>",
17 'javascriptHref': '<a href="javascript:alert(1)">teh hax</a>', 15 'javascriptHref': '<a href="javascript:alert(1)">teh hax</a>',
18 'script': '<script>alert(/xss/)</scr' + 'ipt>', 16 'script': '<script>alert(/xss/)</scr' + 'ipt>',
19 'text': text, 17 'text': text,
20 'nonBreakingSpace': nonBreakingSpace, 18 'nonBreakingSpace': nonBreakingSpace,
21 }; 19 };
22 } 20 }
23 21
24 function testI18n() { 22 function testI18n() {
25 assertEquals(allowedByDefault, I18nBehavior.i18n('allowedByDefault'));
26 assertEquals(text, I18nBehavior.i18n('text')); 23 assertEquals(text, I18nBehavior.i18n('text'));
27 assertEquals(nonBreakingSpace, I18nBehavior.i18n('nonBreakingSpace')); 24 assertEquals(nonBreakingSpace, I18nBehavior.i18n('nonBreakingSpace'));
28 25
29 assertThrows(function() { I18nBehavior.i18n('customAttr'); }); 26 assertThrows(function() { I18nBehavior.i18n('customAttr'); });
30 assertThrows(function() { I18nBehavior.i18n('customTag'); }); 27 assertThrows(function() { I18nBehavior.i18n('customTag'); });
31 assertThrows(function() { I18nBehavior.i18n('javascriptHref'); }); 28 assertThrows(function() { I18nBehavior.i18n('javascriptHref'); });
32 assertThrows(function() { I18nBehavior.i18n('script'); }); 29 assertThrows(function() { I18nBehavior.i18n('script'); });
33 } 30 }
34 31
35 function testI18nAdvanced() { 32 function testI18nAdvanced() {
33 assertEquals(
34 allowedByDefault,
35 I18nBehavior.i18nAdvanced('allowedByDefault'));
36 I18nBehavior.i18nAdvanced('customAttr', { 36 I18nBehavior.i18nAdvanced('customAttr', {
37 attrs: { 37 attrs: {
38 is: function(el, val) { 38 is: function(el, val) {
39 return el.tagName == 'A' && val == 'action-link'; 39 return el.tagName == 'A' && val == 'action-link';
40 }, 40 },
41 }, 41 },
42 }); 42 });
43 I18nBehavior.i18nAdvanced('customTag', {tags: ['X-FOO']}); 43 I18nBehavior.i18nAdvanced('customTag', {tags: ['X-FOO']});
44 } 44 }
45 45
46 function testI18nDynamic() { 46 function testI18nDynamic() {
47 var locale = 'en'; 47 var locale = 'en';
48 assertEquals(text, I18nBehavior.i18nDynamic(locale, 'text')); 48 assertEquals(text, I18nBehavior.i18nDynamic(locale, 'text'));
49 } 49 }
50 50
51 function testI18nExists() { 51 function testI18nExists() {
52 assertTrue(I18nBehavior.i18nExists('text')); 52 assertTrue(I18nBehavior.i18nExists('text'));
53 assertFalse(I18nBehavior.i18nExists('missingText')); 53 assertFalse(I18nBehavior.i18nExists('missingText'));
54 } 54 }
55 55
56 </script> 56 </script>
57 </body> 57 </body>
58 </html> 58 </html>
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/controls/extension_controlled_indicator.js ('k') | ui/webui/resources/js/i18n_behavior.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698