use of com.gargoylesoftware.htmlunit.html.HtmlLabel in project faces by jakartaee.
the class BaseHtmlUnitClient method testList.
// End validateSelectOptions
/**
* This test method is used for testing to List<String> objects.
*
* @param page
* - The HtmlPage that has the the test List Rendered.
* @param myLabels
* - name of the HTMLLabel rendered.
* @param expNum
* - The expected number
* @param expValue
* - The List of expected Strings.
* @param formatter
* - the Formatter that we want test output to be stored.
* @param ordered
* - If true test the List object for ordering.
*/
protected void testList(HtmlPage page, String myLabels, List<String> expValue, int expSize, Formatter formatter, boolean ordered) {
List<HtmlLabel> renderedList = getLabelsContaining(page, myLabels);
String[] result;
String rec;
if (renderedList != null && !renderedList.isEmpty()) {
int ii = renderedList.size();
if (ii != expSize) {
formatter.format("Unexpected Number of Items Rendered for " + myLabels + "! %n" + "Expected: %d %n" + "Received: %d %n", expSize, ii);
}
} else {
formatter.format("No Labels found containing " + myLabels + "!");
}
if (ordered) {
int i = 0;
for (HtmlLabel label : renderedList) {
result = label.asText().split(":");
rec = result[1].trim();
String expectedValue = expValue.get(i);
if (!(expectedValue.equals(rec))) {
formatter.format("Unexpected Value Rendered! %n" + "Found: %s %n" + "Expected: %s %n", rec, expectedValue);
}
i++;
}
} else {
for (HtmlLabel label : renderedList) {
result = label.asText().split(":");
rec = result[1].trim();
if (!(expValue.contains(rec))) {
formatter.format("Unexpected Value Rendered! %n" + "Found: %s %n", rec);
}
}
}
}
use of com.gargoylesoftware.htmlunit.html.HtmlLabel in project faces by jakartaee.
the class BaseHtmlUnitClient method getLabelIncludingFor.
// END validateAttributeSet
/*
* In a given htmlpage(root) look for and return the child Label element from
* the given parent element(tagName), That matches the givin String(forName)
* to its "for" attribute.
*
* Return null if no label element matches.
*/
protected HtmlLabel getLabelIncludingFor(HtmlPage root, String tagName, String forName) {
HtmlLabel result = null;
List list = root.getDocumentElement().getHtmlElementsByTagName(tagName);
for (Iterator i = list.iterator(); i.hasNext(); ) {
HtmlLabel label = (HtmlLabel) i.next();
if (label.getForAttribute().indexOf(forName) > -1) {
result = label;
}
}
return result;
}
use of com.gargoylesoftware.htmlunit.html.HtmlLabel in project faces by jakartaee.
the class URLClient method outputLabelRenderEncodeTest.
/*
* @class.setup_props: webServerHost; webServerPort; ts_home;
*/
/**
* @testName: outputLabelRenderEncodeTest
* @assertion_ids: PENDING
* @test_Strategy: Validate the rendering of the h:OutputLabel tag and its
* attributes. case 1: - The "id", "for" & "styleClass"
* attributes are defined. case 2: - Attributes for "id" &
* "value" are defined. Verify that the default value of the
* escape attribute is 'true' and that text containing angle
* brackets is rendered with escape characters. case 3: -
* Attributes for "id" & "value" & "escape" are defined.
* Verify that when the escape attribute is set to 'true',
* text containing angle brackets is rendered with escape
* characters. case 4: - Attributes for "id" & "value" &
* "escape" are defined. Verify that when the escape attribute
* is set to 'false', text containing angle brackets is
* rendered without escape characters. case 5: - Using the
* binding attribute to tie to a backing bean. make sure that
* the value is rendered correctly.
*
* @since 1.2
*/
public void outputLabelRenderEncodeTest() throws Fault {
StringBuilder messages = new StringBuilder(128);
Formatter formatter = new Formatter(messages);
List<HtmlPage> pages = new ArrayList<HtmlPage>();
pages.add(getPage(CONTEXT_ROOT + "/faces/encodetest_facelet.xhtml"));
for (HtmlPage page : pages) {
// ---------------------------------------------------------- case 1
HtmlLabel label_one = (HtmlLabel) getElementOfTypeIncludingId(page, "label", "labelOne");
if (!validateExistence("labelOne", "label", label_one, formatter)) {
handleTestStatus(messages);
return;
}
if (!"text".equals(label_one.getAttribute("class"))) {
formatter.format("Unexpected rendered value for the " + "\"styleClass\" attribute on the '%s' tag with the " + "id of '%s'. %nExpected: '%s' %nFound: '%s' %n", "h:label", "labelOne", "text", label_one.getAttribute("class"));
}
if (!"name".equals(label_one.getForAttribute())) {
formatter.format("Unexpected rendered value for the \"for\" " + "attribute on the '%s' tag with the id of '%s'. %n" + "Expected: '%s' %nFound: '%s' %n", "h:label", "labelOne", "name", label_one.getForAttribute());
}
// ---------------------------------------------------------- case 2
HtmlLabel label_two = (HtmlLabel) getElementOfTypeIncludingId(page, "label", "labelTwo");
if (!validateExistence("labelTwo", "label", label_two, formatter)) {
handleTestStatus(messages);
return;
}
if (!"<default>".equals(label_two.asText())) {
formatter.format("Unexpected rendered value for the " + "\"value\" attribute. %n" + "Expected: '%s' %n" + "Recieved: '%s' %n", "<default>", label_two.asText());
}
// ---------------------------------------------------------- case 3
HtmlLabel label_three = (HtmlLabel) getElementOfTypeIncludingId(page, "label", "labelThree");
if (!validateExistence("labelThree", "label", label_three, formatter)) {
handleTestStatus(messages);
return;
}
if (!"<true>".equals(label_three.asText())) {
formatter.format("Unexpected rendered value for the " + "\"value\" attribute. %n" + "Expected: '%s' %n" + "Recieved: '%s' %n", "<true>", label_three.asText());
}
// ---------------------------------------------------------- case 4
HtmlLabel label_four = (HtmlLabel) getElementOfTypeIncludingId(page, "label", "labelFour");
if (!validateExistence("labelFour", "label", label_four, formatter)) {
handleTestStatus(messages);
return;
}
if (!"".equals(label_four.asText())) {
formatter.format("Unexpected rendered value for the " + "\"value\" attribute. %n" + "Expected: '%s' %n" + "Recieved: '%s' %n", "", label_four.asText());
}
// ---------------------------------------------------------- case 5
HtmlLabel label_five = (HtmlLabel) getElementOfTypeIncludingId(page, "label", "labelFive");
String expected = "This is an Output UIComponent";
if (!validateExistence("labelFive", "label", label_five, formatter)) {
handleTestStatus(messages);
return;
}
if (!expected.equals(label_five.asText())) {
formatter.format("Unexpected value for '%s' Attribute! %n" + "Expected: '%s' %n" + "Recieved: '%s' %n", "value", expected, label_five.asText());
}
if (!"text".equals(label_five.getAttribute("class"))) {
formatter.format("Unexpected value for '%s'! %n " + "Expected: '%s' %n" + "Found: '%s' %n", "labelFive", "text", label_one.getAttribute("class"));
}
handleTestStatus(messages);
}
}
use of com.gargoylesoftware.htmlunit.html.HtmlLabel in project htmlunit by HtmlUnit.
the class EventTarget method fireEvent.
/**
* Fires the event on the node with capturing and bubbling phase.
* @param event the event
* @return the result
*/
public ScriptResult fireEvent(final Event event) {
final Window window = getWindow();
event.startFire();
final Event previousEvent = window.getCurrentEvent();
window.setCurrentEvent(event);
try {
// These can be null if we aren't tied to a DOM node
final DomNode ourNode = getDomNodeOrNull();
final DomNode ourParentNode = (ourNode != null) ? ourNode.getParentNode() : null;
// Determine the propagation path which is fixed here and not affected by
// DOM tree modification from intermediate listeners (tested in Chrome)
final List<EventTarget> propagationPath = new ArrayList<>();
// We're added to the propagation path first
propagationPath.add(this);
// and MessagePort, etc. will not have any parents)
for (DomNode parent = ourParentNode; parent != null; parent = parent.getParentNode()) {
propagationPath.add(parent.getScriptableObject());
}
// (see Note in https://www.w3.org/TR/DOM-Level-3-Events/#event-type-load)
if (!Event.TYPE_LOAD.equals(event.getType())) {
// Add Window if the the propagation path reached Document
if (propagationPath.get(propagationPath.size() - 1) instanceof Document) {
propagationPath.add(window);
}
}
// capturing phase
event.setEventPhase(Event.CAPTURING_PHASE);
for (int i = propagationPath.size() - 1; i >= 1; i--) {
final EventTarget jsNode = propagationPath.get(i);
final EventListenersContainer elc = jsNode.eventListenersContainer_;
if (elc != null) {
elc.executeCapturingListeners(event, new Object[] { event });
if (event.isPropagationStopped()) {
return new ScriptResult(null);
}
}
}
// at target phase
event.setEventPhase(Event.AT_TARGET);
if (!propagationPath.isEmpty()) {
// Note: This element is not always the same as event.getTarget():
// e.g. the 'load' event targets Document but "at target" is on Window.
final EventTarget jsNode = propagationPath.get(0);
final EventListenersContainer elc = jsNode.eventListenersContainer_;
if (elc != null) {
elc.executeAtTargetListeners(event, new Object[] { event });
if (event.isPropagationStopped()) {
return new ScriptResult(null);
}
}
}
// bubbling phase
if (event.isBubbles()) {
// This belongs here inside the block because events that don't bubble never set
// eventPhase = 3 (tested in Chrome)
event.setEventPhase(Event.BUBBLING_PHASE);
for (int i = 1, size = propagationPath.size(); i < size; i++) {
final EventTarget jsNode = propagationPath.get(i);
final EventListenersContainer elc = jsNode.eventListenersContainer_;
if (elc != null) {
elc.executeBubblingListeners(event, new Object[] { event });
if (event.isPropagationStopped()) {
return new ScriptResult(null);
}
}
}
}
HtmlLabel label = null;
if (event.processLabelAfterBubbling()) {
for (DomNode parent = ourParentNode; parent != null; parent = parent.getParentNode()) {
if (parent instanceof HtmlLabel) {
label = (HtmlLabel) parent;
break;
}
}
}
if (label != null) {
final HtmlElement element = label.getLabeledElement();
if (element != null && element != getDomNodeOrNull()) {
try {
element.click(event.isShiftKey(), event.isCtrlKey(), event.isAltKey(), false, true, true, true);
} catch (final IOException e) {
// ignore for now
}
}
}
} finally {
event.endFire();
// reset event
window.setCurrentEvent(previousEvent);
}
return new ScriptResult(null);
}
Aggregations