OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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.browser.preferences.privacy; | 5 package org.chromium.chrome.browser.preferences.privacy; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.support.test.filters.SmallTest; | 8 import android.support.test.filters.SmallTest; |
9 import android.test.InstrumentationTestCase; | 9 import android.test.InstrumentationTestCase; |
10 import android.test.UiThreadTest; | 10 import android.test.UiThreadTest; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 CRASH_NETWORK_NOT_PERMITTED); | 57 CRASH_NETWORK_NOT_PERMITTED); |
58 } | 58 } |
59 | 59 |
60 private void runTest(boolean isConnected, boolean wifiOn, boolean isMetricsR
eportingEnabled, | 60 private void runTest(boolean isConnected, boolean wifiOn, boolean isMetricsR
eportingEnabled, |
61 boolean expectedMetricsUploadPermitted, | 61 boolean expectedMetricsUploadPermitted, |
62 boolean expectedNetworkAvailableForCrashUploads) { | 62 boolean expectedNetworkAvailableForCrashUploads) { |
63 PermissionContext context = new PermissionContext(getInstrumentation().g
etTargetContext()); | 63 PermissionContext context = new PermissionContext(getInstrumentation().g
etTargetContext()); |
64 ContextUtils.initApplicationContextForTests(context.getApplicationContex
t()); | 64 ContextUtils.initApplicationContextForTests(context.getApplicationContex
t()); |
65 PrivacyPreferencesManager preferenceManager = new MockPrivacyPreferences
Manager( | 65 PrivacyPreferencesManager preferenceManager = new MockPrivacyPreferences
Manager( |
66 context, isConnected, wifiOn, isMetricsReportingEnabled); | 66 context, isConnected, wifiOn, isMetricsReportingEnabled); |
67 preferenceManager.enablePotentialCrashUploading(); | |
68 | 67 |
69 for (int i = 0; i < REPS; i++) { | 68 for (int i = 0; i < REPS; i++) { |
70 String state = String.format("[connected = %b, wifi = %b, reporting
= %b]", isConnected, | 69 String state = String.format("[connected = %b, wifi = %b, reporting
= %b]", isConnected, |
71 wifiOn, isMetricsReportingEnabled); | 70 wifiOn, isMetricsReportingEnabled); |
72 String msg = String.format("Metrics reporting should be %1$b for %2$
s", | 71 String msg = String.format("Metrics reporting should be %1$b for %2$
s", |
73 expectedMetricsUploadPermitted, state); | 72 expectedMetricsUploadPermitted, state); |
74 assertEquals(msg, expectedMetricsUploadPermitted, | 73 assertEquals(msg, expectedMetricsUploadPermitted, |
75 preferenceManager.isMetricsUploadPermitted()); | 74 preferenceManager.isMetricsUploadPermitted()); |
76 | 75 |
77 msg = String.format("Crash reporting should be %1$b for wifi %2$s", | 76 msg = String.format("Crash reporting should be %1$b for wifi %2$s", |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 @Override | 112 @Override |
114 public Object getSystemService(String name) { | 113 public Object getSystemService(String name) { |
115 if (Context.CONNECTIVITY_SERVICE.equals(name)) { | 114 if (Context.CONNECTIVITY_SERVICE.equals(name)) { |
116 return null; | 115 return null; |
117 } | 116 } |
118 fail("Should not ask for any other service than the ConnectionManage
r."); | 117 fail("Should not ask for any other service than the ConnectionManage
r."); |
119 return super.getSystemService(name); | 118 return super.getSystemService(name); |
120 } | 119 } |
121 } | 120 } |
122 } | 121 } |
OLD | NEW |