OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.base.test.util; | 5 package org.chromium.base.test.util; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.net.ConnectivityManager; | 8 import android.net.ConnectivityManager; |
9 import android.net.NetworkInfo; | 9 import android.net.NetworkInfo; |
10 import android.text.TextUtils; | 10 import android.text.TextUtils; |
11 | 11 |
12 import org.junit.runners.model.FrameworkMethod; | 12 import org.junit.runners.model.FrameworkMethod; |
13 | 13 |
14 import org.chromium.base.Log; | 14 import org.chromium.base.Log; |
15 import org.chromium.base.SysUtils; | 15 import org.chromium.base.SysUtils; |
16 | 16 |
17 /** | 17 /** |
18 * Checks if any restrictions exist and skip the test if it meets those restrict
ions. | 18 * Checks if any restrictions exist and skip the test if it meets those restrict
ions. |
19 */ | 19 */ |
20 public class RestrictionSkipCheck extends SkipCheck { | 20 public class RestrictionSkipCheck extends SkipCheck { |
21 | 21 |
22 private static final String TAG = "base_test"; | 22 private static final String TAG = "base_test"; |
23 | 23 |
24 private final Context mTargetContext; | 24 private final Context mTargetContext; |
25 | 25 |
26 public RestrictionSkipCheck(Context targetContext) { | 26 public RestrictionSkipCheck(Context targetContext) { |
27 mTargetContext = targetContext; | 27 mTargetContext = targetContext; |
28 } | 28 } |
29 | 29 |
| 30 protected Context getTargetContext() { |
| 31 return mTargetContext; |
| 32 } |
| 33 |
30 @Override | 34 @Override |
31 public boolean shouldSkip(FrameworkMethod frameworkMethod) { | 35 public boolean shouldSkip(FrameworkMethod frameworkMethod) { |
32 if (frameworkMethod == null) return true; | 36 if (frameworkMethod == null) return true; |
33 | 37 |
34 for (Restriction restriction : getAnnotations(frameworkMethod, Restricti
on.class)) { | 38 for (Restriction restriction : getAnnotations(frameworkMethod, Restricti
on.class)) { |
35 for (String restrictionVal : restriction.value()) { | 39 for (String restrictionVal : restriction.value()) { |
36 if (restrictionApplies(restrictionVal)) { | 40 if (restrictionApplies(restrictionVal)) { |
37 Log.i(TAG, "Test " + frameworkMethod.getDeclaringClass().get
Name() + "#" | 41 Log.i(TAG, "Test " + frameworkMethod.getDeclaringClass().get
Name() + "#" |
38 + frameworkMethod.getName() + " skipped because of r
estriction " | 42 + frameworkMethod.getName() + " skipped because of r
estriction " |
39 + restriction); | 43 + restriction); |
(...skipping 24 matching lines...) Expand all Loading... |
64 return false; | 68 return false; |
65 } | 69 } |
66 | 70 |
67 private boolean isNetworkAvailable() { | 71 private boolean isNetworkAvailable() { |
68 final ConnectivityManager connectivityManager = (ConnectivityManager) | 72 final ConnectivityManager connectivityManager = (ConnectivityManager) |
69 mTargetContext.getSystemService(Context.CONNECTIVITY_SERVICE); | 73 mTargetContext.getSystemService(Context.CONNECTIVITY_SERVICE); |
70 final NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetwo
rkInfo(); | 74 final NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetwo
rkInfo(); |
71 return activeNetworkInfo != null && activeNetworkInfo.isConnected(); | 75 return activeNetworkInfo != null && activeNetworkInfo.isConnected(); |
72 } | 76 } |
73 } | 77 } |
OLD | NEW |