Bug 1214366 - Part 4: Add mochitest-chrome test. r=rnewman
authorNick Alexander <nalexander@mozilla.com>
Fri, 23 Oct 2015 10:09:44 -0700
changeset 304769 8040892f41a854e50e0939101c7301925934f2f3
parent 304768 243bc49d112b253bb081308e97043623cb6bbabd
child 304770 43edf355eaec2e065d8aa62a8c1663f6db2f9bcd
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)
reviewersrnewman
bugs1214366
milestone44.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 1214366 - Part 4: Add mochitest-chrome test. r=rnewman
mobile/android/tests/browser/chrome/chrome.ini
mobile/android/tests/browser/chrome/head.js
mobile/android/tests/browser/chrome/test_get_last_visited.html
--- a/mobile/android/tests/browser/chrome/chrome.ini
+++ b/mobile/android/tests/browser/chrome/chrome.ini
@@ -13,16 +13,17 @@ support-files =
 
 [test_about_logins.html]
 [test_accounts.html]
 [test_android_log.html]
 [test_app_constants.html]
 [test_debugger_server.html]
 [test_desktop_useragent.html]
 [test_device_search_engine.html]
+[test_get_last_visited.html]
 [test_home_provider.html]
 [test_java_addons.html]
 [test_jni.html]
 [test_migrate_ui.html]
 [test_network_manager.html]
 [test_offline_page.html]
 [test_reader_view.html]
 [test_resource_substitutions.html]
--- a/mobile/android/tests/browser/chrome/head.js
+++ b/mobile/android/tests/browser/chrome/head.js
@@ -27,8 +27,29 @@ function promiseNotification(topic) {
       info("Received " + topic + " notification from Gecko");
       Services.obs.removeObserver(observe, topic);
       resolve();
     }
     Services.obs.addObserver(observe, topic, false);
     info("Now waiting for " + topic + " notification from Gecko");
   });
 }
+
+function promiseLinkVisit(url) {
+  Cu.import("resource://gre/modules/Services.jsm");
+
+  var topic = "link-visited";
+  return new Promise((resolve, reject) => {
+    function observe(subject, topic, data) {
+      info("Received " + topic + " notification from Gecko");
+      var uri = subject.QueryInterface(Ci.nsIURI);
+      if (uri.spec != url) {
+        info("Visited URL " + uri.spec + " is not desired URL " + url + "; ignoring.");
+        return;
+      }
+      info("Visited URL " + uri.spec + " is desired URL " + url);
+      Services.obs.removeObserver(observe, topic);
+      resolve();
+    };
+    Services.obs.addObserver(observe, topic, false);
+    info("Now waiting for " + topic + " notification from Gecko with URL " + url);
+  });
+}
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/browser/chrome/test_get_last_visited.html
@@ -0,0 +1,89 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1214366
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1214366</title>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+  <script type="application/javascript" src="head.js"></script>
+  <script type="application/javascript;version=1.7">
+
+  "use strict";
+
+  const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+
+  Cu.import("resource://gre/modules/Services.jsm");
+  Cu.import("resource://gre/modules/Messaging.jsm");
+  Cu.import("resource://gre/modules/Task.jsm");
+
+  let chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
+  let BrowserApp = chromeWin.BrowserApp;
+
+  function get_last_visited(prePath) {
+    return Messaging.sendRequestForResult({
+      type: "History:GetPrePathLastVisitedTimeMilliseconds",
+      prePath: prePath,
+    });
+  };
+
+  var browser = BrowserApp.addTab("about:blank").browser;
+
+  SimpleTest.registerCleanupFunction(function cleanup() {
+    BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
+  });
+
+  // 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";
+
+  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.");
+
+    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 t2 = Date.now();
+    yield add_history_visit(url1);
+    v = yield get_last_visited(prePath);
+    ok(t2 <= v, "Last visited timestamp is updated after visit.");
+
+    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.");
+  });
+
+  </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">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>