Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
c7f528da
Commit
c7f528da
authored
Aug 21, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate some tests to sky/unit/test
parent
b64e1aab
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
463 additions
and
0 deletions
+463
-0
append_child_test.dart
packages/unit/test/engine/append_child_test.dart
+60
-0
attribute_collection_test.dart
packages/unit/test/engine/attribute_collection_test.dart
+61
-0
canvas_test.dart
packages/unit/test/engine/canvas_test.dart
+25
-0
color_test.dart
packages/unit/test/engine/color_test.dart
+40
-0
document_child_mutations_test.dart
packages/unit/test/engine/document_child_mutations_test.dart
+99
-0
dom_utils.dart
packages/unit/test/engine/dom_utils.dart
+15
-0
get_child_elements_test.dart
packages/unit/test/engine/get_child_elements_test.dart
+23
-0
inline_style_test.dart
packages/unit/test/engine/inline_style_test.dart
+38
-0
insert_before_test.dart
packages/unit/test/engine/insert_before_test.dart
+21
-0
owner_scope_test.dart
packages/unit/test/engine/owner_scope_test.dart
+17
-0
replace_child_test.dart
packages/unit/test/engine/replace_child_test.dart
+54
-0
text_test.dart
packages/unit/test/engine/text_test.dart
+10
-0
No files found.
packages/unit/test/engine/append_child_test.dart
0 → 100644
View file @
c7f528da
import
'dart:sky'
;
import
'package:test/test.dart'
;
import
'dom_utils.dart'
;
void
main
(
)
{
Document
document
=
new
Document
();
test
(
"should throw with invalid arguments"
,
()
{
var
parent
=
document
.
createElement
(
"div"
);
expect
(()
{
parent
.
appendChild
();
},
throws
);
expect
(()
{
parent
.
appendChild
(
null
);
},
throws
);
expect
(()
{
parent
.
appendChild
({
"tagName"
:
"div"
});
},
throws
);
});
test
(
"should insert children"
,
()
{
var
parent
=
document
.
createElement
(
"div"
);
var
child1
=
parent
.
appendChild
(
document
.
createElement
(
"div"
));
var
child2
=
parent
.
appendChild
(
document
.
createText
(
" text "
));
var
child3
=
parent
.
appendChild
(
document
.
createText
(
" "
));
var
child4
=
parent
.
appendChild
(
document
.
createElement
(
"div"
));
expect
(
child1
.
parentNode
,
equals
(
parent
));
expect
(
child2
.
parentNode
,
equals
(
parent
));
expect
(
child3
.
parentNode
,
equals
(
parent
));
expect
(
child4
.
parentNode
,
equals
(
parent
));
expect
(
childNodeCount
(
parent
),
equals
(
4
));
expect
(
childElementCount
(
parent
),
equals
(
2
));
});
test
(
"should insert children with a fragment"
,
()
{
var
fragment
=
document
.
createDocumentFragment
();
var
child1
=
fragment
.
appendChild
(
document
.
createElement
(
"div"
));
var
child2
=
fragment
.
appendChild
(
document
.
createText
(
" text "
));
var
child3
=
fragment
.
appendChild
(
document
.
createText
(
" "
));
var
child4
=
fragment
.
appendChild
(
document
.
createElement
(
"div"
));
var
parent
=
document
.
createElement
(
"div"
);
parent
.
appendChild
(
fragment
);
expect
(
child1
.
parentNode
,
equals
(
parent
));
expect
(
child2
.
parentNode
,
equals
(
parent
));
expect
(
child3
.
parentNode
,
equals
(
parent
));
expect
(
child4
.
parentNode
,
equals
(
parent
));
expect
(
childNodeCount
(
parent
),
equals
(
4
));
expect
(
childElementCount
(
parent
),
equals
(
2
));
});
// TODO(dart): These might be real bugs too.
// test("should throw when appending to a text", () {
// var parent = new Text();
// expect(() {
// parent.appendChild(document.createElement("div"));
// }, throws);
// });
}
packages/unit/test/engine/attribute_collection_test.dart
0 → 100644
View file @
c7f528da
import
'dart:sky'
;
import
'package:test/test.dart'
;
void
main
(
)
{
var
div
;
setUp
(()
{
var
document
=
new
Document
();
div
=
document
.
createElement
(
"div"
);
});
test
(
"should get by index"
,
()
{
div
.
setAttribute
(
"attr0"
,
"value0"
);
div
.
setAttribute
(
"attr1"
,
"value1"
);
var
attrs
=
div
.
getAttributes
();
expect
(
attrs
.
length
,
equals
(
2
));
expect
(
attrs
[
0
].
name
,
equals
(
"attr0"
));
expect
(
attrs
[
0
].
value
,
equals
(
"value0"
));
expect
(
attrs
[
1
].
name
,
equals
(
"attr1"
));
expect
(
attrs
[
1
].
value
,
equals
(
"value1"
));
});
test
(
"should set by name"
,
()
{
div
.
setAttribute
(
"attrName"
,
"value0"
);
expect
(
div
.
getAttribute
(
"attrName"
),
equals
(
"value0"
));
expect
(
div
.
getAttributes
()[
0
].
name
,
equals
(
"attrName"
));
expect
(
div
.
getAttributes
()[
0
].
value
,
equals
(
"value0"
));
div
.
setAttribute
(
"attrName"
,
"new value"
);
expect
(
div
.
getAttribute
(
"attrName"
),
equals
(
"new value"
));
expect
(
div
.
getAttributes
()[
0
].
name
,
equals
(
"attrName"
));
expect
(
div
.
getAttributes
()[
0
].
value
,
equals
(
"new value"
));
});
test
(
"should be case sensitive"
,
()
{
div
.
setAttribute
(
"attrName"
,
"value0"
);
expect
(
div
.
getAttribute
(
"attrname"
),
isNull
);
expect
(
div
.
getAttribute
(
"attrName"
),
equals
(
"value0"
));
});
test
(
"should not live update"
,
()
{
div
.
setAttribute
(
"attr0"
,
"0"
);
div
.
setAttribute
(
"attr1"
,
"1"
);
div
.
setAttribute
(
"attr2"
,
"2"
);
var
oldAttributes
=
div
.
getAttributes
();
expect
(
oldAttributes
.
length
,
equals
(
3
));
div
.
removeAttribute
(
"attr1"
);
expect
(
oldAttributes
.
length
,
equals
(
3
));
div
.
setAttribute
(
"attr0"
,
"value0"
);
div
.
setAttribute
(
"attr2"
,
"value2"
);
var
newAttributes
=
div
.
getAttributes
();
expect
(
newAttributes
.
length
,
equals
(
2
));
expect
(
newAttributes
[
0
].
name
,
equals
(
"attr0"
));
expect
(
newAttributes
[
0
].
value
,
equals
(
"value0"
));
expect
(
newAttributes
[
1
].
name
,
equals
(
"attr2"
));
expect
(
newAttributes
[
1
].
value
,
equals
(
"value2"
));
expect
(
newAttributes
,
isNot
(
equals
(
oldAttributes
)));
expect
(
oldAttributes
[
0
].
name
,
equals
(
"attr0"
));
expect
(
oldAttributes
[
0
].
value
,
equals
(
"0"
));
expect
(
oldAttributes
[
1
].
name
,
equals
(
"attr1"
));
expect
(
oldAttributes
[
1
].
value
,
equals
(
"1"
));
expect
(
oldAttributes
[
2
].
name
,
equals
(
"attr2"
));
expect
(
oldAttributes
[
2
].
value
,
equals
(
"2"
));
});
}
packages/unit/test/engine/canvas_test.dart
0 → 100644
View file @
c7f528da
import
'dart:sky'
as
sky
;
import
'dart:sky'
show
Rect
,
Color
,
Paint
;
import
'package:test/test.dart'
;
import
'package:vector_math/vector_math.dart'
;
void
main
(
)
{
sky
.
PictureRecorder
recorder
=
new
sky
.
PictureRecorder
();
sky
.
Canvas
canvas
=
new
sky
.
Canvas
(
recorder
,
new
Rect
.
fromLTRB
(
0.0
,
0.0
,
100.0
,
100.0
));
test
(
"matrix access should work"
,
()
{
// Matrix equality doesn't work!
// https://github.com/google/vector_math.dart/issues/147
expect
(
canvas
.
getTotalMatrix
(),
equals
(
new
Matrix4
.
identity
().
storage
));
Matrix4
matrix
=
new
Matrix4
.
identity
();
// Round-tripping through getTotalMatrix will lose the z value
// So only scale to 1x in the z direction.
matrix
.
scale
(
2.0
,
2.0
,
1.0
);
canvas
.
setMatrix
(
matrix
.
storage
);
canvas
.
drawPaint
(
new
Paint
()..
color
=
const
Color
(
0xFF00FF00
));
expect
(
canvas
.
getTotalMatrix
(),
equals
(
matrix
.
storage
));
});
}
packages/unit/test/engine/color_test.dart
0 → 100644
View file @
c7f528da
import
'dart:sky'
;
import
'package:test/test.dart'
;
void
main
(
)
{
test
(
"color accessors should work"
,
()
{
Color
foo
=
new
Color
(
0x12345678
);
expect
(
foo
.
alpha
,
equals
(
0x12
));
expect
(
foo
.
red
,
equals
(
0x34
));
expect
(
foo
.
green
,
equals
(
0x56
));
expect
(
foo
.
blue
,
equals
(
0x78
));
});
test
(
"paint set to black"
,
()
{
Color
c
=
new
Color
(
0x00000000
);
Paint
p
=
new
Paint
();
p
.
color
=
c
;
expect
(
c
.
toString
(),
equals
(
'Color(0x00000000)'
));
});
test
(
"color created with out of bounds value"
,
()
{
try
{
Color
c
=
new
Color
(
0x100
<<
24
);
Paint
p
=
new
Paint
();
p
.
color
=
c
;
}
catch
(
e
)
{
expect
(
e
!=
null
,
equals
(
true
));
}
});
test
(
"color created with wildly out of bounds value"
,
()
{
try
{
Color
c
=
new
Color
(
1
<<
1000000
);
Paint
p
=
new
Paint
();
p
.
color
=
c
;
}
catch
(
e
)
{
expect
(
e
!=
null
,
equals
(
true
));
}
});
}
packages/unit/test/engine/document_child_mutations_test.dart
0 → 100644
View file @
c7f528da
import
'dart:sky'
;
import
'package:test/test.dart'
;
import
'dom_utils.dart'
;
void
main
(
)
{
var
doc
;
setUp
(()
{
doc
=
new
Document
();
});
test
(
"should allow replacing the document element"
,
()
{
var
oldChild
=
doc
.
appendChild
(
doc
.
createElement
(
"div"
));
expect
(
childElementCount
(
doc
),
equals
(
1
));
var
newChild
=
doc
.
createElement
(
"div"
);
oldChild
.
replaceWith
([
newChild
]);
expect
(
childElementCount
(
doc
),
equals
(
1
));
expect
(
newChild
.
parentNode
,
equals
(
doc
));
expect
(
oldChild
.
parentNode
,
isNull
);
});
test
(
"should allow replacing a text child with an element"
,
()
{
var
oldChild
=
doc
.
appendChild
(
doc
.
createText
(
"text here"
));
expect
(
childElementCount
(
doc
),
equals
(
0
));
expect
(
childNodeCount
(
doc
),
equals
(
1
));
var
newChild
=
doc
.
createElement
(
"div"
);
oldChild
.
replaceWith
([
newChild
]);
expect
(
childElementCount
(
doc
),
equals
(
1
));
expect
(
childNodeCount
(
doc
),
equals
(
1
));
expect
(
newChild
.
parentNode
,
equals
(
doc
));
expect
(
oldChild
.
parentNode
,
isNull
);
});
test
(
"should allow replacing the document element with text"
,
()
{
var
oldChild
=
doc
.
appendChild
(
doc
.
createElement
(
"div"
));
expect
(
childElementCount
(
doc
),
equals
(
1
));
var
newChild
=
doc
.
createText
(
" text "
);
oldChild
.
replaceWith
([
newChild
]);
expect
(
childElementCount
(
doc
),
equals
(
0
));
expect
(
childNodeCount
(
doc
),
equals
(
1
));
expect
(
newChild
.
parentNode
,
equals
(
doc
));
expect
(
oldChild
.
parentNode
,
isNull
);
});
test
(
"should allow inserting text with a fragment"
,
()
{
var
fragment
=
doc
.
createDocumentFragment
();
fragment
.
appendChild
(
doc
.
createText
(
" text "
));
fragment
.
appendChild
(
doc
.
createText
(
" text "
));
expect
(
childNodeCount
(
doc
),
equals
(
0
));
doc
.
appendChild
(
fragment
);
expect
(
childElementCount
(
doc
),
equals
(
0
));
expect
(
childNodeCount
(
doc
),
equals
(
2
));
});
test
(
"should allow replacing the document element with a fragment"
,
()
{
var
oldChild
=
doc
.
appendChild
(
doc
.
createElement
(
"div"
));
expect
(
childElementCount
(
doc
),
equals
(
1
));
var
fragment
=
doc
.
createDocumentFragment
();
fragment
.
appendChild
(
doc
.
createText
(
" text "
));
var
newChild
=
fragment
.
appendChild
(
doc
.
createElement
(
"div"
));
fragment
.
appendChild
(
doc
.
createText
(
" "
));
oldChild
.
replaceWith
([
fragment
]);
expect
(
childElementCount
(
doc
),
equals
(
1
));
expect
(
childNodeCount
(
doc
),
equals
(
3
));
expect
(
newChild
.
parentNode
,
equals
(
doc
));
expect
(
oldChild
.
parentNode
,
isNull
);
});
test
(
"should throw when inserting multiple elements"
,
()
{
doc
.
appendChild
(
doc
.
createElement
(
"div"
));
var
oldChild
=
doc
.
appendChild
(
doc
.
createText
(
" text "
));
expect
(
childElementCount
(
doc
),
equals
(
1
));
var
newChild
=
doc
.
createElement
(
"div"
);
// expect(() {
// doc.replaceChild(newChild, 0);
// }, throws);
// expect(() {
// doc.insertBefore(newChild, oldChild);
// }, throws);
});
test
(
"should throw when inserting multiple elements with a fragment"
,
()
{
var
oldChild
=
doc
.
appendChild
(
doc
.
createElement
(
"div"
));
expect
(
childElementCount
(
doc
),
equals
(
1
));
var
fragment
=
doc
.
createDocumentFragment
();
fragment
.
appendChild
(
doc
.
createText
(
" text "
));
fragment
.
appendChild
(
doc
.
createElement
(
"div"
));
fragment
.
appendChild
(
doc
.
createElement
(
"div"
));
fragment
.
appendChild
(
doc
.
createText
(
" "
));
// expect(() {
// doc.replaceChild(fragment, 0);
// }, throws);
// expect(() {
// doc.insertBefore(fragment, oldChild);
// }, throws);
});
}
packages/unit/test/engine/dom_utils.dart
0 → 100644
View file @
c7f528da
import
'dart:sky'
;
int
childNodeCount
(
parent
)
{
int
count
=
0
;
for
(
Node
node
=
parent
.
firstChild
;
node
!=
null
;
node
=
node
.
nextSibling
)
++
count
;
return
count
;
}
int
childElementCount
(
parent
)
{
int
count
=
0
;
for
(
Element
element
=
parent
.
firstElementChild
;
element
!=
null
;
element
=
element
.
nextElementSibling
)
++
count
;
return
count
;
}
packages/unit/test/engine/get_child_elements_test.dart
0 → 100644
View file @
c7f528da
import
'dart:sky'
;
import
'package:test/test.dart'
;
void
main
(
)
{
test
(
"getChildElements should only include immediate children"
,
()
{
var
doc
=
new
Document
();
var
parent
=
doc
.
createElement
(
'parent'
);
var
child1
=
doc
.
createElement
(
'child1'
);
var
child2
=
doc
.
createElement
(
'child1'
);
var
grandchild
=
doc
.
createElement
(
'grandchild'
);
doc
.
appendChild
(
parent
);
parent
.
appendChild
(
child1
);
parent
.
appendChild
(
child2
);
child1
.
appendChild
(
grandchild
);
var
children
=
parent
.
getChildElements
();
expect
(
children
.
length
,
equals
(
2
));
expect
(
children
[
0
],
equals
(
child1
));
expect
(
children
[
1
],
equals
(
child2
));
});
}
packages/unit/test/engine/inline_style_test.dart
0 → 100644
View file @
c7f528da
import
'dart:sky'
as
sky
;
import
'package:test/test.dart'
;
void
main
(
)
{
test
(
'should be settable using "style" attribute'
,
()
{
sky
.
LayoutRoot
layoutRoot
=
new
sky
.
LayoutRoot
();
var
document
=
new
sky
.
Document
();
var
foo
=
document
.
createElement
(
'foo'
);
layoutRoot
.
rootElement
=
foo
;
foo
.
setAttribute
(
'style'
,
'color: red'
);
expect
(
foo
.
getAttribute
(
'style'
),
equals
(
'color: red'
));
expect
(
foo
.
style
[
"color"
],
equals
(
'rgb(255, 0, 0)'
));
});
test
(
'should not crash when setting style to null'
,
()
{
sky
.
LayoutRoot
layoutRoot
=
new
sky
.
LayoutRoot
();
var
document
=
new
sky
.
Document
();
var
foo
=
document
.
createElement
(
'foo'
);
layoutRoot
.
rootElement
=
foo
;
expect
(
foo
.
style
[
'color'
],
isNull
);
foo
.
style
[
"color"
]
=
null
;
// This used to crash.
expect
(
foo
.
style
[
'color'
],
isNull
);
foo
.
style
[
"color"
]
=
"blue"
;
expect
(
foo
.
style
[
'color'
],
equals
(
"rgb(0, 0, 255)"
));
foo
.
style
[
"color"
]
=
null
;
expect
(
foo
.
style
[
'color'
],
isNull
);
foo
.
style
[
"color"
]
=
"blue"
;
expect
(
foo
.
style
[
'color'
],
equals
(
"rgb(0, 0, 255)"
));
foo
.
style
.
removeProperty
(
"color"
);
expect
(
foo
.
style
[
'color'
],
isNull
);
layoutRoot
.
layout
();
});
}
packages/unit/test/engine/insert_before_test.dart
0 → 100644
View file @
c7f528da
import
'dart:sky'
;
import
'package:test/test.dart'
;
void
main
(
)
{
Document
document
=
new
Document
();
test
(
"should throw with invalid arguments"
,
()
{
var
parent
=
document
.
createElement
(
"div"
);
var
child
=
document
.
createElement
(
"div"
);
parent
.
appendChild
(
child
);
// TODO(eseidel): This should throw!
// expect(() {
// parent.insertBefore([parent]);
// }, throws);
expect
(()
{
child
.
insertBefore
([
parent
]);
},
throws
);
});
}
packages/unit/test/engine/owner_scope_test.dart
0 → 100644
View file @
c7f528da
import
'dart:sky'
;
import
'package:test/test.dart'
;
void
main
(
)
{
test
(
"should return null for elements not a child of a scope"
,
()
{
var
doc
=
new
Document
();
var
element
=
doc
.
createElement
(
"div"
);
expect
(
element
.
owner
,
isNull
);
});
test
(
"should return the document for elements in the document scope"
,
()
{
var
doc
=
new
Document
();
var
element
=
doc
.
createElement
(
"div"
);
doc
.
appendChild
(
element
);
expect
(
element
.
owner
,
equals
(
doc
));
});
}
packages/unit/test/engine/replace_child_test.dart
0 → 100644
View file @
c7f528da
import
'dart:sky'
;
import
'package:test/test.dart'
;
import
'dom_utils.dart'
;
void
main
(
)
{
var
document
=
new
Document
();
test
(
"should replace elements"
,
()
{
var
parent
=
document
.
createElement
(
"div"
);
var
oldChild
=
parent
.
appendChild
(
document
.
createElement
(
"div"
));
var
newChild
=
document
.
createElement
(
"div"
);
oldChild
.
replaceWith
([
newChild
]);
expect
(
oldChild
.
parentNode
,
isNull
);
expect
(
newChild
.
parentNode
,
equals
(
parent
));
});
test
(
"should replace text"
,
()
{
var
parent
=
document
.
createElement
(
"div"
);
var
oldChild
=
parent
.
appendChild
(
document
.
createText
(
" it's a text "
));
var
newChild
=
document
.
createElement
(
"div"
);
oldChild
.
replaceWith
([
newChild
]);
expect
(
oldChild
.
parentNode
,
isNull
);
expect
(
newChild
.
parentNode
,
equals
(
parent
));
});
test
(
"should replace children with a fragment"
,
()
{
var
fragment
=
document
.
createDocumentFragment
();
var
child1
=
fragment
.
appendChild
(
document
.
createElement
(
"div"
));
var
child2
=
fragment
.
appendChild
(
document
.
createText
(
" text "
));
var
child3
=
fragment
.
appendChild
(
document
.
createText
(
" "
));
var
child4
=
fragment
.
appendChild
(
document
.
createElement
(
"div"
));
var
parent
=
document
.
createElement
(
"div"
);
var
oldChild
=
parent
.
appendChild
(
document
.
createElement
(
"div"
));
var
lastChild
=
parent
.
appendChild
(
document
.
createElement
(
"div"
));
oldChild
.
replaceWith
([
fragment
]);
expect
(
child1
.
parentNode
,
equals
(
parent
));
expect
(
child2
.
parentNode
,
equals
(
parent
));
expect
(
child3
.
parentNode
,
equals
(
parent
));
expect
(
child4
.
parentNode
,
equals
(
parent
));
expect
(
oldChild
.
parentNode
,
isNull
);
expect
(
childNodeCount
(
parent
),
equals
(
5
));
expect
(
childElementCount
(
parent
),
equals
(
3
));
expect
(
parent
.
lastChild
,
equals
(
lastChild
));
});
// test("should throw when appending to a text", () {
// var parent = new Text();
// expect(() {
// parent.replaceChild(document.createElement("div"), null);
// }, throws);
// });
}
packages/unit/test/engine/text_test.dart
0 → 100644
View file @
c7f528da
import
'dart:sky'
as
sky
;
import
'package:test/test.dart'
;
void
main
(
)
{
test
(
"createText(null) shouldn't crash"
,
()
{
var
doc
=
new
sky
.
Document
();
doc
.
createText
(
null
);
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment