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

Side by Side Diff: chrome/test/data/webui/load_time_data_browsertest.js

Issue 2917003003: [MD Bookmarks] Support elision of bookmark names in the bookmark toast. (Closed)
Patch Set: fix cros tests 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
(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: '$$', arg: null},
60 {value: '1', arg: '$1'},
61 {value: '2', arg: '$2'},
62 {value: '1', arg: '$1'},
63 {value: '$$2', arg: null},
64 {value: '2', arg: '$2'},
65 {value: '$', arg: null},
66 {value: '1', arg: '$1'},
67 {value: '$', arg: null},
68 ],
69 '$$$$$1$2$1$$$$2$2$$$1$$', '1', '2');
70 });
71
72 TEST_F('LoadTimeDataTest', 'unescapedDollarSign', function() {
73 function assertSubstitutionThrows(label) {
74 assertThrows(() => {
75 loadTimeData.getSubstitutedStringPieces(label);
76 }, 'Assertion failed: Unescaped $ found in localized string.');
77
78 assertThrows(() => {
79 loadTimeData.substituteString(label);
80 }, 'Assertion failed: Unescaped $ found in localized string.');
81 }
82 assertSubstitutionThrows('$');
83 assertSubstitutionThrows('$1$$$a2');
84 assertSubstitutionThrows('$$$');
85 assertSubstitutionThrows('a$');
86 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698