| OLD | NEW |
| 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('CSSStyleDeclarationTest'); | 5 #library('CSSStyleDeclarationTest'); |
| 6 #import('../../lib/unittest/unittest.dart'); | 6 #import('../../lib/unittest/unittest.dart'); |
| 7 #import('../../lib/unittest/html_config.dart'); | 7 #import('../../lib/unittest/html_config.dart'); |
| 8 #import('dart:html'); | 8 #import('dart:html'); |
| 9 | 9 |
| 10 main() { | 10 main() { |
| 11 useHtmlConfiguration(); | 11 useHtmlConfiguration(); |
| 12 | 12 |
| 13 createTestStyle() { | 13 createTestStyle() { |
| 14 return new CSSStyleDeclaration.css(""" | 14 return new CSSStyleDeclaration.css(""" |
| 15 color: blue; | 15 color: blue; |
| 16 width: 2px !important; | 16 width: 2px !important; |
| 17 -webkit-transform: rotate(90deg); | 17 -webkit-transform: rotate(90deg); |
| 18 """); | 18 """); |
| 19 }; | 19 }; |
| 20 | 20 |
| 21 test('default constructor is empty', () { | 21 test('default constructor is empty', () { |
| 22 var style = new CSSStyleDeclaration(); | 22 var style = new CSSStyleDeclaration(); |
| 23 Expect.equals("", style.cssText); | 23 expect(style.cssText, isEmpty); |
| 24 Expect.equals("", style.getPropertyPriority('color')); | 24 expect(style.getPropertyPriority('color'), isEmpty); |
| 25 Expect.equals("", style.item(0)); | 25 expect(style.item(0), isEmpty); |
| 26 Expect.equals(0, style.length); | 26 expect(style, hasLength(0)); |
| 27 // These assertions throw a NotImplementedException in dartium: | 27 // These assertions throw a NotImplementedException in dartium: |
| 28 // Expect.isNull(style.parentRule); | 28 // Expect.isNull(style.parentRule); |
| 29 // Expect.isNull(style.getPropertyCSSValue('color')); | 29 // Expect.isNull(style.getPropertyCSSValue('color')); |
| 30 // Expect.isNull(style.getPropertyShorthand('color')); | 30 // Expect.isNull(style.getPropertyShorthand('color')); |
| 31 }); | 31 }); |
| 32 | 32 |
| 33 test('cssText is wrapped', () { | 33 test('cssText is wrapped', () { |
| 34 var style = createTestStyle(); | 34 var style = createTestStyle(); |
| 35 Expect.equals( | 35 expect(style.cssText, |
| 36 "color: blue; width: 2px !important; -webkit-transform: rotate(90deg); ", | 36 equals("color: blue; width: 2px !important; " |
| 37 style.cssText); | 37 "-webkit-transform: rotate(90deg); ")); |
| 38 style.cssText = "color: red"; | 38 style.cssText = "color: red"; |
| 39 Expect.equals("color: red; ", style.cssText); | 39 expect(style.cssText, equals("color: red; ")); |
| 40 }); | 40 }); |
| 41 | 41 |
| 42 test('length is wrapped', () { | 42 test('length is wrapped', () { |
| 43 Expect.equals(3, createTestStyle().length); | 43 expect(createTestStyle(), hasLength(3)); |
| 44 }); | 44 }); |
| 45 | 45 |
| 46 test('getPropertyPriority is wrapped', () { | 46 test('getPropertyPriority is wrapped', () { |
| 47 var style = createTestStyle(); | 47 var style = createTestStyle(); |
| 48 Expect.equals("", style.getPropertyPriority("color")); | 48 expect(style.getPropertyPriority("color"), isEmpty); |
| 49 Expect.equals("important", style.getPropertyPriority("width")); | 49 expect(style.getPropertyPriority("width"), equals("important")); |
| 50 }); | 50 }); |
| 51 | 51 |
| 52 test('item is wrapped', () { | 52 test('item is wrapped', () { |
| 53 var style = createTestStyle(); | 53 var style = createTestStyle(); |
| 54 Expect.equals("color", style.item(0)); | 54 expect(style.item(0), equals("color")); |
| 55 Expect.equals("width", style.item(1)); | 55 expect(style.item(1), equals("width")); |
| 56 Expect.equals("-webkit-transform", style.item(2)); | 56 expect(style.item(2), equals("-webkit-transform")); |
| 57 }); | 57 }); |
| 58 | 58 |
| 59 test('removeProperty is wrapped', () { | 59 test('removeProperty is wrapped', () { |
| 60 var style = createTestStyle(); | 60 var style = createTestStyle(); |
| 61 style.removeProperty("width"); | 61 style.removeProperty("width"); |
| 62 Expect.equals( | 62 expect(style.cssText, |
| 63 "color: blue; -webkit-transform: rotate(90deg); ", | 63 equals("color: blue; -webkit-transform: rotate(90deg); ")); |
| 64 style.cssText); | |
| 65 }); | 64 }); |
| 66 | 65 |
| 67 test('CSS property getters and setters', () { | 66 test('CSS property getters and setters', () { |
| 68 var style = createTestStyle(); | 67 var style = createTestStyle(); |
| 69 Expect.equals("blue", style.color); | 68 expect(style.color, equals("blue")); |
| 70 Expect.equals("2px", style.width); | 69 expect(style.width, equals("2px")); |
| 71 Expect.equals("rotate(90deg)", style.transform); | 70 expect(style.transform, equals("rotate(90deg)")); |
| 72 | 71 |
| 73 style.color = "red"; | 72 style.color = "red"; |
| 74 style.transform = "translate(10px, 20px)"; | 73 style.transform = "translate(10px, 20px)"; |
| 75 Expect.equals( | 74 expect(style.cssText, |
| 76 "color: red; width: 2px !important; -webkit-transform: translate(10px, 20p
x); ", | 75 equals("color: red; width: 2px !important;" |
| 77 style.cssText); | 76 " -webkit-transform: translate(10px, 20px); ")); |
| 78 }); | 77 }); |
| 79 } | 78 } |
| OLD | NEW |