title: Espresso checking if toasts are displayed (one on top of another)
body: <p>I have an problem with checking if toast is displayed using espresso. I'm using class:</p>
  
  <pre><code>       import android.os.IBinder;
      import android.support.test.espresso.Root;
      import android.view.WindowManager;
      import org.hamcrest.Description;
      import org.hamcrest.TypeSafeMatcher;
  
      public class ToastMatcher extends TypeSafeMatcher&lt;Root&gt; {
  
      @Override
      public void describeTo(Description description) {
          description.appendText("is toast");
      }
  
      @Override
      public boolean matchesSafely(Root root) {
          int type = root.getWindowLayoutParams().get().type;
          if ((type == WindowManager.LayoutParams.TYPE_TOAST)) {
              IBinder windowToken = root.getDecorView().getWindowToken();
              IBinder appToken = root.getDecorView().getApplicationWindowToken();
              if (windowToken == appToken) {
                  // windowToken == appToken means this window isn't contained by any other windows.
                  // if it was a window for an activity, it would have TYPE_BASE_APPLICATION.
                  return true;
              }
          }
          return false;
      }
  
  }
  </code></pre>
  
  <p>and checking Toast by:</p>
  
  <pre><code>onView(withText(R.string.unauthorized)).inRoot(new ToastMatcher())
              .check(matches(isDisplayed()));
  </code></pre>
  
  <p>Everything works fine until I try to check another toast in the same class for example:</p>
  
  <pre><code>@Test
  public void messageOnBack() throws Exception{
  pressBack();
  onView(withText(R.string.exit_on_back)).inRoot(new ToastMatcher())
              .check(matches(isDisplayed()));
  </code></pre>
  
  <p>Then first one is passed but second one puts error:</p>
  
  <pre><code>    android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with string from resource id: &lt;2131165323&gt;[unauthorized] value: Wrong login or password.
  
  View Hierarchy:
  +&gt;LinearLayout{id=-1, visibility=VISIBLE, width=660, height=116, has-focus=false, has-focusable=false, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
  |
  +-&gt;AppCompatTextView{id=16908299, res-name=message, visibility=VISIBLE, width=528, height=58, has-focus=false, has-focusable=false, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=66.0, y=29.0, text=Please click BACK again to exit., input-type=0, ime-target=false, has-links=false}
  |
  at dalvik.system.VMStack.getThreadStackTrace(Native Method)
  </code></pre>
  
  <p>What is weird, when I comment out one of the tests second one works just fine without any changes. Espresso seems to get stupid when one toast is displayed on top of another. Any ideas how to solve this?</p>