@Test public void shouldStoreTheNumberOfTimesGoBackWasCalled() throws Exception { assertThat(shadowOf(webView).getGoBackInvocations()).isEqualTo(0); webView.goBack(); webView.loadUrl("foo.bar", null); // If there is no history (only one page), we shouldn't invoke go back. assertThat(shadowOf(webView).getGoBackInvocations()).isEqualTo(0); webView.loadUrl("foo.bar", null); webView.loadUrl("foo.bar", null); webView.loadUrl("foo.bar", null); webView.loadUrl("foo.bar", null); webView.loadUrl("foo.bar", null); webView.goBack(); assertThat(shadowOf(webView).getGoBackInvocations()).isEqualTo(1); webView.goBack(); webView.goBack(); assertThat(shadowOf(webView).getGoBackInvocations()).isEqualTo(3); webView.goBack(); webView.goBack(); webView.goBack(); // We've gone back one too many times for the history, so we should only have 5 invocations. assertThat(shadowOf(webView).getGoBackInvocations()).isEqualTo(5); }
@Test public void shouldStoreTheNumberOfTimesGoBackWasCalled_SetCanGoBack() { shadowOf(webView).setCanGoBack(true); webView.goBack(); webView.goBack(); assertThat(shadowOf(webView).getGoBackInvocations()).isEqualTo(2); shadowOf(webView).setCanGoBack(false); webView.goBack(); webView.goBack(); assertThat(shadowOf(webView).getGoBackInvocations()).isEqualTo(2); }