Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.test; | 5 package org.chromium.chrome.test; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.os.Build; | 8 import android.os.Build; |
| 9 import android.os.Bundle; | 9 import android.os.Bundle; |
| 10 import android.text.TextUtils; | 10 import android.text.TextUtils; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 | 50 |
| 51 @Override | 51 @Override |
| 52 protected void addTestHooks(BaseTestResult result) { | 52 protected void addTestHooks(BaseTestResult result) { |
| 53 super.addTestHooks(result); | 53 super.addTestHooks(result); |
| 54 result.addSkipCheck(new ChromeRestrictionSkipCheck(getTargetContext())); | 54 result.addSkipCheck(new ChromeRestrictionSkipCheck(getTargetContext())); |
| 55 result.addSkipCheck(new ChromeDisableIfSkipCheck(getTargetContext())); | 55 result.addSkipCheck(new ChromeDisableIfSkipCheck(getTargetContext())); |
| 56 | 56 |
| 57 result.addPreTestHook(Policies.getRegistrationHook()); | 57 result.addPreTestHook(Policies.getRegistrationHook()); |
| 58 } | 58 } |
| 59 | 59 |
| 60 private class ChromeRestrictionSkipCheck extends RestrictionSkipCheck { | 60 static class ChromeRestrictionSkipCheck extends RestrictionSkipCheck { |
| 61 private VrDaydreamApi mDaydreamApi; | 61 private VrDaydreamApi mDaydreamApi; |
| 62 private boolean mAttemptedToGetApi; | 62 private boolean mAttemptedToGetApi; |
| 63 private Context mTargetContext; | |
| 63 | 64 |
| 64 public ChromeRestrictionSkipCheck(Context targetContext) { | 65 public ChromeRestrictionSkipCheck(Context targetContext) { |
| 65 super(targetContext); | 66 super(targetContext); |
| 67 mTargetContext = targetContext; | |
|
jbudorick
2017/03/22 15:58:07
This should not store the target context. Restrict
the real yoland
2017/03/22 17:43:33
Done
| |
| 66 } | 68 } |
| 67 | 69 |
| 68 @SuppressWarnings("unchecked") | 70 @SuppressWarnings("unchecked") |
| 69 private VrDaydreamApi getDaydreamApi() { | 71 private VrDaydreamApi getDaydreamApi() { |
| 70 if (!mAttemptedToGetApi) { | 72 if (!mAttemptedToGetApi) { |
| 71 mAttemptedToGetApi = true; | 73 mAttemptedToGetApi = true; |
| 72 try { | 74 try { |
| 73 Class<? extends VrClassesWrapper> vrClassesBuilderClass = | 75 Class<? extends VrClassesWrapper> vrClassesBuilderClass = |
| 74 (Class<? extends VrClassesWrapper>) Class.forName( | 76 (Class<? extends VrClassesWrapper>) Class.forName( |
| 75 "org.chromium.chrome.browser.vr_shell.VrClas sesWrapperImpl"); | 77 "org.chromium.chrome.browser.vr_shell.VrClas sesWrapperImpl"); |
| 76 Constructor<?> vrClassesBuilderConstructor = | 78 Constructor<?> vrClassesBuilderConstructor = |
| 77 vrClassesBuilderClass.getConstructor(); | 79 vrClassesBuilderClass.getConstructor(); |
| 78 VrClassesWrapper vrClassesBuilder = | 80 VrClassesWrapper vrClassesBuilder = |
| 79 (VrClassesWrapper) vrClassesBuilderConstructor.newIn stance(); | 81 (VrClassesWrapper) vrClassesBuilderConstructor.newIn stance(); |
| 80 mDaydreamApi = vrClassesBuilder.createVrDaydreamApi(getTarge tContext()); | 82 mDaydreamApi = vrClassesBuilder.createVrDaydreamApi(mTargetC ontext); |
|
jbudorick
2017/03/22 15:58:07
Perhaps we should expose that context via a method
the real yoland
2017/03/22 17:43:33
Done
| |
| 81 } catch (ClassNotFoundException | InstantiationException | Illeg alAccessException | 83 } catch (ClassNotFoundException | InstantiationException | Illeg alAccessException |
| 82 | IllegalArgumentException | InvocationTargetException | 84 | IllegalArgumentException | InvocationTargetException |
| 83 | NoSuchMethodException e) { | 85 | NoSuchMethodException e) { |
| 84 return null; | 86 return null; |
| 85 } | 87 } |
| 86 } | 88 } |
| 87 return mDaydreamApi; | 89 return mDaydreamApi; |
| 88 } | 90 } |
| 89 | 91 |
| 90 private boolean isDaydreamReady() { | 92 private boolean isDaydreamReady() { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 114 } | 116 } |
| 115 | 117 |
| 116 private boolean supportsWebVr() { | 118 private boolean supportsWebVr() { |
| 117 // WebVR support is tied to VR Services support, which is only on K+ | 119 // WebVR support is tied to VR Services support, which is only on K+ |
| 118 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; | 120 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; |
| 119 } | 121 } |
| 120 | 122 |
| 121 @Override | 123 @Override |
| 122 protected boolean restrictionApplies(String restriction) { | 124 protected boolean restrictionApplies(String restriction) { |
| 123 if (TextUtils.equals(restriction, ChromeRestriction.RESTRICTION_TYPE _PHONE) | 125 if (TextUtils.equals(restriction, ChromeRestriction.RESTRICTION_TYPE _PHONE) |
| 124 && DeviceFormFactor.isTablet(getTargetContext())) { | 126 && DeviceFormFactor.isTablet(mTargetContext)) { |
| 125 return true; | 127 return true; |
| 126 } | 128 } |
| 127 if (TextUtils.equals(restriction, ChromeRestriction.RESTRICTION_TYPE _TABLET) | 129 if (TextUtils.equals(restriction, ChromeRestriction.RESTRICTION_TYPE _TABLET) |
| 128 && !DeviceFormFactor.isTablet(getTargetContext())) { | 130 && !DeviceFormFactor.isTablet(mTargetContext)) { |
| 131 return true; | |
| 132 } | |
| 133 if (TextUtils.equals( | |
| 134 restriction, ChromeRestriction.RESTRICTION_TYPE_GOOGLE_P LAY_SERVICES) | |
| 135 && (ConnectionResult.SUCCESS | |
| 136 != GoogleApiAvailability.getInstance().isGooglePl ayServicesAvailable( | |
| 137 mTargetContext))) { | |
| 129 return true; | 138 return true; |
| 130 } | 139 } |
| 131 if (TextUtils.equals(restriction, | 140 if (TextUtils.equals(restriction, |
| 132 ChromeRestriction.RESTRICTION_TYPE_GOOGLE_PLAY_SERVICES) | |
| 133 && (ConnectionResult.SUCCESS != GoogleApiAvailability.getIns tance() | |
| 134 .isGooglePlayServicesAvailable(getTargetContext()))) { | |
| 135 return true; | |
| 136 } | |
| 137 if (TextUtils.equals(restriction, | |
| 138 ChromeRestriction.RESTRICTION_TYPE_OFFICIAL_BUILD) | 141 ChromeRestriction.RESTRICTION_TYPE_OFFICIAL_BUILD) |
| 139 && (!ChromeVersionInfo.isOfficialBuild())) { | 142 && (!ChromeVersionInfo.isOfficialBuild())) { |
| 140 return true; | 143 return true; |
| 141 } | 144 } |
| 142 if (TextUtils.equals(restriction, ChromeRestriction.RESTRICTION_TYPE _DEVICE_DAYDREAM) | 145 if (TextUtils.equals(restriction, ChromeRestriction.RESTRICTION_TYPE _DEVICE_DAYDREAM) |
| 143 || TextUtils.equals(restriction, | 146 || TextUtils.equals(restriction, |
| 144 ChromeRestriction.RESTRICTION_TYPE_DEVICE_NON_DAY DREAM)) { | 147 ChromeRestriction.RESTRICTION_TYPE_DEVICE_NON_DAY DREAM)) { |
| 145 boolean isDaydream = isDaydreamReady(); | 148 boolean isDaydream = isDaydreamReady(); |
| 146 if (TextUtils.equals( | 149 if (TextUtils.equals( |
| 147 restriction, ChromeRestriction.RESTRICTION_TYPE_DEVI CE_DAYDREAM) | 150 restriction, ChromeRestriction.RESTRICTION_TYPE_DEVI CE_DAYDREAM) |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 178 } else if (TextUtils.equals(restriction, | 181 } else if (TextUtils.equals(restriction, |
| 179 ChromeRestriction.RESTRICTION_TYPE_WEBVR_UNSU PPORTED) | 182 ChromeRestriction.RESTRICTION_TYPE_WEBVR_UNSU PPORTED) |
| 180 && webvrSupported) { | 183 && webvrSupported) { |
| 181 return true; | 184 return true; |
| 182 } | 185 } |
| 183 } | 186 } |
| 184 return false; | 187 return false; |
| 185 } | 188 } |
| 186 } | 189 } |
| 187 | 190 |
| 188 private class ChromeDisableIfSkipCheck extends DisableIfSkipCheck { | 191 static class ChromeDisableIfSkipCheck extends DisableIfSkipCheck { |
| 189 | |
| 190 private final Context mTargetContext; | 192 private final Context mTargetContext; |
| 191 | 193 |
| 192 public ChromeDisableIfSkipCheck(Context targetContext) { | 194 public ChromeDisableIfSkipCheck(Context targetContext) { |
| 193 mTargetContext = targetContext; | 195 mTargetContext = targetContext; |
| 194 } | 196 } |
| 195 | 197 |
| 196 @Override | 198 @Override |
| 197 protected boolean deviceTypeApplies(String type) { | 199 protected boolean deviceTypeApplies(String type) { |
| 198 if (TextUtils.equals(type, ChromeDisableIf.PHONE) | 200 if (TextUtils.equals(type, ChromeDisableIf.PHONE) |
| 199 && !DeviceFormFactor.isTablet(getTargetContext())) { | 201 && !DeviceFormFactor.isTablet(mTargetContext)) { |
| 200 return true; | 202 return true; |
| 201 } | 203 } |
| 202 if (TextUtils.equals(type, ChromeDisableIf.TABLET) | 204 if (TextUtils.equals(type, ChromeDisableIf.TABLET) |
| 203 && DeviceFormFactor.isTablet(getTargetContext())) { | 205 && DeviceFormFactor.isTablet(mTargetContext)) { |
| 204 return true; | 206 return true; |
| 205 } | 207 } |
| 206 if (TextUtils.equals(type, ChromeDisableIf.LARGETABLET) | 208 if (TextUtils.equals(type, ChromeDisableIf.LARGETABLET) |
| 207 && DeviceFormFactor.isLargeTablet(getTargetContext())) { | 209 && DeviceFormFactor.isLargeTablet(mTargetContext)) { |
| 208 return true; | 210 return true; |
| 209 } | 211 } |
| 210 return false; | 212 return false; |
| 211 } | 213 } |
| 212 } | 214 } |
| 213 } | 215 } |
| OLD | NEW |