Skip to content

Commit

Permalink
Separate entered_left_view tests into separate test files
Browse files Browse the repository at this point in the history
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
srujzs authored and commit-bot@chromium.org committed Mar 4, 2020
1 parent c01417a commit 95bb6d8
Show file tree
Hide file tree
Showing 14 changed files with 485 additions and 317 deletions.
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');
});
});
}
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>
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']);
});
});
}
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>
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 tests/lib_2/html/custom/entered_left_view/shadow_dom_test.dart
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');
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="dart.unittest" content="full-stack-traces">
<title> entered_left_view_test </title>
<title> shadow_dom_test </title>
<style>
.unittest-table { font-family:monospace; border:1px; }
.unittest-pass { background: #6b3;}
Expand All @@ -14,7 +14,7 @@
<script src="/packages/web_components/dart_support.js"></script>
</head>
<body>
<h1> Running entered_left_view_test </h1>
<h1> Running shadow_dom_test </h1>
<script type="text/javascript"
src="/root_dart/pkg/test_runner/lib/src/test_controller.js"></script>
%TEST_SCRIPTS%
Expand Down
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']);
});
});
}
Loading

0 comments on commit 95bb6d8

Please sign in to comment.