Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * vim: sw=2 ts=2 sts=2 et filetype=javascript |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 8 | // Test Purpose: |
michael@0 | 9 | // To verify that all setters of BluetoothAdapter (except for pairing related |
michael@0 | 10 | // APIs) can change properties correctly. |
michael@0 | 11 | // |
michael@0 | 12 | // Test Coverage: |
michael@0 | 13 | // - BluetoothAdapter.setName() |
michael@0 | 14 | // - BluetoothAdapter.setDiscoverable() |
michael@0 | 15 | // - BluetoothAdapter.setDiscoverableTimeout() |
michael@0 | 16 | // |
michael@0 | 17 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 18 | |
michael@0 | 19 | MARIONETTE_TIMEOUT = 60000; |
michael@0 | 20 | MARIONETTE_HEAD_JS = 'head.js'; |
michael@0 | 21 | |
michael@0 | 22 | const BT_DEVICE_NAME = "User friendly name of local BT device"; |
michael@0 | 23 | |
michael@0 | 24 | function setName(aAdapter, aName) { |
michael@0 | 25 | let deferred = Promise.defer(); |
michael@0 | 26 | |
michael@0 | 27 | let request = aAdapter.setName(aName); |
michael@0 | 28 | request.onsuccess = function () { |
michael@0 | 29 | log(" setName succeed: " + aName); |
michael@0 | 30 | is(aAdapter.name, aName, "aAdapter.name"); |
michael@0 | 31 | deferred.resolve(); |
michael@0 | 32 | } |
michael@0 | 33 | request.onerror = function () { |
michael@0 | 34 | ok(false, "setName failed") |
michael@0 | 35 | deferred.reject(); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | return deferred.promise; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | function setDiscoverable(aAdapter, aIsDiscoverable) { |
michael@0 | 42 | let deferred = Promise.defer(); |
michael@0 | 43 | |
michael@0 | 44 | let request = aAdapter.setDiscoverable(aIsDiscoverable); |
michael@0 | 45 | request.onsuccess = function () { |
michael@0 | 46 | log(" setDiscoverable succeed: " + aIsDiscoverable); |
michael@0 | 47 | is(aAdapter.discoverable, aIsDiscoverable, "aAdapter.discoverable"); |
michael@0 | 48 | deferred.resolve(); |
michael@0 | 49 | } |
michael@0 | 50 | request.onerror = function () { |
michael@0 | 51 | ok(false, "setDiscoverable failed") |
michael@0 | 52 | deferred.reject(); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | return deferred.promise; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | function setDiscoverableTimeout(aAdapter, aTimeout) { |
michael@0 | 59 | let deferred = Promise.defer(); |
michael@0 | 60 | |
michael@0 | 61 | let request = aAdapter.setDiscoverableTimeout(aTimeout); |
michael@0 | 62 | request.onsuccess = function () { |
michael@0 | 63 | log(" setDiscoverableTimeout succeed: " + aTimeout); |
michael@0 | 64 | is(aAdapter.discoverableTimeout, aTimeout, "aAdapter.discoverableTimeout"); |
michael@0 | 65 | deferred.resolve(); |
michael@0 | 66 | } |
michael@0 | 67 | request.onerror = function () { |
michael@0 | 68 | ok(false, "setDiscoverableTimeout failed") |
michael@0 | 69 | deferred.reject(); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | return deferred.promise; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | startBluetoothTest(true, function testCaseMain(aAdapter) { |
michael@0 | 76 | log("Testing BluetoothAdapter setters ..."); |
michael@0 | 77 | |
michael@0 | 78 | return Promise.resolve() |
michael@0 | 79 | .then( () => setName(aAdapter, BT_DEVICE_NAME) ) |
michael@0 | 80 | .then( () => setDiscoverableTimeout(aAdapter, 180) ) |
michael@0 | 81 | .then( () => setDiscoverable(aAdapter, true) ) |
michael@0 | 82 | .then( () => setName(aAdapter, EMULATOR_NAME) ) |
michael@0 | 83 | .then( () => setDiscoverable(aAdapter, false) ) |
michael@0 | 84 | .then( () => setDiscoverableTimeout(aAdapter, 120) ); |
michael@0 | 85 | }); |