diff -r 000000000000 -r 6474c204b198 mobile/android/base/tests/testSimpleDiscovery.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mobile/android/base/tests/testSimpleDiscovery.js Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,46 @@ +// -*- 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/. */ +"use strict"; + +const { classes: Cc, interfaces: Ci, utils: Cu } = Components; + +Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/SimpleServiceDiscovery.jsm"); + +function discovery_observer(subject, topic, data) { + do_print("Observer: " + data); + + let service = SimpleServiceDiscovery.findServiceForLocation(data); + if (!service) + return; + + do_check_eq(service.friendlyName, "Pretend Device"); + do_check_eq(service.uuid, "uuid:5ec9ff92-e8b2-4a94-a72c-76b34e6dabb1"); + do_check_eq(service.manufacturer, "Copy Cat Inc."); + do_check_eq(service.modelName, "Eureka Dongle"); + + run_next_test(); +}; + +add_test(function test_default() { + do_register_cleanup(function cleanup() { + Services.obs.removeObserver(discovery_observer, "ssdp-service-found"); + }); + + Services.obs.addObserver(discovery_observer, "ssdp-service-found", false); + + // Create a pretend service + let service = { + location: "http://mochi.test:8888/tests/robocop/simpleservice.xml", + target: "test:service" + }; + + do_print("Force a detailed ping from a pretend service"); + + // Poke the service directly to get the discovery to happen + SimpleServiceDiscovery._processService(service); +}); + +run_next_test();