Bug 1219963 - Try to make test_get_last_visited more robust. r=me

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.

--HG--
extra : commitid : 8ZchXGDOOZs
extra : rebase_source : 22e8f397e6511131e345e187a25c26e7aece4103
This commit is contained in:
Nick Alexander 2015-11-27 10:48:01 -08:00
parent 2505bac2b7
commit 66a738325c

View File

@ -33,8 +33,16 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1214366
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
@ -44,35 +52,44 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1214366
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);
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");
let t1 = Date.now();
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>