Bug 974723 - Send shown event when banner message is displayed. r=margaret
authorJosh Dover <gerfuls@gmail.com>
Thu, 20 Feb 2014 12:38:27 -0800
changeset 171537 9a0daca21f30eb75fc1a30026a728cb9392baca9
parent 171536 7e424486f60e1cfba520e8e436739d593ca1c165
child 171538 01a05eb986294dd099cfe0d83f479194a574ecf3
push id5407
push userryanvm@gmail.com
push dateMon, 03 Mar 2014 22:16:41 +0000
treeherderfx-team@01a05eb98629 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs974723
milestone30.0a1
Bug 974723 - Send shown event when banner message is displayed. r=margaret
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
@@ -133,16 +133,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
@@ -37,23 +37,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
@@ -64,17 +64,20 @@ let HomeBanner = (function () {
 
     let message = _messages[id];
     sendMessageToJava({
       type: "HomeBanner:Data",
       id: message.id,
       text: message.text,
       iconURI: message.iconURI
     });
+  };
 
+  let _handleShown = function(id) {
+    let message = _messages[id];
     if (message.onshown)
       message.onshown();
   };
 
   let _handleClick = function(id) {
     let message = _messages[id];
     if (message.onclick)
       message.onclick();
@@ -88,23 +91,27 @@ let HomeBanner = (function () {
 
   return Object.freeze({
     observe: function(subject, topic, data) {
       switch(topic) {
         case "HomeBanner:Get":
           _handleGet();
           break;
 
+        case "HomeBanner:Shown":
+          _handleShown(data);
+          break;
+
         case "HomeBanner:Click":
           _handleClick(data);
           break;
 
         case "HomeBanner:Dismiss":
           _handleDismiss(data);
-          break; 
+          break;
       }
     },
 
     /**
      * Adds a new banner message to the rotation.
      *
      * @return id Unique identifer for the message.
      */
@@ -114,16 +121,17 @@ let HomeBanner = (function () {
 
       // Add the new message to the end of the queue.
       _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(_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.
         _handleGet();
       }
 
@@ -144,16 +152,17 @@ let HomeBanner = (function () {
 
       // Remove the message from the queue.
       let index = _queue.indexOf(id);
       _queue.splice(index, 1);
 
       // If there are no more messages, remove the observers.
       if (Object.keys(_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(id, options) {