1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.content.browser.test.util;
7 import org.chromium.content.browser.WebContentsObserver;
8 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPageFinishedHelper;
9 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPageStartedHelper;
10 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnReceivedErrorHelper;
11 import org.chromium.content_public.browser.WebContents;
14 * The default WebContentsObserver used by ContentView tests. The below callbacks can be
15 * accessed by using {@link TestCallbackHelperContainer} or extending this class.
17 public class TestWebContentsObserver extends WebContentsObserver {
19 private final OnPageStartedHelper mOnPageStartedHelper;
20 private final OnPageFinishedHelper mOnPageFinishedHelper;
21 private final OnReceivedErrorHelper mOnReceivedErrorHelper;
23 public TestWebContentsObserver(WebContents webContents) {
25 mOnPageStartedHelper = new OnPageStartedHelper();
26 mOnPageFinishedHelper = new OnPageFinishedHelper();
27 mOnReceivedErrorHelper = new OnReceivedErrorHelper();
30 public OnPageStartedHelper getOnPageStartedHelper() {
31 return mOnPageStartedHelper;
34 public OnPageFinishedHelper getOnPageFinishedHelper() {
35 return mOnPageFinishedHelper;
38 public OnReceivedErrorHelper getOnReceivedErrorHelper() {
39 return mOnReceivedErrorHelper;
43 * ATTENTION!: When overriding the following methods, be sure to call
44 * the corresponding methods in the super class. Otherwise
45 * {@link CallbackHelper#waitForCallback()} methods will
49 public void didStartLoading(String url) {
50 super.didStartLoading(url);
51 mOnPageStartedHelper.notifyCalled(url);
55 public void didStopLoading(String url) {
56 super.didStopLoading(url);
57 mOnPageFinishedHelper.notifyCalled(url);
61 public void didFailLoad(boolean isProvisionalLoad, boolean isMainFrame,
62 int errorCode, String description, String failingUrl) {
63 super.didFailLoad(isProvisionalLoad, isMainFrame, errorCode, description, failingUrl);
64 mOnReceivedErrorHelper.notifyCalled(errorCode, description, failingUrl);