• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors
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.base.test.util;
6 
7 import android.content.ComponentCallbacks;
8 import android.content.Context;
9 import android.content.ContextWrapper;
10 
11 /** ContextWrapper that can be used to wrap Application. */
12 public class ApplicationContextWrapper extends ContextWrapper {
ApplicationContextWrapper(Context base)13     public ApplicationContextWrapper(Context base) {
14         super(base);
15     }
16 
17     @Override
getApplicationContext()18     public Context getApplicationContext() {
19         // Prevent calls to getApplicationContext() from escaping our Application wrapper.
20         return this;
21     }
22 
23     @Override
registerComponentCallbacks(ComponentCallbacks callback)24     public void registerComponentCallbacks(ComponentCallbacks callback) {
25         // Base implmementation calls getApplicationContext, so need to explicitly circumvent our
26         // no-op'ing getApplicationContext().
27         getBaseContext().registerComponentCallbacks(callback);
28     }
29 
30     @Override
unregisterComponentCallbacks(ComponentCallbacks callback)31     public void unregisterComponentCallbacks(ComponentCallbacks callback) {
32         // Base implmementation calls getApplicationContext, so need to explicitly circumvent our
33         // no-op'ing getApplicationContext().
34         getBaseContext().unregisterComponentCallbacks(callback);
35     }
36 }
37