Addition: support geolocation emulation (#183) · w3c/geolocation@69cc724 (original) (raw)

`@@ -752,6 +752,9 @@

`

752

752

` change of geographic position is left to the

`

753

753

` implementation. User agents MAY impose a rate limit on how

`

754

754

` frequently position changes are reported.

`

``

755

`+

User agents MUST consider

`

``

756

`+

invoking [=set emulated position data=] as a significant

`

``

757

`+

change.

`

755

758

`

`

756

759

`

  • If |document| is not [=Document/fully active=] or
  • `

    757

    760

    ` [=Document/visibility state=] is not "visible", go back to

    `

    `@@ -823,6 +826,38 @@

    `

    823

    826

    `

    `

    824

    827

    `

  • If |permission| is "granted":
  • `

    825

    828

    `

      `

      ``

      829

      `+

    1. `

      ``

      830

      `+

      Check if an emulated position should be used by running

      `

      ``

      831

      `+

      the following steps:

      `

      ``

      832

      `+

        `

        ``

        833

        `+

      1. Let |emulatedPositionData| be [=get emulated position data=]

        `

        ``

        834

        `+

        passing [=this=].

        `

        ``

        835

        `+

      2. `

        ``

        836

        `+

      3. If |emulatedPositionData| is not null:

        `

        ``

        837

        `+

          `

          ``

          838

          `+

        1. If |emulatedPositionData| is a {{GeolocationPositionError}}:

          `

          ``

          839

          `+

            `

            ``

            840

            `+

          1. [=Call back with error=] passing |errorCallback| and

            `

            ``

            841

            `+

            |emulatedPositionData|.

            `

            ``

            842

            `+

          2. `

            ``

            843

            `+

          3. Terminate this algorithm.
          4. `

            ``

            844

            `+

          `

          ``

          845

          `+

        2. `

          ``

          846

          `` +

        3. Let |position| be [=a new `GeolocationPosition`=]

          ``

          ``

          847

          `+

          passing |emulatedPositionData|, |acquisitionTime| and

          `

          ``

          848

          `+

          |options|.{{PositionOptions/enableHighAccuracy}}.

          `

          ``

          849

          `+

        4. `

          ``

          850

          `+

        5. [=Queue a task=] on the [=geolocation task source=] with

          `

          ``

          851

          `+

          a step that [=invokes=] |successCallback| with

          `

          ``

          852

          `` +

          « |position| » and "report".

          ``

          ``

          853

          `+

        6. `

          ``

          854

          `+

        7. Terminate this algorithm.

          `

          ``

          855

          `+

        8. `

          ``

          856

          `+

        `

        ``

        857

        `+

      4. `

        ``

        858

        `+

      `

      ``

      859

      `+

      `

      ``

      860

      `+

    2. `

      826

      861

      `

    3. Let |position| be null.
    4. `

      827

      862

      `

      `

      828

      863

      `

    5. If |cachedPosition| is not null, and
    6. `

      `@@ -1472,6 +1507,65 @@

      `

      1472

      1507

      ` feature/default allowlist=] is [=default allowlist/'self'=].

      `

      1473

      1508

      `

      `

      1474

      1509

      `

      `

      ``

      1510

      `+

      `

      ``

      1511

      `+

      `

      ``

      1512

      `+

      Emulation

      `

      ``

      1513

      `+

      `

      ``

      1514

      `+

      `

      ``

      1518

      `+

      `

      ``

      1519

      `+

      For the purposes of user-agent automation and application testing, this

      `

      ``

      1520

      `+

      document defines geolocation emulations.

      `

      ``

      1521

      `+

      `

      ``

      1522

      `+

      `

      ``

      1523

      `+

      Each [=top-level traversable=] has an associated

      `

      ``

      1524

      `+

      emulated position data, which is data representing

      `

      ``

      1525

      `+

      {{GeolocationCoordinates}}, {{GeolocationPositionError}} or null,

      `

      ``

      1526

      `+

      initially null.

      `

      ``

      1527

      `+

      `

      ``

      1528

      `+

      `

      ``

      1529

      `+

      To set emulated position data, given

      `

      ``

      1530

      `+

      [=navigable=] |navigable| and an |emulatedPositionData|:

      `

      ``

      1531

      `+

      `

      ``

      1532

      `+

        `

        ``

        1533

        `+

      1. Assert |emulatedPositionData| is either null, a

        `

        ``

        1534

        `+

        {{GeolocationCoordinates}}, or a {{GeolocationPositionError}}.

        `

        ``

        1535

        `+

      2. `

        ``

        1536

        `+

      3. Let |traversable| be |navigable|’s [=navigable/top-level traversable=].

        `

        ``

        1537

        `+

      4. `

        ``

        1538

        `+

      5. If |traversable| is not null:

        `

        ``

        1539

        `+

          `

          ``

          1540

          `+

        1. Set |traversable|'s associated [=emulated position data=] to

          `

          ``

          1541

          `+

          |emulatedPositionData|.

          `

          ``

          1542

          `+

        2. `

          ``

          1543

          `+

        3. User agents MUST consider this as a "significant change" in the

          `

          ``

          1544

          `+

          wait for a significant change of

          `

          ``

          1545

          `+

          geographic position step.

          `

          ``

          1546

          `+

        4. `

          ``

          1547

          `+

        `

        ``

        1548

        `+

      6. `

        ``

        1549

        `+

      `

      ``

      1550

      `+

      `

      ``

      1551

      `+

      To get emulated position data, given {{Geolocation}}

      `

      ``

      1552

      `+

      |geolocation|:

      `

      ``

      1553

      `+

      `

      ``

      1554

      `+

        `

        ``

        1555

        `+

      1. Let |navigable| be |geolocation|'s [=relevant global object=]'s

        `

        ``

        1556

        `` +

        [=associated Document=]'s [=node navigable=].

        ``

        ``

        1557

        `+

      2. `

        ``

        1558

        `+

      3. If |navigable| is null, return null.

        `

        ``

        1559

        `+

      4. `

        ``

        1560

        `+

      5. Let |traversable| be |navigable|’s [=navigable/top-level traversable=].

        `

        ``

        1561

        `+

      6. `

        ``

        1562

        `+

      7. If |traversable| is null, return null.

        `

        ``

        1563

        `+

      8. `

        ``

        1564

        `+

      9. Return |traversable|'s associated [=emulated position data=].

        `

        ``

        1565

        `+

      10. `

        ``

        1566

        `+

      `

      ``

      1567

      `+

      `

      ``

      1568

      `+

      `

      1475

      1569

      `

      `

      1476

      1570

      `

      `

      1477

      1571

      `

      `