UriIdlingResource

public class UriIdlingResource
extends Object implements IdlingResource

java.lang.Object
   ↳ android.support.test.espresso.idling.net.UriIdlingResource


An implementation of IdlingResource useful for monitoring idleness of network traffic.

This is similar to ERROR(/android.support.test.espresso.contrib.CountingIdlingResource), with the additional idleness constraint that the counter must be 0 for a set period of time before the resource becomes idle.

A network timeout is required to be reasonably sure that the webview has finished loading. Imagine the case where each response that comes back causes another request to be made until loading is complete. The counter will go from 0->1->0->1->0->1..., but we don't want to report the webview as idle each time this happens.

This API is currently in beta.

Summary

Nested classes

interface UriIdlingResource.HandlerIntf

Wraps a Handler object. 

Public constructors

UriIdlingResource(String resourceName, long timeoutMs)

Public methods

void beginLoad(String uri)

Called when a request is made.

void endLoad(String uri)

Called when a request is completed (ie the response is returned).

String getName()

Returns the name of the resources (used for logging and idempotency of registration).

void ignoreUri(Pattern pattern)

Add a regex pattern to the ignore list.

boolean isIdleNow()

Returns true if resource is currently idle.

void registerIdleTransitionCallback(IdlingResource.ResourceCallback resourceCallback)

Registers the given IdlingResource.ResourceCallback with the resource.

Inherited methods

From class java.lang.Object
From interface android.support.test.espresso.IdlingResource

Public constructors

UriIdlingResource

UriIdlingResource (String resourceName, 
                long timeoutMs)

Parameters
resourceName String

timeoutMs long

Public methods

beginLoad

void beginLoad (String uri)

Called when a request is made.

If the URI is not blacklisted the idle counter is incremented.

Parameters
uri String

endLoad

void endLoad (String uri)

Called when a request is completed (ie the response is returned).

If the URI is not blacklisted the idle counter is decremented. Once the idle counter reaches 0, the idle update thread will set the resource as idle after the appropriate timeout.

Parameters
uri String

getName

String getName ()

Returns the name of the resources (used for logging and idempotency of registration).

Returns
String

ignoreUri

void ignoreUri (Pattern pattern)

Add a regex pattern to the ignore list.

All request URIs are checked against all patterns, and matches are ignored for the purposes of detecting when the webview is idle.

Ignored patterns can only be added when the webview is idle.

Parameters
pattern Pattern

isIdleNow

boolean isIdleNow ()

Returns true if resource is currently idle. Espresso will always call this method from the main thread, therefore it should be non-blocking and return immediately.

Returns
boolean

registerIdleTransitionCallback

void registerIdleTransitionCallback (IdlingResource.ResourceCallback resourceCallback)

Registers the given IdlingResource.ResourceCallback with the resource. Espresso will call this method:

  • with its implementation of IdlingResource.ResourceCallback so it can be notified asynchronously that your resource is idle
  • from the main thread, but you are free to execute the callback's onTransitionToIdle from any thread
  • once (when it is initially given a reference to your IdlingResource)

You only need to call this upon transition from busy to idle - if the resource is already idle when the method is called invoking the call back is optional and has no significant impact.

Parameters
resourceCallback IdlingResource.ResourceCallback