OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 /** |
| 6 * @constructor |
| 7 * @extends testing.Test |
| 8 */ |
| 9 function LoadTimeDataTest() {} |
| 10 |
| 11 LoadTimeDataTest.prototype = { |
| 12 __proto__: testing.Test.prototype, |
| 13 |
| 14 /** @override */ |
| 15 browsePreload: 'chrome://resources/html/load_time_data.html', |
| 16 }; |
| 17 |
| 18 TEST_F('LoadTimeDataTest', 'getStringPieces', function() { |
| 19 function assertSubstitutedPieces(expected, var_args) { |
| 20 var var_args = Array.prototype.slice.call(arguments, 1); |
| 21 var pieces = |
| 22 loadTimeData.getSubstitutedStringPieces.apply(loadTimeData, var_args); |
| 23 assertDeepEquals(expected, pieces); |
| 24 |
| 25 // Ensure output matches getStringF. |
| 26 assertEquals( |
| 27 loadTimeData.substituteString.apply(loadTimeData, var_args), |
| 28 pieces.map(p => p.value).join('')); |
| 29 } |
| 30 |
| 31 assertSubstitutedPieces([{value: 'paper', arg: null}], 'paper'); |
| 32 assertSubstitutedPieces([{value: 'paper', arg: '$1'}], '$1', 'paper'); |
| 33 |
| 34 assertSubstitutedPieces( |
| 35 [ |
| 36 {value: 'i think ', arg: null}, |
| 37 {value: 'paper mario', arg: '$1'}, |
| 38 {value: ' is a good game', arg: null}, |
| 39 ], |
| 40 'i think $1 is a good game', 'paper mario'); |
| 41 |
| 42 assertSubstitutedPieces( |
| 43 [ |
| 44 {value: 'paper mario', arg: '$1'}, |
| 45 {value: ' costs $', arg: null}, |
| 46 {value: '60', arg: '$2'}, |
| 47 ], |
| 48 '$1 costs $$$2', 'paper mario', '60'); |
| 49 |
| 50 assertSubstitutedPieces( |
| 51 [ |
| 52 {value: 'paper mario', arg: '$1'}, |
| 53 {value: ' costs $60', arg: null}, |
| 54 ], |
| 55 '$1 costs $$60', 'paper mario'); |
| 56 |
| 57 assertSubstitutedPieces( |
| 58 [ |
| 59 {value: 'paper mario', arg: '$1'}, |
| 60 {value: ' costs\n$60 ', arg: null}, |
| 61 {value: 'today', arg: '$2'}, |
| 62 ], |
| 63 '$1 costs\n$$60 $2', 'paper mario', 'today'); |
| 64 |
| 65 assertSubstitutedPieces( |
| 66 [ |
| 67 {value: '$$', arg: null}, |
| 68 {value: '1', arg: '$1'}, |
| 69 {value: '2', arg: '$2'}, |
| 70 {value: '1', arg: '$1'}, |
| 71 {value: '$$2', arg: null}, |
| 72 {value: '2', arg: '$2'}, |
| 73 {value: '$', arg: null}, |
| 74 {value: '1', arg: '$1'}, |
| 75 {value: '$', arg: null}, |
| 76 ], |
| 77 '$$$$$1$2$1$$$$2$2$$$1$$', '1', '2'); |
| 78 }); |
| 79 |
| 80 TEST_F('LoadTimeDataTest', 'unescapedDollarSign', function() { |
| 81 function assertSubstitutionThrows(label) { |
| 82 assertThrows(() => { |
| 83 loadTimeData.getSubstitutedStringPieces(label); |
| 84 }, 'Assertion failed: Unescaped $ found in localized string.'); |
| 85 |
| 86 assertThrows(() => { |
| 87 loadTimeData.substituteString(label); |
| 88 }, 'Assertion failed: Unescaped $ found in localized string.'); |
| 89 } |
| 90 assertSubstitutionThrows('$'); |
| 91 assertSubstitutionThrows('$1$$$a2'); |
| 92 assertSubstitutionThrows('$$$'); |
| 93 assertSubstitutionThrows('a$'); |
| 94 assertSubstitutionThrows('a$\n'); |
| 95 }); |
OLD | NEW |