Bug 1219963 - Try to make test_get_last_visited more robust. r=me a=ritu
authorNick Alexander <nalexander@mozilla.com>
Mon, 21 Dec 2015 10:48:46 -0800
changeset 305853 e58f733c4778d95ac1ce6521e54d044173a407c2
parent 305852 e7aa47e75e677772756edc6d536a88c8d9b8ad07
child 305854 abf1e06c22c999073d0311268572998ef49bcf61
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme, ritu
bugs1219963
milestone43.0
Bug 1219963 - Try to make test_get_last_visited more robust. r=me a=ritu This also logs more of the failure details, logs all "link-visited" events, and waits for an un-used "link-visited" event before terminating in the hope of always witnessing all the expected "link-visited" events.
mobile/android/tests/browser/chrome/test_get_last_visited.html
--- a/mobile/android/tests/browser/chrome/test_get_last_visited.html
+++ b/mobile/android/tests/browser/chrome/test_get_last_visited.html
@@ -28,56 +28,73 @@ https://bugzilla.mozilla.org/show_bug.cg
     return Messaging.sendRequestForResult({
       type: "History:GetPrePathLastVisitedTimeMilliseconds",
       prePath: prePath,
     });
   };
 
   var browser = BrowserApp.addTab("about:blank").browser;
 
+  // It's useful to see *all* "link-visited" events in the face of intermittent failures.
+  let observe = function(subject, topic, data) {
+    var uri = subject.QueryInterface(Ci.nsIURI);
+    info("Witnessed " + topic + " notification from Gecko with URI " + uri.spec);
+  }
+  Services.obs.addObserver(observe, "link-visited", false);
+
   SimpleTest.registerCleanupFunction(function cleanup() {
     BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
+    Services.obs.removeObserver(observe, "link-visited");
   });
 
   // N.b.: the write to the Fennec DB happens before the Gecko notification
   // is fired.  This is delicate.
   function add_history_visit(url) {
     browser.loadURI(url, null, null);
     return promiseLinkVisit(url);
   };
 
-  // Be aware that mochi.test:8888 redirects, while example.org does
-  // not.  The redirects can impact this test, since they can write to
-  // the history database.
-  const url1 = "http://example.org/chrome/mobile/android/tests/browser/chrome/basic_article.html";
-  const url2 = "http://example.org/chrome/mobile/android/tests/browser/chrome/video_discovery.html";
+  // Be aware that some paths under mochi.test and example.org redirect.  The
+  // blank robocop pages appear to not.  Redirects can impact this test, since
+  // they can write to the history database.
+
+  // The apparent mis-ordering here just uses simpler pages (01 and 03) for the
+  // real test, and a more complex page (02) for a final delay.  See comment below.
+  const url1 = "http://example.org/tests/robocop/robocop_blank_01.html";
+  const url2 = "http://example.org/tests/robocop/robocop_blank_03.html";
+  const url3 = "http://example.org/tests/robocop/robocop_blank_02.html";
 
   add_task(function* test_get_last_visited() {
     var v = yield get_last_visited("https://random.com/");
-    is(v, 0, "Last visited timestamp is 0 for unknown prePath.");
+    is(v, 0, `Last visited timestamp is 0 for unknown prePath: ${v}`);
 
     let prePath = Services.io.newURI(url1, null, null).prePath + "/";
     is(prePath, Services.io.newURI(url2, null, null).prePath + "/", "url1 and url2 have the same prePath");
 
     let t0 = Date.now();
     yield add_history_visit(url1);
+    v = yield get_last_visited(prePath);
     let t1 = Date.now();
-    v = yield get_last_visited(prePath);
-    ok(t0 <= v, "Last visited timestamp is after visit.");
-    ok(v <= t1, "Last visited timestamp is before present");
+    ok(t0 <= v, `Last visited timestamp is after visit: ${t0} <= ${v}.`);
+    ok(v <= t1, `Last visited timestamp is before present ${v} <= ${t1}.`);
 
     let t2 = Date.now();
     yield add_history_visit(url1);
     v = yield get_last_visited(prePath);
-    ok(t2 <= v, "Last visited timestamp is updated after visit.");
+    ok(t2 <= v, `Last visited timestamp is updated after visit: ${t2} <= ${v}`);
 
     let t3 = Date.now();
     yield add_history_visit(url2);
     v = yield get_last_visited(prePath);
-    ok(t3 <= v, "Last visited timestamp is updated after visit to URL with same prePath.");
+    ok(t3 <= v, `Last visited timestamp is updated after visit to URL with same prePath: ${t3} <= ${v}`);
+
+    // This whole system is flaky, so we wait for an unrelated visit, so that we
+    // can witness "link-visited" events a little after the test completes
+    // while debugging.
+    yield add_history_visit(url3);
   });
 
   </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1214366">Mozilla Bug 1214366</a>
 <p id="display"></p>
 <div id="content" style="display: none">