| Index: chrome/test/data/webui/load_time_data_browsertest.js
|
| diff --git a/chrome/test/data/webui/load_time_data_browsertest.js b/chrome/test/data/webui/load_time_data_browsertest.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0ef769fb968225257be23e7e90f155ce3e443dfa
|
| --- /dev/null
|
| +++ b/chrome/test/data/webui/load_time_data_browsertest.js
|
| @@ -0,0 +1,95 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +/**
|
| + * @constructor
|
| + * @extends testing.Test
|
| + */
|
| +function LoadTimeDataTest() {}
|
| +
|
| +LoadTimeDataTest.prototype = {
|
| + __proto__: testing.Test.prototype,
|
| +
|
| + /** @override */
|
| + browsePreload: 'chrome://resources/html/load_time_data.html',
|
| +};
|
| +
|
| +TEST_F('LoadTimeDataTest', 'getStringPieces', function() {
|
| + function assertSubstitutedPieces(expected, var_args) {
|
| + var var_args = Array.prototype.slice.call(arguments, 1);
|
| + var pieces =
|
| + loadTimeData.getSubstitutedStringPieces.apply(loadTimeData, var_args);
|
| + assertDeepEquals(expected, pieces);
|
| +
|
| + // Ensure output matches getStringF.
|
| + assertEquals(
|
| + loadTimeData.substituteString.apply(loadTimeData, var_args),
|
| + pieces.map(p => p.value).join(''));
|
| + }
|
| +
|
| + assertSubstitutedPieces([{value: 'paper', arg: null}], 'paper');
|
| + assertSubstitutedPieces([{value: 'paper', arg: '$1'}], '$1', 'paper');
|
| +
|
| + assertSubstitutedPieces(
|
| + [
|
| + {value: 'i think ', arg: null},
|
| + {value: 'paper mario', arg: '$1'},
|
| + {value: ' is a good game', arg: null},
|
| + ],
|
| + 'i think $1 is a good game', 'paper mario');
|
| +
|
| + assertSubstitutedPieces(
|
| + [
|
| + {value: 'paper mario', arg: '$1'},
|
| + {value: ' costs $', arg: null},
|
| + {value: '60', arg: '$2'},
|
| + ],
|
| + '$1 costs $$$2', 'paper mario', '60');
|
| +
|
| + assertSubstitutedPieces(
|
| + [
|
| + {value: 'paper mario', arg: '$1'},
|
| + {value: ' costs $60', arg: null},
|
| + ],
|
| + '$1 costs $$60', 'paper mario');
|
| +
|
| + assertSubstitutedPieces(
|
| + [
|
| + {value: 'paper mario', arg: '$1'},
|
| + {value: ' costs\n$60 ', arg: null},
|
| + {value: 'today', arg: '$2'},
|
| + ],
|
| + '$1 costs\n$$60 $2', 'paper mario', 'today');
|
| +
|
| + assertSubstitutedPieces(
|
| + [
|
| + {value: '$$', arg: null},
|
| + {value: '1', arg: '$1'},
|
| + {value: '2', arg: '$2'},
|
| + {value: '1', arg: '$1'},
|
| + {value: '$$2', arg: null},
|
| + {value: '2', arg: '$2'},
|
| + {value: '$', arg: null},
|
| + {value: '1', arg: '$1'},
|
| + {value: '$', arg: null},
|
| + ],
|
| + '$$$$$1$2$1$$$$2$2$$$1$$', '1', '2');
|
| +});
|
| +
|
| +TEST_F('LoadTimeDataTest', 'unescapedDollarSign', function() {
|
| + function assertSubstitutionThrows(label) {
|
| + assertThrows(() => {
|
| + loadTimeData.getSubstitutedStringPieces(label);
|
| + }, 'Assertion failed: Unescaped $ found in localized string.');
|
| +
|
| + assertThrows(() => {
|
| + loadTimeData.substituteString(label);
|
| + }, 'Assertion failed: Unescaped $ found in localized string.');
|
| + }
|
| + assertSubstitutionThrows('$');
|
| + assertSubstitutionThrows('$1$$$a2');
|
| + assertSubstitutionThrows('$$$');
|
| + assertSubstitutionThrows('a$');
|
| + assertSubstitutionThrows('a$\n');
|
| +});
|
|
|