Bug 1274545 - Add a test for user-set keyword & order preservation on search engine update. r=florian
authorIan Moody <moz-ian@perix.co.uk>
Tue, 12 Jul 2016 12:54:19 +0100
changeset 304970 6b143301ec2f
parent 304969 107b045bcdc4
child 304971 c194fb332a11
push id30449
push usercbook@mozilla.com
push dateFri, 15 Jul 2016 14:14:10 +0000
treeherdermozilla-central@676b7df970b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1274545
milestone50.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 1274545 - Add a test for user-set keyword & order preservation on search engine update. r=florian MozReview-Commit-ID: BC2Jgbwudru
toolkit/components/search/tests/xpcshell/test_engineUpdate.js
toolkit/components/search/tests/xpcshell/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/test_engineUpdate.js
@@ -0,0 +1,50 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/* Test that user-set metadata isn't lost on engine update */
+
+"use strict";
+
+function run_test() {
+  updateAppInfo();
+  useHttpServer();
+
+  run_next_test();
+}
+
+add_task(function* test_engineUpdate() {
+  const KEYWORD = "keyword";
+  const FILENAME = "engine.xml"
+  const TOPIC = "browser-search-engine-modified";
+  const ONE_DAY_IN_MS = 24 * 60 * 60 * 1000;
+
+  yield asyncInit();
+
+  let [engine] = yield addTestEngines([
+    { name: "Test search engine", xmlFileName: FILENAME },
+  ]);
+
+  engine.alias = KEYWORD;
+  Services.search.moveEngine(engine, 0);
+  // can't have an accurate updateURL in the file since we can't know the test
+  // server origin, so manually set it
+  engine.wrappedJSObject._updateURL = gDataUrl + FILENAME;
+
+  yield new Promise(resolve => {
+    Services.obs.addObserver(function obs(subject, topic, data) {
+      if (data == "engine-loaded") {
+        let engine = subject.QueryInterface(Ci.nsISearchEngine);
+        let rawEngine = engine.wrappedJSObject;
+        equal(engine.alias, KEYWORD, "Keyword not cleared by update");
+        equal(rawEngine.getAttr("order"), 1, "Order not cleared by update");
+        Services.obs.removeObserver(obs, TOPIC, false);
+        resolve();
+      }
+    }, TOPIC, false);
+
+    // set last update to 8 days ago, since the default interval is 7, then
+    // trigger an update
+    engine.wrappedJSObject.setAttr("updateexpir", Date.now() - (ONE_DAY_IN_MS * 8));
+    Services.search.QueryInterface(Components.interfaces.nsITimerCallback).notify(null);
+  });
+});
--- a/toolkit/components/search/tests/xpcshell/xpcshell.ini
+++ b/toolkit/components/search/tests/xpcshell/xpcshell.ini
@@ -95,8 +95,9 @@ tags = addons
 [test_currentEngine_fallback.js]
 [test_require_engines_in_cache.js]
 [test_update_telemetry.js]
 [test_svg_icon.js]
 [test_searchReset.js]
 [test_addEngineWithDetails.js]
 [test_chromeresource_icon1.js]
 [test_chromeresource_icon2.js]
+[test_engineUpdate.js]