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

Side by Side Diff: tests/html/element_test.dart

Issue 18060010: Added offset document measurement to Element. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library ElementTest; 5 library ElementTest;
6 import '../../pkg/unittest/lib/unittest.dart'; 6 import '../../pkg/unittest/lib/unittest.dart';
7 import '../../pkg/unittest/lib/html_individual_config.dart'; 7 import '../../pkg/unittest/lib/html_individual_config.dart';
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:html'; 9 import 'dart:html';
10 import 'dart:svg' as svg; 10 import 'dart:svg' as svg;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 test('computedStyle', () { 52 test('computedStyle', () {
53 final element = document.body; 53 final element = document.body;
54 var style = element.getComputedStyle(); 54 var style = element.getComputedStyle();
55 expect(style.getPropertyValue('left'), 'auto'); 55 expect(style.getPropertyValue('left'), 'auto');
56 }); 56 });
57 57
58 test('client position synchronous', () { 58 test('client position synchronous', () {
59 final container = new Element.tag("div"); 59 final container = new Element.tag("div");
60 container.style.position = 'absolute'; 60 container.style.position = 'absolute';
61 container.style.top = '8px'; 61 container.style.top = '8px';
62 container.style.left = '8px'; 62 container.style.left = '9px';
63 final element = new Element.tag("div"); 63 final element = new Element.tag("div");
64 element.style.width = '200px'; 64 element.style.width = '200px';
65 element.style.height = '200px'; 65 element.style.height = '200px';
66 container.children.add(element); 66 container.children.add(element);
67 document.body.children.add(container); 67 document.body.children.add(container);
68 68
69 expect(element.client.width, greaterThan(100)); 69 expect(element.client.width, greaterThan(100));
70 expect(element.client.height, greaterThan(100)); 70 expect(element.client.height, greaterThan(100));
71 expect(element.offset.width, greaterThan(100)); 71 expect(element.offset.width, greaterThan(100));
72 expect(element.offset.height, greaterThan(100)); 72 expect(element.offset.height, greaterThan(100));
73 expect(element.scrollWidth, greaterThan(100)); 73 expect(element.scrollWidth, greaterThan(100));
74 expect(element.scrollHeight, greaterThan(100)); 74 expect(element.scrollHeight, greaterThan(100));
75 expect(element.getBoundingClientRect().left, 8); 75 expect(element.getBoundingClientRect().left, 9);
76 expect(element.getBoundingClientRect().top, 8); 76 expect(element.getBoundingClientRect().top, 8);
77
78 expect(element.documentOffset.x, 9);
Jennifer Messerly 2013/07/24 23:26:23 slightly confused, should this be "documentOffset"
Emily Fortuna 2013/07/25 00:20:07 oh, whoops. It's docOffset. I had moved a variant
79 expect(element.documentOffset.y, 8);
77 container.remove(); 80 container.remove();
78 }); 81 });
79 }); 82 });
80 83
81 group('constructors', () { 84 group('constructors', () {
82 test('error', () { 85 test('error', () {
83 expect(() => new Element.html('<br/><br/>'), throwsArgumentError); 86 expect(() => new Element.html('<br/><br/>'), throwsArgumentError);
84 }); 87 });
85 88
86 test('.html has no parent', () => 89 test('.html has no parent', () =>
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 expect(filtered, isElementIterable); 721 expect(filtered, isElementIterable);
719 }); 722 });
720 723
721 test('sublist', () { 724 test('sublist', () {
722 var range = makeElList().sublist(1, 3); 725 var range = makeElList().sublist(1, 3);
723 expect(range, isElementList); 726 expect(range, isElementList);
724 expect(range[0], isImageElement); 727 expect(range[0], isImageElement);
725 expect(range[1], isInputElement); 728 expect(range[1], isInputElement);
726 }); 729 });
727 }); 730 });
731 void initPage() {
732 /* Set up the following hierarchy:
733 <ul class="level-1">
734 <li class="item-i">I</li>
735 <li class="item-ii" style="position: relative; top: 4px;">II
736 <ul class="level-2">
737 <li class="item-a">A</li>
738 <li class="item-b"
739 style="position: relative; top: 20px; left: 15px;">B
740 <ul class="level-3">
741 <li class="item-1">1</li>
742 <li class="item-2">2</li>
743 <li class="item-3">3</li>
744 </ul>
745 </li>
746 <li class="item-c">C</li>
747 </ul>
748 </li>
749 <li class="item-iii">III</li>
750 </ul> */
751 var level1 = new UListElement()
752 ..classes.add('level-1')
753 ..children.add(new LIElement()..innerHtml = 'I');
754 var itemii = new LIElement()
755 ..classes.add('item-ii')
756 ..style.position = 'relative'
757 ..style.top = '4px'
758 ..innerHtml = 'II';
759 level1.children.add(itemii);
760 var level2 = new UListElement();
761 itemii.children.add(level2);
762 var itema = new LIElement()
763 ..classes.add('item-a')
764 ..innerHtml = 'A';
765 var item1 = new LIElement()
766 ..classes.add('item-1')
767 ..innerHtml = '1';
768 var item2 = new LIElement()
769 ..classes.add('item-2')
770 ..innerHtml = '2';
771 var level3 = new UListElement()
772 ..children.addAll([item1, item2]);
773 var itemb = new LIElement()
774 ..classes.add('item-b')
775 ..style.position = 'relative'
776 ..style.top = '20px'
777 ..style.left = '150px'
778 ..innerHtml = 'B'
779 ..children.add(level3);
780 level2.children.addAll([itema, itemb, new LIElement()..innerHtml = 'C']);
781 document.body.append(level1);
782
783 var bar = new DivElement()..classes.add('bar');
784 var style = bar.style;
785 style..position = 'absolute'
786 ..top = '8px'
787 ..left = '90px';
788 var baz = new DivElement()..classes.add('baz');
789 style = baz.style;
790 style..position = 'absolute'
791 ..top = '600px'
792 ..left = '7000px';
793 bar.children.add(baz);
794
795 var quux = new DivElement()..classes.add('quux');
796 var qux = new DivElement()
797 ..classes.add('qux')
798 ..children.add(quux);
799
800 document.body.append(bar);
801 document.body.append(qux);
802 }
803
804 group('offset', () {
805 setUp(initPage);
806
807 test('offsetTo', () {
808 var itema = query('.item-a');
809 var itemb = query('.item-b');
810 var item1 = query('.item-1');
811 var itemii = query('.item-ii');
812 var level1 = query('.level-1');
813 var baz = query('.baz');
814 var bar = query('.bar');
815 var qux = query('.qux');
816 var quux = query('.quux');
817
818 var point = itema.offsetTo(itemii);
819 expect(point.x, 40);
820 expect(point.y, inInclusiveRange(17, 20));
821
822 expect(baz.offsetTo(bar).x, 7000);
823 expect(baz.offsetTo(bar).y, inInclusiveRange(599, 604));
824
825 qux.style.position = 'fixed';
826 expect(quux.offsetTo(qux).x, 0);
827 expect(quux.offsetTo(qux).y, 0);
828
829 point = item1.offsetTo(itemb);
830 expect(point.x, 40);
831 expect(point.y, inInclusiveRange(17, 20));
832 point = itemb.offsetTo(itemii);
833 expect(point.x, 190);
834 expect(point.y, inInclusiveRange(54, 60));
835 point = item1.offsetTo(itemii);
836 expect(point.x, 230);
837 expect(point.y, inInclusiveRange(74, 80));
838 });
839
840 test('docOffset', () {
841 var bar = query('.bar');
842 var baz = query('.baz');
843 var qux = query('.qux');
844 var quux = query('.quux');
845 var itema = query('.item-a');
846 var itemb = query('.item-b');
847 var item1 = query('.item-1');
848 var itemii = query('.item-ii');
849
850 expect(itema.docOffset.x, 88);
851 expect(itema.docOffset.y, inInclusiveRange(119, 124));
852
853 expect(itemii.docOffset.x, 48);
854 expect(itemii.docOffset.y, inInclusiveRange(101, 105));
855
856 expect(itemb.docOffset.x, 238);
857 expect(itemb.docOffset.y, inInclusiveRange(157, 165));
858
859 expect(item1.docOffset.x, 278);
860 expect(item1.docOffset.y, inInclusiveRange(175, 182));
861
862 expect(bar.docOffset.x, 90);
863 expect(bar.docOffset.y, 8);
864
865 expect(baz.docOffset.x, 7090);
866 expect(baz.docOffset.y, 608);
867
868 expect(qux.docOffset.x, 8);
869 expect(qux.docOffset.y, inInclusiveRange(222, 232));
870
871 expect(quux.docOffset.x, 8);
872 expect(quux.docOffset.y, inInclusiveRange(222, 232));
873 });
874 });
875
728 } 876 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698