diff --git a/dart/lib/async/html.dart b/dart/lib/async/html.dart index 65e48ca6..cd0f7b09 100644 --- a/dart/lib/async/html.dart +++ b/dart/lib/async/html.dart @@ -130,15 +130,16 @@ abstract class HtmlPageLoaderElement implements PageLoaderElement { factory HtmlPageLoaderElement(Node node, HtmlPageLoader loader) { if (node is Element) { return new _ElementPageLoaderElement(node, loader); - } else if (node is Document) { + } + if (node is Document) { return new _DocumentPageLoaderElement(node, loader); - } else if (node is ShadowRoot) { + } + if (node is ShadowRoot) { if (loader.useShadowDom) { return new _ShadowRootPageLoaderElement(node, loader); - } else { - throw new PageLoaderException( - 'Cannot create element for ShadowRoot when useShadowDom is false'); } + throw new PageLoaderException( + 'Cannot create element for ShadowRoot when useShadowDom is false'); } throw new PageLoaderException( 'Unable to create PageLoaderElement for $node'); @@ -208,7 +209,7 @@ abstract class HtmlPageLoaderElement implements PageLoaderElement { @override Future get shadowRoot => - throw new PageLoaderException('$runtimeType.shadowRoot() is unsupported'); + throw new PageLoaderException('$runtimeType.shadowRoot is unsupported'); @override PageLoaderAttributes get style => new _EmptyAttributes(); @@ -230,10 +231,12 @@ class _ElementPageLoaderElement extends HtmlPageLoaderElement { @override Future get shadowRoot async { if (loader.useShadowDom) { - return new HtmlPageLoaderElement(node.shadowRoot, loader); - } else { - return this; + if (node.shadowRoot != null) { + return new HtmlPageLoaderElement(node.shadowRoot, loader); + } + throw new PageLoaderException('$this does not have a shadowRoot'); } + return this; } @override @@ -283,7 +286,7 @@ class _ElementPageLoaderElement extends HtmlPageLoaderElement { node.value = ''; node.dispatchEvent(new TextEvent('textInput', data: '')); } else { - super.clear(); + throw new PageLoaderException('$this does not support clear.'); } await loader.sync(); } diff --git a/dart/lib/async/src/annotations.dart b/dart/lib/async/src/annotations.dart index 52184bbe..474c6363 100644 --- a/dart/lib/async/src/annotations.dart +++ b/dart/lib/async/src/annotations.dart @@ -30,6 +30,8 @@ class _Optional { String toString() => '@optional'; } +/// Used to annotate PageLoader-type fields that should have the instance of PageLoader +/// injected. const inject = const _Inject(); class _Inject { const _Inject(); @@ -38,7 +40,7 @@ class _Inject { String toString() => '@inject'; } -/// By default PageLoader ensure that all elements are displayed. +/// By default PageLoader ensures that all elements are displayed. /// Adding @disableDisplayedCheck to an annotated field or class will disable this check from this /// point onwards. const disableDisplayedCheck = const _DisableDisplayedCheck(); diff --git a/dart/lib/async/src/core.dart b/dart/lib/async/src/core.dart index 7c68a3c6..a674dcd7 100644 --- a/dart/lib/async/src/core.dart +++ b/dart/lib/async/src/core.dart @@ -91,6 +91,10 @@ class _ClassInfo { '${type.simpleName} has Filter annotations but no Finder annotation'); } } + if (finder == root && filters.isEmpty) { + throw new PageLoaderException( + 'Useless @root annotation of ${type.simpleName}'); + } return new _ClassInfo._( type, _fieldInfos(type), finder, filters, displayCheck); diff --git a/dart/lib/async/webdriver.dart b/dart/lib/async/webdriver.dart index 4ad5284d..8e95b835 100644 --- a/dart/lib/async/webdriver.dart +++ b/dart/lib/async/webdriver.dart @@ -97,7 +97,8 @@ abstract class WebDriverPageLoaderElement implements PageLoaderElement { wd.SearchContext context, WebDriverPageLoader loader) { if (context is wd.WebDriver) { return new _WebDriverPageLoaderElement(context, loader); - } else if (context is wd.WebElement) { + } + if (context is wd.WebElement) { return new _WebElementPageLoaderElement(context, loader); } throw new PageLoaderException( @@ -171,10 +172,13 @@ class _WebElementPageLoaderElement extends WebDriverPageLoaderElement { @override Future get shadowRoot async { if (loader.useShadowDom) { - return new _ShadowRootPageLoaderElement(context, loader); - } else { - return this; + if ((await context.driver.execute( + 'arguments[0].shadowRoot != null', [context]))) { + return new _ShadowRootPageLoaderElement(context, loader); + } + throw new PageLoaderException('$this does not have a shadowRoot'); } + return this; } @override diff --git a/dart/pubspec.yaml b/dart/pubspec.yaml index 7c2ddb5d..51bdb320 100644 --- a/dart/pubspec.yaml +++ b/dart/pubspec.yaml @@ -1,5 +1,5 @@ name: pageloader -version: 2.0.0-pre.1 +version: 2.0.0-pre.2 author: Google, Inc. description: > Supports the creation of page objects that can be shared between in-browser tests diff --git a/dart/test/async/html_no_shadow_dom_test.dart b/dart/test/async/html_no_shadow_dom_test.dart index 95c3ffd2..414f9b52 100644 --- a/dart/test/async/html_no_shadow_dom_test.dart +++ b/dart/test/async/html_no_shadow_dom_test.dart @@ -13,132 +13,27 @@ library pageloader.async.test.html_no_shadow_dom; import 'dart:async'; -import 'dart:html' as html; import 'package:pageloader/async/html.dart'; import 'package:unittest/html_enhanced_config.dart' show useHtmlEnhancedConfiguration; import 'package:unittest/unittest.dart'; -import 'page_objects.dart'; +import '../data/html_no_shadow_dom_setup.dart' as html_setup; import 'pageloader_test.dart' as plt; +import 'src/html_test.dart' as html_test; +import 'src/shared.dart' as shared; void main() { useHtmlEnhancedConfiguration(); setUp(() { - var body = html.document.getElementsByTagName('body').first; - const bodyHtml = ''' - - - - - - - - - - -
r1c1r1c2
r2c1r2c2
- -
area for mouse events
- - - - - - test - - - -
- outer div 1 - -
-
- outer div 2 -
- inner div 1 -
-
- inner div 2 -
-
- - - - - - -

   

'''; - - 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(); - var node = (page.text as HtmlPageLoaderElement).node as html.InputElement; - node.onInput.listen((event) { - handlerCalled.complete(true); - }); - expect(await page.text.attributes['value'], ''); - await page.text.type('some text'); - expect(await page.text.attributes['value'], 'some text'); - expect(await handlerCalled.future, isTrue); - }); - - test('keypress events', () async { - var data = 'my data'; - var list = []; - html.document.body.onKeyPress.listen((evt) => list.add(evt.charCode)); - await plt.loader.globalContext.type(data); - expect(new String.fromCharCodes(list), equals(data)); - }); + var div = html_setup.setUp(); + shared.loader = new HtmlPageLoader(div, syncFn, useShadowDom: false); }); plt.runTests(); -} - -class NoOpNodeValidator implements html.NodeValidator { - bool allowsAttribute( - html.Element element, String attributeName, String value) => true; - bool allowsElement(html.Element element) => true; + html_test.runTests(); } Future syncFn() async { diff --git a/dart/test/async/html_test.dart b/dart/test/async/html_test.dart index ee4c3450..76358976 100644 --- a/dart/test/async/html_test.dart +++ b/dart/test/async/html_test.dart @@ -10,141 +10,30 @@ // 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.async.test.html; +library pageloader.async.test.html_no_shadow_dom; import 'dart:async'; -import 'dart:html' as html; import 'package:pageloader/async/html.dart'; import 'package:unittest/html_enhanced_config.dart' show useHtmlEnhancedConfiguration; import 'package:unittest/unittest.dart'; -import 'page_objects.dart'; +import '../data/html_setup.dart' as html_setup; import 'pageloader_test.dart' as plt; +import 'src/html_test.dart' as html_test; +import 'src/shared.dart' as shared; void main() { useHtmlEnhancedConfiguration(); setUp(() { - var body = html.document.getElementsByTagName('body').first; - const bodyHtml = ''' - - - - - - - - - - -
r1c1r1c2
r2c1r2c2
- -
area for mouse events
- - - - - - test - - - -
- outer div 1 - -
-
- outer div 2 -
- inner div 1 -
-
- inner div 2 -
-
- - button 1 - - - button 2 - -

   

'''; - - 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(); - var node = (page.text as HtmlPageLoaderElement).node as html.InputElement; - node.onInput.listen((event) { - handlerCalled.complete(true); - }); - expect(await page.text.attributes['value'], ''); - await page.text.type('some text'); - expect(await page.text.attributes['value'], 'some text'); - expect(await handlerCalled.future, isTrue); - }); - - test('keypress events', () async { - var data = 'my data'; - var list = []; - html.document.body.onKeyPress.listen((evt) => list.add(evt.charCode)); - await plt.loader.globalContext.type(data); - expect(new String.fromCharCodes(list), equals(data)); - }); + var div = html_setup.setUp(); + shared.loader = new HtmlPageLoader(div, syncFn); }); plt.runTests(); -} - -class NoOpNodeValidator implements html.NodeValidator { - bool allowsAttribute( - html.Element element, String attributeName, String value) => true; - bool allowsElement(html.Element element) => true; + html_test.runTests(); } Future syncFn() async { diff --git a/dart/test/async/page_objects.dart b/dart/test/async/page_objects.dart index b97026d2..4976806e 100644 --- a/dart/test/async/page_objects.dart +++ b/dart/test/async/page_objects.dart @@ -13,8 +13,6 @@ library pageloader.async.test.page_objects; -import 'dart:async'; - import 'package:pageloader/async/objects.dart'; class PageForSimpleTest { @@ -25,8 +23,6 @@ class PageForSimpleTest { Table table; } -class SubclassPage extends PageForSimpleTest {} - @All(const [root, const ByTagName('table')]) @IsTag('table') class Table { @@ -37,345 +33,7 @@ class Table { List rows; } -@EnsureTag('table') -class TableForEnsureTag { - @root - PageLoaderElement table; - - @ByTagName('tr') - List rows; -} - class Row { @ByTagName('td') List cells; } - -class PageForClassAnnotationTest { - @root - Table table; -} - -class PageForDisplayedFilteringTest { - @ById('div') - @disableDisplayedCheck - List shouldHaveOneElement; - - @ById('div') - List shouldBeEmpty; - - @ById('div') - @IsDisplayed() - @disableDisplayedCheck - List shouldAlsoBeEmpty; -} - -class PageForSettersTest { - List _shouldHaveOneElement; - var _loader; - - @inject - set loader(PageLoader l) { - this._loader = l; - } - - PageLoader get loader => _loader; - - @ById('div') - @disableDisplayedCheck - set shouldHaveOneElement(List elements) { - _shouldHaveOneElement = elements; - } - - get shouldHaveOneElement => _shouldHaveOneElement; -} - -class PageForSkipFieldsWithoutFinderTest { - @ById('div') - @disableDisplayedCheck - List shouldHaveOneElement; - - List shouldBeNull; -} - -class PageForNoMatchingElementTest { - @ById('non-existent id') - PageLoaderElement doesntExist; -} - -@ById('non-existent id') -class PageForNoMatchingClassElementTest { - @root - PageLoaderElement doesntExist; -} - -class PageForOptionalElementTest { - @ById('non-existent id') - @optional - PageLoaderElement doesntExist; -} - -class PageForMultipleMatchingElementTest { - @ByTagName('td') - PageLoaderElement doesntExist; -} - -@ByTagName('td') -class PageForMultipleMatchingClassElementTest { - @root - PageLoaderElement doesntExist; -} - -class PageForMultipleFinderTest { - @ById('non-existent id') - @ByTagName('a-name') - PageLoaderElement multipleFinder; -} - -@ById('non-existent id') -@ByTagName('a-name') -class PageForMultipleClassFinderTest { - @root - PageLoaderElement multipleFinder; -} - -class PageForInvalidConstructorTest { - PageForInvalidConstructorTest(String someArg); - - @ById('div') - @disableDisplayedCheck - List shouldHaveOneElement; -} - -class PageForWithAttributeTest { - @ByTagName('input') - @WithAttribute('type', 'checkbox') - PageLoaderElement element; -} - -class PageForAmbiguousTest { - @ByTagName('input') - PageLoaderElement element; -} - -class PageForMixinTest extends PageForSimpleTest - with PageForDisplayedFilteringTest {} - -class PageForPrivateConstructorTest extends PageForSimpleTest { - PageForPrivateConstructorTest._(); -} - -class PageForPrivateFieldsTest { - @ByTagName('table') - Table _privateTable; - - Table get table => _privateTable; -} - -class PageForPrivateSettersTest { - Table table; - - @ByTagName('table') - set _table(Table t) => table = t; -} - -class PageForStaticFieldsTest extends PageForSimpleTest { - @ByTagName("table") - static PageLoaderElement dontSet; -} - -class PageForStaticSettersTest extends PageForSimpleTest { - static var _dontSet; - - @ByTagName("table") - static set dontSet(PageLoaderElement el) { - _dontSet = el; - } - - static get dontSet => _dontSet; -} - -typedef NoTypeFn(); - -typedef PageLoaderElement PageLoaderElementFn(); - -typedef Table TableFn(); - -typedef List NoListTypeFn(); - -typedef List PageLoaderElementsFn(); - -typedef List RowsFn(); - -class PageForLazyTest { - @ByTagName('table') - Lazy lazyElement; - - @ByTagName('table') - Lazy lazyTable; - - @ByCss('table tr') - Lazy lazyRowElements; - - @ByCss('table tr') - Lazy> lazyRows; -} - -@InShadowDom() -class ButtonShadowDOM { - @ById("inner") - PageLoaderElement button; -} - -class PageForShadowDomTest { - @ById('button-1') - ButtonShadowDOM button1; - - @ById('button-2') - ButtonShadowDOM button2; - - @ById('inner') - List shouldBeEmpty; -} - -class PageForShadowDomWithVisibleTextTest { - @ByTagName('a-custom-tag') - @WithVisibleText('some') - @WithVisibleText('button 1') - PageLoaderElement button1; -} - -class PageForChainTest { - @ByClass('outer-div') - List outerDivs; - - @Chain(const [const ByClass('outer-div'), const ByClass('inner-div')]) - List innerDivs; - - @Chain(const [ - const ByClass('outer-div'), - const ByClass('inner-div'), - const WithClass('special') - ]) - PageLoaderElement innerDivSpecial; - - @Chain(const [ - const ByClass('outer-div'), - const ByTagName('a-custom-tag'), - const InShadowDom(find: const ById('inner')) - ]) - PageLoaderElement innerShadow; - - Stream get outerDivsText async* { - for (var div in outerDivs) { - yield await div.visibleText; - } - } - - Stream get innerDivsText async* { - for (var div in innerDivs) { - yield await div.visibleText; - } - } -} - -class PageForShadowDomWithInnerTextTest { - @ByTagName('a-custom-tag') - @WithInnerText('some') - @WithInnerText('button 1') - List shouldBeEmpty; - - @ByTagName('a-custom-tag') - @WithInnerText('button 1') - PageLoaderElement button1; -} - -class PageForTextOnShadowRootTest { - @ByTagName('a-custom-tag') - List buttons; -} - -class PageForAttributesTests { - @ById('div') - @disableDisplayedCheck - PageLoaderElement divWithStyle; - - @ByCss('input[type=checkbox]') - PageLoaderElement checkbox; - - @ById('table1') - PageLoaderElement table; - - @ById('select1') - PageLoaderElement select1; - - @ById('option1') - PageLoaderElement option1; - - @ById('option2') - PageLoaderElement option2; - - @ByCss('input[value=radio1]') - PageLoaderElement radio; - - @ById('anchor') - PageLoaderElement anchor; - - @ByTagName('img') - PageLoaderElement img; - - @ById('readonly') - PageLoaderElement readOnly; - - @ById('text') - PageLoaderElement text; -} - -class PageForWithClassTest { - @ByTagName('input') - @WithClass('with-class-test') - PageLoaderElement element; -} - -class PageForOptionalFunctionTest { - @ByTagName('non-existant') - @optional - Lazy shouldBeNull; - - @ById('button-1') - @optional - Lazy shouldBeNonNull; -} - -class PageForMouseTest { - @ById('mouse') - PageLoaderElement element; -} - -class PageForGlobalTest { - @ByTagName('table') - PageLoaderElement table; - - @ByCss('input[value=radio1]') - NestedPageForGlobalTest nested; -} - -class NestedPageForGlobalTest { - @Global(const ByTagName('table')) - PageLoaderElement table; -} - -class PageForTextAreaTypingText { - @ById('textarea') - PageLoaderElement textArea; -} - -class PageForNbspTest { - @ById('nbsp') - PageLoaderElement span; -} - -class PageForExceptionOnFinalsTest { - @ById('help') - final PageLoaderElement el = null; -} diff --git a/dart/test/async/pageloader_test.dart b/dart/test/async/pageloader_test.dart index 94423778..58baf4f9 100644 --- a/dart/test/async/pageloader_test.dart +++ b/dart/test/async/pageloader_test.dart @@ -13,466 +13,26 @@ library pageloader.async.test; -import 'package:matcher/matcher.dart'; -import 'package:pageloader/async/objects.dart'; import 'package:unittest/unittest.dart'; -import 'package:webdriver/async_helpers.dart'; -import 'page_objects.dart'; -PageLoader loader; +import 'src/annotation_test.dart' as annotation; +import 'src/attribute_test.dart' as attribute; +import 'src/basic_test.dart' as basic; +import 'src/display_filtering_test.dart' as display_filtering; +import 'src/error_test.dart' as error; +import 'src/mouse_test.dart' as mouse; +import 'src/shadow_dom_test.dart' as shadow_dom; +import 'src/typing_test.dart' as typing; void runTests() { - verifyRows(List rows) async { - expect(rows, hasLength(2)); - expect(rows.first.cells, hasLength(2)); - expect(rows[1].cells, hasLength(2)); - expect(await rows.first.cells.first.visibleText, 'r1c1'); - expect(await rows.first.cells[1].visibleText, 'r1c2'); - expect(await rows[1].cells.first.visibleText, 'r2c1'); - expect(await rows[1].cells[1].visibleText, 'r2c2'); - } - - verifyTable(Table table) async { - expect(await table.table.name, equalsIgnoringCase('TABLE')); - await verifyRows(table.rows); - } - - group('core tests', () { - test('simple', () async { - PageForSimpleTest page = await loader.getInstance(PageForSimpleTest); - await verifyTable(page.table); - expect(page.loader, loader); - }); - - test('class annotations', () async { - Table table = await loader.getInstance(Table); - await verifyTable(table); - }); - - test('EnsureTag annotation', () async { - TableForEnsureTag table = await loader.getInstance(TableForEnsureTag); - expect(await table.table.name, 'table'); - await verifyRows(table.rows); - - table = await loader.getInstance(TableForEnsureTag, table.table); - expect(await table.table.name, 'table'); - await verifyRows(table.rows); - }); - - test('class annotation on nested field', () async { - PageForClassAnnotationTest page = - await loader.getInstance(PageForClassAnnotationTest); - await verifyTable(page.table); - }); - - test('sub-class', () async { - SubclassPage page = await loader.getInstance(SubclassPage); - await verifyTable(page.table); - }); - - test('displayed filtering', () async { - PageForDisplayedFilteringTest page = - await loader.getInstance(PageForDisplayedFilteringTest); - - expect(page.shouldHaveOneElement, hasLength(1)); - expect(page.shouldBeEmpty, isEmpty); - expect(page.shouldAlsoBeEmpty, isEmpty); - }); - - test('setters', () async { - PageForSettersTest page = await loader.getInstance(PageForSettersTest); - expect(page.shouldHaveOneElement, hasLength(1)); - expect(page.loader, loader); - }); - - test('exception on finals', () { - expect(loader.getInstance(PageForExceptionOnFinalsTest), throws); - }); - - test('skip fields without finders', () async { - PageForSkipFieldsWithoutFinderTest page = - await loader.getInstance(PageForSkipFieldsWithoutFinderTest); - expect(page.shouldHaveOneElement, hasLength(1)); - expect(page.shouldBeNull, isNull); - }); - - test('no matching element', () { - expect(loader.getInstance(PageForNoMatchingElementTest), throws); - }); - - test('no matching class element', () { - expect(loader.getInstance(PageForNoMatchingClassElementTest), throws); - }); - - test('no matching but optional element', () async { - PageForOptionalElementTest page = - await loader.getInstance(PageForOptionalElementTest); - expect(page.doesntExist, isNull); - }); - - test('multiple matching element', () { - expect(loader.getInstance(PageForMultipleMatchingElementTest), throws); - }); - - test('multiple matching element', () { - expect( - loader.getInstance(PageForMultipleMatchingClassElementTest), throws); - }); - - test('multiple finders', () { - expect(loader.getInstance(PageForMultipleFinderTest), throws); - }); - - test('multiple class finders', () { - expect(loader.getInstance(PageForMultipleClassFinderTest), throws); - }); - - test('invalid constructor', () { - expect(loader.getInstance(PageForInvalidConstructorTest), throws); - }); - - test('WithAttribute', () async { - PageForWithAttributeTest page = - await loader.getInstance(PageForWithAttributeTest); - expect(await page.element.attributes['type'], 'checkbox'); - }); - - test('WithClass', () async { - var page = await loader.getInstance(PageForWithClassTest); - expect(await page.element.attributes['type'], 'checkbox'); - expect(await page.element.classes.toList(), - unorderedEquals(['with-class-test', 'class1', 'class2'])); - }); - - test('ambiguous element test', () { - expect(loader.getInstance(PageForAmbiguousTest), throws); - }); - - test('mixin', () async { - PageForMixinTest page = await loader.getInstance(PageForMixinTest); - await verifyTable(page.table); - expect(page.shouldHaveOneElement, hasLength(1)); - expect(page.shouldBeEmpty, isEmpty); - expect(page.shouldAlsoBeEmpty, isEmpty); - }); - - test('private constructor', () async { - PageForPrivateConstructorTest page = - await loader.getInstance(PageForPrivateConstructorTest); - - await verifyTable(page.table); - }); - - test('private fields', () async { - PageForPrivateFieldsTest page = - await loader.getInstance(PageForPrivateFieldsTest); - await verifyTable(page.table); - }); - - test('private setters', () { - expect(loader.getInstance(PageForPrivateSettersTest), throws); - }); - - test('static field', () { - expect(loader.getInstance(PageForStaticFieldsTest), throws); - }); - - test('static setter', () { - expect(loader.getInstance(PageForStaticSettersTest), throws); - }); - - test('Lazy fields', () async { - PageForLazyTest page = await loader.getInstance(PageForLazyTest); - - expect(await (await page.lazyElement()).visibleText, contains('r1c1')); - await verifyTable(await page.lazyTable()); - - expect(await page.lazyRowElements(), hasLength(2)); - await verifyRows(await page.lazyRows()); - }); - - test('shadow dom', () async { - PageForShadowDomTest page = - await loader.getInstance(PageForShadowDomTest); - - expect(await page.button1.button.visibleText, contains('button 1')); - expect(await page.button1.button.visibleText, contains('some')); - expect(await page.button2.button.visibleText, contains('button 2')); - expect(await page.button2.button.visibleText, contains('some')); - if (loader.useShadowDom) { - expect(page.shouldBeEmpty, hasLength(0)); - } - }); - - test('WithVisibleText in shadow dom', () async { - PageForShadowDomWithVisibleTextTest page = - await loader.getInstance(PageForShadowDomWithVisibleTextTest); - - expect(await page.button1.visibleText, contains('button 1')); - expect(await page.button1.visibleText, contains('some')); - }); - - test('chain', () async { - PageForChainTest page = await loader.getInstance(PageForChainTest); - - expect(await page.outerDivsText.toList(), - anyElement(contains('outer div 1'))); - expect(await page.outerDivsText.toList(), - anyElement(contains('outer div 2'))); - expect(await page.innerDivsText.toList(), - orderedEquals(['inner div 1', 'inner div 2'])); - expect(await page.innerDivSpecial.visibleText, 'inner div 2'); - expect(await page.innerShadow.visibleText, contains('some')); - }); - - test('WithInnerText in shadow dom', () async { - if (!loader.useShadowDom) { - // if shadow dom is disabled, then visibleText and innerText are - // identical - return; - } - PageForShadowDomWithInnerTextTest page = - await loader.getInstance(PageForShadowDomWithInnerTextTest); - - expect(page.shouldBeEmpty, isEmpty); - expect(await page.button1.visibleText, contains('button 1')); - expect(await page.button1.visibleText, contains('some')); - expect(await page.button1.innerText, contains('button 1')); - expect(await page.button1.innerText, isNot(contains('some'))); - }); - - test('text methods on shadow root', () async { - PageForTextOnShadowRootTest page = - await loader.getInstance(PageForTextOnShadowRootTest); - - expect(page.buttons, hasLength(3)); - expect(await (await page.buttons[1].shadowRoot).visibleText, - contains('button 1')); - expect(await (await page.buttons[1].shadowRoot).visibleText, - contains('some')); - expect(await (await page.buttons[2].shadowRoot).visibleText, - contains('button 2')); - expect(await (await page.buttons[2].shadowRoot).visibleText, - contains('some')); - if (loader.useShadowDom) { - expect(await (await page.buttons[1].shadowRoot).innerText, - isNot(contains('button 1'))); - } else { - expect(await (await page.buttons[1].shadowRoot).innerText, - contains('button 1')); - } - expect( - await (await page.buttons[1].shadowRoot).innerText, contains('some')); - if (loader.useShadowDom) { - expect(await (await page.buttons[2].shadowRoot).innerText, - isNot(contains('button 2'))); - } else { - expect(await (await page.buttons[2].shadowRoot).innerText, - contains('button 2')); - } - expect( - await (await page.buttons[2].shadowRoot).innerText, contains('some')); - }); - - test('classes', () async { - PageForSimpleTest page = await loader.getInstance(PageForSimpleTest); - - expect(await page.table.table.classes.toList(), - orderedEquals(['class1', 'class2', 'class3'])); - expect(await page.table.rows.first.cells.first.classes.toList(), - hasLength(0)); - }); - - test('style', () async { - PageForSimpleTest page = await loader.getInstance(PageForSimpleTest); - - expect(await page.table.table.style['color'], 'rgb(128, 0, 128)'); - expect(await page.table.table.style['backgroundColor'], ''); - }); - - test('computedStyle', () async { - PageForSimpleTest page = await loader.getInstance(PageForSimpleTest); - - expect(await page.table.table.computedStyle['color'], 'rgb(128, 0, 128)'); - expect(await page.table.table.computedStyle['background-color'], - 'rgb(0, 255, 0)'); - }); - - test('optional with functions', () async { - PageForOptionalFunctionTest page = - await loader.getInstance(PageForOptionalFunctionTest); - - expect(await page.shouldBeNull(), isNull); - expect(await page.shouldBeNonNull(), isNotNull); - }); - - test('mouse', () async { - PageForMouseTest page = await loader.getInstance(PageForMouseTest); - - await loader.mouse.moveTo(page.element, 2, 2); - await waitFor(() => page.element.visibleText, - matcher: contains('MouseMove')); - await loader.mouse.down(0); - await waitFor(() => page.element.visibleText, - matcher: contains('MouseDown')); - await loader.mouse.moveTo(page.element, 10, 10); - await loader.mouse.up(0); - await waitFor(() => page.element.visibleText, - matcher: contains('MouseUp')); - }); - - test('mouse with event target', () async { - PageForMouseTest page = await loader.getInstance(PageForMouseTest); - - // make sure mouse is not on element; - await loader.mouse.moveTo(page.element, -10, -10); - await loader.mouse.down(0, eventTarget: page.element); - await waitFor(() => page.element.visibleText, - matcher: contains('MouseDown')); - await loader.mouse.moveTo(page.element, 200, 200); - await loader.mouse..up(0, eventTarget: page.element); - await waitFor(() => page.element.visibleText, - matcher: contains('MouseUp')); - }); - - test('@Global', () async { - PageForGlobalTest page = await loader.getInstance(PageForGlobalTest); - expect(page.nested.table, equals(page.table)); - }); - - test('Type into textarea', () async { - PageForTextAreaTypingText page = - await loader.getInstance(PageForTextAreaTypingText); - await page.textArea.type('some'); - expect(await page.textArea.attributes['value'], 'some'); - await page.textArea.type(' string'); - expect(await page.textArea.attributes['value'], 'some string'); - await page.textArea.clear(); - expect(await page.textArea.attributes['value'], ''); - }); - - test('nbsp in text', () async { - PageForNbspTest page = await loader.getInstance(PageForNbspTest); - expect(await page.span.visibleText, ' '); - expect(await page.span.innerText, ''); - }); - }); - - group('attributes', () { - test('style', () async { - var page = await loader.getInstance(PageForAttributesTests); - // According to the spec, red below should be returned as an - // RGBA value. - expect(await page.divWithStyle.attributes['style'], - 'display: none; background-color: red;'); - expect(await page.divWithStyle.attributes['STYLE'], - 'display: none; background-color: red;'); - expect(await page.divWithStyle.attributes['StYlE'], - 'display: none; background-color: red;'); - }); - - test('checked', () async { - var page = await loader.getInstance(PageForAttributesTests); - expect(await page.checkbox.attributes['checked'], isNull); - await page.checkbox.click(); - expect(await page.checkbox.attributes['checked'], 'true'); - }); - - test('disabled', () async { - var page = await loader.getInstance(PageForAttributesTests); - expect(await page.readOnly.attributes['disabled'], 'true'); - expect(await page.text.attributes['disabled'], isNull); - }); - - test('not a property', () async { - var page = await loader.getInstance(PageForAttributesTests); - expect( - await page.table.attributes['non-standard'], 'a non standard attr'); - }); - - test('option values', () async { - var page = await loader.getInstance(PageForAttributesTests); - // The expects below are according to the WebDriver spec, but currently - // fail - // expect(page.option1.attributes['value'], 'option 1'); - // expect(page.option1.attributes['VaLuE'], 'option 1'); - expect(await page.option2.attributes['value'], 'value 2'); - expect(await page.option2.attributes['VaLuE'], 'value 2'); - }); - - test('option selected', () async { - var page = await loader.getInstance(PageForAttributesTests); - await page.option2.click(); - expect(await page.select1.attributes['value'], equals('value 2')); - }); - - test('selected on checkbox', () async { - var page = await loader.getInstance(PageForAttributesTests); - expect(await page.checkbox.attributes['selected'], isNull); - expect(await page.checkbox.attributes['SeLeCtEd'], isNull); - await page.checkbox.click(); - expect(await page.checkbox.attributes['selected'], 'true'); - expect(await page.checkbox.attributes['SeLeCtEd'], 'true'); - }); - - test('selected on radio', () async { - var page = await loader.getInstance(PageForAttributesTests); - expect(await page.radio.attributes['selected'], isNull); - expect(await page.radio.attributes['SeLeCtEd'], isNull); - await page.radio.click(); - expect(await page.radio.attributes['selected'], 'true'); - expect(await page.radio.attributes['SeLeCtEd'], 'true'); - }); - - test('href on a', () async { - var page = await loader.getInstance(PageForAttributesTests); - expect(await page.anchor.attributes['href'], endsWith('/test.html')); - }); - - test('src on img', () async { - var page = await loader.getInstance(PageForAttributesTests); - expect(await page.img.attributes['src'], endsWith('/test.png')); - }); - - test('class/className', () async { - var page = await loader.getInstance(PageForAttributesTests); - expect(await page.table.attributes['class'], 'class1 class2 class3'); - expect(await page.table.attributes['className'], 'class1 class2 class3'); - }); - - test('readonly/readOnly', () async { - var page = await loader.getInstance(PageForAttributesTests); - expect(await page.readOnly.attributes['readonly'], 'true'); - expect(await page.readOnly.attributes['readOnly'], 'true'); - expect(await page.text.attributes['readonly'], isNull); - expect(await page.text.attributes['readOnly'], isNull); - }); - - test('value on text', () async { - var page = await loader.getInstance(PageForAttributesTests); - expect(await page.text.attributes['value'], ''); - await page.text.type('some text'); - expect(await page.text.attributes['value'], 'some text'); - }); - }); - - group('typing', () { - test('typing should append', () async { - var page = await loader.getInstance(PageForAttributesTests); - expect(await page.text.attributes['value'], ''); - await page.text.type('some text'); - expect(await page.text.attributes['value'], 'some text'); - await page.text.type(' and more text'); - expect(await page.text.attributes['value'], 'some text and more text'); - }); - - test('value after clear', () async { - var page = await loader.getInstance(PageForAttributesTests); - expect(await page.text.attributes['value'], ''); - await page.text.type('some text'); - expect(await page.text.attributes['value'], 'some text'); - await page.text.clear(); - expect(await page.text.attributes['value'], ''); - }); + group('core PageLoader', () { + annotation.runTests(); + attribute.runTests(); + basic.runTests(); + display_filtering.runTests(); + error.runTests(); + mouse.runTests(); + shadow_dom.runTests(); + typing.runTests(); }); } diff --git a/dart/test/async/src/annotation_test.dart b/dart/test/async/src/annotation_test.dart new file mode 100644 index 00000000..de177426 --- /dev/null +++ b/dart/test/async/src/annotation_test.dart @@ -0,0 +1,133 @@ +// 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.async.test.annotation; + +import 'dart:async'; +import 'package:matcher/matcher.dart'; +import 'package:pageloader/async/objects.dart'; +import 'package:unittest/unittest.dart'; +import 'shared.dart'; + +void runTests() { + group('annotation tests', () { + test('EnsureTag annotation', () async { + TableForEnsureTag table = await loader.getInstance(TableForEnsureTag); + expect(await table.table.name, 'table'); + await verifyRows(table.rows); + + table = await loader.getInstance(TableForEnsureTag, table.table); + expect(await table.table.name, 'table'); + await verifyRows(table.rows); + }); + + test('WithAttribute', () async { + PageForWithAttributeTest page = + await loader.getInstance(PageForWithAttributeTest); + expect(await page.element.attributes['type'], 'checkbox'); + }); + + test('WithClass', () async { + var page = await loader.getInstance(PageForWithClassTest); + expect(await page.element.attributes['type'], 'checkbox'); + expect(await page.element.classes.toList(), + unorderedEquals(['with-class-test', 'class1', 'class2'])); + }); + + test('chain', () async { + PageForChainTest page = await loader.getInstance(PageForChainTest); + + expect(await page.outerDivsText.toList(), + anyElement(contains('outer div 1'))); + expect(await page.outerDivsText.toList(), + anyElement(contains('outer div 2'))); + expect(await page.innerDivsText.toList(), + orderedEquals(['inner div 1', 'inner div 2'])); + expect(await page.innerDivSpecial.visibleText, 'inner div 2'); + expect(await page.innerShadow.visibleText, contains('some')); + }); + + test('@Global', () async { + PageForGlobalTest page = await loader.getInstance(PageForGlobalTest); + expect(page.nested.table, equals(page.table)); + }); + }); +} + +@EnsureTag('table') +class TableForEnsureTag { + @root + PageLoaderElement table; + + @ByTagName('tr') + List rows; +} + +class PageForWithAttributeTest { + @ByTagName('input') + @WithAttribute('type', 'checkbox') + PageLoaderElement element; +} + +class PageForWithClassTest { + @ByTagName('input') + @WithClass('with-class-test') + PageLoaderElement element; +} + +class PageForChainTest { + @ByClass('outer-div') + List outerDivs; + + @Chain(const [const ByClass('outer-div'), const ByClass('inner-div')]) + List innerDivs; + + @Chain(const [ + const ByClass('outer-div'), + const ByClass('inner-div'), + const WithClass('special') + ]) + PageLoaderElement innerDivSpecial; + + @Chain(const [ + const ByClass('outer-div'), + const ByTagName('a-custom-tag'), + const InShadowDom(find: const ById('inner')) + ]) + PageLoaderElement innerShadow; + + Stream get outerDivsText async* { + for (var div in outerDivs) { + yield await div.visibleText; + } + } + + Stream get innerDivsText async* { + for (var div in innerDivs) { + yield await div.visibleText; + } + } +} + +class PageForGlobalTest { + @ByTagName('table') + PageLoaderElement table; + + @ByCss('input[value=radio1]') + NestedPageForGlobalTest nested; +} + +class NestedPageForGlobalTest { + @Global(const ByTagName('table')) + PageLoaderElement table; +} diff --git a/dart/test/async/src/attribute_test.dart b/dart/test/async/src/attribute_test.dart new file mode 100644 index 00000000..26346100 --- /dev/null +++ b/dart/test/async/src/attribute_test.dart @@ -0,0 +1,155 @@ +// 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.async.test.attribute; + +import 'package:matcher/matcher.dart'; +import 'package:pageloader/async/objects.dart'; +import 'package:unittest/unittest.dart'; +import 'shared.dart'; + +void runTests() { + group('attributes', () { + test('style', () async { + var page = await loader.getInstance(PageForAttributesTests); + // According to the spec, red below should be returned as an + // RGBA value. + expect(await page.divWithStyle.attributes['style'], + 'display: none; background-color: red;'); + expect(await page.divWithStyle.attributes['STYLE'], + 'display: none; background-color: red;'); + expect(await page.divWithStyle.attributes['StYlE'], + 'display: none; background-color: red;'); + }); + + test('checked', () async { + var page = await loader.getInstance(PageForAttributesTests); + expect(await page.checkbox.attributes['checked'], isNull); + await page.checkbox.click(); + expect(await page.checkbox.attributes['checked'], 'true'); + }); + + test('disabled', () async { + var page = await loader.getInstance(PageForAttributesTests); + expect(await page.readOnly.attributes['disabled'], 'true'); + expect(await page.text.attributes['disabled'], isNull); + }); + + test('not a property', () async { + var page = await loader.getInstance(PageForAttributesTests); + expect( + await page.table.attributes['non-standard'], 'a non standard attr'); + }); + + test('option values', () async { + var page = await loader.getInstance(PageForAttributesTests); + // The expects below are according to the WebDriver spec, but currently + // fail + // expect(page.option1.attributes['value'], 'option 1'); + // expect(page.option1.attributes['VaLuE'], 'option 1'); + expect(await page.option2.attributes['value'], 'value 2'); + expect(await page.option2.attributes['VaLuE'], 'value 2'); + }); + + test('option selected', () async { + var page = await loader.getInstance(PageForAttributesTests); + await page.option2.click(); + expect(await page.select1.attributes['value'], equals('value 2')); + }); + + test('selected on checkbox', () async { + var page = await loader.getInstance(PageForAttributesTests); + expect(await page.checkbox.attributes['selected'], isNull); + expect(await page.checkbox.attributes['SeLeCtEd'], isNull); + await page.checkbox.click(); + expect(await page.checkbox.attributes['selected'], 'true'); + expect(await page.checkbox.attributes['SeLeCtEd'], 'true'); + }); + + test('selected on radio', () async { + var page = await loader.getInstance(PageForAttributesTests); + expect(await page.radio.attributes['selected'], isNull); + expect(await page.radio.attributes['SeLeCtEd'], isNull); + await page.radio.click(); + expect(await page.radio.attributes['selected'], 'true'); + expect(await page.radio.attributes['SeLeCtEd'], 'true'); + }); + + test('href on a', () async { + var page = await loader.getInstance(PageForAttributesTests); + expect(await page.anchor.attributes['href'], endsWith('/test.html')); + }); + + test('src on img', () async { + var page = await loader.getInstance(PageForAttributesTests); + expect(await page.img.attributes['src'], endsWith('/test.png')); + }); + + test('class/className', () async { + var page = await loader.getInstance(PageForAttributesTests); + expect(await page.table.attributes['class'], 'class1 class2 class3'); + expect(await page.table.attributes['className'], 'class1 class2 class3'); + }); + + test('readonly/readOnly', () async { + var page = await loader.getInstance(PageForAttributesTests); + expect(await page.readOnly.attributes['readonly'], 'true'); + expect(await page.readOnly.attributes['readOnly'], 'true'); + expect(await page.text.attributes['readonly'], isNull); + expect(await page.text.attributes['readOnly'], isNull); + }); + + test('value on text', () async { + var page = await loader.getInstance(PageForAttributesTests); + expect(await page.text.attributes['value'], ''); + await page.text.type('some text'); + expect(await page.text.attributes['value'], 'some text'); + }); + }); +} + +class PageForAttributesTests { + @ById('div') + @disableDisplayedCheck + PageLoaderElement divWithStyle; + + @ByCss('input[type=checkbox]') + PageLoaderElement checkbox; + + @ById('table1') + PageLoaderElement table; + + @ById('select1') + PageLoaderElement select1; + + @ById('option1') + PageLoaderElement option1; + + @ById('option2') + PageLoaderElement option2; + + @ByCss('input[value=radio1]') + PageLoaderElement radio; + + @ById('anchor') + PageLoaderElement anchor; + + @ByTagName('img') + PageLoaderElement img; + + @ById('readonly') + PageLoaderElement readOnly; + + @ById('text') + PageLoaderElement text; +} diff --git a/dart/test/async/src/basic_test.dart b/dart/test/async/src/basic_test.dart new file mode 100644 index 00000000..a2751584 --- /dev/null +++ b/dart/test/async/src/basic_test.dart @@ -0,0 +1,235 @@ +// 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.async.test.basic; + +import 'package:matcher/matcher.dart'; +import 'package:pageloader/async/objects.dart'; +import 'package:unittest/unittest.dart'; +import 'shared.dart'; + +void runTests() { + group('basic tests', () { + test('simple', () async { + PageForSimpleTest page = await loader.getInstance(PageForSimpleTest); + await verifyTable(page.table); + expect(page.loader, loader); + }); + + test('class annotations', () async { + Table table = await loader.getInstance(Table); + await verifyTable(table); + }); + + test('class annotation on nested field', () async { + PageForClassAnnotationTest page = + await loader.getInstance(PageForClassAnnotationTest); + await verifyTable(page.table); + }); + + test('sub-class', () async { + SubclassPage page = await loader.getInstance(SubclassPage); + await verifyTable(page.table); + }); + + test('setters', () async { + PageForSettersTest page = await loader.getInstance(PageForSettersTest); + expect(page.shouldHaveOneElement, hasLength(1)); + expect(page.loader, loader); + }); + + test('skip fields without finders', () async { + PageForSkipFieldsWithoutFinderTest page = + await loader.getInstance(PageForSkipFieldsWithoutFinderTest); + expect(page.shouldHaveOneElement, hasLength(1)); + expect(page.shouldBeNull, isNull); + }); + + test('mixin', () async { + PageForMixinTest page = await loader.getInstance(PageForMixinTest); + await verifyTable(page.table); + expect(page.shouldHaveOneElement, hasLength(1)); + expect(page.shouldBeEmpty, isEmpty); + expect(page.shouldAlsoBeEmpty, isEmpty); + }); + + test('private constructor', () async { + PageForPrivateConstructorTest page = + await loader.getInstance(PageForPrivateConstructorTest); + + await verifyTable(page.table); + }); + + test('private fields', () async { + PageForPrivateFieldsTest page = + await loader.getInstance(PageForPrivateFieldsTest); + await verifyTable(page.table); + }); + + test('Lazy fields', () async { + PageForLazyTest page = await loader.getInstance(PageForLazyTest); + + expect(await (await page.lazyElement()).visibleText, contains('r1c1')); + await verifyTable(await page.lazyTable()); + + expect(await page.lazyRowElements(), hasLength(2)); + await verifyRows(await page.lazyRows()); + }); + + test('classes', () async { + PageForSimpleTest page = await loader.getInstance(PageForSimpleTest); + + expect(await page.table.table.classes.toList(), + orderedEquals(['class1', 'class2', 'class3'])); + expect(await page.table.rows.first.cells.first.classes.toList(), + hasLength(0)); + }); + + test('style', () async { + PageForSimpleTest page = await loader.getInstance(PageForSimpleTest); + + expect(await page.table.table.style['color'], 'rgb(128, 0, 128)'); + expect(await page.table.table.style['backgroundColor'], ''); + }); + + test('computedStyle', () async { + PageForSimpleTest page = await loader.getInstance(PageForSimpleTest); + + expect(await page.table.table.computedStyle['color'], 'rgb(128, 0, 128)'); + expect(await page.table.table.computedStyle['background-color'], + 'rgb(0, 255, 0)'); + }); + + test('optional with Lazy', () async { + PageForOptionalFunctionTest page = + await loader.getInstance(PageForOptionalFunctionTest); + + expect(await page.shouldBeNull(), isNull); + expect(await page.shouldBeNonNull(), isNotNull); + }); + + test('nbsp in text', () async { + PageForNbspTest page = await loader.getInstance(PageForNbspTest); + expect(await page.span.visibleText, ' '); + expect(await page.span.innerText, ''); + }); + + test('optional', () async { + PageForOptionalElementTest page = + await loader.getInstance(PageForOptionalElementTest); + expect(page.doesntExist, isNull); + }); + }); +} + +class PageForOptionalFunctionTest { + @ByTagName('non-existant') + @optional + Lazy shouldBeNull; + + @ById('button-1') + @optional + Lazy shouldBeNonNull; +} + +class SubclassPage extends PageForSimpleTest {} + +class PageForClassAnnotationTest { + @root + Table table; +} + +class PageForSettersTest { + List _shouldHaveOneElement; + var _loader; + + @inject + set loader(PageLoader l) { + this._loader = l; + } + + PageLoader get loader => _loader; + + @ById('div') + @disableDisplayedCheck + set shouldHaveOneElement(List elements) { + _shouldHaveOneElement = elements; + } + + get shouldHaveOneElement => _shouldHaveOneElement; +} + +class PageForSkipFieldsWithoutFinderTest { + @ById('div') + @disableDisplayedCheck + List shouldHaveOneElement; + + List shouldBeNull; +} + +class PageForOptionalElementTest { + @ById('non-existent id') + @optional + PageLoaderElement doesntExist; +} + +class MixinForMixinTest { + @ById('div') + @disableDisplayedCheck + List shouldHaveOneElement; + + @ById('div') + List shouldBeEmpty; + + @ById('div') + @IsDisplayed() + @disableDisplayedCheck + List shouldAlsoBeEmpty; +} + +class PageForAmbiguousTest { + @ByTagName('input') + PageLoaderElement element; +} + +class PageForMixinTest extends PageForSimpleTest with MixinForMixinTest {} + +class PageForPrivateConstructorTest extends PageForSimpleTest { + PageForPrivateConstructorTest._(); +} + +class PageForPrivateFieldsTest { + @ByTagName('table') + Table _privateTable; + + Table get table => _privateTable; +} + +class PageForLazyTest { + @ByTagName('table') + Lazy lazyElement; + + @ByTagName('table') + Lazy
lazyTable; + + @ByCss('table tr') + Lazy lazyRowElements; + + @ByCss('table tr') + Lazy> lazyRows; +} + +class PageForNbspTest { + @ById('nbsp') + PageLoaderElement span; +} diff --git a/dart/test/async/src/display_filtering_test.dart b/dart/test/async/src/display_filtering_test.dart new file mode 100644 index 00000000..66dc6d9a --- /dev/null +++ b/dart/test/async/src/display_filtering_test.dart @@ -0,0 +1,46 @@ +// 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.async.test.display_filtering; + +import 'package:matcher/matcher.dart'; +import 'package:pageloader/async/objects.dart'; +import 'package:unittest/unittest.dart'; +import 'shared.dart'; + +void runTests() { + group('display filtering tests', () { + test('displayed filtering', () async { + PageForDisplayedFilteringTest page = + await loader.getInstance(PageForDisplayedFilteringTest); + + expect(page.shouldHaveOneElement, hasLength(1)); + expect(page.shouldBeEmpty, isEmpty); + expect(page.shouldAlsoBeEmpty, isEmpty); + }); + }); +} + +class PageForDisplayedFilteringTest { + @ById('div') + @disableDisplayedCheck + List shouldHaveOneElement; + + @ById('div') + List shouldBeEmpty; + + @ById('div') + @IsDisplayed() + @disableDisplayedCheck + List shouldAlsoBeEmpty; +} diff --git a/dart/test/async/src/error_test.dart b/dart/test/async/src/error_test.dart new file mode 100644 index 00000000..39a4c292 --- /dev/null +++ b/dart/test/async/src/error_test.dart @@ -0,0 +1,148 @@ +// 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.async.test.error; + +import 'package:matcher/matcher.dart'; +import 'package:pageloader/async/objects.dart'; +import 'package:unittest/unittest.dart'; +import 'shared.dart'; + +void runTests() { + group('error tests', () { + test('exception on finals', () { + expect(loader.getInstance(PageForExceptionOnFinalsTest), throws); + }); + + test('no matching element', () { + expect(loader.getInstance(PageForNoMatchingElementTest), throws); + }); + + test('no matching class element', () { + expect(loader.getInstance(PageForNoMatchingClassElementTest), throws); + }); + + test('multiple matching element', () { + expect(loader.getInstance(PageForMultipleMatchingElementTest), throws); + }); + + test('multiple matching class element', () { + expect( + loader.getInstance(PageForMultipleMatchingClassElementTest), throws); + }); + + test('multiple finders', () { + expect(loader.getInstance(PageForMultipleFinderTest), throws); + }); + + test('multiple class finders', () { + expect(loader.getInstance(PageForMultipleClassFinderTest), throws); + }); + + test('invalid constructor', () { + expect(loader.getInstance(PageForInvalidConstructorTest), throws); + }); + + test('ambiguous element test', () { + expect(loader.getInstance(PageForAmbiguousTest), throws); + }); + + test('private setters', () { + expect(loader.getInstance(PageForPrivateSettersTest), throws); + }); + + test('static field', () { + expect(loader.getInstance(PageForStaticFieldsTest), throws); + }); + + test('static setter', () { + expect(loader.getInstance(PageForStaticSettersTest), throws); + }); + }); +} + +class PageForExceptionOnFinalsTest { + @ById('help') + final PageLoaderElement el = null; +} + +class PageForNoMatchingElementTest { + @ById('non-existent id') + PageLoaderElement doesntExist; +} + +@ById('non-existent id') +class PageForNoMatchingClassElementTest { + @root + PageLoaderElement doesntExist; +} + +class PageForMultipleMatchingElementTest { + @ByTagName('td') + PageLoaderElement doesntExist; +} + +@ByTagName('td') +class PageForMultipleMatchingClassElementTest { + @root + PageLoaderElement doesntExist; +} + +@ById('non-existent id') +@ByTagName('a-name') +class PageForMultipleClassFinderTest { + @root + PageLoaderElement multipleFinder; +} + +class PageForAmbiguousTest { + @ByTagName('input') + PageLoaderElement element; +} + +class PageForPrivateSettersTest { + Table table; + + @ByTagName('table') + set _table(Table t) => table = t; +} + +class PageForMultipleFinderTest { + @ById('non-existent id') + @ByTagName('a-name') + PageLoaderElement multipleFinder; +} + +class PageForInvalidConstructorTest { + PageForInvalidConstructorTest(String someArg); + + @ById('div') + @disableDisplayedCheck + List shouldHaveOneElement; +} + +class PageForStaticFieldsTest extends PageForSimpleTest { + @ByTagName("table") + static PageLoaderElement dontSet; +} + +class PageForStaticSettersTest extends PageForSimpleTest { + static var _dontSet; + + @ByTagName("table") + static set dontSet(PageLoaderElement el) { + _dontSet = el; + } + + static get dontSet => _dontSet; +} diff --git a/dart/test/async/src/html_test.dart b/dart/test/async/src/html_test.dart new file mode 100644 index 00000000..a6ef4a5a --- /dev/null +++ b/dart/test/async/src/html_test.dart @@ -0,0 +1,52 @@ +// 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.async.test.html; + +import 'dart:async'; +import 'dart:html' as html; + +import 'package:matcher/matcher.dart'; +import 'package:pageloader/async/html.dart'; +import 'package:pageloader/async/objects.dart'; +import 'package:unittest/unittest.dart'; +import 'shared.dart'; + +void runTests() { + group('html PageLoader', () { + test('value on text', () async { + PageForTypingTests page = await loader.getInstance(PageForTypingTests); + var handlerCalled = new Completer(); + var node = (page.text as HtmlPageLoaderElement).node as html.InputElement; + node.onInput.listen((event) { + handlerCalled.complete(true); + }); + expect(await page.text.attributes['value'], ''); + await page.text.type('some text'); + expect(await page.text.attributes['value'], 'some text'); + expect(await handlerCalled.future, isTrue); + }); + + test('keypress events', () async { + var data = 'my data'; + var list = []; + html.document.body.onKeyPress.listen((evt) => list.add(evt.charCode)); + await loader.globalContext.type(data); + expect(new String.fromCharCodes(list), equals(data)); + }); + }); +} + +class PageForTypingTests { + @ById('text') + PageLoaderElement text; +} diff --git a/dart/test/async/src/mouse_test.dart b/dart/test/async/src/mouse_test.dart new file mode 100644 index 00000000..07c649a4 --- /dev/null +++ b/dart/test/async/src/mouse_test.dart @@ -0,0 +1,58 @@ +// 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.async.test.mouse; + +import 'package:matcher/matcher.dart'; +import 'package:pageloader/async/objects.dart'; +import 'package:unittest/unittest.dart'; +import 'package:webdriver/async_helpers.dart'; +import 'shared.dart'; + +void runTests() { + group('mouse tests', () { + test('mouse', () async { + PageForMouseTest page = await loader.getInstance(PageForMouseTest); + + await loader.mouse.moveTo(page.element, 2, 2); + await waitFor(() => page.element.visibleText, + matcher: contains('MouseMove')); + await loader.mouse.down(0); + await waitFor(() => page.element.visibleText, + matcher: contains('MouseDown')); + await loader.mouse.moveTo(page.element, 10, 10); + await loader.mouse.up(0); + await waitFor(() => page.element.visibleText, + matcher: contains('MouseUp')); + }); + + test('mouse with event target', () async { + PageForMouseTest page = await loader.getInstance(PageForMouseTest); + + // make sure mouse is not on element; + await loader.mouse.moveTo(page.element, -10, -10); + await loader.mouse.down(0, eventTarget: page.element); + await waitFor(() => page.element.visibleText, + matcher: contains('MouseDown')); + await loader.mouse.moveTo(page.element, 200, 200); + await loader.mouse..up(0, eventTarget: page.element); + await waitFor(() => page.element.visibleText, + matcher: contains('MouseUp')); + }); + }); +} + +class PageForMouseTest { + @ById('mouse') + PageLoaderElement element; +} diff --git a/dart/test/async/src/shadow_dom_test.dart b/dart/test/async/src/shadow_dom_test.dart new file mode 100644 index 00000000..de3adcc2 --- /dev/null +++ b/dart/test/async/src/shadow_dom_test.dart @@ -0,0 +1,143 @@ +// 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.async.test.shadow_dom; + +import 'package:matcher/matcher.dart'; +import 'package:pageloader/async/objects.dart'; +import 'package:unittest/unittest.dart'; +import 'shared.dart'; + +void runTests() { + group('shadow dom tests', () { + test('shadow dom', () async { + PageForShadowDomTest page = + await loader.getInstance(PageForShadowDomTest); + + expect(await page.button1.button.visibleText, contains('button 1')); + expect(await page.button1.button.visibleText, contains('some')); + expect(await page.button2.button.visibleText, contains('button 2')); + expect(await page.button2.button.visibleText, contains('some')); + if (loader.useShadowDom) { + expect(page.shouldBeEmpty, hasLength(0)); + } + }); + + test('WithVisibleText in shadow dom', () async { + PageForShadowDomWithVisibleTextTest page = + await loader.getInstance(PageForShadowDomWithVisibleTextTest); + + expect(await page.button1.visibleText, contains('button 1')); + expect(await page.button1.visibleText, contains('some')); + }); + + test('WithInnerText in shadow dom', () async { + if (!loader.useShadowDom) { + // if shadow dom is disabled, then visibleText and innerText are + // identical + return; + } + PageForShadowDomWithInnerTextTest page = + await loader.getInstance(PageForShadowDomWithInnerTextTest); + + expect(page.shouldBeEmpty, isEmpty); + expect(await page.button1.visibleText, contains('button 1')); + expect(await page.button1.visibleText, contains('some')); + expect(await page.button1.innerText, contains('button 1')); + expect(await page.button1.innerText, isNot(contains('some'))); + }); + + test('text methods on shadow root', () async { + PageForTextOnShadowRootTest page = + await loader.getInstance(PageForTextOnShadowRootTest); + + expect(page.buttons, hasLength(3)); + expect(await (await page.buttons[1].shadowRoot).visibleText, + contains('button 1')); + expect(await (await page.buttons[1].shadowRoot).visibleText, + contains('some')); + expect(await (await page.buttons[2].shadowRoot).visibleText, + contains('button 2')); + expect(await (await page.buttons[2].shadowRoot).visibleText, + contains('some')); + if (loader.useShadowDom) { + expect(await (await page.buttons[1].shadowRoot).innerText, + isNot(contains('button 1'))); + } else { + expect(await (await page.buttons[1].shadowRoot).innerText, + contains('button 1')); + } + expect( + await (await page.buttons[1].shadowRoot).innerText, contains('some')); + if (loader.useShadowDom) { + expect(await (await page.buttons[2].shadowRoot).innerText, + isNot(contains('button 2'))); + } else { + expect(await (await page.buttons[2].shadowRoot).innerText, + contains('button 2')); + } + expect( + await (await page.buttons[2].shadowRoot).innerText, contains('some')); + }); + }); +} + +class PageForShadowDomTest { + @ById('button-1') + ButtonShadowDOM button1; + + @ById('button-2') + ButtonShadowDOM button2; + + @ById('inner') + List shouldBeEmpty; +} + +@InShadowDom() +class ButtonShadowDOM { + @ById("inner") + PageLoaderElement button; +} + +class PageForShadowDomWithVisibleTextTest { + @ByTagName('a-custom-tag') + @WithVisibleText('some') + @WithVisibleText('button 1') + PageLoaderElement button1; +} + +class PageForShadowDomWithInnerTextTest { + @ByTagName('a-custom-tag') + @WithInnerText('some') + @WithInnerText('button 1') + List shouldBeEmpty; + + @ByTagName('a-custom-tag') + @WithInnerText('button 1') + PageLoaderElement button1; +} + +class PageForTextOnShadowRootTest { + @ByTagName('a-custom-tag') + List buttons; +} + +class PageForOptionalFunctionTest { + @ByTagName('non-existant') + @optional + Lazy shouldBeNull; + + @ById('button-1') + @optional + Lazy shouldBeNonNull; +} diff --git a/dart/test/async/src/shared.dart b/dart/test/async/src/shared.dart new file mode 100644 index 00000000..a73153c4 --- /dev/null +++ b/dart/test/async/src/shared.dart @@ -0,0 +1,56 @@ +// 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.async.test.shared; + +import 'package:matcher/matcher.dart'; +import 'package:pageloader/async/objects.dart'; + +PageLoader loader; + +class PageForSimpleTest { + @inject + PageLoader loader; + + @ByTagName('table') + Table table; +} + +@EnsureTag('table') +class Table { + @root + PageLoaderElement table; + + @ByTagName('tr') + List rows; +} + +class Row { + @ByTagName('td') + List cells; +} + +verifyRows(List rows) async { + expect(rows, hasLength(2)); + expect(rows.first.cells, hasLength(2)); + expect(rows[1].cells, hasLength(2)); + expect(await rows.first.cells.first.visibleText, 'r1c1'); + expect(await rows.first.cells[1].visibleText, 'r1c2'); + expect(await rows[1].cells.first.visibleText, 'r2c1'); + expect(await rows[1].cells[1].visibleText, 'r2c2'); +} + +verifyTable(Table table) async { + expect(await table.table.name, equalsIgnoringCase('TABLE')); + await verifyRows(table.rows); +} diff --git a/dart/test/async/src/typing_test.dart b/dart/test/async/src/typing_test.dart new file mode 100644 index 00000000..a362832a --- /dev/null +++ b/dart/test/async/src/typing_test.dart @@ -0,0 +1,62 @@ +// 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.async.test.typing; + +import 'package:matcher/matcher.dart'; +import 'package:pageloader/async/objects.dart'; +import 'package:unittest/unittest.dart'; +import 'shared.dart'; + +void runTests() { + group('typing tests', () { + test('Type into textarea', () async { + PageForTextAreaTypingText page = + await loader.getInstance(PageForTextAreaTypingText); + await page.textArea.type('some'); + expect(await page.textArea.attributes['value'], 'some'); + await page.textArea.type(' string'); + expect(await page.textArea.attributes['value'], 'some string'); + await page.textArea.clear(); + expect(await page.textArea.attributes['value'], ''); + }); + + test('typing should append', () async { + PageForTypingTests page = await loader.getInstance(PageForTypingTests); + expect(await page.text.attributes['value'], ''); + await page.text.type('some text'); + expect(await page.text.attributes['value'], 'some text'); + await page.text.type(' and more text'); + expect(await page.text.attributes['value'], 'some text and more text'); + }); + + test('value after clear', () async { + PageForTypingTests page = await loader.getInstance(PageForTypingTests); + expect(await page.text.attributes['value'], ''); + await page.text.type('some text'); + expect(await page.text.attributes['value'], 'some text'); + await page.text.clear(); + expect(await page.text.attributes['value'], ''); + }); + }); +} + +class PageForTextAreaTypingText { + @ById('textarea') + PageLoaderElement textArea; +} + +class PageForTypingTests { + @ById('text') + PageLoaderElement text; +} diff --git a/dart/test/async/webdriver_no_shadow_dom_test.dart b/dart/test/async/webdriver_no_shadow_dom_test.dart index 6ec06b3e..ebee24fa 100644 --- a/dart/test/async/webdriver_no_shadow_dom_test.dart +++ b/dart/test/async/webdriver_no_shadow_dom_test.dart @@ -22,6 +22,7 @@ import 'package:unittest/vm_config.dart' show useVMConfiguration; import 'package:webdriver/io.dart' show Capabilities, WebDriver, createDriver; import 'pageloader_test.dart' as plt; +import 'src/shared.dart' as shared; void main() { useVMConfiguration(); @@ -31,12 +32,12 @@ void main() { setUp(() async { driver = await _createTestDriver(); await driver.navigate.to(_testPagePath); - plt.loader = new WebDriverPageLoader(driver, useShadowDom: false); + shared.loader = new WebDriverPageLoader(driver, useShadowDom: false); }); tearDown(() async { await driver.quit(); - plt.loader = null; + shared.loader = null; }); plt.runTests(); diff --git a/dart/test/async/webdriver_test.dart b/dart/test/async/webdriver_test.dart index 18f1ebca..23679bca 100644 --- a/dart/test/async/webdriver_test.dart +++ b/dart/test/async/webdriver_test.dart @@ -22,6 +22,7 @@ import 'package:unittest/vm_config.dart' show useVMConfiguration; import 'package:webdriver/io.dart' show Capabilities, WebDriver, createDriver; import 'pageloader_test.dart' as plt; +import 'src/shared.dart' as shared; void main() { useVMConfiguration(); @@ -31,12 +32,12 @@ void main() { setUp(() async { driver = await _createTestDriver(); await driver.navigate.to(_testPagePath); - plt.loader = new WebDriverPageLoader(driver); + shared.loader = new WebDriverPageLoader(driver); }); tearDown(() async { await driver.quit(); - plt.loader = null; + shared.loader = null; }); plt.runTests(); diff --git a/dart/test/data/html_no_shadow_dom_setup.dart b/dart/test/data/html_no_shadow_dom_setup.dart new file mode 100644 index 00000000..b0221917 --- /dev/null +++ b/dart/test/data/html_no_shadow_dom_setup.dart @@ -0,0 +1,104 @@ +// 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_no_shadow_dom_setup; + +import 'dart:html' as html; + +html.Element setUp() { + var body = html.document.getElementsByTagName('body').first; + const bodyHtml = ''' + +
+ + + + + + + + +
r1c1r1c2
r2c1r2c2
+ +
area for mouse events
+ + + + + + test + + + +
+ outer div 1 + +
+
+ outer div 2 +
+ inner div 1 +
+
+ inner div 2 +
+
+ + + + + + +

   

'''; + + 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 = ''' + + + + + + + + + + +
r1c1r1c2
r2c1r2c2
+ +
area for mouse events
+ + + + + + test + + + +
+ outer div 1 + +
+
+ outer div 2 +
+ inner div 1 +
+
+ inner div 2 +
+
+ + button 1 + + + button 2 + +

   

'''; + + 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 = ''' - - - - - - - - - - -
r1c1r1c2
r2c1r2c2
- -
area for mouse events
- - - - - - test - - - -
- outer div 1 - -
-
- outer div 2 -
- inner div 1 -
-
- inner div 2 -
-
- - - - - - -

   

'''; - - 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 = ''' - - - - - - - - - - -
r1c1r1c2
r2c1r2c2
- -
area for mouse events
- - - - - - test - - - -
- outer div 1 - -
-
- outer div 2 -
- inner div 1 -
-
- inner div 2 -
-
- - button 1 - - - button 2 - -

   

'''; - - 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); });