|
| 1 | +<!DOCTYPE html> |
| 2 | +<!-- |
| 3 | +Copryight 2012 Software Freedom Conservancy |
| 4 | +Copyright 2010-2012 WebDriver committers |
| 5 | +
|
| 6 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +you may not use this file except in compliance with the License. |
| 8 | +You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | +Unless required by applicable law or agreed to in writing, software |
| 13 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +See the License for the specific language governing permissions and |
| 16 | +limitations under the License. |
| 17 | +--> |
| 18 | +<html> |
| 19 | + |
| 20 | +<head> |
| 21 | + <title>text_test.html</title> |
| 22 | + <meta charset="UTF-8"> |
| 23 | + <script src="test_bootstrap.js"></script> |
| 24 | + <script type="text/javascript"> |
| 25 | + goog.require('bot.dom'); |
| 26 | + goog.require('bot.locators'); |
| 27 | + goog.require('goog.testing.jsunit'); |
| 28 | + goog.require('goog.testing.ExpectedFailures'); |
| 29 | + </script> |
| 30 | + |
| 31 | + <script type="text/javascript"> |
| 32 | + var findElement = bot.locators.findElement; |
| 33 | + var getText = bot.dom.getVisibleText; |
| 34 | + |
| 35 | + customElements.define('custom-shadow-element', |
| 36 | + class extends HTMLElement { |
| 37 | + constructor() { |
| 38 | + { |
| 39 | + super(); |
| 40 | + this.attachShadow({ mode: 'open' }); |
| 41 | + } |
| 42 | + } |
| 43 | + }); |
| 44 | + function setCustomElement(html) { |
| 45 | + document.querySelector("custom-shadow-element").shadowRoot.innerHTML = html; |
| 46 | + } |
| 47 | + |
| 48 | + function tearDown() { |
| 49 | + let elem = document.querySelector("custom-shadow-element"); |
| 50 | + elem.shadowRoot.innerHTML = ""; |
| 51 | + |
| 52 | + } |
| 53 | + |
| 54 | + function testTextInShadowDOM() { |
| 55 | + setCustomElement("<div><a href=# id=linkText>full link text</a></div>") |
| 56 | + let elem = findElement({ tagName: "custom-shadow-element" }); |
| 57 | + let text = getText(elem); |
| 58 | + assertEquals(text, "full link text"); |
| 59 | + } |
| 60 | + |
| 61 | + function testHiddenTextInShadowDOM() { |
| 62 | + setCustomElement("<div><a href=# id=linkText>full <div style='display:none'>link</div> text</a></div>") |
| 63 | + let elem = findElement({ tagName: "custom-shadow-element" }); |
| 64 | + let text = getText(elem); |
| 65 | + assertEquals(text, "full text"); |
| 66 | + } |
| 67 | + |
| 68 | + </script> |
| 69 | + |
| 70 | +</head> |
| 71 | + |
| 72 | +<body> |
| 73 | + <custom-shadow-element></custom-shadow-element> |
| 74 | +</body> |
| 75 | + |
| 76 | +</html> |
0 commit comments