Bug 1161701 - Listen for AboutReader:Ready notification instead of waiting for content to appear in testReaderView. r=mfinkle
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Mon, 11 May 2015 16:51:41 -0700
changeset 243494 b0c2e8f10b40d88ccb3b37cd34065e17282db854
parent 243493 5f6263cb1e504c462ba7f304f93b93b6d153f026
child 243495 948fc6e57257360fa9259753615cb913102d9db7
push id28740
push userkwierso@gmail.com
push dateTue, 12 May 2015 23:04:57 +0000
treeherdermozilla-central@de1fd9d0682a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs1161701
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1161701 - Listen for AboutReader:Ready notification instead of waiting for content to appear in testReaderView. r=mfinkle
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() {