| <!DOCTYPE html> | |
| <!-- | |
| Copryight 2012 Software Freedom Conservancy | |
| Copyright 2010-2012 WebDriver committers | |
| 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. | |
| --> | |
| <html> | |
| <head> | |
| <title>text_test.html</title> | |
| <meta charset="utf-8"> | |
| <link rel="stylesheet" href="/filez/_main/third_party/js/qunit/qunit.css"> | |
| <script src="/filez/_main/third_party/js/qunit/qunit.js"></script> | |
| <script src="/filez/_main/third_party/js/qunit/qunit_test_runner.js"></script> | |
| <script src="test_bootstrap.js"></script> | |
| <script type="text/javascript"> | |
| goog.require('bot.dom'); | |
| goog.require('bot.locators'); | |
| </script> | |
| <script type="text/javascript"> | |
| var findElement = bot.locators.findElement; | |
| var getText = bot.dom.getVisibleText; | |
| customElements.define('open-shadow-element', | |
| class extends HTMLElement { | |
| constructor() { | |
| super(); | |
| this.attachShadow({ mode: 'open' }); | |
| } | |
| } | |
| ); | |
| customElements.define('closed-shadow-element', | |
| class extends HTMLElement { | |
| constructor() { | |
| super(); | |
| this._shadowRoot = this.attachShadow({ mode: 'closed' }); | |
| } | |
| } | |
| ); | |
| function setCustomElement(html, type='open') { | |
| if (type == 'closed') { | |
| document.querySelector(`closed-shadow-element`)._shadowRoot.innerHTML = html; | |
| } else { | |
| // Set shadow DOM on ALL open-shadow-element instances | |
| document.querySelectorAll(`open-shadow-element`).forEach(elem => { | |
| elem.shadowRoot.innerHTML = html; | |
| }); | |
| } | |
| } | |
| QUnit.testDone(function() { | |
| document.querySelectorAll('open-shadow-element').forEach(elem => { | |
| elem.shadowRoot.innerHTML = ''; | |
| }); | |
| let closed = document.querySelector('closed-shadow-element'); | |
| closed._shadowRoot.innerHTML = ''; | |
| }); | |
| QUnit.test('text in shadow DOM', function(assert) { | |
| setCustomElement('<div><a href=# id=linkText>full link text</a></div>'); | |
| let customEl = findElement({ tagName: 'open-shadow-element' }); | |
| let text = getText(customEl); | |
| assert.strictEqual(text, 'full link text'); | |
| }); | |
| QUnit.test('text for slot value in shadow DOM', function(assert) { | |
| setCustomElement('<slot><span>full</span></slot>'); | |
| let customEl = findElement({ id: 'custom-text' }); | |
| let text = getText(customEl); | |
| assert.strictEqual(text, 'custom'); | |
| }); | |
| QUnit.test('text for slot and extra value in shadow DOM', function(assert) { | |
| setCustomElement('<slot><span>full</span></slot> text'); | |
| let customEl = findElement({ id: 'custom-text' }); | |
| let text = getText(customEl); | |
| assert.strictEqual(text, 'custom text'); | |
| }); | |
| QUnit.test('text for default slot value in shadow DOM', function(assert) { | |
| setCustomElement('<slot><span>full</span></slot> text'); | |
| let customEl = findElement({ tagName: 'open-shadow-element' }); | |
| let text = getText(customEl); | |
| assert.strictEqual(text, 'full text'); | |
| }); | |
| QUnit.test('hidden text in shadow DOM', function(assert) { | |
| setCustomElement( | |
| '<div><a href=# id=linkText>full <div style="display:none">link</div> text</a></div>' | |
| ); | |
| let customEl = findElement({ tagName: 'open-shadow-element' }); | |
| let text = getText(customEl); | |
| assert.strictEqual(text, 'full text'); | |
| }); | |
| QUnit.test('text for element within closed shadow DOM', function(assert) { | |
| setCustomElement('<a href=# id=linkText>full link text</a>', 'closed'); | |
| let customEl = findElement({ tagName: 'closed-shadow-element' }); | |
| let innerEl = findElement({ css: 'a' }, customEl._shadowRoot); | |
| let text = getText(innerEl); | |
| assert.strictEqual(text, 'full link text'); | |
| }); | |
| </script> | |
| </head> | |
| <body> | |
| <div id="qunit"></div> | |
| <div id="qunit-fixture"></div> | |
| <open-shadow-element></open-shadow-element> | |
| <open-shadow-element id="custom-text">custom</open-shadow-element> | |
| <closed-shadow-element></closed-shadow-element> | |
| </body> | |
| </html> |