Bug 974723 - Send shown event when banner message is displayed. r=margaret, a=sledru
authorJosh Dover <gerfuls@gmail.com>
Thu, 20 Feb 2014 12:38:27 -0800
changeset 183234 8c70b73529424602f116613d5644d5f87896d33c
parent 183233 7dfa048bd34579f92056cff9d4675920dda32329
child 183235 bc0a26f61e41a7fe9471c02bf4b213081ad4033a
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret, sledru
bugs974723
milestone29.0a2
Bug 974723 - Send shown event when banner message is displayed. r=margaret, a=sledru
mobile/android/base/home/HomeBanner.java
mobile/android/base/tests/testHomeBanner.java
mobile/android/modules/Home.jsm
--- a/mobile/android/base/home/HomeBanner.java
+++ b/mobile/android/base/home/HomeBanner.java
@@ -135,16 +135,17 @@ public class HomeBanner extends LinearLa
             final Spanned text = Html.fromHtml(message.getString("text"));
 
             // Update the banner message on the UI thread.
             ThreadUtils.postToUiThread(new Runnable() {
                 @Override
                 public void run() {
                     mTextView.setText(text);
                     setVisibility(VISIBLE);
+                    GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("HomeBanner:Shown", (String) getTag()));
 
                     // Animate the banner if it is currently active.
                     if (mActive) {
                         animateUp();
                     }
                 }
             });
         } catch (JSONException e) {
--- a/mobile/android/base/tests/testHomeBanner.java
+++ b/mobile/android/base/tests/testHomeBanner.java
@@ -33,23 +33,21 @@ public class testHomeBanner extends UITe
 
     /**
      * Adds a banner message, verifies that it appears when it should, and verifies that
      * onshown/onclick handlers are called in JS.
      *
      * Note: This test does not remove the message after it is done.
      */
     private void addBannerTest() {
-        addBannerMessage();
-
-        // Load about:home again, and make sure the onshown handler is called.
+        // Load about:home and make sure the onshown handler is called.
         Actions.EventExpecter eventExpecter = getActions().expectGeckoEvent("TestHomeBanner:MessageShown");
+        addBannerMessage();
         NavigationHelper.enterAndLoadUrl("about:home");
-        // TODO: Add shown event passing from Java: bug 974723
-        // eventExpecter.blockForEvent();
+        eventExpecter.blockForEvent();
 
         // Verify that the banner is visible with the correct text.
         mAboutHome.assertBannerText(TEXT);
 
         // Test to make sure the onclick handler is called.
         eventExpecter = getActions().expectGeckoEvent("TestHomeBanner:MessageClicked");
         mAboutHome.clickOnBanner();
         eventExpecter.blockForEvent();
--- a/mobile/android/modules/Home.jsm
+++ b/mobile/android/modules/Home.jsm
@@ -59,16 +59,20 @@ let HomeBanner = {
   _queue: [],
 
   observe: function(subject, topic, data) {
     switch(topic) {
       case "HomeBanner:Get":
         this._handleGet();
         break;
 
+      case "HomeBanner:Shown":
+        this._handleShown(data);
+        break;
+
       case "HomeBanner:Click":
         this._handleClick(data);
         break;
 
       case "HomeBanner:Dismiss":
         this._handleDismiss(data);
         break;
     }
@@ -82,17 +86,20 @@ let HomeBanner = {
 
     let message = this._messages[id];
     sendMessageToJava({
       type: "HomeBanner:Data",
       id: message.id,
       text: message.text,
       iconURI: message.iconURI
     });
+  },
 
+  _handleShown: function(id) {
+    let message = this._messages[id];
     if (message.onshown)
       message.onshown();
   },
 
   _handleClick: function(id) {
     let message = this._messages[id];
     if (message.onclick)
       message.onclick();
@@ -115,16 +122,17 @@ let HomeBanner = {
 
     // Add the new message to the end of the queue.
     this._queue.push(message.id);
 
     // If this is the first message we're adding, add
     // observers to listen for requests from the Java UI.
     if (Object.keys(this._messages).length == 1) {
       Services.obs.addObserver(this, "HomeBanner:Get", false);
+      Services.obs.addObserver(this, "HomeBanner:Shown", false);
       Services.obs.addObserver(this, "HomeBanner:Click", false);
       Services.obs.addObserver(this, "HomeBanner:Dismiss", false);
 
       // Send a message to Java, in case there's an active HomeBanner
       // waiting for a response.
       this._handleGet();
     }
 
@@ -141,16 +149,17 @@ let HomeBanner = {
 
     // Remove the message from the queue.
     let index = this._queue.indexOf(id);
     this._queue.splice(index, 1);
 
     // If there are no more messages, remove the observers.
     if (Object.keys(this._messages).length == 0) {
       Services.obs.removeObserver(this, "HomeBanner:Get");
+      Services.obs.removeObserver(this, "HomeBanner:Shown");
       Services.obs.removeObserver(this, "HomeBanner:Click");
       Services.obs.removeObserver(this, "HomeBanner:Dismiss");
     }
   }
 };
 
 function Panel(options) {
   if ("id" in options)