| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 // This file provides |assert_selection(sample, tester, expectedText)| assertion | 7 // This file provides |assert_selection(sample, tester, expectedText)| assertion |
| 8 // to W3C test harness to write editing test cases easier. | 8 // to W3C test harness to write editing test cases easier. |
| 9 // | 9 // |
| 10 // |sample| is an HTML fragment text which is inserted as |innerHTML|. It should | 10 // |sample| is an HTML fragment text which is inserted as |innerHTML|. It should |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 } | 459 } |
| 460 this.serializeChildren(element); | 460 this.serializeChildren(element); |
| 461 this.emit(`</${tagName}>`); | 461 this.emit(`</${tagName}>`); |
| 462 } | 462 } |
| 463 | 463 |
| 464 /** | 464 /** |
| 465 * @public | 465 * @public |
| 466 * @param {!HTMLDocument} document | 466 * @param {!HTMLDocument} document |
| 467 */ | 467 */ |
| 468 serialize(document) { | 468 serialize(document) { |
| 469 this.serializeChildren(document.body); | 469 if (document.body) |
| 470 this.serializeChildren(document.body); |
| 471 else |
| 472 this.serializeInternal(document.documentElement); |
| 470 return this.strings_.join(''); | 473 return this.strings_.join(''); |
| 471 } | 474 } |
| 472 | 475 |
| 473 /** | 476 /** |
| 474 * @private | 477 * @private |
| 475 * @param {!HTMLElement} element | 478 * @param {!HTMLElement} element |
| 476 */ | 479 */ |
| 477 serializeChildren(element) { | 480 serializeChildren(element) { |
| 478 /** @type {!Array<!Node>} */ | 481 /** @type {!Array<!Node>} */ |
| 479 const childNodes = Array.from(element.childNodes); | 482 const childNodes = Array.from(element.childNodes); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 throw new Error(`${description}\n` + | 680 throw new Error(`${description}\n` + |
| 678 `\t expected ${expectedText},\n` + | 681 `\t expected ${expectedText},\n` + |
| 679 `\t but got ${actualText},\n` + | 682 `\t but got ${actualText},\n` + |
| 680 `\t sameupto ${commonPrefixOf(expectedText, actualText)}`); | 683 `\t sameupto ${commonPrefixOf(expectedText, actualText)}`); |
| 681 } | 684 } |
| 682 | 685 |
| 683 // Export symbols | 686 // Export symbols |
| 684 window.Sample = Sample; | 687 window.Sample = Sample; |
| 685 window.assert_selection = assertSelection; | 688 window.assert_selection = assertSelection; |
| 686 })(); | 689 })(); |
| OLD | NEW |