OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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 #include "core/editing/markers/CompositionMarkerList.h" | |
6 | |
7 #include "core/dom/Document.h" | |
8 #include "core/editing/markers/DocumentMarkerController.h" | |
9 #include "core/testing/DummyPageHolder.h" | |
10 #include "platform/heap/Handle.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 namespace blink { | |
14 | |
15 template <typename EditingMarkerListType> | |
16 class EditingMarkerListTest : public ::testing::Test { | |
17 protected: | |
18 EditingMarkerListTest() | |
19 : m_dummyPageHolder(DummyPageHolder::create(IntSize(800, 600))), | |
20 m_markerList(new EditingMarkerListType(&markerController())) {} | |
21 | |
22 Document& document() const { return m_dummyPageHolder->document(); } | |
23 DocumentMarkerController& markerController() const { | |
24 return document().markers(); | |
25 } | |
26 | |
27 void setBodyInnerHTML(const char* bodyContent) { | |
28 document().body()->setInnerHTML(String::fromUTF8(bodyContent)); | |
29 } | |
30 | |
31 DocumentMarker* createMarker(unsigned startOffset, unsigned endOffset) { | |
32 return new DocumentMarker(startOffset, endOffset, Color::black, false, | |
33 Color::black); | |
34 } | |
35 | |
36 private: | |
37 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | |
38 | |
39 protected: | |
40 // must be listed after m_dummyPageHolder so it can be initialized later | |
41 Persistent<EditingMarkerListType> m_markerList; | |
42 }; | |
43 | |
44 TYPED_TEST_CASE_P(EditingMarkerListTest); | |
45 | |
46 TYPED_TEST_P(EditingMarkerListTest, Insert) { | |
47 this->m_markerList->insert(this->createMarker(1, 2)); | |
48 this->m_markerList->insert(this->createMarker(2, 3)); | |
49 this->m_markerList->insert(this->createMarker(3, 4)); | |
50 this->m_markerList->insert(this->createMarker(0, 1)); | |
51 | |
52 EXPECT_EQ(4u, this->m_markerList->size()); | |
53 | |
54 EXPECT_EQ(1u, this->m_markerList->at(0)->startOffset()); | |
55 EXPECT_EQ(2u, this->m_markerList->at(0)->endOffset()); | |
56 | |
57 EXPECT_EQ(2u, this->m_markerList->at(1)->startOffset()); | |
58 EXPECT_EQ(3u, this->m_markerList->at(1)->endOffset()); | |
59 | |
60 EXPECT_EQ(3u, this->m_markerList->at(2)->startOffset()); | |
61 EXPECT_EQ(4u, this->m_markerList->at(2)->endOffset()); | |
62 | |
63 EXPECT_EQ(0u, this->m_markerList->at(3)->startOffset()); | |
64 EXPECT_EQ(1u, this->m_markerList->at(3)->endOffset()); | |
65 } | |
66 | |
67 TYPED_TEST_P(EditingMarkerListTest, | |
68 RemoveMarkersSortedDoRemovePartiallyOverlapping) { | |
69 this->m_markerList->insert(this->createMarker(0, 5)); | |
70 this->m_markerList->insert(this->createMarker(5, 10)); | |
71 this->m_markerList->insert(this->createMarker(10, 15)); | |
72 this->m_markerList->insert(this->createMarker(15, 20)); | |
73 this->m_markerList->insert(this->createMarker(20, 25)); | |
74 | |
75 EXPECT_EQ(5u, this->m_markerList->size()); | |
76 | |
77 bool didRemoveMarker = false; | |
78 | |
79 // test no-op remove | |
80 this->m_markerList->removeMarkers(100, 100, true, &didRemoveMarker); | |
81 EXPECT_EQ(didRemoveMarker, false); | |
82 EXPECT_EQ(5u, this->m_markerList->size()); | |
83 | |
84 // remove middle marker | |
85 this->m_markerList->removeMarkers(10, 2, true, &didRemoveMarker); | |
86 EXPECT_EQ(didRemoveMarker, true); | |
87 EXPECT_EQ(4u, this->m_markerList->size()); | |
88 | |
89 EXPECT_EQ(0u, this->m_markerList->at(0)->startOffset()); | |
90 EXPECT_EQ(5u, this->m_markerList->at(0)->endOffset()); | |
91 | |
92 EXPECT_EQ(5u, this->m_markerList->at(1)->startOffset()); | |
93 EXPECT_EQ(10u, this->m_markerList->at(1)->endOffset()); | |
94 | |
95 EXPECT_EQ(15u, this->m_markerList->at(2)->startOffset()); | |
96 EXPECT_EQ(20u, this->m_markerList->at(2)->endOffset()); | |
97 | |
98 EXPECT_EQ(20u, this->m_markerList->at(3)->startOffset()); | |
99 EXPECT_EQ(25u, this->m_markerList->at(3)->endOffset()); | |
100 | |
101 // remove middle two markers | |
102 didRemoveMarker = false; | |
103 this->m_markerList->removeMarkers(7, 9, true, &didRemoveMarker); | |
104 EXPECT_EQ(didRemoveMarker, true); | |
105 EXPECT_EQ(2u, this->m_markerList->size()); | |
106 | |
107 EXPECT_EQ(0u, this->m_markerList->at(0)->startOffset()); | |
108 EXPECT_EQ(5u, this->m_markerList->at(0)->endOffset()); | |
109 | |
110 EXPECT_EQ(20u, this->m_markerList->at(1)->startOffset()); | |
111 EXPECT_EQ(25u, this->m_markerList->at(1)->endOffset()); | |
112 } | |
113 | |
114 TYPED_TEST_P(EditingMarkerListTest, | |
115 RemoveMarkersUnsortedDoRemovePartiallyOverlapping) { | |
116 this->m_markerList->insert(this->createMarker(20, 25)); | |
117 this->m_markerList->insert(this->createMarker(15, 20)); | |
118 this->m_markerList->insert(this->createMarker(10, 15)); | |
119 this->m_markerList->insert(this->createMarker(5, 10)); | |
120 this->m_markerList->insert(this->createMarker(0, 5)); | |
121 | |
122 EXPECT_EQ(5u, this->m_markerList->size()); | |
123 | |
124 bool didRemoveMarker = false; | |
125 | |
126 // test no-op remove | |
127 this->m_markerList->removeMarkers(100, 100, true, &didRemoveMarker); | |
128 EXPECT_EQ(didRemoveMarker, false); | |
129 EXPECT_EQ(5u, this->m_markerList->size()); | |
130 | |
131 // remove middle marker | |
132 this->m_markerList->removeMarkers(10, 2, true, &didRemoveMarker); | |
133 EXPECT_EQ(didRemoveMarker, true); | |
134 EXPECT_EQ(4u, this->m_markerList->size()); | |
135 | |
136 EXPECT_EQ(20u, this->m_markerList->at(0)->startOffset()); | |
137 EXPECT_EQ(25u, this->m_markerList->at(0)->endOffset()); | |
138 | |
139 EXPECT_EQ(15u, this->m_markerList->at(1)->startOffset()); | |
140 EXPECT_EQ(20u, this->m_markerList->at(1)->endOffset()); | |
141 | |
142 EXPECT_EQ(5u, this->m_markerList->at(2)->startOffset()); | |
143 EXPECT_EQ(10u, this->m_markerList->at(2)->endOffset()); | |
144 | |
145 EXPECT_EQ(0u, this->m_markerList->at(3)->startOffset()); | |
146 EXPECT_EQ(5u, this->m_markerList->at(3)->endOffset()); | |
147 | |
148 // remove middle two markers | |
149 didRemoveMarker = false; | |
150 this->m_markerList->removeMarkers(7, 9, true, &didRemoveMarker); | |
151 EXPECT_EQ(didRemoveMarker, true); | |
152 EXPECT_EQ(2u, this->m_markerList->size()); | |
153 | |
154 EXPECT_EQ(20u, this->m_markerList->at(0)->startOffset()); | |
155 EXPECT_EQ(25u, this->m_markerList->at(0)->endOffset()); | |
156 | |
157 EXPECT_EQ(0u, this->m_markerList->at(1)->startOffset()); | |
158 EXPECT_EQ(5u, this->m_markerList->at(1)->endOffset()); | |
159 } | |
160 | |
161 TYPED_TEST_P(EditingMarkerListTest, | |
162 RemoveMarkersSortedDontRemovePartiallyOverlapping) { | |
163 this->m_markerList->insert(this->createMarker(0, 5)); | |
164 this->m_markerList->insert(this->createMarker(5, 10)); | |
165 this->m_markerList->insert(this->createMarker(10, 15)); | |
166 this->m_markerList->insert(this->createMarker(15, 20)); | |
167 this->m_markerList->insert(this->createMarker(20, 25)); | |
168 | |
169 EXPECT_EQ(5u, this->m_markerList->size()); | |
170 | |
171 bool didRemoveMarker = false; | |
172 | |
173 // test no-op remove | |
174 this->m_markerList->removeMarkers(100, 100, false, &didRemoveMarker); | |
175 EXPECT_EQ(didRemoveMarker, false); | |
176 EXPECT_EQ(5u, this->m_markerList->size()); | |
177 | |
178 // remove chunk from beginning of middle marker | |
179 this->m_markerList->removeMarkers(10, 2, false, &didRemoveMarker); | |
180 EXPECT_EQ(didRemoveMarker, true); | |
181 EXPECT_EQ(5u, this->m_markerList->size()); | |
182 | |
183 EXPECT_EQ(0u, this->m_markerList->at(0)->startOffset()); | |
184 EXPECT_EQ(5u, this->m_markerList->at(0)->endOffset()); | |
185 | |
186 EXPECT_EQ(5u, this->m_markerList->at(1)->startOffset()); | |
187 EXPECT_EQ(10u, this->m_markerList->at(1)->endOffset()); | |
188 | |
189 EXPECT_EQ(12u, this->m_markerList->at(2)->startOffset()); | |
190 EXPECT_EQ(15u, this->m_markerList->at(2)->endOffset()); | |
191 | |
192 EXPECT_EQ(15u, this->m_markerList->at(3)->startOffset()); | |
193 EXPECT_EQ(20u, this->m_markerList->at(3)->endOffset()); | |
194 | |
195 EXPECT_EQ(20u, this->m_markerList->at(4)->startOffset()); | |
196 EXPECT_EQ(25u, this->m_markerList->at(4)->endOffset()); | |
197 | |
198 // remove chunk from end of second marker | |
199 didRemoveMarker = false; | |
200 this->m_markerList->removeMarkers(8, 2, false, &didRemoveMarker); | |
201 EXPECT_EQ(didRemoveMarker, true); | |
202 EXPECT_EQ(5u, this->m_markerList->size()); | |
203 | |
204 EXPECT_EQ(0u, this->m_markerList->at(0)->startOffset()); | |
205 EXPECT_EQ(5u, this->m_markerList->at(0)->endOffset()); | |
206 | |
207 EXPECT_EQ(5u, this->m_markerList->at(1)->startOffset()); | |
208 EXPECT_EQ(8u, this->m_markerList->at(1)->endOffset()); | |
209 | |
210 EXPECT_EQ(12u, this->m_markerList->at(2)->startOffset()); | |
211 EXPECT_EQ(15u, this->m_markerList->at(2)->endOffset()); | |
212 | |
213 EXPECT_EQ(15u, this->m_markerList->at(3)->startOffset()); | |
214 EXPECT_EQ(20u, this->m_markerList->at(3)->endOffset()); | |
215 | |
216 EXPECT_EQ(20u, this->m_markerList->at(4)->startOffset()); | |
217 EXPECT_EQ(25u, this->m_markerList->at(4)->endOffset()); | |
218 | |
219 // remove chunk from middle of fourth marker | |
220 didRemoveMarker = false; | |
221 this->m_markerList->removeMarkers(16, 1, false, &didRemoveMarker); | |
222 EXPECT_EQ(didRemoveMarker, true); | |
223 EXPECT_EQ(6u, this->m_markerList->size()); | |
224 | |
225 EXPECT_EQ(0u, this->m_markerList->at(0)->startOffset()); | |
226 EXPECT_EQ(5u, this->m_markerList->at(0)->endOffset()); | |
227 | |
228 EXPECT_EQ(5u, this->m_markerList->at(1)->startOffset()); | |
229 EXPECT_EQ(8u, this->m_markerList->at(1)->endOffset()); | |
230 | |
231 EXPECT_EQ(12u, this->m_markerList->at(2)->startOffset()); | |
232 EXPECT_EQ(15u, this->m_markerList->at(2)->endOffset()); | |
233 | |
234 EXPECT_EQ(15u, this->m_markerList->at(3)->startOffset()); | |
235 EXPECT_EQ(16u, this->m_markerList->at(3)->endOffset()); | |
236 | |
237 EXPECT_EQ(17u, this->m_markerList->at(4)->startOffset()); | |
238 EXPECT_EQ(20u, this->m_markerList->at(4)->endOffset()); | |
239 | |
240 EXPECT_EQ(20u, this->m_markerList->at(5)->startOffset()); | |
241 EXPECT_EQ(25u, this->m_markerList->at(5)->endOffset()); | |
242 | |
243 // remove middle four markers | |
244 didRemoveMarker = false; | |
245 this->m_markerList->removeMarkers(5, 15, false, &didRemoveMarker); | |
246 EXPECT_EQ(didRemoveMarker, true); | |
247 EXPECT_EQ(2u, this->m_markerList->size()); | |
248 | |
249 EXPECT_EQ(0u, this->m_markerList->at(0)->startOffset()); | |
250 EXPECT_EQ(5u, this->m_markerList->at(0)->endOffset()); | |
251 | |
252 EXPECT_EQ(20u, this->m_markerList->at(1)->startOffset()); | |
253 EXPECT_EQ(25u, this->m_markerList->at(1)->endOffset()); | |
254 } | |
255 | |
256 TYPED_TEST_P(EditingMarkerListTest, | |
257 RemoveMarkersUnsortedDontRemovePartiallyOverlapping) { | |
258 this->m_markerList->insert(this->createMarker(20, 25)); | |
259 this->m_markerList->insert(this->createMarker(15, 20)); | |
260 this->m_markerList->insert(this->createMarker(10, 15)); | |
261 this->m_markerList->insert(this->createMarker(5, 10)); | |
262 this->m_markerList->insert(this->createMarker(0, 5)); | |
263 | |
264 EXPECT_EQ(5u, this->m_markerList->size()); | |
265 | |
266 bool didRemoveMarker = false; | |
267 | |
268 // test no-op remove | |
269 this->m_markerList->removeMarkers(100, 100, false, &didRemoveMarker); | |
270 EXPECT_EQ(didRemoveMarker, false); | |
271 EXPECT_EQ(5u, this->m_markerList->size()); | |
272 | |
273 // remove chunk from beginning of middle marker | |
274 this->m_markerList->removeMarkers(10, 2, false, &didRemoveMarker); | |
275 EXPECT_EQ(didRemoveMarker, true); | |
276 EXPECT_EQ(5u, this->m_markerList->size()); | |
277 | |
278 EXPECT_EQ(20u, this->m_markerList->at(0)->startOffset()); | |
279 EXPECT_EQ(25u, this->m_markerList->at(0)->endOffset()); | |
280 | |
281 EXPECT_EQ(15u, this->m_markerList->at(1)->startOffset()); | |
282 EXPECT_EQ(20u, this->m_markerList->at(1)->endOffset()); | |
283 | |
284 EXPECT_EQ(5u, this->m_markerList->at(2)->startOffset()); | |
285 EXPECT_EQ(10u, this->m_markerList->at(2)->endOffset()); | |
286 | |
287 EXPECT_EQ(0u, this->m_markerList->at(3)->startOffset()); | |
288 EXPECT_EQ(5u, this->m_markerList->at(3)->endOffset()); | |
289 | |
290 EXPECT_EQ(12u, this->m_markerList->at(4)->startOffset()); | |
291 EXPECT_EQ(15u, this->m_markerList->at(4)->endOffset()); | |
292 | |
293 // remove chunk from end of middle marker | |
294 didRemoveMarker = false; | |
295 this->m_markerList->removeMarkers(8, 2, false, &didRemoveMarker); | |
296 EXPECT_EQ(didRemoveMarker, true); | |
297 EXPECT_EQ(5u, this->m_markerList->size()); | |
298 | |
299 EXPECT_EQ(20u, this->m_markerList->at(0)->startOffset()); | |
300 EXPECT_EQ(25u, this->m_markerList->at(0)->endOffset()); | |
301 | |
302 EXPECT_EQ(15u, this->m_markerList->at(1)->startOffset()); | |
303 EXPECT_EQ(20u, this->m_markerList->at(1)->endOffset()); | |
304 | |
305 EXPECT_EQ(0u, this->m_markerList->at(2)->startOffset()); | |
306 EXPECT_EQ(5u, this->m_markerList->at(2)->endOffset()); | |
307 | |
308 EXPECT_EQ(12u, this->m_markerList->at(3)->startOffset()); | |
309 EXPECT_EQ(15u, this->m_markerList->at(3)->endOffset()); | |
310 | |
311 EXPECT_EQ(5u, this->m_markerList->at(4)->startOffset()); | |
312 EXPECT_EQ(8u, this->m_markerList->at(4)->endOffset()); | |
313 | |
314 // remove chunk from middle of second marker | |
315 didRemoveMarker = false; | |
316 this->m_markerList->removeMarkers(16, 1, false, &didRemoveMarker); | |
317 EXPECT_EQ(didRemoveMarker, true); | |
318 EXPECT_EQ(6u, this->m_markerList->size()); | |
319 | |
320 EXPECT_EQ(20u, this->m_markerList->at(0)->startOffset()); | |
321 EXPECT_EQ(25u, this->m_markerList->at(0)->endOffset()); | |
322 | |
323 EXPECT_EQ(0u, this->m_markerList->at(1)->startOffset()); | |
324 EXPECT_EQ(5u, this->m_markerList->at(1)->endOffset()); | |
325 | |
326 EXPECT_EQ(12u, this->m_markerList->at(2)->startOffset()); | |
327 EXPECT_EQ(15u, this->m_markerList->at(2)->endOffset()); | |
328 | |
329 EXPECT_EQ(5u, this->m_markerList->at(3)->startOffset()); | |
330 EXPECT_EQ(8u, this->m_markerList->at(3)->endOffset()); | |
331 | |
332 EXPECT_EQ(15u, this->m_markerList->at(4)->startOffset()); | |
333 EXPECT_EQ(16u, this->m_markerList->at(4)->endOffset()); | |
334 | |
335 EXPECT_EQ(17u, this->m_markerList->at(5)->startOffset()); | |
336 EXPECT_EQ(20u, this->m_markerList->at(5)->endOffset()); | |
337 | |
338 // remove all markers except 0 to 5 and 20 to 25 | |
339 didRemoveMarker = false; | |
340 this->m_markerList->removeMarkers(5, 15, false, &didRemoveMarker); | |
341 EXPECT_EQ(didRemoveMarker, true); | |
342 EXPECT_EQ(2u, this->m_markerList->size()); | |
343 | |
344 EXPECT_EQ(20u, this->m_markerList->at(0)->startOffset()); | |
345 EXPECT_EQ(25u, this->m_markerList->at(0)->endOffset()); | |
346 | |
347 EXPECT_EQ(0u, this->m_markerList->at(1)->startOffset()); | |
348 EXPECT_EQ(5u, this->m_markerList->at(1)->endOffset()); | |
349 } | |
350 | |
351 TYPED_TEST_P(EditingMarkerListTest, ShiftMarkersDeletions) { | |
352 this->m_markerList->insert(this->createMarker(0, 5)); | |
353 this->m_markerList->insert(this->createMarker(5, 10)); | |
354 this->m_markerList->insert(this->createMarker(10, 15)); | |
355 this->m_markerList->insert(this->createMarker(15, 20)); | |
356 this->m_markerList->insert(this->createMarker(20, 25)); | |
357 // delete end of second marker, entirety of third marker, and start of fourth | |
358 // marker | |
359 this->m_markerList->shiftMarkers(8, 9, 0); | |
360 | |
361 EXPECT_EQ(4u, this->m_markerList->size()); | |
362 | |
363 EXPECT_EQ(0u, this->m_markerList->at(0)->startOffset()); | |
364 EXPECT_EQ(5u, this->m_markerList->at(0)->endOffset()); | |
365 | |
366 EXPECT_EQ(5u, this->m_markerList->at(1)->startOffset()); | |
367 EXPECT_EQ(8u, this->m_markerList->at(1)->endOffset()); | |
368 | |
369 EXPECT_EQ(8u, this->m_markerList->at(2)->startOffset()); | |
370 EXPECT_EQ(11u, this->m_markerList->at(2)->endOffset()); | |
371 | |
372 EXPECT_EQ(11u, this->m_markerList->at(3)->startOffset()); | |
373 EXPECT_EQ(16u, this->m_markerList->at(3)->endOffset()); | |
374 | |
375 this->m_markerList->clear(); | |
376 this->m_markerList->insert(this->createMarker(5, 10)); | |
377 // delete exactly on a marker | |
378 this->m_markerList->shiftMarkers(5, 5, 0); | |
379 EXPECT_EQ(0u, this->m_markerList->size()); | |
380 | |
381 this->m_markerList->insert(this->createMarker(5, 10)); | |
382 // delete middle of marker | |
rlanday
2017/03/24 03:14:30
If we have a marker on some text and we delete par
| |
383 this->m_markerList->shiftMarkers(6, 3, 0); | |
384 EXPECT_EQ(1u, this->m_markerList->size()); | |
385 EXPECT_EQ(5u, this->m_markerList->at(0)->startOffset()); | |
386 EXPECT_EQ(7u, this->m_markerList->at(0)->endOffset()); | |
387 } | |
388 | |
389 TYPED_TEST_P(EditingMarkerListTest, ShiftMarkersInsertions) { | |
390 this->m_markerList->insert(this->createMarker(0, 5)); | |
391 this->m_markerList->insert(this->createMarker(5, 10)); | |
392 this->m_markerList->insert(this->createMarker(10, 15)); | |
393 // insert in middle of second marker | |
394 this->m_markerList->shiftMarkers(7, 0, 5); | |
395 | |
396 EXPECT_EQ(3u, this->m_markerList->size()); | |
397 | |
398 EXPECT_EQ(0u, this->m_markerList->at(0)->startOffset()); | |
399 EXPECT_EQ(5u, this->m_markerList->at(0)->endOffset()); | |
400 | |
401 EXPECT_EQ(5u, this->m_markerList->at(1)->startOffset()); | |
402 EXPECT_EQ(15u, this->m_markerList->at(1)->endOffset()); | |
403 | |
404 EXPECT_EQ(15u, this->m_markerList->at(2)->startOffset()); | |
405 EXPECT_EQ(20u, this->m_markerList->at(2)->endOffset()); | |
406 | |
407 // insert between first and second markers | |
408 this->m_markerList->shiftMarkers(5, 0, 5); | |
409 | |
410 EXPECT_EQ(3u, this->m_markerList->size()); | |
411 | |
412 EXPECT_EQ(0u, this->m_markerList->at(0)->startOffset()); | |
413 EXPECT_EQ(5u, this->m_markerList->at(0)->endOffset()); | |
414 | |
415 EXPECT_EQ(10u, this->m_markerList->at(1)->startOffset()); | |
416 EXPECT_EQ(20u, this->m_markerList->at(1)->endOffset()); | |
417 | |
418 EXPECT_EQ(20u, this->m_markerList->at(2)->startOffset()); | |
419 EXPECT_EQ(25u, this->m_markerList->at(2)->endOffset()); | |
420 } | |
421 | |
422 TYPED_TEST_P(EditingMarkerListTest, ShiftMarkersReplacements) { | |
423 this->m_markerList->insert(this->createMarker(0, 5)); | |
424 this->m_markerList->insert(this->createMarker(5, 10)); | |
425 this->m_markerList->insert(this->createMarker(10, 15)); | |
426 this->m_markerList->insert(this->createMarker(15, 20)); | |
427 this->m_markerList->insert(this->createMarker(20, 25)); | |
428 | |
429 // Replace entirely of third marker and portions of second and fourth | |
430 this->m_markerList->shiftMarkers(7, 11, 1); | |
431 | |
432 EXPECT_EQ(4u, this->m_markerList->size()); | |
433 | |
434 EXPECT_EQ(0u, this->m_markerList->at(0)->startOffset()); | |
435 EXPECT_EQ(5u, this->m_markerList->at(0)->endOffset()); | |
436 | |
437 EXPECT_EQ(5u, this->m_markerList->at(1)->startOffset()); | |
438 EXPECT_EQ(7u, this->m_markerList->at(1)->endOffset()); | |
439 | |
440 EXPECT_EQ(8u, this->m_markerList->at(2)->startOffset()); | |
441 EXPECT_EQ(10u, this->m_markerList->at(2)->endOffset()); | |
442 | |
443 EXPECT_EQ(10u, this->m_markerList->at(3)->startOffset()); | |
444 EXPECT_EQ(15u, this->m_markerList->at(3)->endOffset()); | |
445 | |
446 // Replace end of first marker | |
447 this->m_markerList->shiftMarkers(3, 2, 1); | |
448 | |
449 EXPECT_EQ(4u, this->m_markerList->size()); | |
450 | |
451 EXPECT_EQ(0u, this->m_markerList->at(0)->startOffset()); | |
452 EXPECT_EQ(4u, this->m_markerList->at(0)->endOffset()); | |
453 | |
454 EXPECT_EQ(4u, this->m_markerList->at(1)->startOffset()); | |
455 EXPECT_EQ(6u, this->m_markerList->at(1)->endOffset()); | |
456 | |
457 EXPECT_EQ(7u, this->m_markerList->at(2)->startOffset()); | |
458 EXPECT_EQ(9u, this->m_markerList->at(2)->endOffset()); | |
459 | |
460 EXPECT_EQ(9u, this->m_markerList->at(3)->startOffset()); | |
461 EXPECT_EQ(14u, this->m_markerList->at(3)->endOffset()); | |
462 | |
463 // Replace beginning of fourth marker | |
464 this->m_markerList->shiftMarkers(9, 2, 1); | |
465 | |
466 EXPECT_EQ(4u, this->m_markerList->size()); | |
467 | |
468 EXPECT_EQ(0u, this->m_markerList->at(0)->startOffset()); | |
469 EXPECT_EQ(4u, this->m_markerList->at(0)->endOffset()); | |
470 | |
471 EXPECT_EQ(4u, this->m_markerList->at(1)->startOffset()); | |
472 EXPECT_EQ(6u, this->m_markerList->at(1)->endOffset()); | |
473 | |
474 EXPECT_EQ(7u, this->m_markerList->at(2)->startOffset()); | |
475 EXPECT_EQ(9u, this->m_markerList->at(2)->endOffset()); | |
476 | |
477 EXPECT_EQ(9u, this->m_markerList->at(3)->startOffset()); | |
478 EXPECT_EQ(13u, this->m_markerList->at(3)->endOffset()); | |
479 } | |
480 | |
481 TYPED_TEST_P(EditingMarkerListTest, CopyMarkers) { | |
482 this->setBodyInnerHTML("<div>012</div>"); | |
483 Element* div = toElement(this->document().body()->firstChild()); | |
484 | |
485 this->m_markerList->insert(this->createMarker(0, 1)); | |
486 this->m_markerList->insert(this->createMarker(1, 2)); | |
487 this->m_markerList->insert(this->createMarker(2, 3)); | |
488 this->m_markerList->insert(this->createMarker(3, 4)); | |
489 | |
490 this->m_markerList->copyMarkers(1, 3, div, -1); | |
491 | |
492 EXPECT_EQ(2u, this->markerController().markers().size()); | |
493 | |
494 EXPECT_EQ(0u, this->markerController().markers()[0]->startOffset()); | |
495 EXPECT_EQ(1u, this->markerController().markers()[0]->endOffset()); | |
496 | |
497 EXPECT_EQ(1u, this->markerController().markers()[1]->startOffset()); | |
498 EXPECT_EQ(2u, this->markerController().markers()[1]->endOffset()); | |
499 } | |
500 | |
501 REGISTER_TYPED_TEST_CASE_P(EditingMarkerListTest, | |
502 Insert, | |
503 RemoveMarkersSortedDoRemovePartiallyOverlapping, | |
504 RemoveMarkersUnsortedDoRemovePartiallyOverlapping, | |
505 RemoveMarkersSortedDontRemovePartiallyOverlapping, | |
506 RemoveMarkersUnsortedDontRemovePartiallyOverlapping, | |
507 ShiftMarkersDeletions, | |
508 ShiftMarkersInsertions, | |
509 ShiftMarkersReplacements, | |
510 CopyMarkers); | |
511 | |
512 typedef ::testing::Types<CompositionMarkerList> TestConfigs; | |
513 INSTANTIATE_TYPED_TEST_CASE_P(EditingMarkerList, | |
514 EditingMarkerListTest, | |
515 TestConfigs); | |
516 | |
517 } // namespace blink | |
OLD | NEW |