OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library CssStyleDeclarationTest; |
| 6 import 'package:unittest/unittest.dart'; |
| 7 import 'package:unittest/html_config.dart'; |
| 8 import 'dart:html'; |
| 9 import 'dart:async'; |
| 10 import 'utils.dart'; |
| 11 |
| 12 main() { |
| 13 useHtmlConfiguration(); |
| 14 |
| 15 createTestStyle() { |
| 16 return new CssStyleDeclaration.css(""" |
| 17 color: blue; |
| 18 width: 2px !important; |
| 19 """); |
| 20 }; |
| 21 |
| 22 test('default constructor is empty', () { |
| 23 var style = new CssStyleDeclaration(); |
| 24 expect(style.cssText, isEmpty); |
| 25 expect(style.getPropertyPriority('color'), isEmpty); |
| 26 expect(style.item(0), isEmpty); |
| 27 expect(style, hasLength(0)); |
| 28 // These assertions throw a UnimplementedError in dartium: |
| 29 // expect(style.parentRule, isNull); |
| 30 // expect(style.getPropertyCssValue('color'), isNull); |
| 31 // expect(style.getPropertyShorthand('color'), isNull); |
| 32 }); |
| 33 |
| 34 test('length is wrapped', () { |
| 35 expect(createTestStyle(), hasLength(2)); |
| 36 }); |
| 37 |
| 38 test('getPropertyPriority is wrapped', () { |
| 39 var style = createTestStyle(); |
| 40 expect(style.getPropertyPriority("color"), isEmpty); |
| 41 expect(style.getPropertyPriority("width"), equals("important")); |
| 42 }); |
| 43 |
| 44 test('removeProperty is wrapped', () { |
| 45 var style = createTestStyle(); |
| 46 style.removeProperty("width"); |
| 47 expect(style.cssText.trim(), |
| 48 equals("color: blue;")); |
| 49 }); |
| 50 |
| 51 test('CSS property empty getters and setters', () { |
| 52 var style = createTestStyle(); |
| 53 expect(style.border, equals("")); |
| 54 |
| 55 style.border = "1px solid blue"; |
| 56 style.border = ""; |
| 57 expect(style.border, equals("")); |
| 58 |
| 59 style.border = "1px solid blue"; |
| 60 style.border = null; |
| 61 expect(style.border, equals("")); |
| 62 }); |
| 63 |
| 64 test('CSS property getters and setters', () { |
| 65 var style = createTestStyle(); |
| 66 expect(style.color, equals("blue")); |
| 67 expect(style.width, equals("2px")); |
| 68 |
| 69 style.color = "red"; |
| 70 style.transform = "translate(10px, 20px)"; |
| 71 |
| 72 expect(style.color, equals("red")); |
| 73 expect(style.transform, equals("translate(10px, 20px)")); |
| 74 }); |
| 75 |
| 76 test('Browser prefixes', () { |
| 77 var element = new DivElement(); |
| 78 element.style.transform = 'translateX(10px)'; |
| 79 document.body.children.add(element); |
| 80 |
| 81 var style = element.getComputedStyle(); |
| 82 // Some browsers will normalize this, so it'll be a matrix rather than |
| 83 // the original string. Just check that it's something other than null. |
| 84 expect(style.transform.length, greaterThan(3)); |
| 85 }); |
| 86 |
| 87 // IE9 requires an extra poke for some properties to get applied. |
| 88 test('IE9 Invalidation', () { |
| 89 var element = new DivElement(); |
| 90 document.body.children.add(element); |
| 91 |
| 92 // Need to wait one tick after the element has been added to the page. |
| 93 new Timer(const Duration(milliseconds: 10), expectAsync(() { |
| 94 element.style.textDecoration = 'underline'; |
| 95 var style = element.getComputedStyle(); |
| 96 expect(style.textDecoration, contains('underline')); |
| 97 })); |
| 98 }); |
| 99 |
| 100 test('Invalid values', () { |
| 101 var element = new DivElement(); |
| 102 // Should not throw an error. |
| 103 element.style.background = 'some_bad_value'; |
| 104 }); |
| 105 |
| 106 test('css multi get', () { |
| 107 var listElement = new Element.html('<ul class="foo">' |
| 108 '<li class="bar" style="background-color: red; border-left: 10px;">' |
| 109 '<li class="baz" style="background-color: black;>' |
| 110 '<li class="baz classy" style="background-color: blue; ">' |
| 111 '</ul>', treeSanitizer: new NullTreeSanitizer()); |
| 112 document.documentElement.children.add(listElement); |
| 113 |
| 114 var elements = document.queryAll('li'); |
| 115 expect(elements.style.backgroundColor, equals('red')); |
| 116 expect(elements.style.borderLeftWidth, equals('10px')); |
| 117 elements = document.queryAll('.baz'); |
| 118 expect(elements.style.backgroundColor, equals('black')); |
| 119 expect(elements.style.borderLeftWidth, equals('')); |
| 120 elements = document.queryAll('.bar'); |
| 121 expect(elements.style.backgroundColor, equals('red')); |
| 122 }); |
| 123 |
| 124 test('css multi set', () { |
| 125 var listElement = new Element.html('<ul class="foo">' |
| 126 '<li class="bar" style="background-color: red; border-left: 10px;">' |
| 127 '<li class="baz" style="background-color: black;>' |
| 128 '<li class="baz" id="wat" style="background-color: blue; ">' |
| 129 '</ul>', treeSanitizer: new NullTreeSanitizer()); |
| 130 document.documentElement.children.add(listElement); |
| 131 |
| 132 var elements = document.queryAll('li'); |
| 133 elements.style.backgroundColor = 'green'; |
| 134 expect(elements.style.backgroundColor, equals('green')); |
| 135 expect(elements.style.borderLeftWidth, equals('10px')); |
| 136 |
| 137 elements = document.queryAll('.baz'); |
| 138 expect(elements.style.backgroundColor, equals('green')); |
| 139 elements.style.backgroundColor = 'yellow'; |
| 140 expect(elements.style.backgroundColor, equals('yellow')); |
| 141 expect(elements.style.borderLeftWidth, equals('')); |
| 142 |
| 143 elements = document.queryAll('.bar'); |
| 144 expect(elements.style.backgroundColor, equals('green')); |
| 145 elements = document.queryAll('#wat'); |
| 146 expect(elements.style.backgroundColor, equals('yellow')); |
| 147 |
| 148 elements.style.borderLeftWidth = '18px'; |
| 149 expect(elements.style.borderLeftWidth, equals('18px')); |
| 150 elements = document.queryAll('li'); |
| 151 expect(elements.style.borderLeftWidth, equals('10px')); |
| 152 }); |
| 153 |
| 154 test('supports property', () { |
| 155 expect(document.body.style.supportsProperty('bogus-property'), false); |
| 156 expect(document.body.style.supportsProperty('background'), true); |
| 157 expect(document.body.style.supportsProperty('borderBottomWidth'), true); |
| 158 expect(document.body.style.supportsProperty('animation'), true); |
| 159 }); |
| 160 } |
OLD | NEW |