1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/tests/testSimpleDiscovery.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,46 @@ 1.4 +// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.7 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 +"use strict"; 1.9 + 1.10 +const { classes: Cc, interfaces: Ci, utils: Cu } = Components; 1.11 + 1.12 +Cu.import("resource://gre/modules/Services.jsm"); 1.13 +Cu.import("resource://gre/modules/SimpleServiceDiscovery.jsm"); 1.14 + 1.15 +function discovery_observer(subject, topic, data) { 1.16 + do_print("Observer: " + data); 1.17 + 1.18 + let service = SimpleServiceDiscovery.findServiceForLocation(data); 1.19 + if (!service) 1.20 + return; 1.21 + 1.22 + do_check_eq(service.friendlyName, "Pretend Device"); 1.23 + do_check_eq(service.uuid, "uuid:5ec9ff92-e8b2-4a94-a72c-76b34e6dabb1"); 1.24 + do_check_eq(service.manufacturer, "Copy Cat Inc."); 1.25 + do_check_eq(service.modelName, "Eureka Dongle"); 1.26 + 1.27 + run_next_test(); 1.28 +}; 1.29 + 1.30 +add_test(function test_default() { 1.31 + do_register_cleanup(function cleanup() { 1.32 + Services.obs.removeObserver(discovery_observer, "ssdp-service-found"); 1.33 + }); 1.34 + 1.35 + Services.obs.addObserver(discovery_observer, "ssdp-service-found", false); 1.36 + 1.37 + // Create a pretend service 1.38 + let service = { 1.39 + location: "http://mochi.test:8888/tests/robocop/simpleservice.xml", 1.40 + target: "test:service" 1.41 + }; 1.42 + 1.43 + do_print("Force a detailed ping from a pretend service"); 1.44 + 1.45 + // Poke the service directly to get the discovery to happen 1.46 + SimpleServiceDiscovery._processService(service); 1.47 +}); 1.48 + 1.49 +run_next_test();