/**
* Ensures that {@link RootPanel#get(String)} behaves properly.
*/
public void testGetById() {
Document doc = Document.get();
DivElement div = doc.createDivElement();
doc.getBody().appendChild(div);
div.setInnerHTML("<div id='a'></div><div id='b'></div>");
// You should get the same RootPanel for subsequent calls to get() with the
// same id. But you should get *different* RootPanels for calls with
// different ids.
RootPanel aRoot = RootPanel.get("a");
RootPanel bRoot = RootPanel.get("b");
assertSame(
"RootPanel.get() should return the same instancefor the same id",
aRoot, RootPanel.get("a"));
assertSame(
"RootPanel.get() should return the same instancefor the same id",
bRoot, RootPanel.get("b"));
assertNotSame("RootPanels a and b should be different", aRoot, bRoot);
// If a RootPanel's element is replaced in the DOM, you should get a
// new RootPanel instance if you ask for it again (see issue 1937).
Element aElem = doc.getElementById("a");
Element newAElem = doc.createDivElement();
newAElem.setId("a");
aElem.getParentElement().replaceChild(newAElem, aElem);
RootPanel newARoot = RootPanel.get("a");
assertNotSame("New RootPanel should not be same as old", newARoot, aRoot);