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

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

Issue 2927213002: [MD settings] I18nBehavior return textContent from i18n() (Closed)
Patch Set: closure fix 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. */ 6 /* Execute these tests with the browser_tests executable with
7 * --gtest_filter='WebUIResourceBrowserTest.I18nBehaviorTest'. */
Dan Beam 2017/06/08 23:21:41 these instructions are not useful. i'd rather you
dschuyler 2017/06/09 00:13:39 Done.
7 8
8 var allowedByDefault = '<a href="https://google.com">Google!</a>'; 9 var allowedByDefault = '<a href="https://google.com">Google!</a>';
9 var text = 'I\'m just text, nobody should have a problem with me!'; 10 var text = 'I\'m just text, nobody should have a problem with me!';
10 var nonBreakingSpace = 'A\u00a0B'; // 0xa0 is a unicode nbsp. 11 var nonBreakingSpace = 'A\u00a0B'; // 0xa0 is a unicode nbsp.
11 12
12 function setUpPage() { 13 function setUpPage() {
13 loadTimeData.data = { 14 loadTimeData.data = {
14 'allowedByDefault': allowedByDefault, 15 'allowedByDefault': allowedByDefault,
15 'customAttr': '<a is="action-link">Take action!</a>', 16 'customAttr': '<a is="action-link">Take action!</a>',
16 'customTag': "<x-foo>I'm an X, foo!</x-foo>", 17 'customTag': "<x-foo>I'm an X, foo!</x-foo>",
17 'javascriptHref': '<a href="javascript:alert(1)">teh hax</a>', 18 'javascriptHref': '<a href="javascript:alert(1)">teh hax</a>',
18 'script': '<script>alert(/xss/)</scr' + 'ipt>', 19 'script': '<script>alert(/xss/)</scr' + 'ipt>',
19 'text': text, 20 'text': text,
20 'nonBreakingSpace': nonBreakingSpace, 21 'nonBreakingSpace': nonBreakingSpace,
21 }; 22 };
22 } 23 }
23 24
24 function testI18n() { 25 function testI18n() {
25 assertEquals(allowedByDefault, I18nBehavior.i18n('allowedByDefault'));
26 assertEquals(text, I18nBehavior.i18n('text')); 26 assertEquals(text, I18nBehavior.i18n('text'));
27 assertEquals(nonBreakingSpace, I18nBehavior.i18n('nonBreakingSpace')); 27 assertEquals(nonBreakingSpace, I18nBehavior.i18n('nonBreakingSpace'));
28 28
29 assertThrows(function() { I18nBehavior.i18n('customAttr'); }); 29 assertThrows(function() { I18nBehavior.i18n('customAttr'); });
30 assertThrows(function() { I18nBehavior.i18n('customTag'); }); 30 assertThrows(function() { I18nBehavior.i18n('customTag'); });
31 assertThrows(function() { I18nBehavior.i18n('javascriptHref'); }); 31 assertThrows(function() { I18nBehavior.i18n('javascriptHref'); });
32 assertThrows(function() { I18nBehavior.i18n('script'); }); 32 assertThrows(function() { I18nBehavior.i18n('script'); });
33 } 33 }
34 34
35 function testI18nAdvanced() { 35 function testI18nAdvanced() {
36 assertEquals(
37 allowedByDefault,
38 I18nBehavior.i18nAdvanced('allowedByDefault'));
36 I18nBehavior.i18nAdvanced('customAttr', { 39 I18nBehavior.i18nAdvanced('customAttr', {
37 attrs: { 40 attrs: {
38 is: function(el, val) { 41 is: function(el, val) {
39 return el.tagName == 'A' && val == 'action-link'; 42 return el.tagName == 'A' && val == 'action-link';
40 }, 43 },
41 }, 44 },
42 }); 45 });
43 I18nBehavior.i18nAdvanced('customTag', {tags: ['X-FOO']}); 46 I18nBehavior.i18nAdvanced('customTag', {tags: ['X-FOO']});
44 } 47 }
45 48
46 function testI18nDynamic() { 49 function testI18nDynamic() {
47 var locale = 'en'; 50 var locale = 'en';
48 assertEquals(text, I18nBehavior.i18nDynamic(locale, 'text')); 51 assertEquals(text, I18nBehavior.i18nDynamic(locale, 'text'));
49 } 52 }
50 53
51 function testI18nExists() { 54 function testI18nExists() {
52 assertTrue(I18nBehavior.i18nExists('text')); 55 assertTrue(I18nBehavior.i18nExists('text'));
53 assertFalse(I18nBehavior.i18nExists('missingText')); 56 assertFalse(I18nBehavior.i18nExists('missingText'));
54 } 57 }
55 58
56 </script> 59 </script>
57 </body> 60 </body>
58 </html> 61 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698