From 5927d48c9d053975e82075c2a2e8bbeb6fc67523 Mon Sep 17 00:00:00 2001 From: Mark Finkle Date: Wed, 5 Jun 2013 22:29:44 -0400 Subject: [PATCH] Bug 861164 - use different search URLs for tablet vs. non-tablet [tests] r=margaret --- build/mobile/robocop/Makefile.in | 1 + mobile/android/base/tests/devicesearch.xml | 17 ++++++ mobile/android/base/tests/robocop.ini | 1 + .../base/tests/testDeviceSearchEngine.java.in | 11 ++++ .../base/tests/testDeviceSearchEngine.js | 58 +++++++++++++++++++ 5 files changed, 88 insertions(+) create mode 100644 mobile/android/base/tests/devicesearch.xml create mode 100644 mobile/android/base/tests/testDeviceSearchEngine.java.in create mode 100644 mobile/android/base/tests/testDeviceSearchEngine.js diff --git a/build/mobile/robocop/Makefile.in b/build/mobile/robocop/Makefile.in index 44ef161fa9b..d52504bb2cd 100644 --- a/build/mobile/robocop/Makefile.in +++ b/build/mobile/robocop/Makefile.in @@ -73,6 +73,7 @@ MOCHITEST_ROBOCOP_FILES := \ $(wildcard $(TESTPATH)/*.sjs) \ $(wildcard $(TESTPATH)/test*.js) \ $(wildcard $(TESTPATH)/robocop*.js) \ + $(wildcard $(TESTPATH)/*.xml) \ $(NULL) GARBAGE += \ diff --git a/mobile/android/base/tests/devicesearch.xml b/mobile/android/base/tests/devicesearch.xml new file mode 100644 index 00000000000..5b472acf5c3 --- /dev/null +++ b/mobile/android/base/tests/devicesearch.xml @@ -0,0 +1,17 @@ + + +Test search engine +A test search engine (based on Google search) +UTF-8 +data:image/png;base64,AAABAAEAEBAAAAEAGABoAwAAFgAAACgAAAAQAAAAIAAAAAEAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADs9Pt8xetPtu9FsfFNtu%2BTzvb2%2B%2Fne4dFJeBw0egA%2FfAJAfAA8ewBBegAAAAD%2B%2FPtft98Mp%2BwWsfAVsvEbs%2FQeqvF8xO7%2F%2F%2F63yqkxdgM7gwE%2FggM%2BfQA%2BegBDeQDe7PIbotgQufcMufEP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AD%2F%2FPvi28ymXyChTATRrIb8%2F%2F3v8fk6P8MAAdUCAvoAAP0CAP0AAfYAAO4AAACAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQAA + + + + + + + + + +http://example.com/ + diff --git a/mobile/android/base/tests/robocop.ini b/mobile/android/base/tests/robocop.ini index b1bbe740844..4ab681034da 100644 --- a/mobile/android/base/tests/robocop.ini +++ b/mobile/android/base/tests/robocop.ini @@ -41,6 +41,7 @@ [testAddSearchEngine] [testImportFromAndroid] [testMasterPassword] +[testDeviceSearchEngine] # Used for Talos, please don't use in mochitest #[testPan] diff --git a/mobile/android/base/tests/testDeviceSearchEngine.java.in b/mobile/android/base/tests/testDeviceSearchEngine.java.in new file mode 100644 index 00000000000..240cfad2b39 --- /dev/null +++ b/mobile/android/base/tests/testDeviceSearchEngine.java.in @@ -0,0 +1,11 @@ +#filter substitution +package @ANDROID_PACKAGE_NAME@.tests; + +import @ANDROID_PACKAGE_NAME@.*; + + +public class testDeviceSearchEngine extends JavascriptTest { + public testDeviceSearchEngine() { + super("testDeviceSearchEngine.js"); + } +} diff --git a/mobile/android/base/tests/testDeviceSearchEngine.js b/mobile/android/base/tests/testDeviceSearchEngine.js new file mode 100644 index 00000000000..125261d2f1a --- /dev/null +++ b/mobile/android/base/tests/testDeviceSearchEngine.js @@ -0,0 +1,58 @@ +// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +Components.utils.import("resource://gre/modules/Services.jsm"); + +var Cc = Components.classes; +var Ci = Components.interfaces; + +function search_observer(aSubject, aTopic, aData) { + let engine = aSubject.QueryInterface(Ci.nsISearchEngine); + do_print("Observer: " + aData + " for " + engine.name); + + if (aData != "engine-added") + return; + + if (engine.name != "Test search engine") + return; + + function check_submission(aExpected, aSearchTerm, aType) { + do_check_eq(engine.getSubmission(aSearchTerm, aType).uri.spec, "http://example.com/search" + aExpected); + } + + // Force the type and check for the expected URL + check_submission("?q=foo", "foo", "text/html"); + check_submission("/tablet?q=foo", "foo", "application/x-moz-tabletsearch"); + check_submission("/phone?q=foo", "foo", "application/x-moz-phonesearch"); + + // Let the service pick the appropriate type based on the device + // and check for expected URL + let sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2); + if (sysInfo.get("tablet")) { + do_print("Device: tablet"); + check_submission("/tablet?q=foo", "foo", null); + } else { + do_print("Device: phone"); + check_submission("/phone?q=foo", "foo", null); + } + + do_test_finished(); +}; + +add_task(function test_default() { + let search = Services.search; // Cause service initialization + + do_register_cleanup(function cleanup() { + Services.obs.removeObserver(search_observer, "browser-search-engine-modified"); + }); + + do_test_pending(); + Services.obs.addObserver(search_observer, "browser-search-engine-modified", false); + + do_print("Loading search engine"); + search.addEngine("http://mochi.test:8888/tests/robocop/devicesearch.xml", Ci.nsISearchEngine.DATA_XML, null, false); +}); + +run_next_test();