CheckBox.ensureDebugId() now sets the ID of the input element. Previously, it only set the ID of the label because the input element already had an ID. I also updated RadioButtonTest because RadioButton is a subclass of CheckBox, but it did not have a test specifically for debug IDs.
Patch by: jlabanca
Review by: ajr
Issue: 2534
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@3071 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/CheckBox.java b/user/src/com/google/gwt/user/client/ui/CheckBox.java
index 6ef4f64..14bc01c 100644
--- a/user/src/com/google/gwt/user/client/ui/CheckBox.java
+++ b/user/src/com/google/gwt/user/client/ui/CheckBox.java
@@ -202,6 +202,8 @@
protected void onEnsureDebugId(String baseID) {
super.onEnsureDebugId(baseID);
ensureDebugId(labelElem, baseID, "label");
+ ensureDebugId(inputElem, baseID, "input");
+ DOM.setElementProperty(labelElem, "htmlFor", inputElem.getId());
}
/**
diff --git a/user/test/com/google/gwt/user/client/ui/CheckBoxTest.java b/user/test/com/google/gwt/user/client/ui/CheckBoxTest.java
index 4182624..963308b 100644
--- a/user/test/com/google/gwt/user/client/ui/CheckBoxTest.java
+++ b/user/test/com/google/gwt/user/client/ui/CheckBoxTest.java
@@ -16,8 +16,8 @@
package com.google.gwt.user.client.ui;
import com.google.gwt.junit.client.GWTTestCase;
-import com.google.gwt.user.client.Command;
-import com.google.gwt.user.client.DeferredCommand;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Element;
/**
* Tests the CheckBox Widget.
@@ -59,16 +59,16 @@
public void testDebugId() {
CheckBox check = new CheckBox("myLabel");
+
+ // We need to replace the input element so we can keep a handle to it
+ Element newInput = DOM.createInputCheck();
+ check.replaceInputElement(newInput);
+
check.ensureDebugId("myCheck");
RootPanel.get().add(check);
-
+
UIObjectTest.assertDebugId("myCheck", check.getElement());
- DeferredCommand.addCommand(new Command() {
- public void execute() {
- UIObjectTest.assertDebugIdContents("myCheck-label", "myLabel");
- finishTest();
- }
- });
- delayTestFinish(250);
+ UIObjectTest.assertDebugId("myCheck-input", newInput);
+ UIObjectTest.assertDebugIdContents("myCheck-label", "myLabel");
}
}
diff --git a/user/test/com/google/gwt/user/client/ui/RadioButtonTest.java b/user/test/com/google/gwt/user/client/ui/RadioButtonTest.java
index a19041c..a03ec82 100644
--- a/user/test/com/google/gwt/user/client/ui/RadioButtonTest.java
+++ b/user/test/com/google/gwt/user/client/ui/RadioButtonTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2007 Google Inc.
+ * Copyright 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
@@ -16,14 +16,32 @@
package com.google.gwt.user.client.ui;
import com.google.gwt.junit.client.GWTTestCase;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Element;
/**
* Tests the RadioButton class.
*/
public class RadioButtonTest extends GWTTestCase {
+ @Override
public String getModuleName() {
- return "com.google.gwt.user.User";
+ return "com.google.gwt.user.DebugTest";
+ }
+
+ public void testDebugId() {
+ RadioButton radio = new RadioButton("myName", "myLabel");
+
+ // We need to replace the input element so we can keep a handle to it
+ Element newInput = DOM.createInputRadio("MyName");
+ radio.replaceInputElement(newInput);
+
+ radio.ensureDebugId("myRadio");
+ RootPanel.get().add(radio);
+
+ UIObjectTest.assertDebugId("myRadio", radio.getElement());
+ UIObjectTest.assertDebugId("myRadio-input", newInput);
+ UIObjectTest.assertDebugIdContents("myRadio-label", "myLabel");
}
/**