From 68dc5655f15dac28d7d439dc164c4b642e7b3f25 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Fri, 21 Aug 2015 08:53:31 -0700 Subject: [PATCH] Migrate some tests to sky/unit/test --- sky/tests/dom/appendChild-expected.txt | 8 ---- .../dom/attribute_collection-expected.txt | 9 ----- .../dom/document_child_mutations-expected.txt | 12 ------ sky/tests/dom/getChildElements-expected.txt | 6 --- sky/tests/dom/insertBefore-expected.txt | 6 --- sky/tests/dom/ownerScope-expected.txt | 7 ---- sky/tests/dom/replaceChild-expected.txt | 8 ---- .../framework/color_accessors-expected.txt | 6 --- sky/tests/framework/color_accessors.dart | 19 --------- sky/tests/painting/canvas-expected.txt | 6 --- sky/tests/raw/color_bounds-expected.txt | 8 ---- sky/tests/raw/color_bounds.dart | 35 ---------------- sky/tests/raw/null_text_crash-expected.txt | 6 --- sky/tests/raw/null_text_crash.dart | 17 -------- sky/tests/styles/inline_style-expected.txt | 6 --- sky/tests/styles/inline_style.dart | 20 ---------- .../styles/inline_style_crash-expected.txt | 6 --- .../test/engine/append_child_test.dart} | 12 +++--- .../engine/attribute_collection_test.dart} | 7 +--- .../test/engine/canvas_test.dart} | 12 +++--- sky/unit/test/engine/color_test.dart | 40 +++++++++++++++++++ .../document_child_mutations_test.dart} | 10 ++--- sky/unit/test/engine/dom_utils.dart | 15 +++++++ .../test/engine/get_child_elements_test.dart} | 7 +--- .../test/engine/inline_style_test.dart} | 21 +++++++--- .../test/engine/insert_before_test.dart} | 8 +--- .../test/engine/owner_scope_test.dart} | 7 +--- .../test/engine/replace_child_test.dart} | 10 ++--- sky/unit/test/engine/text_test.dart | 10 +++++ 29 files changed, 106 insertions(+), 238 deletions(-) delete mode 100644 sky/tests/dom/appendChild-expected.txt delete mode 100644 sky/tests/dom/attribute_collection-expected.txt delete mode 100644 sky/tests/dom/document_child_mutations-expected.txt delete mode 100644 sky/tests/dom/getChildElements-expected.txt delete mode 100644 sky/tests/dom/insertBefore-expected.txt delete mode 100644 sky/tests/dom/ownerScope-expected.txt delete mode 100644 sky/tests/dom/replaceChild-expected.txt delete mode 100644 sky/tests/framework/color_accessors-expected.txt delete mode 100644 sky/tests/framework/color_accessors.dart delete mode 100644 sky/tests/painting/canvas-expected.txt delete mode 100644 sky/tests/raw/color_bounds-expected.txt delete mode 100644 sky/tests/raw/color_bounds.dart delete mode 100644 sky/tests/raw/null_text_crash-expected.txt delete mode 100644 sky/tests/raw/null_text_crash.dart delete mode 100644 sky/tests/styles/inline_style-expected.txt delete mode 100644 sky/tests/styles/inline_style.dart delete mode 100644 sky/tests/styles/inline_style_crash-expected.txt rename sky/{tests/dom/appendChild.dart => unit/test/engine/append_child_test.dart} (90%) rename sky/{tests/dom/attribute_collection.dart => unit/test/engine/attribute_collection_test.dart} (94%) rename sky/{tests/painting/canvas.dart => unit/test/engine/canvas_test.dart} (68%) create mode 100644 sky/unit/test/engine/color_test.dart rename sky/{tests/dom/document_child_mutations.dart => unit/test/engine/document_child_mutations_test.dart} (95%) create mode 100644 sky/unit/test/engine/dom_utils.dart rename sky/{tests/dom/getChildElements.dart => unit/test/engine/get_child_elements_test.dart} (83%) rename sky/{tests/styles/inline_style_crash.dart => unit/test/engine/inline_style_test.dart} (54%) rename sky/{tests/dom/insertBefore.dart => unit/test/engine/insert_before_test.dart} (72%) rename sky/{tests/dom/ownerScope.dart => unit/test/engine/owner_scope_test.dart} (77%) rename sky/{tests/dom/replaceChild.dart => unit/test/engine/replace_child_test.dart} (92%) create mode 100644 sky/unit/test/engine/text_test.dart diff --git a/sky/tests/dom/appendChild-expected.txt b/sky/tests/dom/appendChild-expected.txt deleted file mode 100644 index 66cd2b233ec..00000000000 --- a/sky/tests/dom/appendChild-expected.txt +++ /dev/null @@ -1,8 +0,0 @@ -unittest-suite-wait-for-done -PASS: should throw with invalid arguments -PASS: should insert children -PASS: should insert children with a fragment - -All 3 tests passed. -unittest-suite-success -DONE diff --git a/sky/tests/dom/attribute_collection-expected.txt b/sky/tests/dom/attribute_collection-expected.txt deleted file mode 100644 index 4148c22b22d..00000000000 --- a/sky/tests/dom/attribute_collection-expected.txt +++ /dev/null @@ -1,9 +0,0 @@ -unittest-suite-wait-for-done -PASS: should get by index -PASS: should set by name -PASS: should be case sensitive -PASS: should not live update - -All 4 tests passed. -unittest-suite-success -DONE diff --git a/sky/tests/dom/document_child_mutations-expected.txt b/sky/tests/dom/document_child_mutations-expected.txt deleted file mode 100644 index 31bb91109a7..00000000000 --- a/sky/tests/dom/document_child_mutations-expected.txt +++ /dev/null @@ -1,12 +0,0 @@ -unittest-suite-wait-for-done -PASS: should allow replacing the document element -PASS: should allow replacing a text child with an element -PASS: should allow replacing the document element with text -PASS: should allow inserting text with a fragment -PASS: should allow replacing the document element with a fragment -PASS: should throw when inserting multiple elements -PASS: should throw when inserting multiple elements with a fragment - -All 7 tests passed. -unittest-suite-success -DONE diff --git a/sky/tests/dom/getChildElements-expected.txt b/sky/tests/dom/getChildElements-expected.txt deleted file mode 100644 index fd3d56c2ac6..00000000000 --- a/sky/tests/dom/getChildElements-expected.txt +++ /dev/null @@ -1,6 +0,0 @@ -unittest-suite-wait-for-done -PASS: getChildElements should only include immediate children - -All 1 tests passed. -unittest-suite-success -DONE diff --git a/sky/tests/dom/insertBefore-expected.txt b/sky/tests/dom/insertBefore-expected.txt deleted file mode 100644 index 764a0575976..00000000000 --- a/sky/tests/dom/insertBefore-expected.txt +++ /dev/null @@ -1,6 +0,0 @@ -unittest-suite-wait-for-done -PASS: should throw with invalid arguments - -All 1 tests passed. -unittest-suite-success -DONE diff --git a/sky/tests/dom/ownerScope-expected.txt b/sky/tests/dom/ownerScope-expected.txt deleted file mode 100644 index d2ec79f23e0..00000000000 --- a/sky/tests/dom/ownerScope-expected.txt +++ /dev/null @@ -1,7 +0,0 @@ -unittest-suite-wait-for-done -PASS: should return null for elements not a child of a scope -PASS: should return the document for elements in the document scope - -All 2 tests passed. -unittest-suite-success -DONE diff --git a/sky/tests/dom/replaceChild-expected.txt b/sky/tests/dom/replaceChild-expected.txt deleted file mode 100644 index 3d7e353309d..00000000000 --- a/sky/tests/dom/replaceChild-expected.txt +++ /dev/null @@ -1,8 +0,0 @@ -unittest-suite-wait-for-done -PASS: should replace elements -PASS: should replace text -PASS: should replace children with a fragment - -All 3 tests passed. -unittest-suite-success -DONE diff --git a/sky/tests/framework/color_accessors-expected.txt b/sky/tests/framework/color_accessors-expected.txt deleted file mode 100644 index 7d1cee3a956..00000000000 --- a/sky/tests/framework/color_accessors-expected.txt +++ /dev/null @@ -1,6 +0,0 @@ -unittest-suite-wait-for-done -PASS: color accessors should work - -All 1 tests passed. -unittest-suite-success -DONE diff --git a/sky/tests/framework/color_accessors.dart b/sky/tests/framework/color_accessors.dart deleted file mode 100644 index 93b03c670c0..00000000000 --- a/sky/tests/framework/color_accessors.dart +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:sky'; -import '../resources/third_party/unittest/unittest.dart'; -import '../resources/unit.dart'; - -void main() { - initUnit(); - - 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)); - }); -} diff --git a/sky/tests/painting/canvas-expected.txt b/sky/tests/painting/canvas-expected.txt deleted file mode 100644 index ac43fca2423..00000000000 --- a/sky/tests/painting/canvas-expected.txt +++ /dev/null @@ -1,6 +0,0 @@ -unittest-suite-wait-for-done -PASS: matrix access should work - -All 1 tests passed. -unittest-suite-success -DONE diff --git a/sky/tests/raw/color_bounds-expected.txt b/sky/tests/raw/color_bounds-expected.txt deleted file mode 100644 index 27b67a359b2..00000000000 --- a/sky/tests/raw/color_bounds-expected.txt +++ /dev/null @@ -1,8 +0,0 @@ -unittest-suite-wait-for-done -PASS: paint set to black -PASS: color created with out of bounds value -PASS: color created with wildly out of bounds value - -All 3 tests passed. -unittest-suite-success -DONE diff --git a/sky/tests/raw/color_bounds.dart b/sky/tests/raw/color_bounds.dart deleted file mode 100644 index aa63d2b6c3f..00000000000 --- a/sky/tests/raw/color_bounds.dart +++ /dev/null @@ -1,35 +0,0 @@ -import 'dart:sky' as sky; - -import '../resources/third_party/unittest/unittest.dart'; -import '../resources/unit.dart'; - -void main() { - initUnit(); - - test("paint set to black", () { - sky.Color c = new sky.Color(0x00000000); - sky.Paint p = new sky.Paint(); - p.color = c; - expect(c.toString(), equals('Color(0x00000000)')); - }); - - test("color created with out of bounds value", () { - try { - sky.Color c = new sky.Color(0x100 << 24); - sky.Paint p = new sky.Paint(); - p.color = c; - } catch (e) { - expect(e != null, equals(true)); - } - }); - - test("color created with wildly out of bounds value", () { - try { - sky.Color c = new sky.Color(1 << 1000000); - sky.Paint p = new sky.Paint(); - p.color = c; - } catch (e) { - expect(e != null, equals(true)); - } - }); -} diff --git a/sky/tests/raw/null_text_crash-expected.txt b/sky/tests/raw/null_text_crash-expected.txt deleted file mode 100644 index a442880287a..00000000000 --- a/sky/tests/raw/null_text_crash-expected.txt +++ /dev/null @@ -1,6 +0,0 @@ -unittest-suite-wait-for-done -PASS: createText(null) shouldn't crash - -All 1 tests passed. -unittest-suite-success -DONE diff --git a/sky/tests/raw/null_text_crash.dart b/sky/tests/raw/null_text_crash.dart deleted file mode 100644 index 441646ab2a8..00000000000 --- a/sky/tests/raw/null_text_crash.dart +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:sky' as sky; - -import '../resources/third_party/unittest/unittest.dart'; -import '../resources/unit.dart'; - -void main() { - initUnit(); - - test("createText(null) shouldn't crash", () { - var doc = new sky.Document(); - doc.createText(null); - }); -} diff --git a/sky/tests/styles/inline_style-expected.txt b/sky/tests/styles/inline_style-expected.txt deleted file mode 100644 index 0ff3690ee6b..00000000000 --- a/sky/tests/styles/inline_style-expected.txt +++ /dev/null @@ -1,6 +0,0 @@ -unittest-suite-wait-for-done -PASS: should be settable using "style" attribute - -All 1 tests passed. -unittest-suite-success -DONE diff --git a/sky/tests/styles/inline_style.dart b/sky/tests/styles/inline_style.dart deleted file mode 100644 index cd8b6bac2dc..00000000000 --- a/sky/tests/styles/inline_style.dart +++ /dev/null @@ -1,20 +0,0 @@ -import "../resources/third_party/unittest/unittest.dart"; -import "../resources/unit.dart"; - -import "dart:sky"; - -void main() { - initUnit(); - - test('should be settable using "style" attribute', () { - LayoutRoot layoutRoot = new LayoutRoot(); - var document = new 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)')); - }); -} diff --git a/sky/tests/styles/inline_style_crash-expected.txt b/sky/tests/styles/inline_style_crash-expected.txt deleted file mode 100644 index 614448abd42..00000000000 --- a/sky/tests/styles/inline_style_crash-expected.txt +++ /dev/null @@ -1,6 +0,0 @@ -unittest-suite-wait-for-done -PASS: should not crash when setting style to null - -All 1 tests passed. -unittest-suite-success -DONE diff --git a/sky/tests/dom/appendChild.dart b/sky/unit/test/engine/append_child_test.dart similarity index 90% rename from sky/tests/dom/appendChild.dart rename to sky/unit/test/engine/append_child_test.dart index 1a8b1e6bd06..2fc1e41f4b5 100644 --- a/sky/tests/dom/appendChild.dart +++ b/sky/unit/test/engine/append_child_test.dart @@ -1,12 +1,10 @@ -import "../resources/dom_utils.dart"; -import "../resources/third_party/unittest/unittest.dart"; -import "../resources/unit.dart"; +import 'dart:sky'; -import "dart:sky"; +import 'package:test/test.dart'; + +import 'dom_utils.dart'; void main() { - initUnit(); - Document document = new Document(); test("should throw with invalid arguments", () { @@ -18,7 +16,7 @@ void main() { parent.appendChild(null); }, throws); expect(() { - parent.appendChild({tagName: "div"}); + parent.appendChild({"tagName": "div"}); }, throws); }); diff --git a/sky/tests/dom/attribute_collection.dart b/sky/unit/test/engine/attribute_collection_test.dart similarity index 94% rename from sky/tests/dom/attribute_collection.dart rename to sky/unit/test/engine/attribute_collection_test.dart index 87f2c3e0fc4..2619f6afd6b 100644 --- a/sky/tests/dom/attribute_collection.dart +++ b/sky/unit/test/engine/attribute_collection_test.dart @@ -1,11 +1,8 @@ -import "../resources/third_party/unittest/unittest.dart"; -import "../resources/unit.dart"; +import 'dart:sky'; -import "dart:sky"; +import 'package:test/test.dart'; void main() { - initUnit(); - var div; setUp(() { var document = new Document(); diff --git a/sky/tests/painting/canvas.dart b/sky/unit/test/engine/canvas_test.dart similarity index 68% rename from sky/tests/painting/canvas.dart rename to sky/unit/test/engine/canvas_test.dart index 7955774364e..25df2bb2991 100644 --- a/sky/tests/painting/canvas.dart +++ b/sky/unit/test/engine/canvas_test.dart @@ -1,15 +1,13 @@ -import "../resources/dom_utils.dart"; -import "../resources/third_party/unittest/unittest.dart"; -import "../resources/unit.dart"; +import 'dart:sky' as sky; +import 'dart:sky' show Rect, Color, Paint; -import "dart:sky"; +import 'package:test/test.dart'; import 'package:vector_math/vector_math.dart'; void main() { - initUnit(); - PictureRecorder recorder = new PictureRecorder(); - Canvas canvas = new Canvas(recorder, new Rect.fromLTRB(0.0, 0.0, 100.0, 100.0)); + 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! diff --git a/sky/unit/test/engine/color_test.dart b/sky/unit/test/engine/color_test.dart new file mode 100644 index 00000000000..53a74072a08 --- /dev/null +++ b/sky/unit/test/engine/color_test.dart @@ -0,0 +1,40 @@ +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)); + } + }); +} diff --git a/sky/tests/dom/document_child_mutations.dart b/sky/unit/test/engine/document_child_mutations_test.dart similarity index 95% rename from sky/tests/dom/document_child_mutations.dart rename to sky/unit/test/engine/document_child_mutations_test.dart index cc89c4d38fd..d36937b0df4 100644 --- a/sky/tests/dom/document_child_mutations.dart +++ b/sky/unit/test/engine/document_child_mutations_test.dart @@ -1,12 +1,10 @@ -import "../resources/dom_utils.dart"; -import "../resources/third_party/unittest/unittest.dart"; -import "../resources/unit.dart"; +import 'dart:sky'; -import "dart:sky"; +import 'package:test/test.dart'; + +import 'dom_utils.dart'; void main() { - initUnit(); - var doc; setUp(() { diff --git a/sky/unit/test/engine/dom_utils.dart b/sky/unit/test/engine/dom_utils.dart new file mode 100644 index 00000000000..ceb96907dbb --- /dev/null +++ b/sky/unit/test/engine/dom_utils.dart @@ -0,0 +1,15 @@ +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; +} diff --git a/sky/tests/dom/getChildElements.dart b/sky/unit/test/engine/get_child_elements_test.dart similarity index 83% rename from sky/tests/dom/getChildElements.dart rename to sky/unit/test/engine/get_child_elements_test.dart index c5ce427799f..0161c569801 100644 --- a/sky/tests/dom/getChildElements.dart +++ b/sky/unit/test/engine/get_child_elements_test.dart @@ -1,11 +1,8 @@ -import "../resources/third_party/unittest/unittest.dart"; -import "../resources/unit.dart"; +import 'dart:sky'; -import "dart:sky"; +import 'package:test/test.dart'; void main() { - initUnit(); - test("getChildElements should only include immediate children", () { var doc = new Document(); var parent = doc.createElement('parent'); diff --git a/sky/tests/styles/inline_style_crash.dart b/sky/unit/test/engine/inline_style_test.dart similarity index 54% rename from sky/tests/styles/inline_style_crash.dart rename to sky/unit/test/engine/inline_style_test.dart index 9583f020422..148ffca8db8 100644 --- a/sky/tests/styles/inline_style_crash.dart +++ b/sky/unit/test/engine/inline_style_test.dart @@ -1,14 +1,23 @@ -import "../resources/third_party/unittest/unittest.dart"; -import "../resources/unit.dart"; +import 'dart:sky' as sky; -import "dart:sky"; +import 'package:test/test.dart'; void main() { - initUnit(); + 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', () { - LayoutRoot layoutRoot = new LayoutRoot(); - var document = new Document(); + sky.LayoutRoot layoutRoot = new sky.LayoutRoot(); + var document = new sky.Document(); var foo = document.createElement('foo'); layoutRoot.rootElement = foo; diff --git a/sky/tests/dom/insertBefore.dart b/sky/unit/test/engine/insert_before_test.dart similarity index 72% rename from sky/tests/dom/insertBefore.dart rename to sky/unit/test/engine/insert_before_test.dart index 6318b9f9069..2e6a5fa1e29 100644 --- a/sky/tests/dom/insertBefore.dart +++ b/sky/unit/test/engine/insert_before_test.dart @@ -1,12 +1,8 @@ -import "../resources/dom_utils.dart"; -import "../resources/third_party/unittest/unittest.dart"; -import "../resources/unit.dart"; +import 'dart:sky'; -import "dart:sky"; +import 'package:test/test.dart'; void main() { - initUnit(); - Document document = new Document(); test("should throw with invalid arguments", () { diff --git a/sky/tests/dom/ownerScope.dart b/sky/unit/test/engine/owner_scope_test.dart similarity index 77% rename from sky/tests/dom/ownerScope.dart rename to sky/unit/test/engine/owner_scope_test.dart index 4d2ad0a41cf..6f3d69e6503 100644 --- a/sky/tests/dom/ownerScope.dart +++ b/sky/unit/test/engine/owner_scope_test.dart @@ -1,11 +1,8 @@ -import "../resources/third_party/unittest/unittest.dart"; -import "../resources/unit.dart"; +import 'dart:sky'; -import "dart:sky"; +import 'package:test/test.dart'; void main() { - initUnit(); - test("should return null for elements not a child of a scope", () { var doc = new Document(); var element = doc.createElement("div"); diff --git a/sky/tests/dom/replaceChild.dart b/sky/unit/test/engine/replace_child_test.dart similarity index 92% rename from sky/tests/dom/replaceChild.dart rename to sky/unit/test/engine/replace_child_test.dart index 2ec376636a4..d275693c3b6 100644 --- a/sky/tests/dom/replaceChild.dart +++ b/sky/unit/test/engine/replace_child_test.dart @@ -1,12 +1,10 @@ -import "../resources/dom_utils.dart"; -import "../resources/third_party/unittest/unittest.dart"; -import "../resources/unit.dart"; +import 'dart:sky'; -import "dart:sky"; +import 'package:test/test.dart'; + +import 'dom_utils.dart'; void main() { - initUnit(); - var document = new Document(); test("should replace elements", () { diff --git a/sky/unit/test/engine/text_test.dart b/sky/unit/test/engine/text_test.dart new file mode 100644 index 00000000000..acec02a66cb --- /dev/null +++ b/sky/unit/test/engine/text_test.dart @@ -0,0 +1,10 @@ +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); + }); +}