Skip to content

Commit 91b9865

Browse files
authored
Merge pull request #2068 from jakartaee/issue_1590
#1590: fix failing tests wrt CSP support
2 parents 850ee57 + fd34781 commit 91b9865

File tree

5 files changed

+42
-22
lines changed

5 files changed

+42
-22
lines changed

tck/faces23/searchExpression/src/main/webapp/issue4331.xhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<title>Issue4331IT - adding new keyword resolver via faces-config.xml</title>
2626
</h:head>
2727
<h:body>
28-
<h:inputText id="input">
28+
<h:inputText id="issue4331ITInput1">
2929
<f:ajax render="@custom" />
3030
</h:inputText>
3131
</h:body>

tck/faces23/searchExpression/src/test/java/ee/jakarta/tck/faces/test/javaee8/searchExpression_selenium/Issue4331IT.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ void test() throws Exception {
4545
public void testCustomSearchKeywordResolverAddedViaFacesConfig() throws Exception {
4646
WebPage page = getPage("issue4331.xhtml");
4747

48-
WebElement input = getWebDriver().findElement(By.id("input"));
49-
assertFalse(input.getDomAttribute("onchange").contains("@custom"));
50-
assertTrue(input.getDomAttribute("onchange").contains("input"));
48+
WebElement input = getWebDriver().findElement(By.id("issue4331ITInput1"));
49+
50+
String behaviorScript = getBehaviorScript(page, input);
51+
52+
assertFalse(behaviorScript.contains("@custom"));
53+
assertTrue(behaviorScript.contains("issue4331ITInput1"));
5154
}
5255

5356

tck/faces23/searchExpression/src/test/java/ee/jakarta/tck/faces/test/javaee8/searchExpression_selenium/Spec1238IT.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919

2020
import static org.junit.jupiter.api.Assertions.assertEquals;
21-
import static org.junit.jupiter.api.Assertions.assertFalse;
2221
import static org.junit.jupiter.api.Assertions.assertTrue;
2322

2423
import java.time.Duration;
@@ -51,17 +50,16 @@ public void testSearchExpression() throws Exception {
5150
ExtendedWebDriver webDriver = getWebDriver();
5251
WebElement label = webDriver.findElement(By.id("label"));
5352
WebElement input = webDriver.findElement(By.id("spec1238ITinput1"));
54-
53+
5554
assertEquals(label.getDomAttribute("for"), input.getDomAttribute("id"));
56-
57-
String onchange = input.getDomAttribute("onchange");
5855

59-
if (onchange.contains("@this")) {
60-
assertFalse(onchange.contains("spec1238ITinput1"));
56+
String behaviorScript = getBehaviorScript(page, input);
57+
58+
if (behaviorScript.contains("@this")) {
59+
assertTrue(behaviorScript.contains("@this spec1238ITinput2"));
6160
}
6261
else {
63-
assertTrue(onchange.contains("spec1238ITinput1"));
62+
assertTrue(behaviorScript.contains("spec1238ITinput1 spec1238ITinput2"));
6463
}
65-
assertTrue(onchange.contains("spec1238ITinput2"));
6664
}
6765
}

tck/old-tck-selenium/commandLink/src/test/java/ee/jakarta/tck/faces/test/oldtck/commandlink_selenium/CommandLinkTestsIT.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static org.junit.jupiter.api.Assertions.assertEquals;
2020
import static org.junit.jupiter.api.Assertions.assertFalse;
21+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2122
import static org.junit.jupiter.api.Assertions.assertNull;
2223

2324
import java.util.ArrayList;
@@ -79,23 +80,23 @@ void clinkRenderEncodeTest() throws Exception {
7980
WebElement link1 = page.findElement(By.id("form:link1"));
8081
assertEquals("#",link1.getDomAttribute​("href"));
8182
assertEquals("Click Me1",link1.getText());
82-
assertFalse(link1.getDomAttribute​("onclick").length() < 0);
83+
assertNotNull(getBehaviorScript(page, link1));
8384

8485
WebElement link2 = page.findElement(By.id("form:link2"));
8586
assertEquals("#",link1.getDomAttribute​("href"));
8687
assertEquals("Click Me2",link2.getText());
8788
assertEquals("sansserif", link2.getDomAttribute​("class"));
88-
assertFalse(link2.getDomAttribute​("onclick").length() < 0);
89+
assertNotNull(getBehaviorScript(page, link2));
8990

9091
WebElement link3 = page.findElement(By.id("form:link3"));
9192
assertEquals("#",link3.getDomAttribute​("href"));
9293
assertEquals("Click Me3",link3.getText());
93-
assertFalse(link3.getDomAttribute​("onclick").length() < 0);
94+
assertNotNull(getBehaviorScript(page, link3));
9495

9596
WebElement link5 = page.findElement(By.id("form:link5"));
9697
assertEquals("sansserif", link5.getDomAttribute​("class"));
9798
assertEquals("Disabled Link",link5.getText());
98-
assertNull(link5.getDomAttribute​("onclick"));
99+
assertNull(getBehaviorScript(page, link5));
99100

100101
WebElement span2 = page.findElement(By.id("form:link6"));
101102
assertEquals("Disabled Link(Nested)",span2.getText());

tck/util/src/main/java/ee/jakarta/tck/faces/test/util/selenium/BaseITNG.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
*/
1616
package ee.jakarta.tck.faces.test.util.selenium;
1717

18+
import static java.lang.Boolean.parseBoolean;
19+
import static java.lang.System.getProperty;
20+
import static org.jboss.shrinkwrap.api.ShrinkWrap.create;
21+
import static org.junit.jupiter.api.extension.ConditionEvaluationResult.disabled;
22+
import static org.junit.jupiter.api.extension.ConditionEvaluationResult.enabled;
23+
1824
import java.io.File;
1925
import java.net.URL;
2026
import java.time.Duration;
@@ -34,15 +40,10 @@
3440
import org.junit.jupiter.api.extension.ExecutionCondition;
3541
import org.junit.jupiter.api.extension.ExtendWith;
3642
import org.junit.jupiter.api.extension.ExtensionContext;
43+
import org.openqa.selenium.By;
3744
import org.openqa.selenium.WebElement;
3845
import org.openqa.selenium.support.PageFactory;
3946

40-
import static java.lang.Boolean.parseBoolean;
41-
import static java.lang.System.getProperty;
42-
import static org.jboss.shrinkwrap.api.ShrinkWrap.create;
43-
import static org.junit.jupiter.api.extension.ConditionEvaluationResult.disabled;
44-
import static org.junit.jupiter.api.extension.ConditionEvaluationResult.enabled;
45-
4647
/**
4748
* Use this for Selenium based tests.
4849
*/
@@ -126,4 +127,21 @@ protected String getHrefURI(WebElement link) {
126127

127128
return uriWithoutJsessionId;
128129
}
130+
131+
protected String getBehaviorScript(WebPage page, WebElement input) {
132+
var id = input.getAttribute("id");
133+
134+
for (var script : page.findElements(By.tagName("script"))) {
135+
var src = script.getAttribute("src");
136+
if (src == null || src.isEmpty()) {
137+
var content = script.getDomProperty("textContent");
138+
139+
if (content.contains("'" + id + "'") || content.contains("\"" + id + "\"")) {
140+
return content;
141+
}
142+
}
143+
}
144+
145+
return null;
146+
}
129147
}

0 commit comments

Comments
 (0)