| <!DOCTYPE html> |
| <!-- |
| Copyright 2011 WebDriver committers |
| Copyright 2011 Google Inc. |
| |
| 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> |
| <meta charset="utf-8"> |
| <title>bot.dom.getVisibleText Table Test</title> |
| <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 src="text_util.js"></script> |
| <script type="text/javascript"> |
| goog.require('bot.dom'); |
| goog.require('bot.userAgent'); |
| goog.require('goog.array'); |
| goog.require('goog.dom'); |
| goog.require('goog.testing.ExpectedFailures'); |
| goog.require('goog.userAgent'); |
| </script> |
| <style> |
| table { |
| width: 100%; |
| border: 1px solid black; |
| margin: 0.5em; |
| } |
| </style> |
| </head> |
| <body> |
| <div id="qunit"></div> |
| <div id="qunit-fixture"></div> |
| <script type="text/javascript"> |
| // Aliases for helping with creating tables. |
| var TABLE = goog.partial(goog.dom.createDom, goog.dom.TagName.TABLE, null); |
| var CAPTION = goog.partial( |
| goog.dom.createDom, goog.dom.TagName.CAPTION, null); |
| var TBODY = goog.partial(goog.dom.createDom, goog.dom.TagName.TBODY, null); |
| var TH = goog.partial(goog.dom.createDom, goog.dom.TagName.TH, null); |
| var TR = goog.partial(goog.dom.createDom, goog.dom.TagName.TR, null); |
| var TD = goog.partial(goog.dom.createDom, goog.dom.TagName.TD, null); |
| var P = goog.partial(goog.dom.createDom, goog.dom.TagName.P, null); |
| |
| var expectedFailures; |
| |
| QUnit.testStart(function() { |
| expectedFailures = new goog.testing.ExpectedFailures(); |
| }); |
| |
| QUnit.testDone(function() { |
| expectedFailures.handleTearDown(); |
| }); |
| |
| QUnit.test('empty table', function(assert) { |
| assertTextIs(assert, 'empty table', TABLE(), ''); |
| }); |
| |
| |
| QUnit.test('empty table body', function(assert) { |
| assertTextIs(assert, 'empty table body', TABLE(TBODY()), ''); |
| }); |
| |
| |
| QUnit.test('empty row', function(assert) { |
| assertTextIs(assert, 'empty row', TABLE(TBODY(TR(), ''))); |
| }); |
| |
| |
| QUnit.test('one empty cell', function(assert) { |
| assertTextIs(assert, 'one empty cell', TABLE(TBODY(TR(TD()), ''))); |
| }); |
| |
| |
| QUnit.test('two empty cells', function(assert) { |
| assertTextIs(assert, 'two empty cells', TABLE(TBODY(TR(TD(), TD()), ''))); |
| }); |
| |
| QUnit.test('table without tbody', function(assert) { |
| // IE < 8 does not render cells in a dynamically-added table with a <tbody>. |
| assertTextIs(assert, 'table without tbody', TABLE(TR(TD('a'))), bot.userAgent.IE_DOC_PRE8 ? '' : 'a'); |
| }); |
| |
| QUnit.test('one line table', function(assert) { |
| assertTextIs(assert, 'one line table', TABLE(TBODY(TR(TD('a'), TD('b')))), 'a b'); |
| }); |
| |
| QUnit.test('simple table', function(assert) { |
| assertTextIs(assert, 'simple table', |
| TABLE(TBODY( |
| TR(TD('a'), TD('b')), |
| TR(TD('c'), TD('d')))), |
| 'a b', |
| 'c d'); |
| }); |
| |
| QUnit.test('simple table with empty row', function(assert) { |
| assertTextIs(assert, 'simple table with empty row', |
| TABLE(TBODY( |
| TR(TD('a'), TD('b')), |
| TR(TD(), TD()))), |
| 'a b'); |
| }); |
| |
| QUnit.test('simple table with newlines between cells', function(assert) { |
| assertTextIs(assert, 'simple table with newlines between cells', |
| TABLE(TBODY( |
| TR(TD('a'), '\n', TD('b')), |
| TR(TD('c'), '\n', TD('d')))), |
| 'a b', |
| 'c d'); |
| }); |
| |
| QUnit.test('simple table cells end with newlines', function(assert) { |
| assertTextIs(assert, 'simple table cells end with newlines', |
| TABLE(TBODY( |
| TR(TD('a\n'), TD('b\n')), |
| TR(TD('c\n'), TD('d\n')))), |
| 'a b', |
| 'c d'); |
| }); |
| |
| QUnit.test('simple table with newlines between rows', function(assert) { |
| assertTextIs(assert, 'simple table with newlines between rows', |
| TABLE(TBODY( |
| TR(TD('a'), TD('b'), '\n\n'), |
| TR(TD('c'), TD('d')))), |
| 'a b', |
| 'c d'); |
| }); |
| |
| QUnit.test('a table with a caption', function(assert) { |
| assertTextIs(assert, 'a table with a caption', |
| TABLE(TBODY( |
| CAPTION('This is a caption'), |
| TR(TD('a'), TD('b')), |
| TR(TD('c'), TD('d')))), |
| 'This is a caption', |
| 'a b', |
| 'c d'); |
| }); |
| |
| QUnit.test('a table with empty cells', function(assert) { |
| assertTextIs(assert, 'a table with empty cells', |
| TABLE(TBODY( |
| TR(TD('a'), TD('b'), TD('c')), |
| TR(TD(), TD(), TD('Previous two cells were empty')))), |
| 'a b c', |
| 'Previous two cells were empty'); |
| }); |
| |
| QUnit.test('a table with paragraphs', function(assert) { |
| assertTextIs(assert, 'a table with paragraphs', |
| TABLE(TBODY(TR( |
| TD(P('table cell '), P('with '), P('paragraphs')), |
| TD('Cell #2')))), |
| 'table cell', |
| 'with', |
| 'paragraphs', |
| 'Cell #2'); |
| }); |
| |
| QUnit.test('nested tables', function(assert) { |
| assertTextIs(assert, 'nested tables', |
| TABLE(TBODY( |
| TR(TD("Table 1, Row 1, Cell 1"), TD("Table 1, Row 1, Cell 2")), |
| TR(TD("Table 1, Row 2, Cell 1"), |
| TD("Table 1, Row 2, Cell 2", |
| TABLE(TBODY( |
| TR(TD("Table 2, Row 1, Cell 1"), |
| TD("Table 2, Row 1, Cell 2")))))))), |
| "Table 1, Row 1, Cell 1 Table 1, Row 1, Cell 2", |
| "Table 1, Row 2, Cell 1 Table 1, Row 2, Cell 2", |
| "Table 2, Row 1, Cell 1 Table 2, Row 1, Cell 2"); |
| }); |
| |
| |
| QUnit.test('nested tables rows in outer table after inner table', function(assert) { |
| assertTextIs(assert, 'nested tables rows in outer table after inner table', |
| TABLE(TBODY( |
| TR(TD("Table 1, Row 1, Cell 1"), TD("Table 1, Row 1, Cell 2")), |
| TR(TD("Table 1, Row 2, Cell 1"), |
| TD("Table 1, Row 2, Cell 2", |
| TABLE(TBODY( |
| TR(TD("Table 2, Row 1, Cell 1"), |
| TD("Table 2, Row 1, Cell 2")))))), |
| TR(TD("Table 1, Row 3, Cell 1"), TD("Table 1, Row 3, Cell 2")))), |
| "Table 1, Row 1, Cell 1 Table 1, Row 1, Cell 2", |
| "Table 1, Row 2, Cell 1 Table 1, Row 2, Cell 2", |
| "Table 2, Row 1, Cell 1 Table 2, Row 1, Cell 2", |
| "Table 1, Row 3, Cell 1 Table 1, Row 3, Cell 2"); |
| }); |
| |
| |
| QUnit.test('nested tables now with newlines', function(assert) { |
| assertTextIs(assert, 'nested tables now with newlines', |
| goog.dom.getElement('nestedTable'), |
| "Table 1, Row 1, Cell 1 Table 1, Row 1, Cell 2", |
| "Table 1, Row 2, Cell 1 Table 1, Row 2, Cell 2", |
| "Table 2, Row 1, Cell 1 Table 2, Row 1, Cell 2", |
| "Table 1, Row 3, Cell 1 Table 1, Row 3, Cell 2"); |
| }); |
| |
| |
| QUnit.test('table with collapsed rows', function(assert) { |
| expectedFailures.expectFailureFor( |
| (goog.userAgent.IE && !goog.userAgent.isDocumentModeOrHigher(8)), |
| 'IE does not support visibility:collapsed until IE8'); |
| expectedFailures.run(function() { |
| assertTextIs(assert, 'table with collapsed rows', |
| goog.dom.getElement('collapsedTable'), |
| 'a', 'c'); |
| }); |
| }); |
| </script> |
| <table id="collapsedTable"> |
| <tr><td>a</td></tr> |
| <tr style="visibility:collapse"><td>b</td></tr> |
| <tr><td>c</td></tr> |
| </table> |
| <table id="nestedTable"> |
| <tr> |
| <td> |
| Table 1, Row 1, Cell 1 |
| </td> |
| <td> |
| Table 1, Row 1, Cell 2 |
| </td> |
| </tr> |
| <tr> |
| <td> |
| Table 1, Row 2, Cell 1 |
| </td> |
| <td> |
| Table 1, Row 2, Cell 2 |
| <table> |
| <tr> |
| <td> |
| Table 2, Row 1, Cell 1 |
| </td> |
| <td> |
| Table 2, Row 1, Cell 2 |
| </td> |
| </tr> |
| </table> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| Table 1, Row 3, Cell 1 |
| </td> |
| <td> |
| Table 1, Row 3, Cell 2 |
| </td> |
| </tr> |
| </table> |
| </body> |
| </html> |