Add getter for active EventBus

Review by: unnurg@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10701 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/activity/shared/ActivityManager.java b/user/src/com/google/gwt/activity/shared/ActivityManager.java
index c961357..cc56355 100644
--- a/user/src/com/google/gwt/activity/shared/ActivityManager.java
+++ b/user/src/com/google/gwt/activity/shared/ActivityManager.java
@@ -91,6 +91,18 @@
   }
 
   /**
+  * Returns an event bus which is in use by the currently running activity.
+  * <p>
+  * Any handlers attached to the returned event bus will be de-registered when
+  * the current activity is stopped.
+  *
+  * @return the event bus used by the current activity
+  */
+  public EventBus getActiveEventBus() {
+    return stopperedEventBus;
+  }
+ 
+  /**
    * Deactivate the current activity, find the next one from our ActivityMapper,
    * and start it.
    * <p>
diff --git a/user/test/com/google/gwt/activity/shared/ActivityManagerTest.java b/user/test/com/google/gwt/activity/shared/ActivityManagerTest.java
index 62a4af8..7b98368 100644
--- a/user/test/com/google/gwt/activity/shared/ActivityManagerTest.java
+++ b/user/test/com/google/gwt/activity/shared/ActivityManagerTest.java
@@ -139,6 +139,37 @@
   private ActivityManager manager = new ActivityManager(
       myMap, eventBus);
 
+  public void testActiveEventBus() {
+    final AsyncActivity asyncActivity1 = new AsyncActivity(new MyView());
+    final AsyncActivity asyncActivity2 = new AsyncActivity(new MyView());
+
+    ActivityMapper map = new ActivityMapper() {
+      public Activity getActivity(Place place) {
+        if (place.equals(place1)) {
+          return asyncActivity1;
+        }
+        if (place.equals(place2)) {
+          return asyncActivity2;
+        }
+
+        return null;
+      }
+    };
+
+    manager = new ActivityManager(map, eventBus);
+    manager.setDisplay(realDisplay);
+
+    eventBus.fireEvent(new PlaceChangeEvent(place1));
+    com.google.web.bindery.event.shared.EventBus activeEventBus =
+        manager.getActiveEventBus();
+ 
+    activeEventBus.addHandler(Event.TYPE, new Handler());
+    assertEquals(1, eventBus.getCount(Event.TYPE));
+
+    eventBus.fireEvent(new PlaceChangeEvent(place2));
+    assertEquals(0, eventBus.getCount(Event.TYPE));
+  }
+  
   public void testAsyncDispatch() {
     final AsyncActivity asyncActivity1 = new AsyncActivity(new MyView());
     final AsyncActivity asyncActivity2 = new AsyncActivity(new MyView());