OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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.chrome.browser.compositor.layouts; |
| 6 |
| 7 import android.content.Context; |
| 8 import android.content.pm.ApplicationInfo; |
| 9 import android.content.pm.PackageManager; |
| 10 import android.content.res.Resources; |
| 11 import android.os.Looper; |
| 12 import android.test.mock.MockContext; |
| 13 import android.test.mock.MockResources; |
| 14 |
| 15 /** |
| 16 * This is the minimal {@link Context} needed by the {@link LayoutManager} to be
working properly. |
| 17 * It points to a {@link MockResources} for anything that is based on xml config
urations. For |
| 18 * everything else the standard provided Context should be sufficient. |
| 19 */ |
| 20 public class MockContextForLayout extends MockContext { |
| 21 private final Context mValidContext; |
| 22 private final MockResourcesForLayout mResources; |
| 23 private final Resources.Theme mTheme; |
| 24 |
| 25 public MockContextForLayout(Context validContext) { |
| 26 mValidContext = validContext; |
| 27 mResources = new MockResourcesForLayout(validContext.getResources()); |
| 28 mTheme = mResources.newTheme(); |
| 29 } |
| 30 |
| 31 @Override |
| 32 public Resources getResources() { |
| 33 return mResources; |
| 34 } |
| 35 |
| 36 @Override |
| 37 public ApplicationInfo getApplicationInfo() { |
| 38 return mValidContext.getApplicationInfo(); |
| 39 } |
| 40 |
| 41 @Override |
| 42 public Object getSystemService(String name) { |
| 43 return mValidContext.getSystemService(name); |
| 44 } |
| 45 |
| 46 @Override |
| 47 public PackageManager getPackageManager() { |
| 48 return mValidContext.getPackageManager(); |
| 49 } |
| 50 |
| 51 @Override |
| 52 public Context getApplicationContext() { |
| 53 return this; |
| 54 } |
| 55 |
| 56 @Override |
| 57 public int checkCallingOrSelfPermission(String permission) { |
| 58 return mValidContext.checkCallingOrSelfPermission(permission); |
| 59 } |
| 60 |
| 61 @Override |
| 62 public Looper getMainLooper() { |
| 63 return mValidContext.getMainLooper(); |
| 64 } |
| 65 |
| 66 @Override |
| 67 public Resources.Theme getTheme() { |
| 68 return mTheme; |
| 69 } |
| 70 } |
OLD | NEW |