Bug 861164 - use different search URLs for tablet vs. non-tablet [tests] r=margaret

This commit is contained in:
Mark Finkle 2013-06-05 22:29:44 -04:00
Родитель d33ddcb2c2
Коммит c933212b6c
5 изменённых файлов: 88 добавлений и 0 удалений

Просмотреть файл

@ -73,6 +73,7 @@ MOCHITEST_ROBOCOP_FILES := \
$(wildcard $(TESTPATH)/*.sjs) \
$(wildcard $(TESTPATH)/test*.js) \
$(wildcard $(TESTPATH)/robocop*.js) \
$(wildcard $(TESTPATH)/*.xml) \
$(NULL)
GARBAGE += \

Просмотреть файл

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>Test search engine</ShortName>
<Description>A test search engine (based on Google search)</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16">data:image/png;base64,AAABAAEAEBAAAAEAGABoAwAAFgAAACgAAAAQAAAAIAAAAAEAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADs9Pt8xetPtu9FsfFNtu%2BTzvb2%2B%2Fne4dFJeBw0egA%2FfAJAfAA8ewBBegAAAAD%2B%2FPtft98Mp%2BwWsfAVsvEbs%2FQeqvF8xO7%2F%2F%2F63yqkxdgM7gwE%2FggM%2BfQA%2BegBDeQDe7PIbotgQufcMufEPtfIPsvAbs%2FQvq%2Bfz%2Bf%2F%2B%2B%2FZKhR05hgBBhQI8hgBAgAI9ewD0%2B%2Fg3pswAtO8Cxf4Kw%2FsJvvYAqupKsNv%2B%2Fv7%2F%2FP5VkSU0iQA7jQA9hgBDgQU%2BfQH%2F%2Ff%2FQ6fM4sM4KsN8AteMCruIqqdbZ7PH8%2Fv%2Fg6Nc%2Fhg05kAA8jAM9iQI%2BhQA%2BgQDQu6b97uv%2F%2F%2F7V8Pqw3eiWz97q8%2Ff%2F%2F%2F%2F7%2FPptpkkqjQE4kwA7kAA5iwI8iAA8hQCOSSKdXjiyflbAkG7u2s%2F%2B%2F%2F39%2F%2F7r8utrqEYtjQE8lgA7kwA7kwA9jwA9igA9hACiWSekVRyeSgiYSBHx6N%2F%2B%2Fv7k7OFRmiYtlAA5lwI7lwI4lAA7kgI9jwE9iwI4iQCoVhWcTxCmb0K%2BooT8%2Fv%2F7%2F%2F%2FJ2r8fdwI1mwA3mQA3mgA8lAE8lAE4jwA9iwE%2BhwGfXifWvqz%2B%2Ff%2F58u%2Fev6Dt4tr%2B%2F%2F2ZuIUsggA7mgM6mAM3lgA5lgA6kQE%2FkwBChwHt4dv%2F%2F%2F728ei1bCi7VAC5XQ7kz7n%2F%2F%2F6bsZkgcB03lQA9lgM7kwA2iQktZToPK4r9%2F%2F%2F9%2F%2F%2FSqYK5UwDKZAS9WALIkFn%2B%2F%2F3%2F%2BP8oKccGGcIRJrERILYFEMwAAuEAAdX%2F%2Ff7%2F%2FP%2B%2BfDvGXQLIZgLEWgLOjlf7%2F%2F%2F%2F%2F%2F9QU90EAPQAAf8DAP0AAfMAAOUDAtr%2F%2F%2F%2F7%2B%2Fu2bCTIYwDPZgDBWQDSr4P%2F%2Fv%2F%2F%2FP5GRuABAPkAA%2FwBAfkDAPAAAesAAN%2F%2F%2B%2Fz%2F%2F%2F64g1C5VwDMYwK8Yg7y5tz8%2Fv%2FV1PYKDOcAAP0DAf4AAf0AAfYEAOwAAuAAAAD%2F%2FPvi28ymXyChTATRrIb8%2F%2F3v8fk6P8MAAdUCAvoAAP0CAP0AAfYAAO4AAACAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQAA</Image>
<Url type="text/html" method="GET" template="http://example.com/search">
<Param name="q" value="{searchTerms}"/>
</Url>
<Url type="application/x-moz-tabletsearch" method="GET" template="http://example.com/search/tablet">
<Param name="q" value="{searchTerms}"/>
</Url>
<Url type="application/x-moz-phonesearch" method="GET" template="http://example.com/search/phone">
<Param name="q" value="{searchTerms}"/>
</Url>
<SearchForm>http://example.com/</SearchForm>
</SearchPlugin>

Просмотреть файл

@ -41,6 +41,7 @@
[testAddSearchEngine]
[testImportFromAndroid]
[testMasterPassword]
[testDeviceSearchEngine]
# Used for Talos, please don't use in mochitest
#[testPan]

Просмотреть файл

@ -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");
}
}

Просмотреть файл

@ -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();