| <!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'); |
| goog.require('goog.userAgent'); |
| </script> |
| |
| <script type="text/javascript"> |
| |
| QUnit.test('getVisibleText should return one line text', function(assert) { |
| var text = getVisibleTextByElementId('oneline'); |
| |
| assert.strictEqual(text, "A single line of text"); |
| }); |
| |
| QUnit.test('getVisibleText should return multiline text', function(assert) { |
| var text = getVisibleTextByElementId('multiline'); |
| |
| assertContains(assert, "A div containing", text); |
| assertContains(assert, "More than one line of text", text); |
| assertContains(assert, "and block level elements", text); |
| }); |
| |
| QUnit.test('getVisibleText should ignore script elements', function(assert) { |
| var text = getVisibleTextByElementId('script'); |
| |
| assert.strictEqual(text, "Some text that contains script tags"); |
| }); |
| |
| QUnit.test('getVisibleText should ignore title elements', function(assert) { |
| var titleElement = bot.locators.findElement({tagName: 'title'}); |
| var text = bot.dom.getVisibleText(titleElement); |
| |
| assert.strictEqual(text, ''); |
| }); |
| |
| QUnit.test('getVisibleText should recursively ignore title elements', function(assert) { |
| var headElement = bot.locators.findElement({tagName: 'head'}); |
| var text = bot.dom.getVisibleText(headElement); |
| |
| assert.strictEqual(text, ''); |
| }); |
| |
| QUnit.test('getVisibleText should represent a block level element as a newline', function(assert) { |
| var text = getVisibleTextByElementId('multiline'); |
| |
| assertStartsWith(assert, "A div containing\n", text); |
| assertContains(assert, "More than one line of text\n", text); |
| assertEndsWith(assert, "and block level elements", text); |
| }); |
| |
| QUnit.test('getVisible should collapse multiple whitespaces into a single space', function(assert) { |
| var text = getVisibleTextByElementId('lotsofspaces'); |
| |
| assert.strictEqual(text, "This line has lots of spaces."); |
| }); |
| |
| QUnit.test('getVisibleText should convert non-breaking space in a space char', function(assert) { |
| var text = getVisibleTextByElementId('nbsp'); |
| |
| assert.strictEqual(text, "This line has a non-breaking space"); |
| }); |
| |
| QUnit.test('getVisibleText should not collapse non-breaking spaces', function(assert) { |
| var text = getVisibleTextByElementId("nbspandspaces"); |
| assert.strictEqual(text, "This line has a non-breaking space and spaces"); |
| }); |
| |
| QUnit.test('getVisibleText should not trim trailing non-breaking spaces', function(assert) { |
| var text = getVisibleTextByElementId("trailingnbsp"); |
| assert.strictEqual(text, "This line has trailing non-breaking spaces "); |
| }); |
| |
| QUnit.test('getVisibleText should not trim non-breaking spaces at the end of a line in the middle of text', function(assert) { |
| var text = getVisibleTextByElementId("multilinetrailingnbsp"); |
| assertStartsWith(assert, "These lines \n", text); |
| }); |
| |
| QUnit.test('getVisibleText should not trim non-breaking spaces at the start of a line in the middle of text', function(assert) { |
| var text = getVisibleTextByElementId("multilinetrailingnbsp"); |
| assertContains(assert, "\n have", text); |
| }); |
| |
| QUnit.test('getVisibleText should not trim trailing non-breaking spaces in multiline text', function(assert) { |
| var text = getVisibleTextByElementId("multilinetrailingnbsp"); |
| assertEndsWith(assert, "trailing NBSPs ", text); |
| }); |
| |
| QUnit.test('getVisibleText inline elements should not affect returned text', function(assert) { |
| var text = getVisibleTextByElementId("inline"); |
| |
| assert.strictEqual(text, "This line has text within elements that are meant" + |
| " to be displayed inline"); |
| }); |
| |
| QUnit.test('getVisibleText should return the entire text of inline elements', function(assert) { |
| var text = getVisibleTextByElementId("span"); |
| |
| assert.strictEqual(text, "An inline element"); |
| }); |
| |
| QUnit.test('getVisibleText should return empty string when text is only spaces', function(assert) { |
| var text = getVisibleTextByElementId("spaces"); |
| |
| assert.strictEqual(text, ""); |
| }); |
| |
| QUnit.test('getVisibleText should return empty string when text is empty', function(assert) { |
| var text = getVisibleTextByElementId("empty"); |
| |
| assert.strictEqual(text, ""); |
| }); |
| |
| QUnit.test('getVisibleText should return empty string when tag is self closing', function(assert) { |
| var text = getVisibleTextByElementId("self-closed"); |
| |
| assert.strictEqual(text, ""); |
| }); |
| |
| QUnit.test('getVisibleText should not trim spaces when line wraps', function(assert) { |
| var text = getVisibleTextByElementId("wrappingtd"); |
| |
| assert.strictEqual(text, "beforeSpace afterSpace"); |
| }); |
| |
| QUnit.test('getVisibleText correctly handles an entire table', function(assert) { |
| var text = getVisibleTextByElementId("wrappingtable"); |
| |
| assert.strictEqual(text, "beforeSpace afterSpace"); |
| }); |
| |
| QUnit.test('getVisibleText should handle sibling block level elements', function(assert) { |
| var text = getVisibleTextByElementId("twoblocks"); |
| |
| assert.strictEqual(text, "Some text\nSome more text"); |
| }); |
| |
| QUnit.test('getVisibleText should handle nested block level elements', function(assert) { |
| var text = getVisibleTextByElementId("nestedblocks"); |
| |
| assert.strictEqual(text, "Cheese\nSome text\nSome more text\nand also\nBrie"); |
| }); |
| |
| QUnit.test('getVisibleText should handle whitespace in inline elements', function(assert) { |
| var text = getVisibleTextByElementId("inlinespan"); |
| |
| assert.strictEqual(text, "line has text"); |
| }); |
| |
| QUnit.test('getVisibleText should handle lack of spaces between inline elements', function(assert) { |
| var text = getVisibleTextByElementId("inlinenospaces"); |
| assert.strictEqual(text, "oooOooo"); |
| var text2 = getVisibleTextByElementId("inlinenospaces2"); |
| assert.strictEqual(text2, "A B"); |
| }); |
| |
| QUnit.test('getVisibleText should not add extra spaces', function(assert) { |
| var text = getVisibleTextByElementId("descartes"); |
| var text2 = getVisibleTextByElementId("abc"); |
| |
| assert.strictEqual(text, "Dubito, ergo cogito, ergo sum."); |
| assert.strictEqual(text2, "a bc"); |
| }); |
| |
| QUnit.test('getVisible test get text with line break for inline element', function(assert) { |
| var text = getVisibleTextByElementId("label1"); |
| assertContains(assert, "foo\nbar", text); |
| }); |
| |
| QUnit.test('getVisibleText should only include visible text', function(assert) { |
| var empty = getVisibleTextByElementId("suppressedParagraph"); |
| var explicit = getVisibleTextByElementId("outer"); |
| |
| assert.strictEqual(empty, ""); |
| assert.strictEqual(explicit, "sub-element that is explicitly visible"); |
| }); |
| |
| QUnit.test('getVisibleText on anchors with whitespaces', function(assert) { |
| var text = getVisibleTextByElementId("links"); |
| |
| assert.strictEqual(text, "link with leading space " + "link with trailing space " + |
| "link with formatting tags"); |
| }); |
| |
| QUnit.test('getVisibleText handles trailing whitespaces', function(assert) { |
| var text = getVisibleTextByElementId("trailingSpaces"); |
| assert.strictEqual(text, "1 2 3 4"); |
| }); |
| |
| QUnit.test('getVisibleText handles trailing breaks', function(assert) { |
| var text = getVisibleTextByElementId("trailingBreaks"); |
| assert.strictEqual(text, "a\nb"); |
| }); |
| |
| QUnit.test('keeps non-breaking spaces before a tag', function(assert) { |
| var text = getVisibleTextByElementId("id2"); |
| |
| assert.strictEqual(text, "this is the second element"); |
| }); |
| |
| QUnit.test('removes zero width characters', function(assert) { |
| var text = getVisibleTextByElementId("zerowidth"); |
| |
| assert.strictEqual(text, "This line has a bunch of zero-width characters in it."); |
| }); |
| |
| QUnit.test('transparent text is ignored', function(assert) { |
| var text = getVisibleTextByElementId("opaque"); |
| |
| assert.strictEqual(text, "Some text"); |
| }); |
| |
| QUnit.test('should retain the formatting of text within a pre element', function(assert) { |
| var text = getVisibleTextByElementId("preformatted"); |
| |
| assert.strictEqual(text, " This section has a preformatted\n text block\n split in four lines\n "); |
| }); |
| |
| QUnit.test('should retain the formatting of text within a pre element that is within a regular block', function(assert) { |
| var text = getVisibleTextByElementId("div-with-pre"); |
| |
| assert.strictEqual(text, "before pre\n This section has a preformatted\n text block\n split in four lines\n \nafter pre"); |
| }); |
| |
| QUnit.test('getVisibleText should handle css content replacement', function(assert) { |
| var supportsContentReplacement = !(goog.userAgent.GECKO || goog.userAgent.IE || |
| goog.userAgent.SAFARI || goog.userAgent.WEBKIT || goog.userAgent.EDGE); |
| |
| if (!supportsContentReplacement) { |
| assert.ok(true, "Skipping: Does not support CSS3 content: 'foo' replacement"); |
| return; |
| } |
| |
| var text = getVisibleTextByElementId("css3-content"); |
| assert.strictEqual(text, "PASS"); |
| }); |
| |
| QUnit.test('getVisibleText should handle text transform property', function(assert) { |
| var text = getVisibleTextByElementId("capitalized"); |
| assert.strictEqual(text, "Hello, World! Bla-Bla-BLA"); |
| text = getVisibleTextByElementId("lowercased"); |
| assert.strictEqual(text, "hello, world! bla-bla-bla"); |
| text = getVisibleTextByElementId("uppercased"); |
| assert.strictEqual(text, "HELLO, WORLD! BLA-BLA-BLA"); |
| |
| text = getVisibleTextByElementId("capitalized_accented_character"); |
| assert.strictEqual(text, "Fecha De Expiración"); |
| text = getVisibleTextByElementId("capitalized_enye"); |
| assert.strictEqual(text, "Mañana"); |
| |
| text = getVisibleTextByElementId("capitalized-1"); |
| assert.strictEqual(text, "Äåìî"); |
| text = getVisibleTextByElementId("capitalized-2"); |
| assert.strictEqual(text, "Manipulowanie Przepływem"); |
| text = getVisibleTextByElementId("capitalized-3"); |
| assert.strictEqual(text, "Manipulowanie Przepływem"); |
| text = getVisibleTextByElementId("capitalized-4"); |
| assert.strictEqual(text, "Manipulowanie Pr0123z4epływem"); |
| text = getVisibleTextByElementId("capitalized-5"); |
| assert.strictEqual(text, "Lorem Ipsum Dolor Sit Amet, Consectetur Adipisicing Elit,"); |
| text = getVisibleTextByElementId("capitalized-6"); |
| assert.strictEqual(text, "Ⓐⓑⓒ (Ⓓⓔⓕ) —Ⓖⓗⓘ— Ⓙkl"); |
| text = getVisibleTextByElementId("capitalized-7"); |
| assert.strictEqual(text, '(This) "Is" [A] –Short– -Test- «For» *The* _Css_ ¿Capitalize? ?¡Transfor'); |
| text = getVisibleTextByElementId("capitalized-8"); |
| assert.strictEqual(text, 'The Dutch Word: "Ijsland" Starts With A Digraph'); |
| text = getVisibleTextByElementId("capitalized-9"); |
| assert.strictEqual(text, 'Test_text'); |
| }); |
| |
| function getVisibleTextByElementId(id) { |
| var e = bot.locators.findElement({id: id}); |
| return bot.dom.getVisibleText(e); |
| } |
| |
| function assertContains(assert, expectedText, text) { |
| assert.ok(text.indexOf(expectedText) >= 0, |
| "Text [" + text + "] does not contain [" + expectedText + "]"); |
| } |
| |
| function assertStartsWith(assert, expectedText, text) { |
| assert.ok(text.indexOf(expectedText) == 0, |
| "Text [" + text + "] does not start with [" + expectedText + "]"); |
| } |
| |
| function assertEndsWith(assert, expectedText, text) { |
| assert.ok(text.lastIndexOf(expectedText) == text.length - expectedText.length, |
| "Text [" + text + "] does not end with [" + expectedText + "]"); |
| } |
| |
| QUnit.test('bug exposed by issue 1293', function(assert) { |
| var spaces = getVisibleTextByElementId('spaces'); |
| assert.strictEqual(spaces, ''); |
| |
| var table = getVisibleTextByElementId('wrappingtd'); |
| assert.strictEqual(table, 'beforeSpace afterSpace'); |
| }); |
| </script> |
| |
| <style type="text/css"> |
| .transparent { |
| opacity: 0; /* non IE */ |
| filter:alpha(opacity=0); /* IE 6+ */ |
| } |
| </style> |
| |
| </head> |
| <body> |
| <div id="qunit"></div> |
| <div id="qunit-fixture"></div> |
| <p id="oneline">A single line of text</p> |
| |
| <div id="multiline"> |
| <div> |
| <p>A div containing</p> |
| More than one line of text<br/> |
| |
| <div>and block level elements</div> |
| </div> |
| </div> |
| <span id="span">An inline element</span> |
| |
| <p id="lotsofspaces">This line has lots |
| |
| of spaces. |
| </p> |
| |
| <p id="nbsp">This line has a non-breaking space</p> |
| |
| <p id="spaces"> </p> |
| |
| <p id="empty"></p> |
| |
| <p id="self-closed" /> |
| |
| <p id="suppressedParagraph" style="display: none">A paragraph suppressed using CSS display=none</p> |
| |
| <p id="outer" style="visibility: hidden">A <b id="visibleSubElement" style="visibility: visible">sub-element that is explicitly visible</b> using CSS visibility=visible</p> |
| |
| <p id="script">Some text<script>function shouldIgnoreMe() {}</script> that contains script tags</p> |
| <p id="nbspandspaces">This line has a non-breaking space and spaces</p> |
| <p id="trailingnbsp">This line has trailing non-breaking spaces </p> |
| <p id="multilinetrailingnbsp">These lines  <br />  have leading and trailing NBSPs </p> |
| <p id="css3-content" style="content: 'PASS'">FAIL</p> |
| |
| <p id="inline">This <span id="inlinespan"> line has <em>text</em> </span> within elements that are meant to be displayed |
| <!-- not as a block but --> inline</p> |
| |
| <div id="div-with-pre"> |
| <p>before pre</p> |
| <pre id="preformatted"> This section has a preformatted |
| text block |
| split in four lines |
| </pre> |
| <p>after pre</p> |
| </div> |
| |
| <div id="twoblocks"><p>Some text</p><p>Some more text</p></div> |
| |
| <div id="nestedblocks">Cheese <div><p>Some text</p><div><p>Some more text</p><p>and also</p></div></div>Brie</div> |
| |
| <div id="collapsingtext"><span></span><div>Hello, world</div><span></span></div> |
| |
| <div id="inlinenospaces">ooo<strong>O</strong>ooo</div> |
| <div id="inlinenospaces2"><span>A <span></span>B</span></div> |
| |
| <form action="resultPage.html"> |
| <p> |
| <input type="checkbox" id="checkbox1"> |
| <label id="label1" for="checkbox1">foo<br />bar</label> |
| </p> |
| </form> |
| |
| <div id="links"> |
| <a href=""> link with leading space</a> |
| <a href="" id="linkWithTrailingSpace">link with trailing space |
| </a> |
| <a href=""><b>link with formatting tags</b></a> |
| </div> |
| <div id="trailingSpaces"> |
| 1 |
| <a href="">2</a> |
| 3 |
| <a href="">4</a></div> |
| |
| <div id="trailingBreaks"> |
| <span>a<br></span><span>b</span> |
| </div> |
| |
| <table id="wrappingtable"> |
| <tbody> |
| <tr><td id="wrappingtd" style="width: 10px;"><span>beforeSpace</span><span> </span><span>afterSpace</span></td></tr> |
| </tbody> |
| </table> |
| |
| <span><strong id="descartes">Dubito, <em>ergo cogito</em>, ergo sum.</strong></span> |
| <span id="abc"><b>a</b> <b>b</b>c</span> |
| |
| <a id="id2" >this is the <b>second</b> <span>element</span></a> |
| |
| <div id="opaque">Some <span class="transparent">transparent</span> text</div> |
| |
| <span id="zerowidth">This line has a bunch of ze​ro-width‎ characters‏ in it.</span> |
| |
| <div> |
| <a id="capitalized" style="text-transform: capitalize">hello, world! bla-bla-BLA</a><br/> |
| <a id="lowercased" style="text-transform: lowercase">Hello, world! bla-bla-BLA</a><br/> |
| <a id="uppercased" style="text-transform: uppercase">hello, world! bla-bla-BLA</a><br/> |
| </div> |
| |
| <div> |
| <a id="capitalized_accented_character" style="text-transform: capitalize">Fecha de expiración</a><br/> |
| <a id="capitalized_enye" style="text-transform: capitalize">mañana</a><br/> |
| </div> |
| |
| <div> |
| <a lang="ru" id="capitalized-1" style="text-transform: capitalize">äåìî</a><br/> |
| <a id="capitalized-2" style="text-transform: capitalize">Manipulowanie przepływem</a><br/> |
| <a id="capitalized-3" style="text-transform: capitalize">manipulowanie przepływem</a><br/> |
| <a id="capitalized-4" style="text-transform: capitalize">Manipulowanie pr0123z4epływem</a><br/> |
| <a id="capitalized-5" style="text-transform: capitalize">Lorem ipsum dolor sit amet, consectetur adipisicing elit,</a><br/> |
| <a id="capitalized-6" style="text-transform: capitalize">ⓐⓑⓒ (ⓓⓔⓕ) —ⓖⓗⓘ— ⓙkl</a><br/> |
| <a id="capitalized-7" style="text-transform: capitalize">(this) "is" [a] –short– -test- «for» *the* _css_ ¿capitalize? ?¡transfor</a><br/> |
| <a id="capitalized-8" style="text-transform: capitalize">The Dutch word: "ijsland" starts with a digraph</a><br/> |
| <a id="capitalized-9" style="text-transform: capitalize">test_text</a><br/> |
| </div> |
| |
| </body> |
| </html> |