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

Side by Side Diff: third_party/WebKit/LayoutTests/editing/assert_selection.js

Issue 2105663002: [Editing][Codehealth] Rewrite user-select-all-selection.html with assert_selection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 */ 510 */
511 constructor(sampleText) { 511 constructor(sampleText) {
512 /** @const @type {!HTMLIFame} */ 512 /** @const @type {!HTMLIFame} */
513 this.iframe_ = document.createElement('iframe'); 513 this.iframe_ = document.createElement('iframe');
514 document.body.appendChild(this.iframe_); 514 document.body.appendChild(this.iframe_);
515 /** @const @type {!HTMLDocument} */ 515 /** @const @type {!HTMLDocument} */
516 this.document_ = this.iframe_.contentDocument; 516 this.document_ = this.iframe_.contentDocument;
517 /** @const @type {!Selection} */ 517 /** @const @type {!Selection} */
518 this.selection_ = this.iframe_.contentWindow.getSelection(); 518 this.selection_ = this.iframe_.contentWindow.getSelection();
519 this.selection_.document = this.document_; 519 this.selection_.document = this.document_;
520 this.selection_.document.offsetLeft = this.iframe_.offsetLeft;
yosin_UTC9 2016/06/30 03:47:37 Not sure about these changes. Document doesn't hav
yoichio 2016/07/04 06:28:17 That's because we need iframe offset to use eventS
521 this.selection_.document.offsetTop = this.iframe_.offsetTop;
520 522
521 this.load(sampleText); 523 this.load(sampleText);
522 } 524 }
523 525
524 /** @return {!HTMLDocument} */ 526 /** @return {!HTMLDocument} */
525 get document() { return this.document_; } 527 get document() { return this.document_; }
526 528
527 /** @return {!Selection} */ 529 /** @return {!Selection} */
528 get selection() { return this.selection_; } 530 get selection() { return this.selection_; }
529 531
530 /** 532 /**
531 * @private 533 * @private
532 * @param {string} sampleText 534 * @param {string} sampleText
533 */ 535 */
534 load(sampleText) { 536 load(sampleText) {
535 const anchorMarker = sampleText.indexOf('^'); 537 const anchorMarker = sampleText.indexOf('^');
536 const focusMarker = sampleText.indexOf('|'); 538 const focusMarker = sampleText.indexOf('|');
537 if (focusMarker < 0) { 539 if (focusMarker < 0 && anchorMarker >= 0) {
yosin_UTC9 2016/06/30 03:47:37 We should have another CL for this change to expli
538 throw new Error(`You should specify caret position in "${sampleText}".`); 540 throw new Error(`You should specify caret position in "${sampleText}".`);
539 } 541 }
540 if (focusMarker != sampleText.lastIndexOf('|')) { 542 if (focusMarker != sampleText.lastIndexOf('|')) {
541 throw new Error( 543 throw new Error(
542 `You should have at least one focus marker "|" in "${sampleText}".`); 544 `You should have at least one focus marker "|" in "${sampleText}".`);
543 } 545 }
544 if (anchorMarker != sampleText.lastIndexOf('^')) { 546 if (anchorMarker != sampleText.lastIndexOf('^')) {
545 throw new Error( 547 throw new Error(
546 `You should have at most one anchor marker "^" in "${sampleText}".`); 548 `You should have at most one anchor marker "^" in "${sampleText}".`);
547 } 549 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 // case. 654 // case.
653 if (actualText === expectedText) 655 if (actualText === expectedText)
654 sample.remove(); 656 sample.remove();
655 assert_equals(actualText, expectedText, description); 657 assert_equals(actualText, expectedText, description);
656 } 658 }
657 659
658 // Export symbols 660 // Export symbols
659 window.Sample = Sample; 661 window.Sample = Sample;
660 window.assert_selection = assertSelection; 662 window.assert_selection = assertSelection;
661 })(); 663 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698