Author: e...@google.com
Date: Thu Feb 26 13:10:29 2009
New Revision: 4885

Added:
    releases/1.6/user/test/com/google/gwt/user/client/ui/WidgetTest.java
Modified:
    releases/1.6/user/src/com/google/gwt/user/client/ui/Widget.java
    releases/1.6/user/test/com/google/gwt/user/UISuite.java

Log:
Fixes issue 3378 by adding getHandlerCount()
Review by:rjrjr

Modified: releases/1.6/user/src/com/google/gwt/user/client/ui/Widget.java
==============================================================================
--- releases/1.6/user/src/com/google/gwt/user/client/ui/Widget.java      
(original)
+++ releases/1.6/user/src/com/google/gwt/user/client/ui/Widget.java     Thu Feb 
 
26 13:10:29 2009
@@ -22,6 +22,7 @@
  import com.google.gwt.event.shared.HandlerManager;
  import com.google.gwt.event.shared.HandlerRegistration;
  import com.google.gwt.event.shared.HasHandlers;
+import com.google.gwt.event.shared.GwtEvent.Type;
  import com.google.gwt.user.client.DOM;
  import com.google.gwt.user.client.Event;
  import com.google.gwt.user.client.EventListener;
@@ -193,6 +194,16 @@
     * @see #onDetach()
     */
    protected void doDetachChildren() {
+  }
+
+  /**
+   * Gets the number of handlers listening to the event type.
+   *
+   * @param type the event type
+   * @return the number of registered handlers
+   */
+  protected int getHandlerCount(Type<?> type) {
+    return handlerManager == null ? 0 :  
handlerManager.getHandlerCount(type);
    }

    /**

Modified: releases/1.6/user/test/com/google/gwt/user/UISuite.java
==============================================================================
--- releases/1.6/user/test/com/google/gwt/user/UISuite.java     (original)
+++ releases/1.6/user/test/com/google/gwt/user/UISuite.java     Thu Feb 26  
13:10:29 2009
@@ -22,6 +22,7 @@
  import com.google.gwt.user.client.WindowTest;
  import com.google.gwt.user.client.ui.AbsolutePanelTest;
  import com.google.gwt.user.client.ui.AnchorTest;
+import com.google.gwt.user.client.ui.WidgetTest;
  import com.google.gwt.user.client.ui.ButtonTest;
  import com.google.gwt.user.client.ui.CaptionPanelTest;
  import com.google.gwt.user.client.ui.CheckBoxTest;
@@ -164,6 +165,7 @@
      suite.addTestSuite(ClassInitTest.class);
      suite.addTestSuite(DateChangeEventTest.class);
      suite.addTestSuite(CreateEventTest.class);
+    suite.addTestSuite(WidgetTest.class);
      return suite;
    }
  }

Added: releases/1.6/user/test/com/google/gwt/user/client/ui/WidgetTest.java
==============================================================================
--- (empty file)
+++ releases/1.6/user/test/com/google/gwt/user/client/ui/WidgetTest.java        
 
Thu Feb 26 13:10:29 2009
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2009 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
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations  
under
+ * the License.
+ */
+package com.google.gwt.user.client.ui;
+
+import com.google.gwt.event.dom.client.ChangeEvent;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.junit.client.GWTTestCase;
+
+/**
+ * Tests the basic widget infrastructure.
+ *
+ */
+public class WidgetTest extends GWTTestCase {
+
+  ClickHandler handlerA = new ClickHandler() {
+
+    public void onClick(ClickEvent event) {
+    }
+  };
+
+  ClickHandler handlerB = new ClickHandler() {
+
+    public void onClick(ClickEvent event) {
+    }
+  };
+
+  @Override
+  public String getModuleName() {
+    return "com.google.gwt.user.User";
+  }
+
+  public void testHandlerCount() {
+    Widget a = new Widget();
+    assertEquals(0, a.getHandlerCount(ClickEvent.getType()));
+    HandlerRegistration r1 = a.addDomHandler(handlerA,  
ClickEvent.getType());
+    assertEquals(1, a.getHandlerCount(ClickEvent.getType()));
+    HandlerRegistration r2 = a.addHandler(handlerB, ClickEvent.getType());
+    assertEquals(2, a.getHandlerCount(ClickEvent.getType()));
+
+    assertEquals(0, a.getHandlerCount(ChangeEvent.getType()));
+    r1.removeHandler();
+    r2.removeHandler();
+    assertEquals(0, a.getHandlerCount(ClickEvent.getType()));
+  }
+
+}

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to