|
1 // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 "use strict"; |
|
6 |
|
7 const { classes: Cc, interfaces: Ci, utils: Cu } = Components; |
|
8 |
|
9 Cu.import("resource://gre/modules/Services.jsm"); |
|
10 Cu.import("resource://gre/modules/SimpleServiceDiscovery.jsm"); |
|
11 |
|
12 function discovery_observer(subject, topic, data) { |
|
13 do_print("Observer: " + data); |
|
14 |
|
15 let service = SimpleServiceDiscovery.findServiceForLocation(data); |
|
16 if (!service) |
|
17 return; |
|
18 |
|
19 do_check_eq(service.friendlyName, "Pretend Device"); |
|
20 do_check_eq(service.uuid, "uuid:5ec9ff92-e8b2-4a94-a72c-76b34e6dabb1"); |
|
21 do_check_eq(service.manufacturer, "Copy Cat Inc."); |
|
22 do_check_eq(service.modelName, "Eureka Dongle"); |
|
23 |
|
24 run_next_test(); |
|
25 }; |
|
26 |
|
27 add_test(function test_default() { |
|
28 do_register_cleanup(function cleanup() { |
|
29 Services.obs.removeObserver(discovery_observer, "ssdp-service-found"); |
|
30 }); |
|
31 |
|
32 Services.obs.addObserver(discovery_observer, "ssdp-service-found", false); |
|
33 |
|
34 // Create a pretend service |
|
35 let service = { |
|
36 location: "http://mochi.test:8888/tests/robocop/simpleservice.xml", |
|
37 target: "test:service" |
|
38 }; |
|
39 |
|
40 do_print("Force a detailed ping from a pretend service"); |
|
41 |
|
42 // Poke the service directly to get the discovery to happen |
|
43 SimpleServiceDiscovery._processService(service); |
|
44 }); |
|
45 |
|
46 run_next_test(); |