Bug 1161701 - Listen for AboutReader:Ready notification instead of waiting for content to appear in testReaderView. r=mfinkle a=lmandel
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Mon, 11 May 2015 16:51:41 -0700
changeset 276850 2bef28fc7f9ed9ca1ebff46d4dc569be7d5022ef
parent 276849 27ae85ce4ffda997a381ab0b0da0e9e98941375a
child 276851 04ad1da8b468d795a18ab62d981e238595978800
push id3356
push userbsmedberg@mozilla.com
push dateThu, 09 Jul 2015 21:52:23 +0000
reviewersmfinkle, lmandel
bugs1161701
milestone40.0a2
Bug 1161701 - Listen for AboutReader:Ready notification instead of waiting for content to appear in testReaderView. r=mfinkle a=lmandel
mobile/android/tests/browser/robocop/testReaderView.js
toolkit/components/reader/AboutReader.jsm
--- a/mobile/android/tests/browser/robocop/testReaderView.js
+++ b/mobile/android/tests/browser/robocop/testReaderView.js
@@ -20,30 +20,23 @@ function promiseBrowserEvent(browser, ev
       resolve(event);
     }
 
     browser.addEventListener(eventType, handle, true);
     do_print("Now waiting for " + eventType + " event from browser");
   });
 }
 
-function promiseWaitForCondition(win, condition) {
+function promiseNotification(topic) {
   return new Promise((resolve, reject) => {
-    var tries = 0;
-    var interval = win.setInterval(function() {
-      if (tries >= 30) {
-        do_print("Condition didn't pass. Moving on.");
-        moveOn();
-      }
-      if (condition()) {
-        moveOn();
-      }
-      tries++;
-    }, 200);
-    var moveOn = function() { win.clearInterval(interval); resolve(); };
+    function observe(subject, topic, data) {
+      Services.obs.removeObserver(observe, topic);
+      resolve();
+    }
+    Services.obs.addObserver(observe, topic, false);
   });
 }
 
 add_task(function* test_reader_view_visibility() {
   let gWin = Services.wm.getMostRecentWindow("navigator:browser");
   let BrowserApp = gWin.BrowserApp;
 
   let url = "http://mochi.test:8888/tests/robocop/reader_mode_pages/basic_article.html";
@@ -55,13 +48,13 @@ add_task(function* test_reader_view_visi
     BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
   });
 
   let doc = browser.contentDocument;
   let title = doc.getElementById("reader-title");
 
   // We need to wait for reader content to appear because AboutReader.jsm
   // asynchronously fetches the content after about:reader loads.
-  yield promiseWaitForCondition(gWin, () => title.textContent);
+  yield promiseNotification("AboutReader:Ready");
   do_check_eq(title.textContent, "Article title");
 });
 
 run_next_test();
--- a/toolkit/components/reader/AboutReader.jsm
+++ b/toolkit/components/reader/AboutReader.jsm
@@ -786,16 +786,18 @@ AboutReader.prototype = {
 
     this._contentElement.style.display = "block";
     this._updateImageMargins();
     this._requestReadingListStatus();
 
     this._showListIntro();
     this._requestFavicon();
     this._doc.body.classList.add("loaded");
+
+    Services.obs.notifyObservers(null, "AboutReader:Ready", "");
   },
 
   _hideContent: function Reader_hideContent() {
     this._headerElement.style.display = "none";
     this._contentElement.style.display = "none";
   },
 
   _showProgressDelayed: function Reader_showProgressDelayed() {