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

Side by Side Diff: chrome/test/data/webui/media_router/media_router_search_highlighter.js

Issue 1766473002: [Media Router] Further split media_router_container tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed function param docs Created 4 years, 9 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 /** @fileoverview Suite of tests for media-router-search-highlighter. */
6 cr.define('media_router_search_highlighter', function() {
7 function registerTests() {
8 suite('MediaRouterSearchHighlighter', function() {
9 /**
10 * Media Router Search Highlighted created before each test.
11 * @type {MediaRouterSearchHighlighter}
12 */
13 var searchHighlighter;
14
15 // Checks whether the |textContent| of |searchHighlighter| and its |text|
16 // property matches |expected|.
17 var checkTextContent = function(expected) {
18 assertEquals(expected, searchHighlighter.$['text'].textContent);
19 assertEquals(expected, searchHighlighter.text);
20 }
21
22 // Computes the flat text string that should be displayed when the search
23 // highlighter is given |data|.
24 var computeAnswerText = function(data) {
25 var answer = '';
26 for (var i = 0; i < data.highlightedText.length; ++i) {
27 if (data.plainText[i]) {
28 answer += data.plainText[i];
29 }
30 if (data.highlightedText[i]) {
31 answer += data.highlightedText[i];
32 }
33 }
34 return answer;
35 }
36
37 // Import media_router_search_highlighter.html before running suite.
38 suiteSetup(function() {
39 return PolymerTest.importHtml(
40 'chrome://media-router/elements/media_router_search_highlighter/' +
41 'media_router_search_highlighter.html');
42 });
43
44 // Initialize a media-router-search-highlighter before each test.
45 setup(function(done) {
46 PolymerTest.clearBody();
47 searchHighlighter =
48 document.createElement('media-router-search-highlighter');
49
50
51 document.body.appendChild(searchHighlighter);
52 // Let the search highlighter be created and attached.
53 setTimeout(done);
54 });
55
56 test('text content correct', function(done) {
57 var testInputs = [];
58
59 // Both null and '' should be acceptable in the arrays for producing no
60 // text.
61 var highlightedOnlyMultiple = {
62 highlightedText: ['one', 'two', 'three'],
63 plainText: ['', null, ''],
64 };
65 testInputs.push(highlightedOnlyMultiple);
66
67 var highlightedOnlySingle = {
68 highlightedText: ['onelongsection'],
69 plainText: [null],
70 };
71 testInputs.push(highlightedOnlySingle);
72
73 var htmlHighlightedSingle = {
74 highlightedText: ['<b></b>'],
75 plainText: ['one'],
76 };
77 testInputs.push(htmlHighlightedSingle);
78
79 var htmlHighlightedSplit = {
80 highlightedText: ['<b>', '</b>'],
81 plainText: ['one', 'two'],
82 };
83 testInputs.push(htmlHighlightedSplit);
84
85 var htmlMixedSingle = {
86 highlightedText: ['&amp;'],
87 plainText: ['<&lt;>'],
88 };
89 testInputs.push(htmlMixedSingle);
90
91 var htmlMixedSplit = {
92 highlightedText: ['/>'],
93 plainText: ['<br'],
94 };
95 testInputs.push(htmlMixedSplit);
96
97 var htmlPlainSingle = {
98 highlightedText: [''],
99 plainText: ['<br/>'],
100 };
101 testInputs.push(htmlPlainSingle);
102
103 var htmlPlainSplit = {
104 highlightedText: [null, null],
105 plainText: ['<spa', 'n>'],
106 };
107 testInputs.push(htmlPlainSplit);
108
109 var mixedHighlightedFirstMultiple = {
110 highlightedText: ['first', 'last'],
111 plainText: [null, 'middle'],
112 };
113 testInputs.push(mixedHighlightedFirstMultiple);
114
115 var mixedHighlightedFirstSingle = {
116 highlightedText: ['onlytext', null],
117 plainText: ['', 'plain'],
118 };
119 testInputs.push(mixedHighlightedFirstSingle);
120
121 var mixedPlainFirstMultiple = {
122 highlightedText: ['second', null],
123 plainText: ['first', 'third'],
124 };
125 testInputs.push(mixedPlainFirstMultiple);
126
127 var mixedPlainFirstSingle = {
128 highlightedText: ['', 'highlight'],
129 plainText: ['plaintextonly', ''],
130 };
131 testInputs.push(mixedPlainFirstSingle);
132
133 var plainTextOnlyMultiple = {
134 highlightedText: [null, '', null],
135 plainText: ['one', 'two', 'three'],
136 };
137 testInputs.push(plainTextOnlyMultiple);
138
139 var plainTextOnlySingle = {
140 highlightedText: [''],
141 plainText: ['lonestring'],
142 };
143 testInputs.push(plainTextOnlySingle);
144
145 testInputs.forEach(function(data) {
146 searchHighlighter.data = data;
147 checkTextContent(computeAnswerText(data));
148 });
149 done();
150 });
151 });
152 }
153
154 return {
155 registerTests: registerTests,
156 };
157 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698