Author: [EMAIL PROTECTED]
Date: Thu Oct 23 06:58:08 2008
New Revision: 3823

Modified:
     
branches/1_6_events/user/test/com/google/gwt/user/client/ui/CompositeTest.java

Log:
Add handler tests to CompositeTest.

Patch by: jlabanca



Modified:  
branches/1_6_events/user/test/com/google/gwt/user/client/ui/CompositeTest.java
==============================================================================
---  
branches/1_6_events/user/test/com/google/gwt/user/client/ui/CompositeTest.java  
 
(original)
+++  
branches/1_6_events/user/test/com/google/gwt/user/client/ui/CompositeTest.java  
 
Thu Oct 23 06:58:08 2008
@@ -15,8 +15,14 @@
   */
  package com.google.gwt.user.client.ui;

+import com.google.gwt.event.dom.client.BlurEvent;
+import com.google.gwt.event.dom.client.BlurHandler;
+import com.google.gwt.event.dom.client.FocusEvent;
+import com.google.gwt.event.dom.client.FocusHandler;
  import com.google.gwt.junit.client.GWTTestCase;
+import com.google.gwt.user.client.Command;
  import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.DeferredCommand;
  import com.google.gwt.user.client.Event;

  /**
@@ -24,6 +30,7 @@
   */
  public class CompositeTest extends GWTTestCase {

+  @Override
    public String getModuleName() {
      return "com.google.gwt.user.User";
    }
@@ -32,6 +39,8 @@
      TextBox tb = new TextBox();
      boolean widgetFocusFired;
      boolean widgetLostFocusFired;
+    boolean widgetFocusHandlerFired;
+    boolean widgetBlurHandlerFired;
      boolean domFocusFired;
      boolean domBlurFired;

@@ -48,6 +57,17 @@
            widgetFocusFired = true;
          }
        });
+
+      tb.addFocusHandler(new FocusHandler() {
+        public void onFocus(FocusEvent event) {
+          widgetFocusHandlerFired = true;
+        }
+      });
+      tb.addBlurHandler(new BlurHandler() {
+        public void onBlur(BlurEvent event) {
+          widgetBlurHandlerFired = true;
+        }
+      });
      }

      @Override
@@ -68,38 +88,39 @@
      }
    }

-  public void testBrowserEvents() {
-// TODO: re-enable this test when we figure out why the focus events aren't
-// firing on some browsers.
-//
-//    final EventTestComposite c = new EventTestComposite();
-//    RootPanel.get().add(c);
-//
-//    this.delayTestFinish(1000);
-//
-//    // Focus, then blur, the composite's text box. This has to be done in
-//    // deferred commands, because focus events usually require the event  
loop
-//    // to be pumped in order to fire.
-//    DeferredCommand.addCommand(new Command() {
-//      public void execute() {
-//        DeferredCommand.addCommand(new Command() {
-//          public void execute() {
-//            // Ensure all events fired as expected.
-//            assertTrue(c.domFocusFired);
-//            assertTrue(c.domBlurFired);
-//            assertTrue(c.widgetLostFocusFired);
-//
-//            // Ensure that the widget's focus event was eaten by the
-//            // composite's implementation of onBrowserEvent().
-//            assertFalse(c.widgetFocusFired);
-//            finishTest();
-//          }
-//        });
-//
-//        c.tb.setFocus(false);
-//      }
-//    });
-//
-//    c.tb.setFocus(true);
+  public void disabledTestBrowserEvents() {
+    // TODO: re-enable this test when we figure out why the focus events  
aren't
+    // firing on some browsers.
+    final EventTestComposite c = new EventTestComposite();
+    RootPanel.get().add(c);
+
+    this.delayTestFinish(1000);
+
+    // Focus, then blur, the composite's text box. This has to be done in
+    // deferred commands, because focus events usually require the event  
loop
+    // to be pumped in order to fire.
+    DeferredCommand.addCommand(new Command() {
+      public void execute() {
+        DeferredCommand.addCommand(new Command() {
+          public void execute() {
+            // Ensure all events fired as expected.
+            assertTrue(c.domFocusFired);
+            assertTrue(c.domBlurFired);
+            assertTrue(c.widgetLostFocusFired);
+            assertTrue(c.widgetBlurHandlerFired);
+
+            // Ensure that the widget's focus event was eaten by the
+            // composite's implementation of onBrowserEvent().
+            assertFalse(c.widgetFocusFired);
+            assertFalse(c.widgetFocusHandlerFired);
+            finishTest();
+          }
+        });
+
+        c.tb.setFocus(false);
+      }
+    });
+
+    c.tb.setFocus(true);
    }
  }

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

Reply via email to