use of com.github.bordertech.wcomponents.WMenu in project wcomponents by BorderTech.
the class WMenuItemRenderer_Test method testRoleWhenSelectedNotSelectable.
@Test
public void testRoleWhenSelectedNotSelectable() throws IOException, SAXException, XpathException {
/*
* A WMenuItem may be set as selected even if it is not in a selection container. This is a flaw in an
* old part of the WComponents API.
*/
WMenuItem item = new WMenuItem(itemText);
WMenu wrapped = wrapMenuItem(item);
wrapped.setSelectionMode(MenuSelectContainer.SelectionMode.SINGLE);
assertXpathNotExists("//ui:menuitem/@selected", item);
wrapped.setSelectedItem(item);
assertSchemaMatch(wrapped);
assertXpathEvaluatesTo("true", "//ui:menuitem/@selected", item);
}
use of com.github.bordertech.wcomponents.WMenu in project wcomponents by BorderTech.
the class WMenuItemRenderer_Test method testXssEscaping.
@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
WMenu menu = new WMenu();
WMenuItem item = new WMenuItem(getMaliciousAttribute());
menu.add(item);
assertSafeContent(menu);
item.setToolTip(getMaliciousAttribute());
assertSafeContent(menu);
item.setAccessibleText(getMaliciousAttribute());
assertSafeContent(menu);
item.setUrl(getMaliciousAttribute());
assertSafeContent(menu);
}
use of com.github.bordertech.wcomponents.WMenu in project wcomponents by BorderTech.
the class WMenuItemRenderer_Test method testSelectability.
@Test
public void testSelectability() throws IOException, SAXException, XpathException {
// Selectability - output as @role
WMenuItem item = new WMenuItem(itemText);
WMenu wrapped = wrapMenuItem(item);
wrapped.setSelectionMode(MenuSelectContainer.SelectionMode.SINGLE);
// default selectability is selectable
assertXpathEvaluatesTo("menuitemradio", "//ui:menuitem/@role", item);
item = new WMenuItem(itemText);
wrapped.add(item);
item.setSelectability(Boolean.FALSE);
assertSchemaMatch(wrapped);
assertXpathNotExists("//ui:menuitem/@role", item);
item = new WMenuItem(itemText);
wrapped.add(item);
item.setSelectability(Boolean.TRUE);
assertSchemaMatch(wrapped);
assertXpathEvaluatesTo("menuitemradio", "//ui:menuitem/@role", item);
item = new WMenuItem(itemText);
wrapped = wrapMenuItem(item);
wrapped.setSelectionMode(MenuSelectContainer.SelectionMode.MULTIPLE);
// default selectability is selectable and so role is menuitemcheckbox
assertXpathEvaluatesTo("menuitemcheckbox", "//ui:menuitem/@role", item);
item = new WMenuItem(itemText);
wrapped.add(item);
item.setSelectability(Boolean.FALSE);
assertXpathNotExists("//ui:menuitem/@role", item);
item = new WMenuItem(itemText);
wrapped.add(item);
item.setSelectability(Boolean.TRUE);
assertXpathEvaluatesTo("menuitemcheckbox", "//ui:menuitem/@role", item);
}
use of com.github.bordertech.wcomponents.WMenu in project wcomponents by BorderTech.
the class WMenuItemRenderer_Test method testAccessKey.
@Test
public void testAccessKey() throws IOException, SAXException, XpathException {
// AccessKey
WMenuItem item = new WMenuItem(itemText, url);
WMenu wrapped = wrapMenuItem(item);
item.setAccessKey('A');
assertSchemaMatch(wrapped);
assertXpathEvaluatesTo("A", "//ui:menuitem/@accessKey", item);
// no access key if nested
WSubMenu sub = new WSubMenu("sub");
wrapped.add(sub);
item = new WMenuItem(itemText, url);
sub.add(item);
item.setAccessKey('A');
assertSchemaMatch(wrapped);
assertXpathNotExists("//ui:menuitem/@accessKey", item);
}
use of com.github.bordertech.wcomponents.WMenu in project wcomponents by BorderTech.
the class WMenuItemRenderer_Test method testHidden.
@Test
public void testHidden() throws IOException, SAXException, XpathException {
WMenuItem item = new WMenuItem(itemText, url);
WMenu wrapped = wrapMenuItem(item);
setFlag(item, ComponentModel.HIDE_FLAG, true);
assertSchemaMatch(wrapped);
assertXpathEvaluatesTo("true", "//ui:menuitem/@hidden", item);
}
Aggregations