Skip to content

Commit 321fff4

Browse files
andreasttAutomatedTester
authored andcommitted
navigation: refactor waiting for navigation and response checks
This patch creates two new definitions to _wait for navigation to complete_ and for _post-navigation checks_ that can be referenced and reused in commands where we expect navigation to occur, such as Element Click, Go, and Refresh. It references the Web App Security specification, as HTML does, when it looks at the outcome of the response from navigating. The patch furthermore defines page loading strategies (and fixes a lot of references to them throughout) and makes sure theyare taken into consideration when waiting for the document's ready state to change. It also adds a few examples. Signed-off-by: AutomatedTester <[email protected]>
1 parent a8ac274 commit 321fff4

File tree

1 file changed

+149
-67
lines changed

1 file changed

+149
-67
lines changed

webdriver-spec.html

+149-67
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,16 @@ <h3>Dependencies</h3>
136136
-->
137137

138138
<dl>
139+
<dt>Web App Security
140+
<dd><p>The following terms are defined
141+
in the Content Security Policy Level 3 specification: [[!CSP3]]
142+
<ul>
143+
<li><dfn data-lt="blocked by content security policy"><a href=https://w3c.github.io/webappsec-csp/#should-block-navigation-response>Should block navigation response</a></dfn>
144+
</ul>
145+
139146
<dt>DOM
140-
<dd><p>The following terms are defined in the Document Object Model specification: [[!DOM]]
147+
<dd><p>The following terms are defined
148+
in the Document Object Model specification: [[!DOM]]
141149
<ul>
142150
<!-- Attribute --> <li><dfn><a href=https://dom.spec.whatwg.org/#concept-attribute>Attribute</a></dfn>
143151
<!-- context object --><li><dfn><a href="https://dom.spec.whatwg.org/#context-object">context object</a></dfn>
@@ -279,6 +287,7 @@ <h3>Dependencies</h3>
279287
<!-- Disabled --> <li><dfn><a href=https://html.spec.whatwg.org/#concept-fe-disabled>Disabled</a></dfn>
280288
<!-- Document address --> <li><dfn data-lt=address><a href=https://dom.spec.whatwg.org/#concept-document-url>Document address</a></dfn>
281289
<!-- Document title --> <li><dfn data-lt=title><a href=https://html.spec.whatwg.org/#document.title>Document title</a></dfn>
290+
<!-- Document readiness --> <li><dfn><a href=https://html.spec.whatwg.org/#current-document-readiness>Document readiness</a></dfn>
282291
<!-- Enumerated attribute --> <li><dfn><a href=https://html.spec.whatwg.org/#enumerated-attribute>Enumerated attribute</a></dfn>
283292
<!-- Environment settings object --> <li><dfn><a href=https://html.spec.whatwg.org/#environment-settings-object>Environment settings object</a></dfn>
284293
<!-- Event loop --> <li><dfn><a href=https://html.spec.whatwg.org/#event-loop>Event loop</a></dfn>
@@ -290,7 +299,7 @@ <h3>Dependencies</h3>
290299
<!-- Input type file selected --> <li><dfn><a href="https://html.spec.whatwg.org/#concept-input-type-file-selected">Selected Files</a></dfn>
291300
<!-- Joint session history --> <li><dfn><a href=https://html.spec.whatwg.org/#joint-session-history>Joint session history</a></dfn>
292301
<!-- Missing value default state --> <li><dfn><a href=https://html.spec.whatwg.org/#missing-value-default>Missing value default state</a></dfn>
293-
<!-- Navigate --> <li><dfn><a href=https://html.spec.whatwg.org/#navigate>Navigate</a></dfn>
302+
<!-- Navigate --> <li><dfn data-lt="navigating|navigation"><a href=https://html.spec.whatwg.org/#navigate>Navigate</a></dfn>
294303
<!-- Nested browsing context --> <li><dfn><a href=https://html.spec.whatwg.org/#nested-browsing-context>Nested browsing context</a></dfn>
295304
<!-- Origin-clean --> <li><dfn><a href=https://html.spec.whatwg.org/#concept-canvas-origin-clean>Origin-clean</a></dfn>
296305
<!-- Parent browsing context --> <li><dfn><a href=https://html.spec.whatwg.org/#parent-browsing-context>Parent browsing context</a></dfn>
@@ -354,6 +363,7 @@ <h3>Dependencies</h3>
354363
<dd><p>The following events are also defined in the HTML specification:
355364
<ul>
356365
<!-- beforeunload --> <li><dfn><a href=https://html.spec.whatwg.org/#event-beforeunload><code>beforeunload</code></a></dfn>
366+
<!-- DOMContentLoaded --> <li><dfn><a href=https://html.spec.whatwg.org/#event-domcontentloaded><code>DOMContentLoaded</code></a></dfn>
357367
</ul>
358368

359369
<dd><p>The “data” URL scheme specification defines the following terms: [[!RFC2397]]
@@ -1200,6 +1210,14 @@ <h3>Handling Errors</h3>
12001210
<a data-lt="keyboard interactable">keyboard</a> <a>interactable</a>.
12011211
</tr>
12021212

1213+
<tr>
1214+
<td><dfn>insecure certificate</dfn>
1215+
<td>400
1216+
<td><code>insecure certificate</code>
1217+
<td><a>Navigation</a> caused
1218+
the user agent to hit a certificate warning,
1219+
which is usually the result of an expired or invalid TLS certificate.
1220+
12031221
<tr>
12041222
<td><dfn>invalid argument</dfn>
12051223
<td>400
@@ -1680,10 +1698,10 @@ <h2>Capabilities</h2>
16801698
append a string saying that a JSON Object is required,
16811699
else call <a>set the proxy</a> passing in <var>proxy</var>.
16821700

1683-
<li><p>Let <var>page load strategy</var> be the result of <a>getting a property</a>
1684-
named <code>pageLoadStrategy</code> from <var>unprocessed capability</var>.
1685-
If <var>page load strategy</var> is <a>undefined</a>,
1686-
then set the entry <code>pageLoadStrategy</code>
1701+
<li><p>Let <var>page loading strategy</var> be the result of <a>getting a property</a>
1702+
named <code>pageLoadingStrategy</code> from <var>unprocessed capability</var>.
1703+
If <var>page loading strategy</var> is <a>undefined</a>,
1704+
then set the entry <code>pageLoadingStrategy</code>
16871705
in <var>server capabilities</var> to <a>normal</a>.
16881706
</ol>
16891707

@@ -1850,8 +1868,8 @@ <h2>Sessions</h2>
18501868
Unless stated otherwise it is zero milliseconds.
18511869

18521870
<p>A <a>session</a> has an associated <dfn>page loading strategy</dfn>,
1853-
which is one of <i>none</i>, <i>normal</i>, and <i>eager</i>.
1854-
Unless stated otherwise, it is <i>normal</i>.
1871+
which is one of <a>none</a>, <a>normal</a>, and <a>eager</a>.
1872+
Unless stated otherwise, it is <a>normal</a>.
18551873

18561874
<p>A <a>session</a> has an associated <dfn>secure SSL</dfn> state
18571875
that indicates whether untrusted or self-signed SSL certificates
@@ -2143,24 +2161,112 @@ <h3>Set Timeouts</h3>
21432161

21442162
<section>
21452163
<h2>Navigation</h2>
2164+
21462165
<p>The <a>commands</a> in this section allow navigation of
21472166
the <a>current top-level browsing context</a> to new URLs
21482167
and introspection of the document currently loaded in this <a>browsing context</a>.
21492168

2150-
<p>For commands that cause a new document to load,
2151-
the point at which the <a>command</a> returns
2152-
is determined by the session’s <a>page load strategy</a>.
2153-
A value of <code>normal</code> causes the command
2154-
to return after the <code>load</code> event fires on the new page,
2155-
a value of <code>eager</code> causes it to return
2156-
after <code>DOMContentLoaded</code> fires,
2157-
and a value of <code>none</code> causes it to return immediately.
2169+
<p>For <a>commands</a> that cause a new document to load,
2170+
the point at which the command returns
2171+
is determined by the session’s <a>page loading strategy</a>.
2172+
The <a>normal</a> state causes it
2173+
to return after the load event fires on the new page,
2174+
<a>eager</a> causes it to return
2175+
after the <a><code>DOMContentLoaded</code></a> event fires,
2176+
and <a>none</a> causes it to return immediately.
21582177

21592178
<p>Navigation actions are also affected by the value of
21602179
the <a>session page load timeout</a>,
21612180
which determines the maximum time that commands will block
21622181
before returning with a <a>timeout</a> <a>error</a>.
21632182

2183+
<p>The following is the <dfn>table of page load strategies</dfn>
2184+
that links the <code>pageLoadingStrategy</code> <a>capability</a> keyword
2185+
to a <a>page loading strategy</a> state,
2186+
and shows which <a>document readiness</a> state
2187+
that corresponds to it:
2188+
2189+
<table class=simple>
2190+
<tr>
2191+
<th>Keyword
2192+
<th>Page load strategy state
2193+
<th>Document readiness state
2194+
</tr>
2195+
2196+
<tr>
2197+
<td>"<code>none</code>"
2198+
<td><dfn data-lt="none page loading strategy">none</dfn>
2199+
<td>
2200+
</tr>
2201+
2202+
<tr>
2203+
<td>"<code>eager</code>"
2204+
<td><dfn data-lt="eager page loading strategy">eager</dfn>
2205+
<td>"<code>interactive</code>"
2206+
</tr>
2207+
2208+
<tr>
2209+
<td>"<code>normal</code>"
2210+
<td><dfn data-lt="normal page loading strategy">normal</dfn>
2211+
<td>"<code>complete</code>"
2212+
</tr>
2213+
</table>
2214+
2215+
<p>When asked to <dfn data-lt="waiting for the navigation to complete">wait for navigation to complete</dfn>,
2216+
run the following steps:
2217+
2218+
<ol>
2219+
<li><p>If the <a>current session</a> has a <a>page loading strategy</a>:
2220+
2221+
<ol>
2222+
<li><p>Let <var>readiness target</var> be the <a>document readiness</a> state
2223+
tied to the <a>current session</a>’s <a>page loading strategy</a>,
2224+
which can be found in the <a>table of page load strategies</a>.
2225+
2226+
<li><p>Wait for the the <a>current browsing context</a>’s
2227+
<a>document readiness</a> state
2228+
to reach <var>readiness target</var>,
2229+
or for the <a>session page load timeout</a> to pass,
2230+
whichever occurs sooner.
2231+
2232+
<p class=example>This can typically be implemented
2233+
by registering an event handler for
2234+
the <a><code>DOMContentLoaded</code></a> event,
2235+
and comparing the <a>document readiness</a> state
2236+
against <var>readiness target</var> whenever it fires.
2237+
When it reaches its designated <var>readiness target</var>,
2238+
return from the overall step of this algorithm.
2239+
2240+
<li><p>If the previous step completed
2241+
by the load timeout being reached
2242+
and the browser is does not have an <a>active user prompt</a>,
2243+
return <a>error</a> with <a>error code</a> <a>timeout</a>.
2244+
</ol>
2245+
</ol>
2246+
2247+
<p>When asked to run the <dfn>post-navigation checks</dfn>,
2248+
run the substeps of the first matching statement:
2249+
2250+
<dl class=switch>
2251+
<dt><a>response</a> is a network error
2252+
<dd><p>Return <a>error</a> with <a>error code</a> <a>unknown error</a>.
2253+
2254+
<dt><a>response</a> be <a>blocked by content security policy</a>
2255+
<dd><p>If the <a>current session</a>’s <a>secure SSL</a> state is disabled,
2256+
take implementation specific steps to ensure
2257+
the navigation is not aborted
2258+
and that the untrusted- or invalid TLS certificate error
2259+
that would normally occur under these circumstances,
2260+
are suppressed.
2261+
2262+
<p>Otherwise return <a>error</a> with <a>error code</a> <a>insecure certificate</a>.
2263+
2264+
<dt><a>response</a>’s <a>HTTP status code</a> is 401
2265+
<dt>Otherwise
2266+
<dd><p>Irrespective of how a possible authentication challenge is handled,
2267+
return <a>success</a> with data null.
2268+
</dl>
2269+
21642270
<section>
21652271
<h3>Go</h3>
21662272

@@ -2219,39 +2325,11 @@ <h3>Go</h3>
22192325

22202326
<li><p><a>Navigate</a> the <a>current top-level browsing context</a> to <var>url</var>.
22212327

2222-
<p>If this navigation’s HTTP request
2223-
results in a HTTP 401 response,
2224-
the <a>remote end</a> must proceed with the steps below,
2225-
irrespective of how the authentication challenge is handled.
2226-
2227-
<p>If this navigation’s HTTP request
2228-
results in a TLS client certificate negotiation
2229-
and the certificate is found to not be valid
2230-
and the <a>active session</a>’s <a>secure SSL</a> state is disabled,
2231-
take implementation specific steps to ensure
2232-
the navigation is not aborted
2233-
and that the untrusted- or invalid SSL certificate error
2234-
that would normally occur under these circumstances, are suppressed.
2328+
<li><p>Run the <a>post-navigation checks</a>
2329+
and return its value if it is an <a>error</a>.
22352330

2236-
<li><p>If the <a>current session</a>’s <a>page loading strategy</a>
2237-
is <a>none</a> jump to the next step in this overall set of steps.
2238-
2239-
<p>Otherwise:
2240-
2241-
<ol>
2242-
<li><p>Let <var>readiness target</var> be "<code>interactive</code>"
2243-
if the <a>current session</a>’s <a>page loading strategy</a> is <a>eager</a>,
2244-
or "<code>complete</code>" if it is <a>normal</a>.
2245-
2246-
<li><p>Wait for the <a>current document readiness</a> to reach <var>readiness target</var>,
2247-
or for the <a>session page load timeout</a> milliseconds to pass,
2248-
whichever occurs sooner.
2249-
2250-
<li><p>If the previous step completed by the <a>load timeout</a> being reached,
2251-
and the browser is not currently displaying an alert,
2252-
<!-- perhaps? Not sure if this is what the spec is trying to say -->
2253-
return <a>error</a> with <a>error code</a> <a>timeout</a>.
2254-
</ol>
2331+
<li><p><a>Wait for navigation to complete</a>
2332+
and return its value if it is an <a>error</a>.
22552333

22562334
<li><p>Set the <a>current browsing context</a>
22572335
to the <a>current top-level browsing context</a>.
@@ -2436,31 +2514,19 @@ <h3>Refresh</h3>
24362514

24372515
<li><p><a>Handle any user prompts</a> and return its value if it is an <a>error</a>.
24382516

2439-
<li><p class=issue>Not sure if this needs to consider the reload override flag.
2440-
2441-
<p><a>Navigate</a> the <a>current top-level browsing context</a>
2517+
<li><p><a>Navigate</a> the <a>current top-level browsing context</a>
24422518
to the same resource as its <a>active document</a>,
24432519
with <a>replacement enabled</a>.
24442520
</li>
24452521

2446-
<li><p>If the <a>current session</a>’s <a>page load strategy</a> is <a>none</a>,
2447-
jump to the next step in this overall set of steps.
2448-
2449-
<p>Otherwise:
2450-
2451-
<ol>
2452-
<li><p>Let <var>readiness target</var> be "<code>interactive</code>"
2453-
if the <a>current session</a>’s <a>page load strategy</a> is <a>eager</a>,
2454-
or "<code>complete</code>" if it is <a>normal</a>.
2522+
<li><p>Run the <a>post-navigation checks</a>
2523+
and return its value if it is an <a>error</a>.
24552524

2456-
<li><p>Wait for the <a>current document readiness</a> to reach <var>readiness target</var>,
2457-
or for the <a>session page load timeout</a> milliseconds to pass,
2458-
whichever occurs sooner.
2525+
<li><p><a>Wait for navigation to complete</a>
2526+
and return its value if it is an <a>error</a>.
24592527

2460-
<li><p>If the previous step completed by the <a>load timeout</a> being reached,
2461-
and the browser is not currently displaying an alert,
2462-
return <a>error</a> with <a>error code</a> <a>timeout</a>.
2463-
</ol>
2528+
<li><p>Set the <a>current browsing context</a>
2529+
to the <a>current top-level browsing context</a>.
24642530

24652531
<li><p>Return <a>success</a> with data null.
24662532
</ol>
@@ -4383,6 +4449,22 @@ <h3>Element Click</h3>
43834449

43844450
<li><p class=issue>Run interaction steps on coordinate.
43854451

4452+
<li><p>If the click causes <a>navigation</a>:
4453+
4454+
<ol>
4455+
<li><p>Run the <a>post-navigation checks</a>
4456+
and return its value if it is an <a>error</a>.
4457+
4458+
<li><p><a>Wait for navigation to complete</a>
4459+
and return its value if it is an <a>error</a>.
4460+
</ol>
4461+
4462+
<p class=example>Note that one may not know
4463+
if a click causes <a>navigation</a>.
4464+
It is safe to run the <a>post-navigation checks</a>
4465+
and <a>waiting for the navigation to complete</a>
4466+
even though navigation <em>did not</em> occur.
4467+
43864468
<li><p>Return <a>success</a> with data null.
43874469
</ol>
43884470
</section> <!-- /Element Click -->

0 commit comments

Comments
 (0)