forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate entered_left_view tests into separate test files
Note that groups are maintained since group-level setUps are applied to each test. This removes html_individual_config. Change-Id: I62e722252202372880d888161e9b7544b1194034 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138045 Reviewed-by: Sigmund Cherem <sigmund@google.com> Reviewed-by: Bob Nystrom <rnystrom@google.com> Commit-Queue: Srujan Gaddam <srujzs@google.com>
- Loading branch information
Showing
14 changed files
with
485 additions
and
317 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
tests/lib_2/html/custom/entered_left_view/disconnected_subtree_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) 2020 the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
library entered_left_view_test; | ||
|
||
import 'dart:async'; | ||
import 'dart:html'; | ||
import 'dart:js' as js; | ||
|
||
import 'entered_left_view_util.dart'; | ||
import 'package:unittest/unittest.dart'; | ||
|
||
import '../utils.dart'; | ||
|
||
main() { | ||
setUp(setupFunc); | ||
group('disconnected_subtree', () { | ||
var div = new DivElement(); | ||
|
||
setUp(() { | ||
invocations = []; | ||
}); | ||
|
||
test('Enters a disconnected subtree of DOM', () { | ||
div.setInnerHtml('<x-a></x-a>', treeSanitizer: nullSanitizer); | ||
upgradeCustomElements(div); | ||
|
||
expect(invocations, ['created'], | ||
reason: 'the attached callback should not be invoked when inserted ' | ||
'into a disconnected subtree'); | ||
}); | ||
|
||
test('Leaves a disconnected subtree of DOM', () { | ||
div.innerHtml = ''; | ||
expect(invocations, [], | ||
reason: | ||
'the detached callback should not be invoked when removed from a ' | ||
'disconnected subtree'); | ||
}); | ||
|
||
test('Enters a document with a view as a constituent of a subtree', () { | ||
div.setInnerHtml('<x-a></x-a>', treeSanitizer: nullSanitizer); | ||
upgradeCustomElements(div); | ||
invocations = []; | ||
document.body.append(div); | ||
customElementsTakeRecords(); | ||
expect(invocations, ['attached'], | ||
reason: | ||
'the attached callback should be invoked when inserted into a ' | ||
'document with a view as part of a subtree'); | ||
}); | ||
}); | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/lib_2/html/custom/entered_left_view/disconnected_subtree_test.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="dart.unittest" content="full-stack-traces"> | ||
<title> disconnected_subtree_test </title> | ||
<style> | ||
.unittest-table { font-family:monospace; border:1px; } | ||
.unittest-pass { background: #6b3;} | ||
.unittest-fail { background: #d55;} | ||
.unittest-error { background: #a11;} | ||
</style> | ||
<script src="/packages/web_components/webcomponents.js"></script> | ||
<script src="/packages/web_components/dart_support.js"></script> | ||
</head> | ||
<body> | ||
<h1> Running disconnected_subtree_test </h1> | ||
<script type="text/javascript" | ||
src="/root_dart/pkg/test_runner/lib/src/test_controller.js"></script> | ||
%TEST_SCRIPTS% | ||
</body> | ||
</html> |
60 changes: 60 additions & 0 deletions
60
tests/lib_2/html/custom/entered_left_view/entered_left_view_standard_events_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) 2020 the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
library entered_left_view_test; | ||
|
||
import 'dart:async'; | ||
import 'dart:html'; | ||
import 'dart:js' as js; | ||
|
||
import 'entered_left_view_util.dart'; | ||
import 'package:unittest/unittest.dart'; | ||
|
||
import '../utils.dart'; | ||
|
||
main() { | ||
setUp(setupFunc); | ||
group('standard_events', () { | ||
var a; | ||
setUp(() { | ||
invocations = []; | ||
}); | ||
|
||
test('Created', () { | ||
a = new Element.tag('x-a'); | ||
expect(invocations, ['created']); | ||
}); | ||
|
||
test('attached', () { | ||
document.body.append(a); | ||
customElementsTakeRecords(); | ||
expect(invocations, ['attached']); | ||
}); | ||
|
||
test('detached', () { | ||
a.remove(); | ||
customElementsTakeRecords(); | ||
expect(invocations, ['detached']); | ||
}); | ||
|
||
var div = new DivElement(); | ||
test('nesting does not trigger attached', () { | ||
div.append(a); | ||
customElementsTakeRecords(); | ||
expect(invocations, []); | ||
}); | ||
|
||
test('nested entering triggers attached', () { | ||
document.body.append(div); | ||
customElementsTakeRecords(); | ||
expect(invocations, ['attached']); | ||
}); | ||
|
||
test('nested leaving triggers detached', () { | ||
div.remove(); | ||
customElementsTakeRecords(); | ||
expect(invocations, ['detached']); | ||
}); | ||
}); | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/lib_2/html/custom/entered_left_view/entered_left_view_standard_events_test.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="dart.unittest" content="full-stack-traces"> | ||
<title> entered_left_view_standard_events_test </title> | ||
<style> | ||
.unittest-table { font-family:monospace; border:1px; } | ||
.unittest-pass { background: #6b3;} | ||
.unittest-fail { background: #d55;} | ||
.unittest-error { background: #a11;} | ||
</style> | ||
<script src="/packages/web_components/webcomponents.js"></script> | ||
<script src="/packages/web_components/dart_support.js"></script> | ||
</head> | ||
<body> | ||
<h1> Running entered_left_view_standard_events_test </h1> | ||
<script type="text/javascript" | ||
src="/root_dart/pkg/test_runner/lib/src/test_controller.js"></script> | ||
%TEST_SCRIPTS% | ||
</body> | ||
</html> |
80 changes: 80 additions & 0 deletions
80
tests/lib_2/html/custom/entered_left_view/entered_left_view_util.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
library entered_left_view_test; | ||
|
||
import 'dart:async'; | ||
import 'dart:html'; | ||
import 'dart:js' as js; | ||
|
||
import 'package:unittest/unittest.dart'; | ||
|
||
import '../utils.dart'; | ||
|
||
var invocations = []; | ||
|
||
class Foo extends HtmlElement { | ||
factory Foo() => null; | ||
Foo.created() : super.created() { | ||
invocations.add('created'); | ||
} | ||
|
||
void attached() { | ||
invocations.add('attached'); | ||
} | ||
|
||
void enteredView() { | ||
// Deprecated name. Should never be called since we override "attached". | ||
invocations.add('enteredView'); | ||
} | ||
|
||
void detached() { | ||
invocations.add('detached'); | ||
} | ||
|
||
void leftView() { | ||
// Deprecated name. Should never be called since we override "detached". | ||
invocations.add('leftView'); | ||
} | ||
|
||
void attributeChanged(String name, String oldValue, String newValue) { | ||
invocations.add('attribute changed'); | ||
} | ||
} | ||
|
||
// Test that the deprecated callbacks still work. | ||
class FooOldCallbacks extends HtmlElement { | ||
factory FooOldCallbacks() => null; | ||
FooOldCallbacks.created() : super.created() { | ||
invocations.add('created'); | ||
} | ||
|
||
void enteredView() { | ||
invocations.add('enteredView'); | ||
} | ||
|
||
void leftView() { | ||
invocations.add('leftView'); | ||
} | ||
|
||
void attributeChanged(String name, String oldValue, String newValue) { | ||
invocations.add('attribute changed'); | ||
} | ||
} | ||
|
||
var docA = document; | ||
var docB = document.implementation.createHtmlDocument(''); | ||
var nullSanitizer = new NullTreeSanitizer(); | ||
var registeredTypes = false; | ||
|
||
setupFunc() { | ||
// Adapted from Blink's | ||
// fast/dom/custom/attached-detached-document.html test. | ||
return customElementsReady.then((_) { | ||
if (registeredTypes) return; | ||
registeredTypes = true; | ||
document.registerElement2('x-a', {'prototype': Foo}); | ||
document.registerElement2('x-a-old', {'prototype': FooOldCallbacks}); | ||
}); | ||
} |
65 changes: 65 additions & 0 deletions
65
tests/lib_2/html/custom/entered_left_view/shadow_dom_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) 2020 the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
library entered_left_view_test; | ||
|
||
import 'dart:async'; | ||
import 'dart:html'; | ||
import 'dart:js' as js; | ||
|
||
import 'entered_left_view_util.dart'; | ||
import 'package:unittest/unittest.dart'; | ||
|
||
import '../utils.dart'; | ||
|
||
main() { | ||
setUp(setupFunc); | ||
group('shadow_dom', () { | ||
var div; | ||
var s; | ||
setUp(() { | ||
invocations = []; | ||
div = new DivElement(); | ||
s = div.createShadowRoot(); | ||
}); | ||
|
||
tearDown(() { | ||
customElementsTakeRecords(); | ||
}); | ||
|
||
test('Created in Shadow DOM that is not in a document', () { | ||
s.setInnerHtml('<x-a></x-a>', treeSanitizer: nullSanitizer); | ||
upgradeCustomElements(s); | ||
|
||
expect(invocations, ['created'], | ||
reason: 'the attached callback should not be invoked when entering a ' | ||
'Shadow DOM subtree not in the document'); | ||
}); | ||
|
||
test('Leaves Shadow DOM that is not in a document', () { | ||
s.innerHtml = ''; | ||
expect(invocations, [], | ||
reason: 'the detached callback should not be invoked when leaving a ' | ||
'Shadow DOM subtree not in the document'); | ||
}); | ||
|
||
test('Enters a document with a view as a constituent of Shadow DOM', () { | ||
s.setInnerHtml('<x-a></x-a>', treeSanitizer: nullSanitizer); | ||
upgradeCustomElements(s); | ||
|
||
document.body.append(div); | ||
customElementsTakeRecords(); | ||
expect(invocations, ['created', 'attached'], | ||
reason: 'the attached callback should be invoked when inserted into ' | ||
'a document with a view as part of Shadow DOM'); | ||
|
||
div.remove(); | ||
customElementsTakeRecords(); | ||
|
||
expect(invocations, ['created', 'attached', 'detached'], | ||
reason: 'the detached callback should be invoked when removed from a ' | ||
'document with a view as part of Shadow DOM'); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
tests/lib_2/html/custom/entered_left_view/standard_events_old_callback_names_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2020 the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
library entered_left_view_test; | ||
|
||
import 'dart:async'; | ||
import 'dart:html'; | ||
import 'dart:js' as js; | ||
|
||
import 'entered_left_view_util.dart'; | ||
import 'package:unittest/unittest.dart'; | ||
|
||
import '../utils.dart'; | ||
|
||
main() { | ||
setUp(setupFunc); | ||
// TODO(jmesserly): remove after deprecation period. | ||
group('standard_events_old_callback_names', () { | ||
var a; | ||
setUp(() { | ||
invocations = []; | ||
}); | ||
|
||
test('Created', () { | ||
a = new Element.tag('x-a-old'); | ||
expect(invocations, ['created']); | ||
}); | ||
|
||
test('enteredView', () { | ||
document.body.append(a); | ||
customElementsTakeRecords(); | ||
expect(invocations, ['enteredView']); | ||
}); | ||
|
||
test('leftView', () { | ||
a.remove(); | ||
customElementsTakeRecords(); | ||
expect(invocations, ['leftView']); | ||
}); | ||
|
||
var div = new DivElement(); | ||
test('nesting does not trigger enteredView', () { | ||
div.append(a); | ||
customElementsTakeRecords(); | ||
expect(invocations, []); | ||
}); | ||
|
||
test('nested entering triggers enteredView', () { | ||
document.body.append(div); | ||
customElementsTakeRecords(); | ||
expect(invocations, ['enteredView']); | ||
}); | ||
|
||
test('nested leaving triggers leftView', () { | ||
div.remove(); | ||
customElementsTakeRecords(); | ||
expect(invocations, ['leftView']); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.