Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
|
Jennifer Messerly
2013/07/16 22:03:16
2013
Emily Fortuna
2013/07/18 22:45:02
Done.
| |
| 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 | |
| 4 | |
| 5 library elementDimensionsTest; | |
|
Jennifer Messerly
2013/07/16 22:03:16
hmm, i'm not sure if we have a style guide here, b
Emily Fortuna
2013/07/18 22:45:02
Done.
| |
| 6 import 'package:unittest/unittest.dart'; | |
| 7 import 'package:unittest/html_config.dart'; | |
| 8 import 'dart:html'; | |
| 9 | |
| 10 main() { | |
| 11 useHtmlConfiguration(); | |
| 12 | |
| 13 var isElement = predicate((x) => x is Element, 'is an Element'); | |
| 14 var isCanvasElement = | |
| 15 predicate((x) => x is CanvasElement, 'is a CanvasElement'); | |
| 16 var isDivElement = predicate((x) => x is DivElement, 'is a isDivElement'); | |
| 17 | |
| 18 var div = new DivElement(); | |
| 19 div.id = 'test'; | |
| 20 document.body.nodes.add(div); | |
| 21 | |
| 22 void initDiv() { | |
|
Jennifer Messerly
2013/07/16 22:03:16
maybe this should be a "setUp(() { ... })"
http://
Emily Fortuna
2013/07/18 22:45:02
Done.
| |
| 23 div.style.padding = '4px'; | |
| 24 div.style.border = '0px solid #fff'; | |
|
Jennifer Messerly
2013/07/16 22:03:16
use cascades? :)
Emily Fortuna
2013/07/18 22:45:02
Done. I hadn't originally because what I really wa
| |
| 25 div.style.margin = '6px'; | |
| 26 div.style.height = '10px'; | |
| 27 div.style.width = '11px'; | |
| 28 div.style.boxSizing = 'content-box'; | |
| 29 div.style.overflow = 'visible'; | |
| 30 } | |
| 31 | |
| 32 div.nodes.addAll([ | |
| 33 new DivElement(), | |
| 34 new CanvasElement(), | |
| 35 new DivElement(), | |
| 36 new Text('Hello'), | |
| 37 new DivElement(), | |
| 38 new Text('World'), | |
| 39 new CanvasElement()]); | |
| 40 | |
| 41 test('contentEdge.height', () { | |
| 42 initDiv(); | |
| 43 var all1 = queryAll('#test'); | |
| 44 | |
| 45 expect(all1.contentEdge.height, 10); | |
| 46 expect(all1[0].getComputedStyle().getPropertyValue('height'), '10px'); | |
| 47 | |
| 48 all1.contentEdge.height = new Dimension.px(600); | |
| 49 expect(all1.contentEdge.height, 600); | |
| 50 expect(all1[0].getComputedStyle().getPropertyValue('height'), '600px'); | |
| 51 all1[0].style.visibility = 'hidden'; | |
| 52 expect(all1.contentEdge.height, 600); | |
| 53 all1[0].style.visibility = 'visible'; | |
| 54 | |
| 55 // If user passes in a negative number, set height to 0. | |
| 56 all1.contentEdge.height = new Dimension.px(-1); | |
| 57 expect(all1.contentEdge.height, 0); | |
| 58 | |
| 59 // Adding padding or border shouldn't affect the height for non-box-sizing. | |
| 60 div.style.padding = '20pc'; | |
| 61 expect(all1.contentEdge.height, 0); | |
| 62 div.style.border = '2px solid #fff'; | |
| 63 expect(all1.contentEdge.height, 0); | |
| 64 | |
| 65 initDiv(); | |
|
Jennifer Messerly
2013/07/16 22:03:16
the re-init here makes me wonder if it should be a
Emily Fortuna
2013/07/18 22:45:02
split into individual tests.
| |
| 66 div.style.boxSizing = 'border-box'; | |
| 67 expect(all1.contentEdge.height, 2); | |
| 68 div.style.padding = '20pc'; | |
| 69 expect(all1.contentEdge.height, 0); | |
| 70 div.style.border = '2px solid #fff'; | |
| 71 expect(all1.contentEdge.height, 0); | |
| 72 }); | |
| 73 | |
| 74 test('contentEdge.width', () { | |
| 75 initDiv(); | |
| 76 var all1 = queryAll('#test'); | |
| 77 expect(all1.contentEdge.width, 11); | |
| 78 expect(all1[0].getComputedStyle().getPropertyValue('width'), '11px'); | |
| 79 | |
| 80 all1.contentEdge.width = new Dimension.px(600); | |
| 81 expect(all1.contentEdge.width, 600); | |
| 82 expect(all1[0].getComputedStyle().getPropertyValue('width'), '600px'); | |
| 83 all1[0].style.visibility = 'hidden'; | |
| 84 expect(all1.contentEdge.width, 600); | |
| 85 all1[0].style.visibility = 'visible'; | |
| 86 | |
| 87 // If user passes in a negative number, set width to 0. | |
| 88 all1.contentEdge.width = new Dimension.px(-1); | |
| 89 expect(all1.contentEdge.width, 0); | |
| 90 | |
| 91 // Adding padding or border shouldn't affect the width. | |
| 92 div.style.padding = '20pc'; | |
| 93 expect(all1.contentEdge.width, 0); | |
| 94 div.style.border = '2px solid #fff'; | |
| 95 expect(all1.contentEdge.width, 0); | |
| 96 | |
| 97 initDiv(); | |
| 98 div.style.boxSizing = 'border-box'; | |
| 99 expect(all1.contentEdge.width, 3); | |
| 100 div.style.padding = '20pc'; | |
| 101 expect(all1.contentEdge.width, 0); | |
| 102 div.style.border = '2px solid #fff'; | |
| 103 expect(all1.contentEdge.width, 0); | |
| 104 | |
| 105 }); | |
|
Jennifer Messerly
2013/07/16 22:03:16
newline after
Emily Fortuna
2013/07/18 22:45:02
Done.
| |
| 106 test('paddingEdge.height', () { | |
| 107 initDiv(); | |
| 108 | |
| 109 var all1 = queryAll('#test'); | |
| 110 expect(all1.paddingEdge.height, 18); | |
| 111 all1[0].style.visibility = 'hidden'; | |
| 112 expect(all1.paddingEdge.height, 18); | |
| 113 all1[0].style.visibility = 'visible'; | |
| 114 | |
| 115 // Adding border shouldn't affect the paddingEdge.height. | |
| 116 div.style.border = '2px solid #fff'; | |
| 117 expect(all1.paddingEdge.height, 18); | |
| 118 // Adding padding should affect the paddingEdge.height. | |
| 119 div.style.padding = '20pc'; | |
| 120 expect(all1.paddingEdge.height, 650); | |
| 121 | |
| 122 initDiv(); | |
| 123 div.style.boxSizing = 'border-box'; | |
| 124 expect(all1.paddingEdge.height, 10); | |
| 125 div.style.padding = '20pc'; | |
| 126 expect(all1.paddingEdge.height, 640); | |
| 127 div.style.border = '2px solid #fff'; | |
| 128 expect(all1.paddingEdge.height, 640); | |
| 129 }); | |
| 130 | |
| 131 test('paddingEdge.width', () { | |
| 132 initDiv(); | |
| 133 var all1 = queryAll('#test'); | |
| 134 expect(all1.paddingEdge.width, 19); | |
| 135 all1[0].style.visibility = 'hidden'; | |
| 136 expect(all1.paddingEdge.width, 19); | |
| 137 all1[0].style.visibility = 'visible'; | |
| 138 | |
| 139 // Adding border shouldn't affect the width. | |
| 140 div.style.border = '2px solid #fff'; | |
| 141 expect(all1.paddingEdge.width, 19); | |
| 142 | |
| 143 // Adding padding should affect the paddingEdge.width. | |
| 144 div.style.padding = '20pc'; | |
| 145 expect(all1.paddingEdge.width, 651); | |
| 146 | |
| 147 initDiv(); | |
| 148 div.style.boxSizing = 'border-box'; | |
| 149 expect(all1.paddingEdge.width, 11); | |
| 150 div.style.padding = '20pc'; | |
| 151 expect(all1.paddingEdge.width, 640); | |
| 152 div.style.border = '2px solid #fff'; | |
| 153 expect(all1.paddingEdge.width, 640); | |
| 154 }); | |
| 155 | |
| 156 test('borderEdge.height and marginEdge.height', () { | |
| 157 initDiv(); | |
| 158 | |
| 159 var all1 = queryAll('#test'); | |
| 160 expect(div.borderEdge.height, 18); | |
| 161 expect(div.marginEdge.height, 30); | |
| 162 expect(all1.borderEdge.height, 18); | |
| 163 expect(all1.marginEdge.height, 30); | |
| 164 all1[0].style.visibility = 'hidden'; | |
| 165 expect(all1.borderEdge.height, 18); | |
| 166 all1[0].style.visibility = 'visible'; | |
| 167 | |
| 168 // Adding border should affect the borderEdge.height. | |
| 169 div.style.border = '2px solid #fff'; | |
| 170 expect(all1.borderEdge.height, 22); | |
| 171 // Adding padding should affect the borderEdge.height. | |
| 172 div.style.padding = '20pc'; | |
| 173 expect(all1.borderEdge.height, 654); | |
| 174 expect(all1.marginEdge.height, 666); | |
| 175 | |
| 176 initDiv(); | |
| 177 div.style.boxSizing = 'border-box'; | |
| 178 expect(all1.borderEdge.height, 10); | |
| 179 expect(all1.marginEdge.height, 22); | |
| 180 div.style.padding = '20pc'; | |
| 181 expect(all1.borderEdge.height, 640); | |
| 182 expect(all1.marginEdge.height, 652); | |
| 183 div.style.border = '2px solid #fff'; | |
| 184 expect(all1.borderEdge.height, 644); | |
| 185 expect(all1.marginEdge.height, 656); | |
| 186 }); | |
| 187 | |
| 188 test('borderEdge.width and marginEdge.width', () { | |
| 189 initDiv(); | |
| 190 var all1 = queryAll('#test'); | |
| 191 expect(all1.borderEdge.width, 19); | |
| 192 expect(all1.marginEdge.width, 31); | |
| 193 | |
| 194 // Adding border should affect the width. | |
| 195 div.style.border = '2px solid #fff'; | |
| 196 expect(all1.borderEdge.width, 23); | |
| 197 | |
| 198 // Adding padding should affect the borderEdge.width. | |
| 199 div.style.padding = '20pc'; | |
| 200 expect(all1.borderEdge.width, 655); | |
| 201 expect(all1.marginEdge.width, 667); | |
| 202 | |
| 203 initDiv(); | |
| 204 div.style.boxSizing = 'border-box'; | |
| 205 expect(all1.borderEdge.width, 11); | |
| 206 expect(all1.marginEdge.width, 23); | |
| 207 div.style.padding = '20pc'; | |
| 208 expect(all1.borderEdge.width, 640); | |
| 209 expect(all1.marginEdge.width, 652); | |
| 210 div.style.border = '2px solid #fff'; | |
| 211 expect(all1.borderEdge.width, 644); | |
| 212 expect(all1.marginEdge.width, 656); | |
| 213 }); | |
| 214 | |
| 215 test('left and top', () { | |
| 216 initDiv(); | |
| 217 div.style.border = '1px solid #fff'; | |
| 218 div.style.margin = '6px 7px'; | |
| 219 div.style.padding = '4px 5px'; | |
| 220 var all1 = queryAll('#test'); | |
| 221 | |
| 222 expect(all1.borderEdge.left, all1[0].getBoundingClientRect().left); | |
| 223 expect(all1.borderEdge.top, all1[0].getBoundingClientRect().top); | |
| 224 | |
| 225 expect(all1.contentEdge.left, all1[0].getBoundingClientRect().left + 1 + 5); | |
| 226 expect(all1.contentEdge.top, all1[0].getBoundingClientRect().top + 1 + 4); | |
| 227 | |
| 228 expect(all1.marginEdge.left, all1[0].getBoundingClientRect().left - 7); | |
| 229 expect(all1.marginEdge.top, all1[0].getBoundingClientRect().top - 6); | |
| 230 | |
| 231 expect(all1.paddingEdge.left, all1[0].getBoundingClientRect().left + 1); | |
| 232 expect(all1.paddingEdge.top, all1[0].getBoundingClientRect().top + 1); | |
| 233 }); | |
| 234 | |
| 235 test('setHeight ElementList', () { | |
| 236 initDiv(); | |
| 237 div.style.border = '1px solid #fff'; | |
| 238 div.style.margin = '6px 7px'; | |
| 239 div.style.padding = '4px 5px'; | |
| 240 var all1 = queryAll('div'); | |
| 241 all1.contentEdge.height = new Dimension.px(200); | |
| 242 for (Element elem in all1) { | |
| 243 expect(elem.contentEdge.height, 200); | |
| 244 } | |
| 245 all1.contentEdge.height = new Dimension.px(10); | |
| 246 for (Element elem in all1) { | |
| 247 expect(elem.contentEdge.height, 10); | |
| 248 } | |
| 249 }); | |
| 250 } | |
| OLD | NEW |