From c362efa115dc56d1ca479fdc1d8a589409e07bc9 Mon Sep 17 00:00:00 2001 From: James Graham Date: Tue, 8 Sep 2020 10:37:50 +0100 Subject: [PATCH 1/2] Store the top-level and parent browsing contexts explicitly. Previously the parent and top-level browsing contexts were computed properties based on the current browsing context. This fails in the case where the frame containing the current browsing context is removed from the DOM tree since the browsing context is then discarded meaning that trying to compute its parents will fail. In practice we expect operations working with the top-level browsing context to continue working in that case (and indeed implementations are mostly/entirely not following the current spec), so this makes the top-level and parent browsing contexts explictly stored properties of the session that are updated at the point where we change browsing contexts. --- index.html | 77 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/index.html b/index.html index 3cd214c4b..35e763b73 100644 --- a/index.html +++ b/index.html @@ -2160,14 +2160,14 @@

Sessions

representation of a UUID) used to uniquely identify this session. Unless stated otherwise it is null. -

A session has an associated current browsing context, - which is the browsing context against which commands will run. - -

A session has an associated - current top-level browsing context, which is the current browsing - context if it itself is a top-level browsing context, and otherwise - is the top-level browsing context of the current browsing - context. +

A session has an associated current browsing + context, which is the browsing context against + which commands will run, an associated current parent + browsing context, which is set to the parent of the current + browsing context when changing browsing contexts, and an + associated current top-level browsing context, which is + set to the top-browsing context ancestor of the current browsing + context, when changing browsing contexts.

A session has an associated session timeouts @@ -2432,10 +2432,9 @@

New Sessio
  • Set the webdriver-active flag to true.

    -
  • Set the current top-level browsing context - for session in an implementation-specific way. This - should be the top-level browsing context of the UA’s - current browsing context. +

  • Set the current top-level browsing context + for session with the top-level browsing context + of the UA’s current browsing context.

    WebDriver implementations typically start a completely new browser instance, but there is no requirement in @@ -2932,8 +2931,8 @@

    Navigate To

  • Try to run the post-navigation checks. -

  • Set the current browsing context - to the current top-level browsing context. +

  • Set the current browsing context with the current + top-level browsing context.

  • If the current top-level browsing context contains a refresh state pragma directive of time 1 second @@ -3101,8 +3100,8 @@

    Refresh

  • Try to run the post-navigation checks. -

  • Set the current browsing context - to the current top-level browsing context. +

  • Set the current browsing context with current + top-level browsing context.

  • Return success with data null. @@ -3195,6 +3194,28 @@

    Contexts

    +

    When required to set the current browsing context given + a context, an implementation must follow the following + steps: +

      +
    1. Set the current session’s current browsing + context to context. +
    2. Set the current session’s current parent browsing + context to the parent browsing context + of context, if that context exists, or null + otherwise. +
    + +

    When required to set the current top-level browsing + context given a context, an implementation must + follow the following steps: +

      +
    1. Assert: context is a top-level browsing context. +
    2. Set the current session’s current top-level browsing + context to context. +
    3. Set the current browsing context to context. +
    +

    In accordance with the focus @@ -3292,10 +3313,11 @@

    Switch To Window

    focussing of another top-level browsing context, return error with error code unexpected alert open. -
  • If handle is equal to the associated window handle - for some top-level browsing context in the current session, - set the session’s current browsing context - to that browsing context. +

  • If handle is equal to the associated window + handle for some top-level browsing context in + the current session, let context be the that + browsing context, and + set the current top-level browsing context with context.

    Otherwise, return error with error code no such window. @@ -3455,7 +3477,7 @@

    Switch To Frame

    id is null
      -
    1. Set the current browsing context to +

    2. Set the current browsing context with the current top-level browsing context.

    @@ -3478,7 +3500,7 @@

    Switch To Frame

    window.[[\GetOwnProperty]] (id). -
  • Set the current browsing context to +

  • Set the current browsing context with child window’s browsing context. @@ -3496,8 +3518,8 @@

    Switch To Frame

    or iframe element, return error with error code no such frame. -
  • Set the current browsing context to element’s - nested browsing context. +

  • Set the current browsing context + with element’s nested browsing context. @@ -3539,10 +3561,9 @@

    Switch To Parent Frame

  • Handle any user prompts and return its value if it is an error. -

  • If the current browsing context is not equal to - the current top-level browsing context, - set the current browsing context to - the parent browsing context of the current browsing context. +

  • If the current session's current parent browsing + context is not null, set the current browsing + context with the current parent browsing context.

  • Update any implementation-specific state that would result from the user selecting the current browsing context for From 43f6e94f9809f5b3c69450544e35b2359602a420 Mon Sep 17 00:00:00 2001 From: James Graham Date: Tue, 8 Sep 2020 12:11:58 +0100 Subject: [PATCH 2/2] Update the browsing context checks for switch to [parent] frame This ensures that we only fail these operations if the browsing context we're trying to switch to is missing, not the current browsing context. --- index.html | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/index.html b/index.html index 35e763b73..f961bde2c 100644 --- a/index.html +++ b/index.html @@ -3465,20 +3465,21 @@

    Switch To Frame

    or an Object that represents a web element, return error with error code invalid argument. -
  • If the current browsing context is no longer open, - return error with error code no such window. - -

  • Handle any user prompts - and return its value if it is an error. -

  • Run the substeps of the first matching condition:

    id is null
      +
    1. If the current top-level browsing context is no + longer open, return error with error code no + such window. + +

    2. Handle any user prompts + and return its value if it is an error. +

    3. Set the current browsing context with - the current top-level browsing context. + the current top-level browsing context.

    id is a Number object @@ -3487,6 +3488,13 @@

    Switch To Frame

  • If id is less than 0 or greater than 216 – 1, return error with error code invalid argument. +

  • If the current browsing context is no + longer open, return error with error code no + such window. + +

  • Handle any user prompts + and return its value if it is an error. +

  • Let window be the associated window of the current browsing context’s active document. @@ -3507,6 +3515,13 @@

    Switch To Frame

    id represents a web element
      +
    1. If the current browsing context is no + longer open, return error with error code no + such window. + +

    2. Handle any user prompts + and return its value if it is an error. +

    3. Let element be the result of trying to get a known element by web element reference id. @@ -3556,8 +3571,9 @@

      Switch To Parent Frame

      The remote end steps are:

        -
      1. If the current browsing context is no longer open, - return error with error code no such window. +

      2. If the current parent browsing context is no longer + open, return error with error code no such + window.

      3. Handle any user prompts and return its value if it is an error.