| 1 | // Copyright (c) 2013 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 android.content.Context; |
| 8 | import android.view.ActionMode; |
| 9 | import android.view.KeyEvent; |
| 10 | |
| 11 | import org.chromium.content.browser.ContentViewClient; |
| 12 | import org.chromium.content.browser.SelectActionModeCallback; |
| 13 | import org.chromium.content.browser.SelectActionModeCallback.ActionHandler; |
| 14 | import org.chromium.content.browser.test.util.TestContentViewClient; |
| 15 | |
| 16 | /** |
| 17 | * Simplistic {@link TestContentViewClient} for browser tests. |
| 18 | * Wraps around existing client so that specific methods can be overridden if needed. |
| 19 | * This class MUST override ALL METHODS OF the ContentViewClient and pass them |
| 20 | * to the wrapped client. |
| 21 | */ |
| 22 | public class TestContentViewClientWrapper extends TestContentViewClient { |
| 23 | |
| 24 | private ContentViewClient mWrappedClient; |
| 25 | |
| 26 | public TestContentViewClientWrapper(ContentViewClient wrappedClient) { |
| 27 | assert wrappedClient != null; |
| 28 | mWrappedClient = wrappedClient; |
| 29 | } |
| 30 | |
| 31 | @Override |
| 32 | public void onUpdateTitle(String title) { |
| 33 | super.onUpdateTitle(title); |
| 34 | mWrappedClient.onUpdateTitle(title); |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public void onScaleChanged(float oldScale, float newScale) { |
| 39 | super.onScaleChanged(oldScale, newScale); |
| 40 | mWrappedClient.onScaleChanged(oldScale, newScale); |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public void onRendererCrash(boolean processWasOomProtected) { |
| 45 | super.onRendererCrash(processWasOomProtected); |
| 46 | mWrappedClient.onRendererCrash(processWasOomProtected); |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public boolean shouldOverrideKeyEvent(KeyEvent event) { |
| 51 | return mWrappedClient.shouldOverrideKeyEvent(event); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public void onImeEvent() { |
| 56 | super.onImeEvent(); |
| 57 | mWrappedClient.onImeEvent(); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public boolean shouldOverrideScroll(float deltaX, float deltaY, float currX, float currY) { |
| 62 | return mWrappedClient.shouldOverrideScroll(deltaX, deltaY, currX, currX); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public ActionMode.Callback getSelectActionModeCallback( |
| 67 | Context context, ActionHandler actionHandler, boolean incognito) { |
| 68 | return mWrappedClient.getSelectActionModeCallback(context, actionHandler, incognito); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public void onContextualActionBarShown() { |
| 73 | super.onContextualActionBarShown(); |
| 74 | mWrappedClient.onContextualActionBarShown(); |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public void onContextualActionBarHidden() { |
| 79 | super.onContextualActionBarHidden(); |
| 80 | mWrappedClient.onContextualActionBarHidden(); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public void onStartContentIntent(Context context, String contentUrl) { |
| 85 | super.onStartContentIntent(context, contentUrl); |
| 86 | mWrappedClient.onStartContentIntent(context, contentUrl); |
| 87 | } |
| 88 | } |