<!DOCTYPEHTML>
<html>
<head>
<meta charset="utf-8">
<title>Test pasting table rows</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<style>
/**
* A small font-size, so that the loaded document fits on the screens of all
* test devices.
*/
* { font-size: 8px; }
/**
* Helps fitting the tables on the screens of all test devices.
*/ div[class="tableContainer"] {
display: inline-block;
}
</style>
<script>
const kEditabilityModeContenteditable = "contenteditable";
const kEditabilityModeDesignMode = "designMode";
// All column names of the test-tables used below.
const kColumns = ["c1", "c2", "c3"];
// Ctrl+click on table cells to select them.
const kSelectionModeClickSelection = "click-selection";
// Click and drag from the first given row to the end of the last given row.
const kSelectionModeDragSelection = "drag-selection";
// Where a table is pasted to in the test.
const kTargetElementId = "targetElement";
/**
* @param aTableName see Test::constructor::aTableName.
* @param aRowsInTable see Test::constructor::aRowsInTable.
* @return an array of elements of aRowsInTable.
*/
function FilterRowsWithParentTag(aTableName, aRowsInTable, aTagName) {
return aRowsInTable.filter(rowName => document.getElementById(aTableName +
rowName).parentElement.tagName == aTagName);
}
/**
* Tables used with this class are required to:
* - have ids of the following form for each table cell:
<tableName><rowName><column>. Where <column> has to be one of
`kColumns`.
- have exactly `kColumns.length` columns per row.
- have an id of the form <tableName><rowName> for each table row.
*/
class Test {
/**
* @param aTableName indicates which table to operate on.
* @param aRowsInTable an array of row names. Ordered from top to bottom.
* @param aEditabilityMode `kEditabilityModeContenteditable` or
* `kEditabilityModeDesignMode`.
* @param aSelectionMode `kSelectionModeClickSelection` or
* `kSelectionModeDragSelection`.
*/
constructor(aTableName, aRowsInTable, aEditabilityMode, aSelectionMode) {
ok(aEditabilityMode == kEditabilityModeContenteditable ||
aEditabilityMode == kEditabilityModeDesignMode, "Editablity mode is valid.");
if (this._editabilityMode == kEditabilityModeDesignMode) {
this._removeContenteditableAttributeOfTarget();
document.designMode = "on";
}
SimpleTest.info("Constructed the test (" + this._toString() + ").");
}
/**
* Call `_restoreStateOfDocumentBeforeRun` afterwards.
*/
async _run() {
// Generate the expected pasted HTML before pasting the clipboard's
// content, because that may duplicate ids, hence leading to creating
// a wrong expectation string.
const expectedPastedHTML = this._createExpectedOuterHTMLOfTable();
const targetElement = document.getElementById(kTargetElementId);
is(targetElement.children.length, 1, "Target element has exactly one child.");
is(targetElement.children[0]?.tagName, kTableTagName, "Target element has a table child.");
// Linebreaks and whitespace after tags are irrelevant, hence stripping
// them.
is(SimpleTest.stripLinebreaksAndWhitespaceAfterTags(
targetElement.children[0]?.outerHTML), expectedPastedHTML, "Pasted table (" + this._toString() + ") has expected outerHTML.");
}
const expectedPastedHTML = (() => {
if (navigator.platform.includes(kPlatformWindows)) {
// TODO: ideally, this should be factored out, see bug 1669963.
function validatorFn(aData) {
// The data's format doesn't specify whether there should be line
// breaks or whitspace between tags. Hence, remove them.
if (SimpleTest.stripLinebreaksAndWhitespaceAfterTags(aData) ==
SimpleTest.stripLinebreaksAndWhitespaceAfterTags(expectedPastedHTML)) {
return true;
}
info(`Waiting clipboard data: expected:\n"${
SimpleTest.stripLinebreaksAndWhitespaceAfterTags(expectedPastedHTML)
}"\n, but got:\n"${
SimpleTest.stripLinebreaksAndWhitespaceAfterTags(aData)
}"`);
return false;
}
for (const editabilityMode of kEditabilityModes) {
for (const testGroup of kTestGroups) {
for (const tableName of testGroup.tablesToTest) {
for (const rowsToSelect of testGroup.rowsToSelect) {
if (DoesContainRowInTheadAndTbody(tableName, rowsToSelect) ||
DoesContainRowInTbodyAndTfoot(tableName, rowsToSelect)) {
todo(false, 'Rows to select (' + rowsToSelect.toString() + ') contains ' + ' row in and or of table "' +
tableName + '", see bug 1667786.');
continue;
}
const test = new Test(tableName, rowsToSelect, editabilityMode,
testGroup.selectionMode);
try {
await test._run();
} catch (ex) {
ok(false, `Aborting the following tests due to unexpected error: ${ex.message}`);
SimpleTest.finish();
return;
}
test._restoreStateOfDocumentBeforeRun();
}
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.