B2G/gecko/toolkit/content/tests/widgets/tree_shared.js
// column 1 must not be editable.
column 1 must not be editable.
column 1 must not be editable .
function testtag_tree(treeid, treerowinfoid, seltype, columnstype, testid)
{
  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  function preventDefault(event) {
    event.preventDefault();
  }
  document.addEventListener("keypress", preventDefault, false);
  var multiple = (seltype == "multiple");
  var tree = document.getElementById(treeid);
  var treerowinfo = document.getElementById(treerowinfoid);
  var rowInfo;
  if (testid =="tree view")
    rowInfo = getCustomTreeViewCellInfo();
  else
    rowInfo = convertDOMtoTreeRowInfo(treerowinfo, 0, { value: -1 });
  var columnInfo = (columnstype == "simple") ? columns_simpletree : columns_hiertree;
  is(tree.view.selection.currentColumn, null, testid + " initial currentColumn");
  is(tree.selType, seltype == "multiple" ? "" : seltype, testid + " seltype");
  if (seltype == "cell")
    tree.view.selection.currentColumn = tree.columns[0];
  testtag_tree_columns(tree, columnInfo, testid);
  testtag_tree_TreeSelection(tree, testid, multiple);
  testtag_tree_TreeSelection_UI(tree, testid, multiple);
  if (seltype == "cell")
    testtag_tree_TreeSelection_UI_cell(tree, testid, rowInfo);
  testtag_tree_TreeView(tree, testid, rowInfo);
  is(tree.editable, false, "tree should not be editable");
  is(tree.editingRow, -1, testid + " initial editingRow");
  is(tree.editingColumn, null, testid + " initial editingColumn");
  testtag_tree_UI_editing(tree, testid, rowInfo);
  is(tree.editable, false, "tree should not be editable after testtag_tree_UI_editing");
  is(tree.editingRow, -1, testid + " initial editingRow (continued)");
  is(tree.editingColumn, null, testid + " initial editingColumn (continued)");
  var ecolumn = tree.columns[0];
  ok(!tree.startEditing(1, ecolumn), "non-editable trees shouldn't start editing");
  is(tree.editingRow, -1, testid + " failed startEditing shouldn't set editingRow");
  is(tree.editingColumn, null, testid + " failed startEditing shouldn't set editingColumn");  
  tree.editable = true;
  ok(tree.startEditing(1, ecolumn), "startEditing should have returned true");
  is(tree.editingRow, 1, testid + " startEditing editingRow");
  is(tree.editingColumn, ecolumn, testid + " startEditing editingColumn");
  is(tree.getAttribute("editing"), "true", testid + " startEditing editing attribute");
  tree.stopEditing(true);
  is(tree.editingRow, -1, testid + " stopEditing editingRow");
  is(tree.editingColumn, null, testid + " stopEditing editingColumn");
  is(tree.hasAttribute("editing"), false, testid + " stopEditing editing attribute");
  tree.startEditing(-1, ecolumn);
  is(tree.editingRow == -1 && tree.editingColumn == null, true, testid + " startEditing -1 editingRow");
  tree.startEditing(15, ecolumn);
  is(tree.editingRow == -1 && tree.editingColumn == null, true, testid + " startEditing 15 editingRow");
  tree.startEditing(1, null);
  is(tree.editingRow == -1 && tree.editingColumn == null, true, testid + " startEditing null column editingRow");
  tree.startEditing(2, tree.columns[1]);
  is(tree.editingRow == -1 && tree.editingColumn == null, true, testid + " startEditing non editable cell editingRow");
  tree.startEditing(1, ecolumn);
  var inputField = tree.inputField;
  is(inputField instanceof Components.interfaces.nsIDOMXULTextBoxElement, true, testid + "inputField");
  inputField.value = "Changed Value";
  tree.stopEditing(true);
  is(tree.view.getCellText(1, ecolumn), "Changed Value", testid + "edit cell accept");
  tree.startEditing(1, ecolumn);
  inputField.value = "Second Value";
  tree.stopEditing(false);
  is(tree.view.getCellText(1, ecolumn), "Changed Value", testid + "edit cell no accept");
  tree.editable = false;
  if (testid !="tree view")
    testtag_tree_TreeView_rows_sort(tree, testid, rowInfo);
  testtag_tree_wheel(tree);
  document.removeEventListener("keypress", preventDefault, false);
  SimpleTest.finish();
}
function testtag_tree ( treeid , treerowinfoid , seltype , columnstype , testid ) { netscape . security . PrivilegeManager . enablePrivilege ( "UniversalXPConnect" ) ; function preventDefault ( event ) { event . preventDefault ( ) ; } document . addEventListener ( "keypress" , preventDefault , false ) ; var multiple = ( seltype == "multiple" ) ; var tree = document . getElementById ( treeid ) ; var treerowinfo = document . getElementById ( treerowinfoid ) ; var rowInfo ; if ( testid == "tree view" ) rowInfo = getCustomTreeViewCellInfo ( ) ; else rowInfo = convertDOMtoTreeRowInfo ( treerowinfo , 0 , { value : - 1 } ) ; var columnInfo = ( columnstype == "simple" ) ? columns_simpletree : columns_hiertree ; is ( tree . view . selection . currentColumn , null , testid + " initial currentColumn" ) ; is ( tree . selType , seltype == "multiple" ? "" : seltype , testid + " seltype" ) ; if ( seltype == "cell" ) tree . view . selection . currentColumn = tree . columns [ 0 ] ; testtag_tree_columns ( tree , columnInfo , testid ) ; testtag_tree_TreeSelection ( tree , testid , multiple ) ; testtag_tree_TreeSelection_UI ( tree , testid , multiple ) ; if ( seltype == "cell" ) testtag_tree_TreeSelection_UI_cell ( tree , testid , rowInfo ) ; testtag_tree_TreeView ( tree , testid , rowInfo ) ; is ( tree . editable , false , "tree should not be editable" ) ; is ( tree . editingRow , - 1 , testid + " initial editingRow" ) ; is ( tree . editingColumn , null , testid + " initial editingColumn" ) ; testtag_tree_UI_editing ( tree , testid , rowInfo ) ; is ( tree . editable , false , "tree should not be editable after testtag_tree_UI_editing" ) ; is ( tree . editingRow , - 1 , testid + " initial editingRow (continued)" ) ; is ( tree . editingColumn , null , testid + " initial editingColumn (continued)" ) ; var ecolumn = tree . columns [ 0 ] ; ok ( ! tree . startEditing ( 1 , ecolumn ) , "non-editable trees shouldn't start editing" ) ; is ( tree . editingRow , - 1 , testid + " failed startEditing shouldn't set editingRow" ) ; is ( tree . editingColumn , null , testid + " failed startEditing shouldn't set editingColumn" ) ; tree . editable = true ; ok ( tree . startEditing ( 1 , ecolumn ) , "startEditing should have returned true" ) ; is ( tree . editingRow , 1 , testid + " startEditing editingRow" ) ; is ( tree . editingColumn , ecolumn , testid + " startEditing editingColumn" ) ; is ( tree . getAttribute ( "editing" ) , "true" , testid + " startEditing editing attribute" ) ; tree . stopEditing ( true ) ; is ( tree . editingRow , - 1 , testid + " stopEditing editingRow" ) ; is ( tree . editingColumn , null , testid + " stopEditing editingColumn" ) ; is ( tree . hasAttribute ( "editing" ) , false , testid + " stopEditing editing attribute" ) ; tree . startEditing ( - 1 , ecolumn ) ; is ( tree . editingRow == - 1 && tree . editingColumn == null , true , testid + " startEditing -1 editingRow" ) ; tree . startEditing ( 15 , ecolumn ) ; is ( tree . editingRow == - 1 && tree . editingColumn == null , true , testid + " startEditing 15 editingRow" ) ; tree . startEditing ( 1 , null ) ; is ( tree . editingRow == - 1 && tree . editingColumn == null , true , testid + " startEditing null column editingRow" ) ; tree . startEditing ( 2 , tree . columns [ 1 ] ) ; is ( tree . editingRow == - 1 && tree . editingColumn == null , true , testid + " startEditing non editable cell editingRow" ) ; tree . startEditing ( 1 , ecolumn ) ; var inputField = tree . inputField ; is ( inputField instanceof Components . interfaces . nsIDOMXULTextBoxElement , true , testid + "inputField" ) ; inputField . value = "Changed Value" ; tree . stopEditing ( true ) ; is ( tree . view . getCellText ( 1 , ecolumn ) , "Changed Value" , testid + "edit cell accept" ) ; tree . startEditing ( 1 , ecolumn ) ; inputField . value = "Second Value" ; tree . stopEditing ( false ) ; is ( tree . view . getCellText ( 1 , ecolumn ) , "Changed Value" , testid + "edit cell no accept" ) ; tree . editable = false ; if ( testid != "tree view" ) testtag_tree_TreeView_rows_sort ( tree , testid , rowInfo ) ; testtag_tree_wheel ( tree ) ; document . removeEventListener ( "keypress" , preventDefault , false ) ; SimpleTest . finish ( ) ; }
column 1 must not be editable.
column 1 must not be editable .
// Stop keystrokes that aren't handled by the tree from leaking out and // scrolling the main Mochitests window! // note: the functions below should be in this order due to changes made in later tests // select the first column in cell selection mode so that the selection // functions can be tested // currently, the editable flag means that tree editing cannot be invoked // by the user. However, editing can still be started with a script. // currently, the editable flag means that tree editing cannot be invoked // by the user. However, editing can still be started with a script. // this cell can be edited, but stopEditing(false) means don't accept the change. // do the sorting tests last as it will cause the rows to rearrange // skip them for the custom tree view