Skip to content

Commit

Permalink
Add tests so we validate with and without removing dom elts
Browse files Browse the repository at this point in the history
  • Loading branch information
niloc132 committed Sep 25, 2024
1 parent 5e94243 commit a3c78c3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
12 changes: 6 additions & 6 deletions user/test/com/google/gwt/user/client/ui/ElementWrappingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ public void testButton() {
public void testDetachNowTwiceFails() {
// Testing hosted-mode-only assertion.
if (!GWT.isScript()) {
// Trying to pass the same widget to RootPanel.detachNow() twice
// should fail an assertion.
ensureDiv().setInnerHTML(
"<a id='foo' href='" + TEST_URL + "'>myAnchor</a>");
Anchor a = Anchor.wrap(Document.get().getElementById("foo"));
RootPanel.detachNow(a); // pass
try {
// Trying to pass the same widget to RootPanel.detachNow() twice
// should fail an assertion.
ensureDiv().setInnerHTML(
"<a id='foo' href='" + TEST_URL + "'>myAnchor</a>");
Anchor a = Anchor.wrap(Document.get().getElementById("foo"));
RootPanel.detachNow(a); // pass
RootPanel.detachNow(a); // fail
throw new Error("Expected assertion failure calling detachNow() twice");
} catch (AssertionError e) {
Expand Down
37 changes: 36 additions & 1 deletion user/test/com/google/gwt/user/client/ui/ImageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -790,11 +790,28 @@ public void testWrapOfSubclass() {
assertNotNull(image);

// Cleanup.
Document.get().getBody().removeChild(div);
RootPanel.detachNow(image);
}

/**
* Same test, but with removeFromParent
* Same test, but don't remove from the dom first
*/
public void testWrapOfSubclassWithoutRemove() {
String uid = Document.get().createUniqueId();
DivElement div = Document.get().createDivElement();
div.setInnerHTML("<img id='" + uid + "' src='counting-forwards.png'>");
Document.get().getBody().appendChild(div);

final TestImage image = TestImage.wrap(Document.get().getElementById(uid));
assertNotNull(image);

// Cleanup.
RootPanel.detachNow(image);
}

/**
* Same test, but with removeFromParent instead of detachNow
*/
public void testRemoveFromParent() {
String uid = Document.get().createUniqueId();
Expand All @@ -805,6 +822,24 @@ public void testRemoveFromParent() {
final TestImage image = TestImage.wrap(Document.get().getElementById(uid));
assertNotNull(image);

// Cleanup.
Document.get().getBody().removeChild(div);
image.removeFromParent();
}

/**
* Same test, but with removeFromParent isntead of detachNow, and don't remove the dom manually
* first.
*/
public void testRemoveFromParentWithoutRemove() {
String uid = Document.get().createUniqueId();
DivElement div = Document.get().createDivElement();
div.setInnerHTML("<img id='" + uid + "' src='counting-forwards.png'>");
Document.get().getBody().appendChild(div);

final TestImage image = TestImage.wrap(Document.get().getElementById(uid));
assertNotNull(image);

// Cleanup.
image.removeFromParent();
}
Expand Down

0 comments on commit a3c78c3

Please sign in to comment.