Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / public / test / android / javatests / src / org / chromium / content / browser / test / util / TestWebContentsObserver.java
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.
4
5 package org.chromium.content.browser.test.util;
6
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;
12
13 /**
14  * The default WebContentsObserver used by ContentView tests. The below callbacks can be
15  * accessed by using {@link TestCallbackHelperContainer} or extending this class.
16  */
17 public class TestWebContentsObserver extends WebContentsObserver {
18
19     private final OnPageStartedHelper mOnPageStartedHelper;
20     private final OnPageFinishedHelper mOnPageFinishedHelper;
21     private final OnReceivedErrorHelper mOnReceivedErrorHelper;
22
23     public TestWebContentsObserver(WebContents webContents) {
24         super(webContents);
25         mOnPageStartedHelper = new OnPageStartedHelper();
26         mOnPageFinishedHelper = new OnPageFinishedHelper();
27         mOnReceivedErrorHelper = new OnReceivedErrorHelper();
28     }
29
30     public OnPageStartedHelper getOnPageStartedHelper() {
31         return mOnPageStartedHelper;
32     }
33
34     public OnPageFinishedHelper getOnPageFinishedHelper() {
35         return mOnPageFinishedHelper;
36     }
37
38     public OnReceivedErrorHelper getOnReceivedErrorHelper() {
39         return mOnReceivedErrorHelper;
40     }
41
42     /**
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
46      * stop working!
47      */
48     @Override
49     public void didStartLoading(String url) {
50         super.didStartLoading(url);
51         mOnPageStartedHelper.notifyCalled(url);
52     }
53
54     @Override
55     public void didStopLoading(String url) {
56         super.didStopLoading(url);
57         mOnPageFinishedHelper.notifyCalled(url);
58     }
59
60     @Override
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);
65     }
66 }