r1c1 | -r1c2 | -
r2c1 | -r2c2 | -
'''; - - var div = body.querySelectorAll('div[id=testdocument]'); - if (div.length == 1) { - div = div[0]; - } else { - div = new html.DivElement(); - div.id = 'testdocument'; - body.append(div); - } - div.setInnerHtml(bodyHtml, validator: new NoOpNodeValidator()); - - var displayedDiv = html.document.getElementById('mouse'); - displayedDiv.onMouseDown.listen((evt) { - displayedDiv.text = displayedDiv.text + - " MouseDown: ${evt.client.x}, ${evt.client.y}; " - "${evt.screen.x}, ${evt.screen.y}"; - }); - displayedDiv.onMouseUp.listen((evt) { - displayedDiv.text = displayedDiv.text + - " MouseUp: ${evt.client.x}, ${evt.client.y}; " - "${evt.screen.x}, ${evt.screen.y}"; - }); - displayedDiv.onMouseMove.listen((evt) { - displayedDiv.text = displayedDiv.text + - " MouseMove: ${evt.client.x}, ${evt.client.y}; " - "${evt.screen.x}, ${evt.screen.y}"; - }); - - plt.loader = new HtmlPageLoader(div, syncFn, useShadowDom: false); - }); - - group('html specific tests', () { - test('value on text', () async { - var page = await plt.loader.getInstance(PageForAttributesTests); - var handlerCalled = new Completer
r1c1 | -r1c2 | -
r2c1 | -r2c2 | -
'''; - - var templateHtml = ''; - - var div = body.querySelectorAll('div[id=testdocument]'); - if (div.length == 1) { - div = div[0]; - } else { - div = new html.DivElement(); - div.id = 'testdocument'; - body.append(div); - } - div.setInnerHtml(bodyHtml, validator: new NoOpNodeValidator()); - - html.document.getElementsByTagName('a-custom-tag').forEach((element) { - var shadow = element.createShadowRoot(); - shadow.setInnerHtml(templateHtml, validator: new NoOpNodeValidator()); - }); - var displayedDiv = html.document.getElementById('mouse'); - displayedDiv.onMouseDown.listen((evt) { - displayedDiv.text = displayedDiv.text + - " MouseDown: ${evt.client.x}, ${evt.client.y}; " - "${evt.screen.x}, ${evt.screen.y}"; - }); - displayedDiv.onMouseUp.listen((evt) { - displayedDiv.text = displayedDiv.text + - " MouseUp: ${evt.client.x}, ${evt.client.y}; " - "${evt.screen.x}, ${evt.screen.y}"; - }); - displayedDiv.onMouseMove.listen((evt) { - displayedDiv.text = displayedDiv.text + - " MouseMove: ${evt.client.x}, ${evt.client.y}; " - "${evt.screen.x}, ${evt.screen.y}"; - }); - - plt.loader = new HtmlPageLoader(div, syncFn); - }); - - group('html specific tests', () { - test('value on text', () async { - var page = await plt.loader.getInstance(PageForAttributesTests); - var handlerCalled = new Completer
r1c1 | +r1c2 | +
r2c1 | +r2c2 | +
'''; + + var div = body.querySelectorAll('div[id=testdocument]'); + if (div.length == 1) { + div = div[0]; + } else { + div = new html.DivElement(); + div.id = 'testdocument'; + body.append(div); + } + div.setInnerHtml(bodyHtml, validator: new NoOpNodeValidator()); + + var displayedDiv = html.document.getElementById('mouse'); + displayedDiv.onMouseDown.listen((evt) { + displayedDiv.text = displayedDiv.text + + " MouseDown: ${evt.client.x}, ${evt.client.y}; " + "${evt.screen.x}, ${evt.screen.y}"; + }); + displayedDiv.onMouseUp.listen((evt) { + displayedDiv.text = displayedDiv.text + + " MouseUp: ${evt.client.x}, ${evt.client.y}; " + "${evt.screen.x}, ${evt.screen.y}"; + }); + displayedDiv.onMouseMove.listen((evt) { + displayedDiv.text = displayedDiv.text + + " MouseMove: ${evt.client.x}, ${evt.client.y}; " + "${evt.screen.x}, ${evt.screen.y}"; + }); + + return div; +} + +class NoOpNodeValidator implements html.NodeValidator { + bool allowsAttribute( + html.Element element, String attributeName, String value) => true; + bool allowsElement(html.Element element) => true; +} diff --git a/dart/test/data/html_setup.dart b/dart/test/data/html_setup.dart new file mode 100644 index 00000000..f9b5ae9f --- /dev/null +++ b/dart/test/data/html_setup.dart @@ -0,0 +1,110 @@ +// Copyright 2014 Google Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +library pageloader.test.data.html; + +import 'dart:html' as html; + +html.Element setUp() { + var body = html.document.getElementsByTagName('body').first; + const bodyHtml = ''' + +
r1c1 | +r1c2 | +
r2c1 | +r2c2 | +
'''; + + var templateHtml = ''; + + var div = body.querySelectorAll('div[id=testdocument]'); + if (div.length == 1) { + div = div[0]; + } else { + div = new html.DivElement(); + div.id = 'testdocument'; + body.append(div); + } + div.setInnerHtml(bodyHtml, validator: new NoOpNodeValidator()); + + html.document.getElementsByTagName('a-custom-tag').forEach((element) { + var shadow = element.createShadowRoot(); + shadow.setInnerHtml(templateHtml, validator: new NoOpNodeValidator()); + }); + var displayedDiv = html.document.getElementById('mouse'); + displayedDiv.onMouseDown.listen((evt) { + displayedDiv.text = displayedDiv.text + + " MouseDown: ${evt.client.x}, ${evt.client.y}; " + "${evt.screen.x}, ${evt.screen.y}"; + }); + displayedDiv.onMouseUp.listen((evt) { + displayedDiv.text = displayedDiv.text + + " MouseUp: ${evt.client.x}, ${evt.client.y}; " + "${evt.screen.x}, ${evt.screen.y}"; + }); + displayedDiv.onMouseMove.listen((evt) { + displayedDiv.text = displayedDiv.text + + " MouseMove: ${evt.client.x}, ${evt.client.y}; " + "${evt.screen.x}, ${evt.screen.y}"; + }); + + return div; +} + +class NoOpNodeValidator implements html.NodeValidator { + bool allowsAttribute( + html.Element element, String attributeName, String value) => true; + bool allowsElement(html.Element element) => true; +} diff --git a/dart/test/sync/html_no_shadow_dom_test.dart b/dart/test/sync/html_no_shadow_dom_test.dart index 9ba4b817..7c788c04 100644 --- a/dart/test/sync/html_no_shadow_dom_test.dart +++ b/dart/test/sync/html_no_shadow_dom_test.dart @@ -19,6 +19,7 @@ import 'package:unittest/html_enhanced_config.dart' show useHtmlEnhancedConfiguration; import 'package:unittest/unittest.dart'; +import '../data/html_no_shadow_dom_setup.dart' as html_setup; import 'page_objects.dart'; import 'pageloader_test.dart' as plt; @@ -26,84 +27,7 @@ void main() { useHtmlEnhancedConfiguration(); setUp(() { - var body = html.document.getElementsByTagName('body').first; - const bodyHtml = ''' - -
r1c1 | -r1c2 | -
r2c1 | -r2c2 | -
'''; - - var div = body.querySelectorAll('div[id=testdocument]'); - if (div.length == 1) { - div = div[0]; - } else { - div = new html.DivElement(); - div.id = 'testdocument'; - body.append(div); - } - div.setInnerHtml(bodyHtml, validator: new NoOpNodeValidator()); - - var displayedDiv = html.document.getElementById('mouse'); - displayedDiv.onMouseDown.listen((evt) { - displayedDiv.text = displayedDiv.text + - " MouseDown: ${evt.client.x}, ${evt.client.y}; " - "${evt.screen.x}, ${evt.screen.y}"; - }); - displayedDiv.onMouseUp.listen((evt) { - displayedDiv.text = displayedDiv.text + - " MouseUp: ${evt.client.x}, ${evt.client.y}; " - "${evt.screen.x}, ${evt.screen.y}"; - }); - displayedDiv.onMouseMove.listen((evt) { - displayedDiv.text = displayedDiv.text + - " MouseMove: ${evt.client.x}, ${evt.client.y}; " - "${evt.screen.x}, ${evt.screen.y}"; - }); + var div = html_setup.setUp(); plt.loader = new HtmlPageLoader(div, useShadowDom: false); }); diff --git a/dart/test/sync/html_test.dart b/dart/test/sync/html_test.dart index 93563154..5043376a 100644 --- a/dart/test/sync/html_test.dart +++ b/dart/test/sync/html_test.dart @@ -19,6 +19,7 @@ import 'package:unittest/html_enhanced_config.dart' show useHtmlEnhancedConfiguration; import 'package:unittest/unittest.dart'; +import '../data/html_setup.dart' as html_setup; import 'page_objects.dart'; import 'pageloader_test.dart' as plt; @@ -26,90 +27,7 @@ void main() { useHtmlEnhancedConfiguration(); setUp(() { - var body = html.document.getElementsByTagName('body').first; - const bodyHtml = ''' - -
r1c1 | -r1c2 | -
r2c1 | -r2c2 | -
'''; - - var templateHtml = ''; - - var div = body.querySelectorAll('div[id=testdocument]'); - if (div.length == 1) { - div = div[0]; - } else { - div = new html.DivElement(); - div.id = 'testdocument'; - body.append(div); - } - div.setInnerHtml(bodyHtml, validator: new NoOpNodeValidator()); - - html.document.getElementsByTagName('a-custom-tag').forEach((element) { - var shadow = element.createShadowRoot(); - shadow.setInnerHtml(templateHtml, validator: new NoOpNodeValidator()); - }); - var displayedDiv = html.document.getElementById('mouse'); - displayedDiv.onMouseDown.listen((evt) { - displayedDiv.text = displayedDiv.text + - " MouseDown: ${evt.client.x}, ${evt.client.y}; " - "${evt.screen.x}, ${evt.screen.y}"; - }); - displayedDiv.onMouseUp.listen((evt) { - displayedDiv.text = displayedDiv.text + - " MouseUp: ${evt.client.x}, ${evt.client.y}; " - "${evt.screen.x}, ${evt.screen.y}"; - }); - displayedDiv.onMouseMove.listen((evt) { - displayedDiv.text = displayedDiv.text + - " MouseMove: ${evt.client.x}, ${evt.client.y}; " - "${evt.screen.x}, ${evt.screen.y}"; - }); + var div = html_setup.setUp(); plt.loader = new HtmlPageLoader(div); });