1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78

content / web_test / common / fake_bluetooth_chooser.mojom [blame]

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module content.mojom;

import "url/mojom/origin.mojom";

// This interface is being developed to support Web Platform Tests for Web
// Bluetooth.
// https://docs.google.com/document/d/1Nhv_oVDCodd1pEH_jj9k8gF4rPGb_84VYaZ9IG8M_WY
//
// These interfaces are not intended to be used directly.
// `web-bluetooth-test.js` makes the Fake Bluetooth interface easier to work
// with.
// *   Calls are synchronous.
// *   IDs are cached.
//
// If another C++ client intends to use FakeBluetooth a C++ wrapper similar to
// `web-bluetooth-test.js` should be created.
//
// The implementation details of FakeBluetoothChooser can be found in the Web
// Bluetooth Test Scanning design document.
// https://docs.google.com/document/d/1XFl_4ZAgO8ddM6U53A9AfUuZeWgJnlYD5wtbXqEpzeg

// Indicates the types of Bluetooth chooser events.
enum ChooserEventType {
  CHOOSER_OPENED,
  CHOOSER_CLOSED,
  ADAPTER_REMOVED,
  ADAPTER_DISABLED,
  ADAPTER_ENABLED,
  DISCOVERY_FAILED_TO_START,
  DISCOVERING,
  DISCOVERY_IDLE,
  ADD_OR_UPDATE_DEVICE,
  UNAUTHORIZED,
};

// FakeBluetoothChooser allows clients to control the global state of the
// Bluetooth chooser during a web test.
interface FakeBluetoothChooser {
  // Simulates a user selecting the given |peripheral_address| in the Bluetooth
  // chooser.
  SelectPeripheral(string peripheral_address);

  // Calls the event handler function with the CANCELLED event.
  Cancel();

  // Calls the event handler function with the RESCAN event.
  Rescan();
};

// FakeBluetoothChooserFactory ensures that FakeBluetoothChoosers are created
// with an associated FakeBluetoothChooserClient.
interface FakeBluetoothChooserFactory {
  CreateFakeBluetoothChooser(
      pending_receiver<FakeBluetoothChooser> fake_chooser,
      pending_associated_remote<FakeBluetoothChooserClient> client) => ();
};

// FakeBluetoothChooserEvent describes the type of chooser event that has been
// produced by the FakeBluetoothChooser.
struct FakeBluetoothChooserEvent {
  ChooserEventType type;

  // Describes the origin the chooser is currently displaying.
  // This field will be used by the |CHOOSER_OPENED| event type.
  url.mojom.Origin? origin;

  // Describes the MAC address of the Bluetooth device.
  string? peripheral_address;
};

// Classes that implement this interface will be notified of chooser events.
interface FakeBluetoothChooserClient {
  OnEvent(FakeBluetoothChooserEvent event);
};