-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZK-5730: Harden smartUpdate to check for null desktop or null webapp
- Loading branch information
1 parent
0a90356
commit 8f510bf
Showing
8 changed files
with
214 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
zktest/src/main/java/org/zkoss/zktest/test2/B101_ZK_5730Composer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* B101_ZK_5730Composer.java | ||
Purpose: | ||
Description: | ||
History: | ||
12:10 PM 2024/10/9, Created by jumperchen | ||
Copyright (C) 2024 Potix Corporation. All Rights Reserved. | ||
*/ | ||
package org.zkoss.zktest.test2; | ||
|
||
import org.zkoss.zk.ui.Component; | ||
import org.zkoss.zk.ui.Sessions; | ||
import org.zkoss.zk.ui.event.Events; | ||
import org.zkoss.zk.ui.http.SimpleSession; | ||
import org.zkoss.zk.ui.select.SelectorComposer; | ||
import org.zkoss.zk.ui.select.annotation.Listen; | ||
import org.zkoss.zk.ui.select.annotation.Wire; | ||
import org.zkoss.zul.Div; | ||
import org.zkoss.zul.Grid; | ||
import org.zkoss.zul.ListModelList; | ||
|
||
/** | ||
* @author jumperchen | ||
*/ | ||
public class B101_ZK_5730Composer extends SelectorComposer { | ||
|
||
@Wire private Grid grid; | ||
private Div rootDiv; | ||
private ListModelList model = new ListModelList(); | ||
|
||
@Override | ||
public void doAfterCompose(Component comp) throws Exception { | ||
super.doAfterCompose(comp); | ||
rootDiv = (Div) comp; | ||
grid.setModel(model); | ||
} | ||
|
||
@Listen(Events.ON_CLICK + "=#logout") | ||
public void logout() { | ||
((SimpleSession)Sessions.getCurrent()).invalidateNow(); | ||
} | ||
|
||
@Listen(Events.ON_CLICK + "=#op2") | ||
public void longOp() { | ||
fakeOperation(3); | ||
grid.addSclass("success"); | ||
} | ||
|
||
static public void fakeOperation(int seconds) { | ||
long endTime = System.currentTimeMillis() + seconds * 1000; | ||
while (System.currentTimeMillis() < endTime) { | ||
// Just a busy-wait. In real scenarios, this could be some meaningful computation. | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
zktest/src/main/java/org/zkoss/zktest/test2/B101_ZK_5730_1Composer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* B101_ZK_5730_1Composer.java | ||
Purpose: | ||
Description: | ||
History: | ||
12:32 PM 2024/10/9, Created by jumperchen | ||
Copyright (C) 2024 Potix Corporation. All Rights Reserved. | ||
*/ | ||
package org.zkoss.zktest.test2; | ||
|
||
import java.util.Optional; | ||
|
||
import org.zkoss.zk.ui.Component; | ||
import org.zkoss.zk.ui.Desktop; | ||
import org.zkoss.zk.ui.Executions; | ||
import org.zkoss.zk.ui.event.Event; | ||
import org.zkoss.zk.ui.event.EventListener; | ||
import org.zkoss.zk.ui.event.Events; | ||
import org.zkoss.zk.ui.sys.PageCtrl; | ||
import org.zkoss.zk.ui.util.Composer; | ||
import org.zkoss.zul.Button; | ||
import org.zkoss.zul.Label; | ||
|
||
/** | ||
* @author jumperchen | ||
*/ | ||
public class B101_ZK_5730_1Composer implements Composer { | ||
@Override | ||
public void doAfterCompose(Component comp) throws Exception { | ||
Desktop dt = Executions.getCurrent().getDesktop(); | ||
dt.enableServerPush(true); | ||
|
||
Button button = new Button("schedule"); | ||
Label myLabel = new Label("my label"); | ||
|
||
comp.appendChild(button); | ||
comp.appendChild(myLabel); | ||
|
||
button.addEventListener(Events.ON_CLICK, event -> { | ||
Runnable runnable = () -> { | ||
System.out.println("runnable - run()"); | ||
myLabel.addSclass("bg-red"); | ||
}; | ||
EventListener<? super Event> executeEventListener = this::executeEventListener; | ||
Executions.schedule(dt, executeEventListener, new Event("ExecuteEvent", null, runnable)); | ||
|
||
// This causes an NPE in the runnable above | ||
((PageCtrl)comp.getPage()).destroy(); | ||
}); | ||
|
||
} | ||
|
||
public void executeEventListener(Event event) { | ||
Optional.ofNullable((Runnable)event.getData()).ifPresent(Runnable::run); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
B101-ZK-5730-1.zul | ||
Purpose: | ||
Description: | ||
History: | ||
2024/10/9, Created by jumperchen | ||
Copyright (C) 2024 Potix Corporation. All Rights Reserved. | ||
--> | ||
<zk> | ||
<style> | ||
.z-label.bg-red { | ||
background-color: red; | ||
} | ||
</style> | ||
<div apply="org.zkoss.zktest.test2.B101_ZK_5730_1Composer"/> | ||
</zk> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
B101-ZK-5730.zul | ||
Purpose: | ||
Description: | ||
History: | ||
2024/10/9, Created by jumperchen | ||
Copyright (C) 2024 Potix Corporation. All Rights Reserved. | ||
--> | ||
<zk> | ||
<div apply="org.zkoss.zktest.test2.B101_ZK_5730Composer"> | ||
<button id="op2" label="sync long op"/> | ||
<button id="logout" label="logout" /> | ||
<grid id="grid"></grid> | ||
</div> | ||
</zk> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
zktest/src/test/java/org/zkoss/zktest/zats/test2/B101_ZK_5730Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* B101_ZK_5730Test.java | ||
Purpose: | ||
Description: | ||
History: | ||
12:11 PM 2024/10/9, Created by jumperchen | ||
Copyright (C) 2024 Potix Corporation. All Rights Reserved. | ||
*/ | ||
package org.zkoss.zktest.zats.test2; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.openqa.selenium.WindowType; | ||
|
||
import org.zkoss.test.webdriver.WebDriverTestCase; | ||
|
||
/** | ||
* @author jumperchen | ||
*/ | ||
public class B101_ZK_5730Test extends WebDriverTestCase { | ||
|
||
@Test | ||
public void test() { | ||
connect(); | ||
driver.switchTo().newWindow(WindowType.TAB); | ||
driver.get(getAddress() + "/test2/B101-ZK-5730.zul"); | ||
waitResponse(); | ||
Object[] windowHandles = driver.getWindowHandles().toArray(); | ||
driver.switchTo().window((String) windowHandles[0]); | ||
click(jq("$op2")); | ||
driver.switchTo().window((String) windowHandles[1]); | ||
click(jq("$logout")); | ||
driver.switchTo().window((String) windowHandles[0]); | ||
waitResponse(); | ||
assertNoZKError(); | ||
} | ||
|
||
@Test | ||
public void testCase1() { | ||
connect("/test2/B101-ZK-5730-1.zul"); | ||
click(jq("@button")); | ||
waitResponse(); | ||
assertNoZKError(); | ||
} | ||
} |