| 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.omaha; | 5 package org.chromium.chrome.browser.omaha; |
| 6 | 6 |
| 7 import android.app.Service; | |
| 8 import android.content.Context; | 7 import android.content.Context; |
| 9 import android.content.SharedPreferences; | 8 import android.content.SharedPreferences; |
| 10 import android.support.test.filters.SmallTest; | 9 import android.support.test.filters.SmallTest; |
| 11 import android.test.InstrumentationTestCase; | 10 import android.test.InstrumentationTestCase; |
| 12 | 11 |
| 13 import org.chromium.base.test.util.AdvancedMockContext; | 12 import org.chromium.base.test.util.AdvancedMockContext; |
| 14 import org.chromium.base.test.util.Feature; | 13 import org.chromium.base.test.util.Feature; |
| 15 import org.chromium.chrome.test.omaha.MockRequestGenerator; | 14 import org.chromium.chrome.test.omaha.MockRequestGenerator; |
| 16 import org.chromium.chrome.test.omaha.MockRequestGenerator.DeviceType; | 15 import org.chromium.chrome.test.omaha.MockRequestGenerator.DeviceType; |
| 17 | 16 |
| 18 import java.io.ByteArrayInputStream; | 17 import java.io.ByteArrayInputStream; |
| 19 import java.io.ByteArrayOutputStream; | 18 import java.io.ByteArrayOutputStream; |
| 20 import java.io.IOException; | 19 import java.io.IOException; |
| 21 import java.io.InputStream; | 20 import java.io.InputStream; |
| 22 import java.io.OutputStream; | 21 import java.io.OutputStream; |
| 23 import java.net.HttpURLConnection; | 22 import java.net.HttpURLConnection; |
| 24 import java.net.MalformedURLException; | 23 import java.net.MalformedURLException; |
| 25 import java.net.SocketTimeoutException; | 24 import java.net.SocketTimeoutException; |
| 26 import java.net.URL; | 25 import java.net.URL; |
| 27 import java.util.ArrayList; | 26 import java.util.ArrayList; |
| 28 import java.util.LinkedList; | 27 import java.util.LinkedList; |
| 29 import java.util.List; | 28 import java.util.List; |
| 30 | 29 |
| 31 /** | 30 /** |
| 32 * Tests for the {@link OmahaClient}. | 31 * Tests for the {@link OmahaClient}. |
| 33 * Tests override the original OmahaClient's functions with the MockOmahaClient,
which | 32 * Tests override the original OmahaClient's functions with the MockOmahaClient,
which |
| 34 * provides a way to hook into functions to return values that would normally be
provided by the | 33 * provides a way to hook into functions to return values that would normally be
provided by the |
| 35 * system, such as whether Chrome was installed through the system image. | 34 * system, such as whether Chrome was installed through the system image. |
| 36 */ | 35 */ |
| 37 public class OmahaClientTest extends InstrumentationTestCase { | 36 public class OmahaBaseTest extends InstrumentationTestCase { |
| 38 private static class TimestampPair { | 37 private static class TimestampPair { |
| 39 public long timestampNextRequest; | 38 public long timestampNextRequest; |
| 40 public long timestampNextPost; | 39 public long timestampNextPost; |
| 41 | 40 |
| 42 public TimestampPair(long timestampNextRequest, long timestampNextPost)
{ | 41 public TimestampPair(long timestampNextRequest, long timestampNextPost)
{ |
| 43 this.timestampNextRequest = timestampNextRequest; | 42 this.timestampNextRequest = timestampNextRequest; |
| 44 this.timestampNextPost = timestampNextPost; | 43 this.timestampNextPost = timestampNextPost; |
| 45 } | 44 } |
| 46 } | 45 } |
| 47 | 46 |
| 48 private static class MockOmahaDelegate extends OmahaDelegate { | 47 private static class MockOmahaDelegate extends OmahaDelegate { |
| 49 private final List<Integer> mPostResults = new ArrayList<Integer>(); | 48 private final List<Integer> mPostResults = new ArrayList<Integer>(); |
| 50 private final List<Boolean> mGenerateAndPostRequestResults = new ArrayLi
st<Boolean>(); | 49 private final List<Boolean> mGenerateAndPostRequestResults = new ArrayLi
st<Boolean>(); |
| 51 | 50 |
| 51 private final Context mContext; |
| 52 private final boolean mIsOnTablet; | 52 private final boolean mIsOnTablet; |
| 53 private final boolean mIsInForeground; | 53 private final boolean mIsInForeground; |
| 54 private final boolean mIsInSystemImage; | 54 private final boolean mIsInSystemImage; |
| 55 private final MockExponentialBackoffScheduler mMockScheduler; | 55 private final MockExponentialBackoffScheduler mMockScheduler; |
| 56 private MockRequestGenerator mMockGenerator; | 56 private MockRequestGenerator mMockGenerator; |
| 57 | 57 |
| 58 private int mNumUUIDsGenerated; | 58 private int mNumUUIDsGenerated; |
| 59 private long mNextScheduledTimestamp = -1; | 59 private long mNextScheduledTimestamp = -1; |
| 60 | 60 |
| 61 private boolean mInstallEventWasSent; | 61 private boolean mInstallEventWasSent; |
| 62 private TimestampPair mTimestampsOnRegisterNewRequest; | 62 private TimestampPair mTimestampsOnRegisterNewRequest; |
| 63 private TimestampPair mTimestampsOnSaveState; | 63 private TimestampPair mTimestampsOnSaveState; |
| 64 | 64 |
| 65 MockOmahaDelegate(Context context, DeviceType deviceType, InstallSource
installSource) { | 65 MockOmahaDelegate(Context context, DeviceType deviceType, InstallSource
installSource) { |
| 66 super(context); | 66 mContext = context; |
| 67 mIsOnTablet = deviceType == DeviceType.TABLET; | 67 mIsOnTablet = deviceType == DeviceType.TABLET; |
| 68 mIsInForeground = true; | 68 mIsInForeground = true; |
| 69 mIsInSystemImage = installSource == InstallSource.SYSTEM_IMAGE; | 69 mIsInSystemImage = installSource == InstallSource.SYSTEM_IMAGE; |
| 70 | 70 |
| 71 mMockScheduler = new MockExponentialBackoffScheduler(OmahaBase.PREF_
PACKAGE, context, | 71 mMockScheduler = new MockExponentialBackoffScheduler(OmahaBase.PREF_
PACKAGE, context, |
| 72 OmahaClient.MS_POST_BASE_DELAY, OmahaClient.MS_POST_MAX_DELA
Y); | 72 OmahaBase.MS_POST_BASE_DELAY, OmahaBase.MS_POST_MAX_DELAY); |
| 73 } | 73 } |
| 74 | 74 |
| 75 @Override | 75 @Override |
| 76 protected RequestGenerator createRequestGenerator(Context context) { | 76 protected RequestGenerator createRequestGenerator(Context context) { |
| 77 mMockGenerator = new MockRequestGenerator( | 77 mMockGenerator = new MockRequestGenerator( |
| 78 context, mIsOnTablet ? DeviceType.TABLET : DeviceType.HANDSE
T); | 78 context, mIsOnTablet ? DeviceType.TABLET : DeviceType.HANDSE
T); |
| 79 return mMockGenerator; | 79 return mMockGenerator; |
| 80 } | 80 } |
| 81 | 81 |
| 82 @Override | 82 @Override |
| (...skipping 11 matching lines...) Expand all Loading... |
| 94 mNumUUIDsGenerated += 1; | 94 mNumUUIDsGenerated += 1; |
| 95 return "UUID" + mNumUUIDsGenerated; | 95 return "UUID" + mNumUUIDsGenerated; |
| 96 } | 96 } |
| 97 | 97 |
| 98 @Override | 98 @Override |
| 99 protected boolean isChromeBeingUsed() { | 99 protected boolean isChromeBeingUsed() { |
| 100 return mIsInForeground; | 100 return mIsInForeground; |
| 101 } | 101 } |
| 102 | 102 |
| 103 @Override | 103 @Override |
| 104 void scheduleService(Service service, long nextTimestamp) { | 104 void scheduleService(long currentTimestampMs, long nextTimestampMs) { |
| 105 mNextScheduledTimestamp = nextTimestamp; | 105 mNextScheduledTimestamp = nextTimestampMs; |
| 106 } | 106 } |
| 107 | 107 |
| 108 @Override | 108 @Override |
| 109 void onHandlePostRequestDone(int result, boolean installEventWasSent) { | 109 void onHandlePostRequestDone(int result, boolean installEventWasSent) { |
| 110 mPostResults.add(result); | 110 mPostResults.add(result); |
| 111 mInstallEventWasSent = installEventWasSent; | 111 mInstallEventWasSent = installEventWasSent; |
| 112 } | 112 } |
| 113 | 113 |
| 114 @Override | 114 @Override |
| 115 void onRegisterNewRequestDone(long nextRequestTimestamp, long nextPostTi
mestamp) { | 115 void onRegisterNewRequestDone(long nextRequestTimestamp, long nextPostTi
mestamp) { |
| 116 mTimestampsOnRegisterNewRequest = | 116 mTimestampsOnRegisterNewRequest = |
| 117 new TimestampPair(nextRequestTimestamp, nextPostTimestamp); | 117 new TimestampPair(nextRequestTimestamp, nextPostTimestamp); |
| 118 } | 118 } |
| 119 | 119 |
| 120 @Override | 120 @Override |
| 121 void onGenerateAndPostRequestDone(boolean result) { | 121 void onGenerateAndPostRequestDone(boolean result) { |
| 122 mGenerateAndPostRequestResults.add(result); | 122 mGenerateAndPostRequestResults.add(result); |
| 123 } | 123 } |
| 124 | 124 |
| 125 @Override | 125 @Override |
| 126 void onSaveStateDone(long nextRequestTimestamp, long nextPostTimestamp)
{ | 126 void onSaveStateDone(long nextRequestTimestamp, long nextPostTimestamp)
{ |
| 127 mTimestampsOnSaveState = new TimestampPair(nextRequestTimestamp, nex
tPostTimestamp); | 127 mTimestampsOnSaveState = new TimestampPair(nextRequestTimestamp, nex
tPostTimestamp); |
| 128 } | 128 } |
| 129 |
| 130 @Override |
| 131 Context getContext() { |
| 132 return mContext; |
| 133 } |
| 129 } | 134 } |
| 130 | 135 |
| 131 private enum InstallSource { SYSTEM_IMAGE, ORGANIC } | 136 private enum InstallSource { SYSTEM_IMAGE, ORGANIC } |
| 132 private enum ServerResponse { SUCCESS, FAILURE } | 137 private enum ServerResponse { SUCCESS, FAILURE } |
| 133 private enum ConnectionStatus { RESPONDS, TIMES_OUT } | 138 private enum ConnectionStatus { RESPONDS, TIMES_OUT } |
| 134 private enum InstallEvent { SEND, DONT_SEND } | 139 private enum InstallEvent { SEND, DONT_SEND } |
| 135 private enum PostStatus { DUE, NOT_DUE } | 140 private enum PostStatus { DUE, NOT_DUE } |
| 136 | 141 |
| 137 private AdvancedMockContext mContext; | 142 private AdvancedMockContext mContext; |
| 138 private MockOmahaDelegate mDelegate; | 143 private MockOmahaDelegate mDelegate; |
| 139 private MockOmahaClient mOmahaClient; | 144 private MockOmahaBase mOmahaBase; |
| 140 | 145 |
| 141 private MockOmahaClient createOmahaClient() { | 146 private MockOmahaBase createOmahaBase() { |
| 142 return createOmahaClient( | 147 return createOmahaBase( |
| 143 ServerResponse.SUCCESS, ConnectionStatus.RESPONDS, DeviceType.HA
NDSET); | 148 ServerResponse.SUCCESS, ConnectionStatus.RESPONDS, DeviceType.HA
NDSET); |
| 144 } | 149 } |
| 145 | 150 |
| 146 private MockOmahaClient createOmahaClient( | 151 private MockOmahaBase createOmahaBase( |
| 147 ServerResponse response, ConnectionStatus status, DeviceType deviceT
ype) { | 152 ServerResponse response, ConnectionStatus status, DeviceType deviceT
ype) { |
| 148 MockOmahaClient omahaClient = new MockOmahaClient(mContext, response, st
atus, deviceType); | 153 MockOmahaBase omahaClient = new MockOmahaBase(mDelegate, response, statu
s, deviceType); |
| 149 omahaClient.onCreate(); | |
| 150 omahaClient.restoreState(mContext); | |
| 151 return omahaClient; | 154 return omahaClient; |
| 152 } | 155 } |
| 153 | 156 |
| 154 @Override | 157 @Override |
| 155 protected void setUp() throws Exception { | 158 protected void setUp() throws Exception { |
| 156 super.setUp(); | 159 super.setUp(); |
| 157 Context targetContext = getInstrumentation().getTargetContext(); | 160 Context targetContext = getInstrumentation().getTargetContext(); |
| 158 OmahaBase.setIsDisabledForTesting(false); | 161 OmahaBase.setIsDisabledForTesting(false); |
| 159 mContext = new AdvancedMockContext(targetContext); | 162 mContext = new AdvancedMockContext(targetContext); |
| 160 } | 163 } |
| 161 | 164 |
| 162 @Override | 165 @Override |
| 163 public void tearDown() throws Exception { | 166 public void tearDown() throws Exception { |
| 164 OmahaBase.setIsDisabledForTesting(true); | 167 OmahaBase.setIsDisabledForTesting(true); |
| 165 super.tearDown(); | 168 super.tearDown(); |
| 166 } | 169 } |
| 167 | 170 |
| 168 private class MockOmahaClient extends OmahaClient { | 171 private class MockOmahaBase extends OmahaBase { |
| 169 private final LinkedList<MockConnection> mMockConnections = new LinkedLi
st<>(); | 172 private final LinkedList<MockConnection> mMockConnections = new LinkedLi
st<>(); |
| 170 | 173 |
| 171 private final boolean mSendValidResponse; | 174 private final boolean mSendValidResponse; |
| 172 private final boolean mConnectionTimesOut; | 175 private final boolean mConnectionTimesOut; |
| 173 private final boolean mIsOnTablet; | 176 private final boolean mIsOnTablet; |
| 174 | 177 |
| 175 public MockOmahaClient(Context context, ServerResponse serverResponse, | 178 public MockOmahaBase(OmahaDelegate delegate, ServerResponse serverRespon
se, |
| 176 ConnectionStatus connectionStatus, DeviceType deviceType) { | 179 ConnectionStatus connectionStatus, DeviceType deviceType) { |
| 177 attachBaseContext(context); | 180 super(delegate); |
| 178 setDelegateForTests(mDelegate); | |
| 179 | |
| 180 mSendValidResponse = serverResponse == ServerResponse.SUCCESS; | 181 mSendValidResponse = serverResponse == ServerResponse.SUCCESS; |
| 181 mConnectionTimesOut = connectionStatus == ConnectionStatus.TIMES_OUT
; | 182 mConnectionTimesOut = connectionStatus == ConnectionStatus.TIMES_OUT
; |
| 182 mIsOnTablet = deviceType == DeviceType.TABLET; | 183 mIsOnTablet = deviceType == DeviceType.TABLET; |
| 183 } | 184 } |
| 184 | 185 |
| 185 /** | 186 /** |
| 186 * Gets the number of MockConnections created. | 187 * Gets the number of MockConnections created. |
| 187 */ | 188 */ |
| 188 public int getNumConnectionsMade() { | 189 public int getNumConnectionsMade() { |
| 189 return mMockConnections.size(); | 190 return mMockConnections.size(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 229 |
| 229 @SmallTest | 230 @SmallTest |
| 230 @Feature({"Omaha"}) | 231 @Feature({"Omaha"}) |
| 231 public void testPipelineFreshInstall() { | 232 public void testPipelineFreshInstall() { |
| 232 final long now = 11684; | 233 final long now = 11684; |
| 233 | 234 |
| 234 mDelegate = new MockOmahaDelegate(mContext, DeviceType.HANDSET, InstallS
ource.ORGANIC); | 235 mDelegate = new MockOmahaDelegate(mContext, DeviceType.HANDSET, InstallS
ource.ORGANIC); |
| 235 mDelegate.getScheduler().setCurrentTime(now); | 236 mDelegate.getScheduler().setCurrentTime(now); |
| 236 | 237 |
| 237 // Trigger Omaha. | 238 // Trigger Omaha. |
| 238 mOmahaClient = createOmahaClient(); | 239 mOmahaBase = createOmahaBase(); |
| 239 mOmahaClient.run(); | 240 mOmahaBase.run(); |
| 240 | 241 |
| 241 // A fresh install results in two requests to the Omaha server: one for
the install request | 242 // A fresh install results in two requests to the Omaha server: one for
the install request |
| 242 // and one for the ping request. | 243 // and one for the ping request. |
| 243 assertTrue(mDelegate.mInstallEventWasSent); | 244 assertTrue(mDelegate.mInstallEventWasSent); |
| 244 assertEquals(1, mDelegate.mPostResults.size()); | 245 assertEquals(1, mDelegate.mPostResults.size()); |
| 245 assertEquals(OmahaClient.POST_RESULT_SENT, mDelegate.mPostResults.get(0)
.intValue()); | 246 assertEquals(OmahaBase.POST_RESULT_SENT, mDelegate.mPostResults.get(0).i
ntValue()); |
| 246 assertEquals(2, mDelegate.mGenerateAndPostRequestResults.size()); | 247 assertEquals(2, mDelegate.mGenerateAndPostRequestResults.size()); |
| 247 assertTrue(mDelegate.mGenerateAndPostRequestResults.get(0)); | 248 assertTrue(mDelegate.mGenerateAndPostRequestResults.get(0)); |
| 248 assertTrue(mDelegate.mGenerateAndPostRequestResults.get(1)); | 249 assertTrue(mDelegate.mGenerateAndPostRequestResults.get(1)); |
| 249 | 250 |
| 250 // Successful requests mean that the next scheduled event should be chec
king for when the | 251 // Successful requests mean that the next scheduled event should be chec
king for when the |
| 251 // user is active. | 252 // user is active. |
| 252 assertEquals(now + OmahaClient.MS_BETWEEN_REQUESTS, mDelegate.mNextSched
uledTimestamp); | 253 assertEquals(now + OmahaBase.MS_BETWEEN_REQUESTS, mDelegate.mNextSchedul
edTimestamp); |
| 253 checkTimestamps(now + OmahaClient.MS_BETWEEN_REQUESTS, now + OmahaClient
.MS_POST_BASE_DELAY, | 254 checkTimestamps(now + OmahaBase.MS_BETWEEN_REQUESTS, now + OmahaBase.MS_
POST_BASE_DELAY, |
| 254 mDelegate.mTimestampsOnSaveState); | 255 mDelegate.mTimestampsOnSaveState); |
| 255 } | 256 } |
| 256 | 257 |
| 257 @SmallTest | 258 @SmallTest |
| 258 @Feature({"Omaha"}) | 259 @Feature({"Omaha"}) |
| 259 public void testPipelineRegularPing() { | 260 public void testPipelineRegularPing() { |
| 260 final long now = 11684; | 261 final long now = 11684; |
| 261 | 262 |
| 262 mDelegate = new MockOmahaDelegate(mContext, DeviceType.HANDSET, InstallS
ource.ORGANIC); | 263 mDelegate = new MockOmahaDelegate(mContext, DeviceType.HANDSET, InstallS
ource.ORGANIC); |
| 263 mDelegate.getScheduler().setCurrentTime(now); | 264 mDelegate.getScheduler().setCurrentTime(now); |
| 264 | 265 |
| 265 // Record that an install event has already been sent and that we're due
for a new request. | 266 // Record that an install event has already been sent and that we're due
for a new request. |
| 266 SharedPreferences.Editor editor = OmahaBase.getSharedPreferences(mContex
t).edit(); | 267 SharedPreferences.Editor editor = OmahaBase.getSharedPreferences(mContex
t).edit(); |
| 267 editor.putBoolean(OmahaBase.PREF_SEND_INSTALL_EVENT, false); | 268 editor.putBoolean(OmahaBase.PREF_SEND_INSTALL_EVENT, false); |
| 268 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEW_REQUEST, now); | 269 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEW_REQUEST, now); |
| 269 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEXT_POST_ATTEMPT, now); | 270 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEXT_POST_ATTEMPT, now); |
| 270 editor.apply(); | 271 editor.apply(); |
| 271 | 272 |
| 272 // Trigger Omaha. | 273 // Trigger Omaha. |
| 273 mOmahaClient = createOmahaClient(); | 274 mOmahaBase = createOmahaBase(); |
| 274 mOmahaClient.run(); | 275 mOmahaBase.run(); |
| 275 | 276 |
| 276 // Only the regular ping should have been sent. | 277 // Only the regular ping should have been sent. |
| 277 assertFalse(mDelegate.mInstallEventWasSent); | 278 assertFalse(mDelegate.mInstallEventWasSent); |
| 278 assertEquals(1, mDelegate.mPostResults.size()); | 279 assertEquals(1, mDelegate.mPostResults.size()); |
| 279 assertEquals(OmahaClient.POST_RESULT_SENT, mDelegate.mPostResults.get(0)
.intValue()); | 280 assertEquals(OmahaBase.POST_RESULT_SENT, mDelegate.mPostResults.get(0).i
ntValue()); |
| 280 assertEquals(1, mDelegate.mGenerateAndPostRequestResults.size()); | 281 assertEquals(1, mDelegate.mGenerateAndPostRequestResults.size()); |
| 281 assertTrue(mDelegate.mGenerateAndPostRequestResults.get(0)); | 282 assertTrue(mDelegate.mGenerateAndPostRequestResults.get(0)); |
| 282 | 283 |
| 283 // Successful requests mean that the next scheduled event should be chec
king for when the | 284 // Successful requests mean that the next scheduled event should be chec
king for when the |
| 284 // user is active. | 285 // user is active. |
| 285 assertEquals(now + OmahaClient.MS_BETWEEN_REQUESTS, mDelegate.mNextSched
uledTimestamp); | 286 assertEquals(now + OmahaBase.MS_BETWEEN_REQUESTS, mDelegate.mNextSchedul
edTimestamp); |
| 286 checkTimestamps(now + OmahaClient.MS_BETWEEN_REQUESTS, now + OmahaClient
.MS_POST_BASE_DELAY, | 287 checkTimestamps(now + OmahaBase.MS_BETWEEN_REQUESTS, now + OmahaBase.MS_
POST_BASE_DELAY, |
| 287 mDelegate.mTimestampsOnSaveState); | 288 mDelegate.mTimestampsOnSaveState); |
| 288 } | 289 } |
| 289 | 290 |
| 290 @SmallTest | 291 @SmallTest |
| 291 @Feature({"Omaha"}) | 292 @Feature({"Omaha"}) |
| 292 public void testTooEarlyToPing() { | 293 public void testTooEarlyToPing() { |
| 293 final long now = 0; | 294 final long now = 0; |
| 294 final long later = 10000; | 295 final long later = 10000; |
| 295 | 296 |
| 296 mDelegate = new MockOmahaDelegate(mContext, DeviceType.HANDSET, InstallS
ource.ORGANIC); | 297 mDelegate = new MockOmahaDelegate(mContext, DeviceType.HANDSET, InstallS
ource.ORGANIC); |
| 297 mDelegate.getScheduler().setCurrentTime(now); | 298 mDelegate.getScheduler().setCurrentTime(now); |
| 298 | 299 |
| 299 // Put the time for the next request in the future. | 300 // Put the time for the next request in the future. |
| 300 SharedPreferences prefs = OmahaBase.getSharedPreferences(mContext); | 301 SharedPreferences prefs = OmahaBase.getSharedPreferences(mContext); |
| 301 prefs.edit().putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEW_REQUEST, later).ap
ply(); | 302 prefs.edit().putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEW_REQUEST, later).ap
ply(); |
| 302 | 303 |
| 303 // Trigger Omaha. | 304 // Trigger Omaha. |
| 304 mOmahaClient = createOmahaClient(); | 305 mOmahaBase = createOmahaBase(); |
| 305 mOmahaClient.run(); | 306 mOmahaBase.run(); |
| 306 | 307 |
| 307 // Nothing should have been POSTed. | 308 // Nothing should have been POSTed. |
| 308 assertEquals(0, mDelegate.mPostResults.size()); | 309 assertEquals(0, mDelegate.mPostResults.size()); |
| 309 assertEquals(0, mDelegate.mGenerateAndPostRequestResults.size()); | 310 assertEquals(0, mDelegate.mGenerateAndPostRequestResults.size()); |
| 310 | 311 |
| 311 // The next scheduled event is the request generation. Because there wa
s nothing to POST, | 312 // The next scheduled event is the request generation. Because there wa
s nothing to POST, |
| 312 // its timestamp should have remained unchanged and shouldn't have been
considered when the | 313 // its timestamp should have remained unchanged and shouldn't have been
considered when the |
| 313 // new alarm was scheduled. | 314 // new alarm was scheduled. |
| 314 assertEquals(later, mDelegate.mNextScheduledTimestamp); | 315 assertEquals(later, mDelegate.mNextScheduledTimestamp); |
| 315 checkTimestamps(later, now, mDelegate.mTimestampsOnSaveState); | 316 checkTimestamps(later, now, mDelegate.mTimestampsOnSaveState); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 332 // Make it so that a request was generated and is just waiting to be sen
t. | 333 // Make it so that a request was generated and is just waiting to be sen
t. |
| 333 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEW_REQUEST, timeSendNewRequ
est); | 334 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEW_REQUEST, timeSendNewRequ
est); |
| 334 editor.putLong(OmahaBase.PREF_TIMESTAMP_OF_REQUEST, timeGeneratedRequest
); | 335 editor.putLong(OmahaBase.PREF_TIMESTAMP_OF_REQUEST, timeGeneratedRequest
); |
| 335 editor.putString(OmahaBase.PREF_PERSISTED_REQUEST_ID, "persisted_id"); | 336 editor.putString(OmahaBase.PREF_PERSISTED_REQUEST_ID, "persisted_id"); |
| 336 | 337 |
| 337 // Put the time for the next post in the future. | 338 // Put the time for the next post in the future. |
| 338 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEXT_POST_ATTEMPT, timeSendN
ewPost); | 339 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEXT_POST_ATTEMPT, timeSendN
ewPost); |
| 339 editor.apply(); | 340 editor.apply(); |
| 340 | 341 |
| 341 // Trigger Omaha. | 342 // Trigger Omaha. |
| 342 mOmahaClient = createOmahaClient(); | 343 mOmahaBase = createOmahaBase(); |
| 343 mOmahaClient.run(); | 344 mOmahaBase.run(); |
| 344 | 345 |
| 345 // Request generation code should be skipped. | 346 // Request generation code should be skipped. |
| 346 assertNull(mDelegate.mTimestampsOnRegisterNewRequest); | 347 assertNull(mDelegate.mTimestampsOnRegisterNewRequest); |
| 347 | 348 |
| 348 // Should be too early to post, causing it to be rescheduled. | 349 // Should be too early to post, causing it to be rescheduled. |
| 349 assertEquals(1, mDelegate.mPostResults.size()); | 350 assertEquals(1, mDelegate.mPostResults.size()); |
| 350 assertEquals(OmahaClient.POST_RESULT_SCHEDULED, mDelegate.mPostResults.g
et(0).intValue()); | 351 assertEquals(OmahaBase.POST_RESULT_SCHEDULED, mDelegate.mPostResults.get
(0).intValue()); |
| 351 assertEquals(0, mDelegate.mGenerateAndPostRequestResults.size()); | 352 assertEquals(0, mDelegate.mGenerateAndPostRequestResults.size()); |
| 352 | 353 |
| 353 // The next scheduled event is the POST. Because request generation cod
e wasn't run, the | 354 // The next scheduled event is the POST. Because request generation cod
e wasn't run, the |
| 354 // timestamp for it shouldn't have changed. | 355 // timestamp for it shouldn't have changed. |
| 355 assertEquals(timeSendNewPost, mDelegate.mNextScheduledTimestamp); | 356 assertEquals(timeSendNewPost, mDelegate.mNextScheduledTimestamp); |
| 356 checkTimestamps(timeSendNewRequest, timeSendNewPost, mDelegate.mTimestam
psOnSaveState); | 357 checkTimestamps(timeSendNewRequest, timeSendNewPost, mDelegate.mTimestam
psOnSaveState); |
| 357 } | 358 } |
| 358 | 359 |
| 359 @SmallTest | 360 @SmallTest |
| 360 @Feature({"Omaha"}) | 361 @Feature({"Omaha"}) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 374 editor.putBoolean(OmahaBase.PREF_SEND_INSTALL_EVENT, false); | 375 editor.putBoolean(OmahaBase.PREF_SEND_INSTALL_EVENT, false); |
| 375 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEW_REQUEST, timeRegisterNew
Request); | 376 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEW_REQUEST, timeRegisterNew
Request); |
| 376 editor.putLong(OmahaBase.PREF_TIMESTAMP_OF_REQUEST, timeGeneratedRequest
); | 377 editor.putLong(OmahaBase.PREF_TIMESTAMP_OF_REQUEST, timeGeneratedRequest
); |
| 377 editor.putString(OmahaBase.PREF_PERSISTED_REQUEST_ID, "persisted_id"); | 378 editor.putString(OmahaBase.PREF_PERSISTED_REQUEST_ID, "persisted_id"); |
| 378 | 379 |
| 379 // Send the POST now. | 380 // Send the POST now. |
| 380 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEXT_POST_ATTEMPT, timeSendN
ewPost); | 381 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEXT_POST_ATTEMPT, timeSendN
ewPost); |
| 381 editor.apply(); | 382 editor.apply(); |
| 382 | 383 |
| 383 // Trigger Omaha. | 384 // Trigger Omaha. |
| 384 mOmahaClient = createOmahaClient(); | 385 mOmahaBase = createOmahaBase(); |
| 385 mOmahaClient.run(); | 386 mOmahaBase.run(); |
| 386 | 387 |
| 387 // Registering code shouldn't have fired. | 388 // Registering code shouldn't have fired. |
| 388 assertNull(mDelegate.mTimestampsOnRegisterNewRequest); | 389 assertNull(mDelegate.mTimestampsOnRegisterNewRequest); |
| 389 | 390 |
| 390 // Because we didn't send an install event, only one POST should have oc
curred. | 391 // Because we didn't send an install event, only one POST should have oc
curred. |
| 391 assertEquals(1, mDelegate.mPostResults.size()); | 392 assertEquals(1, mDelegate.mPostResults.size()); |
| 392 assertEquals(OmahaClient.POST_RESULT_SENT, mDelegate.mPostResults.get(0)
.intValue()); | 393 assertEquals(OmahaBase.POST_RESULT_SENT, mDelegate.mPostResults.get(0).i
ntValue()); |
| 393 assertEquals(1, mDelegate.mGenerateAndPostRequestResults.size()); | 394 assertEquals(1, mDelegate.mGenerateAndPostRequestResults.size()); |
| 394 assertTrue(mDelegate.mGenerateAndPostRequestResults.get(0)); | 395 assertTrue(mDelegate.mGenerateAndPostRequestResults.get(0)); |
| 395 | 396 |
| 396 // The next scheduled event is the request generation because there is n
othing to POST. | 397 // The next scheduled event is the request generation because there is n
othing to POST. |
| 397 // A successful POST adjusts all timestamps for the current time. | 398 // A successful POST adjusts all timestamps for the current time. |
| 398 assertEquals(timeRegisterNewRequest, mDelegate.mNextScheduledTimestamp); | 399 assertEquals(timeRegisterNewRequest, mDelegate.mNextScheduledTimestamp); |
| 399 checkTimestamps(now + OmahaClient.MS_BETWEEN_REQUESTS, now + OmahaClient
.MS_POST_BASE_DELAY, | 400 checkTimestamps(now + OmahaBase.MS_BETWEEN_REQUESTS, now + OmahaBase.MS_
POST_BASE_DELAY, |
| 400 mDelegate.mTimestampsOnSaveState); | 401 mDelegate.mTimestampsOnSaveState); |
| 401 } | 402 } |
| 402 | 403 |
| 403 @SmallTest | 404 @SmallTest |
| 404 @Feature({"Omaha"}) | 405 @Feature({"Omaha"}) |
| 405 public void testPostExistingButFails() { | 406 public void testPostExistingButFails() { |
| 406 final long timeGeneratedRequest = 0L; | 407 final long timeGeneratedRequest = 0L; |
| 407 final long now = 10000L; | 408 final long now = 10000L; |
| 408 final long timeSendNewPost = now; | 409 final long timeSendNewPost = now; |
| 409 final long timeRegisterNewRequest = timeGeneratedRequest + OmahaClient.M
S_BETWEEN_REQUESTS; | 410 final long timeRegisterNewRequest = timeGeneratedRequest + OmahaBase.MS_
BETWEEN_REQUESTS; |
| 410 | 411 |
| 411 mDelegate = new MockOmahaDelegate(mContext, DeviceType.HANDSET, InstallS
ource.ORGANIC); | 412 mDelegate = new MockOmahaDelegate(mContext, DeviceType.HANDSET, InstallS
ource.ORGANIC); |
| 412 mDelegate.getScheduler().setCurrentTime(now); | 413 mDelegate.getScheduler().setCurrentTime(now); |
| 413 | 414 |
| 414 SharedPreferences prefs = OmahaBase.getSharedPreferences(mContext); | 415 SharedPreferences prefs = OmahaBase.getSharedPreferences(mContext); |
| 415 SharedPreferences.Editor editor = prefs.edit(); | 416 SharedPreferences.Editor editor = prefs.edit(); |
| 416 | 417 |
| 417 // Make it so that a regular <ping> was generated and is just waiting to
be sent. | 418 // Make it so that a regular <ping> was generated and is just waiting to
be sent. |
| 418 editor.putBoolean(OmahaBase.PREF_SEND_INSTALL_EVENT, false); | 419 editor.putBoolean(OmahaBase.PREF_SEND_INSTALL_EVENT, false); |
| 419 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEW_REQUEST, timeRegisterNew
Request); | 420 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEW_REQUEST, timeRegisterNew
Request); |
| 420 editor.putLong(OmahaBase.PREF_TIMESTAMP_OF_REQUEST, timeGeneratedRequest
); | 421 editor.putLong(OmahaBase.PREF_TIMESTAMP_OF_REQUEST, timeGeneratedRequest
); |
| 421 editor.putString(OmahaBase.PREF_PERSISTED_REQUEST_ID, "persisted_id"); | 422 editor.putString(OmahaBase.PREF_PERSISTED_REQUEST_ID, "persisted_id"); |
| 422 | 423 |
| 423 // Send the POST now. | 424 // Send the POST now. |
| 424 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEXT_POST_ATTEMPT, timeSendN
ewPost); | 425 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEXT_POST_ATTEMPT, timeSendN
ewPost); |
| 425 editor.apply(); | 426 editor.apply(); |
| 426 | 427 |
| 427 // Trigger Omaha. | 428 // Trigger Omaha. |
| 428 mOmahaClient = createOmahaClient( | 429 mOmahaBase = createOmahaBase( |
| 429 ServerResponse.FAILURE, ConnectionStatus.RESPONDS, DeviceType.HA
NDSET); | 430 ServerResponse.FAILURE, ConnectionStatus.RESPONDS, DeviceType.HA
NDSET); |
| 430 mOmahaClient.run(); | 431 mOmahaBase.run(); |
| 431 | 432 |
| 432 // Registering code shouldn't have fired. | 433 // Registering code shouldn't have fired. |
| 433 assertNull(mDelegate.mTimestampsOnRegisterNewRequest); | 434 assertNull(mDelegate.mTimestampsOnRegisterNewRequest); |
| 434 | 435 |
| 435 // Because we didn't send an install event, only one POST should have oc
curred. | 436 // Because we didn't send an install event, only one POST should have oc
curred. |
| 436 assertEquals(1, mDelegate.mPostResults.size()); | 437 assertEquals(1, mDelegate.mPostResults.size()); |
| 437 assertEquals(OmahaClient.POST_RESULT_FAILED, mDelegate.mPostResults.get(
0).intValue()); | 438 assertEquals(OmahaBase.POST_RESULT_FAILED, mDelegate.mPostResults.get(0)
.intValue()); |
| 438 assertEquals(1, mDelegate.mGenerateAndPostRequestResults.size()); | 439 assertEquals(1, mDelegate.mGenerateAndPostRequestResults.size()); |
| 439 assertFalse(mDelegate.mGenerateAndPostRequestResults.get(0)); | 440 assertFalse(mDelegate.mGenerateAndPostRequestResults.get(0)); |
| 440 | 441 |
| 441 // The next scheduled event should be the POST event, which is delayed b
y the base delay | 442 // The next scheduled event should be the POST event, which is delayed b
y the base delay |
| 442 // because no failures have happened yet. | 443 // because no failures have happened yet. |
| 443 assertEquals(mDelegate.mTimestampsOnSaveState.timestampNextPost, | 444 assertEquals(mDelegate.mTimestampsOnSaveState.timestampNextPost, |
| 444 mDelegate.mNextScheduledTimestamp); | 445 mDelegate.mNextScheduledTimestamp); |
| 445 checkTimestamps(timeRegisterNewRequest, now + OmahaClient.MS_POST_BASE_D
ELAY, | 446 checkTimestamps(timeRegisterNewRequest, now + OmahaBase.MS_POST_BASE_DEL
AY, |
| 446 mDelegate.mTimestampsOnSaveState); | 447 mDelegate.mTimestampsOnSaveState); |
| 447 } | 448 } |
| 448 | 449 |
| 449 @SmallTest | 450 @SmallTest |
| 450 @Feature({"Omaha"}) | 451 @Feature({"Omaha"}) |
| 451 public void testTimestampWithinBounds() { | 452 public void testTimestampWithinBounds() { |
| 452 final long now = 0L; | 453 final long now = 0L; |
| 453 final long timeRegisterNewRequest = OmahaClient.MS_BETWEEN_REQUESTS + 1; | 454 final long timeRegisterNewRequest = OmahaBase.MS_BETWEEN_REQUESTS + 1; |
| 454 | 455 |
| 455 mDelegate = new MockOmahaDelegate(mContext, DeviceType.HANDSET, InstallS
ource.ORGANIC); | 456 mDelegate = new MockOmahaDelegate(mContext, DeviceType.HANDSET, InstallS
ource.ORGANIC); |
| 456 mDelegate.getScheduler().setCurrentTime(now); | 457 mDelegate.getScheduler().setCurrentTime(now); |
| 457 | 458 |
| 458 SharedPreferences prefs = OmahaBase.getSharedPreferences(mContext); | 459 SharedPreferences prefs = OmahaBase.getSharedPreferences(mContext); |
| 459 SharedPreferences.Editor editor = prefs.edit(); | 460 SharedPreferences.Editor editor = prefs.edit(); |
| 460 | 461 |
| 461 // Indicate that the next request should be generated way past an expect
ed timeframe. | 462 // Indicate that the next request should be generated way past an expect
ed timeframe. |
| 462 editor.putBoolean(OmahaBase.PREF_SEND_INSTALL_EVENT, false); | 463 editor.putBoolean(OmahaBase.PREF_SEND_INSTALL_EVENT, false); |
| 463 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEW_REQUEST, timeRegisterNew
Request); | 464 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEW_REQUEST, timeRegisterNew
Request); |
| 464 editor.apply(); | 465 editor.apply(); |
| 465 | 466 |
| 466 // Trigger Omaha. | 467 // Trigger Omaha. |
| 467 mOmahaClient = createOmahaClient(); | 468 mOmahaBase = createOmahaBase(); |
| 468 mOmahaClient.run(); | 469 mOmahaBase.run(); |
| 469 | 470 |
| 470 // Request generation code should fire. | 471 // Request generation code should fire. |
| 471 assertNotNull(mDelegate.mTimestampsOnRegisterNewRequest); | 472 assertNotNull(mDelegate.mTimestampsOnRegisterNewRequest); |
| 472 | 473 |
| 473 // Because we didn't send an install event, only one POST should have oc
curred. | 474 // Because we didn't send an install event, only one POST should have oc
curred. |
| 474 assertEquals(1, mDelegate.mPostResults.size()); | 475 assertEquals(1, mDelegate.mPostResults.size()); |
| 475 assertEquals(OmahaClient.POST_RESULT_SENT, mDelegate.mPostResults.get(0)
.intValue()); | 476 assertEquals(OmahaBase.POST_RESULT_SENT, mDelegate.mPostResults.get(0).i
ntValue()); |
| 476 assertEquals(1, mDelegate.mGenerateAndPostRequestResults.size()); | 477 assertEquals(1, mDelegate.mGenerateAndPostRequestResults.size()); |
| 477 assertTrue(mDelegate.mGenerateAndPostRequestResults.get(0)); | 478 assertTrue(mDelegate.mGenerateAndPostRequestResults.get(0)); |
| 478 | 479 |
| 479 // The next scheduled event should be the timestamp for a new request ge
neration. | 480 // The next scheduled event should be the timestamp for a new request ge
neration. |
| 480 assertEquals(mDelegate.mTimestampsOnSaveState.timestampNextRequest, | 481 assertEquals(mDelegate.mTimestampsOnSaveState.timestampNextRequest, |
| 481 mDelegate.mNextScheduledTimestamp); | 482 mDelegate.mNextScheduledTimestamp); |
| 482 checkTimestamps(now + OmahaClient.MS_BETWEEN_REQUESTS, now + OmahaClient
.MS_POST_BASE_DELAY, | 483 checkTimestamps(now + OmahaBase.MS_BETWEEN_REQUESTS, now + OmahaBase.MS_
POST_BASE_DELAY, |
| 483 mDelegate.mTimestampsOnSaveState); | 484 mDelegate.mTimestampsOnSaveState); |
| 484 } | 485 } |
| 485 | 486 |
| 486 @SmallTest | 487 @SmallTest |
| 487 @Feature({"Omaha"}) | 488 @Feature({"Omaha"}) |
| 488 public void testOverdueRequestCausesNewRegistration() { | 489 public void testOverdueRequestCausesNewRegistration() { |
| 489 final long timeGeneratedRequest = 0L; | 490 final long timeGeneratedRequest = 0L; |
| 490 final long now = 10000L; | 491 final long now = 10000L; |
| 491 final long timeSendNewPost = now; | 492 final long timeSendNewPost = now; |
| 492 final long timeRegisterNewRequest = | 493 final long timeRegisterNewRequest = |
| 493 timeGeneratedRequest + OmahaClient.MS_BETWEEN_REQUESTS * 5; | 494 timeGeneratedRequest + OmahaBase.MS_BETWEEN_REQUESTS * 5; |
| 494 | 495 |
| 495 mDelegate = new MockOmahaDelegate(mContext, DeviceType.HANDSET, InstallS
ource.ORGANIC); | 496 mDelegate = new MockOmahaDelegate(mContext, DeviceType.HANDSET, InstallS
ource.ORGANIC); |
| 496 mDelegate.getScheduler().setCurrentTime(now); | 497 mDelegate.getScheduler().setCurrentTime(now); |
| 497 | 498 |
| 498 // Record that a regular <ping> was generated, but not sent, then assign
it an invalid | 499 // Record that a regular <ping> was generated, but not sent, then assign
it an invalid |
| 499 // timestamp and try to send it now. | 500 // timestamp and try to send it now. |
| 500 SharedPreferences prefs = OmahaBase.getSharedPreferences(mContext); | 501 SharedPreferences prefs = OmahaBase.getSharedPreferences(mContext); |
| 501 SharedPreferences.Editor editor = prefs.edit(); | 502 SharedPreferences.Editor editor = prefs.edit(); |
| 502 editor.putBoolean(OmahaBase.PREF_SEND_INSTALL_EVENT, false); | 503 editor.putBoolean(OmahaBase.PREF_SEND_INSTALL_EVENT, false); |
| 503 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEW_REQUEST, timeRegisterNew
Request); | 504 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEW_REQUEST, timeRegisterNew
Request); |
| 504 editor.putLong(OmahaBase.PREF_TIMESTAMP_OF_REQUEST, timeGeneratedRequest
); | 505 editor.putLong(OmahaBase.PREF_TIMESTAMP_OF_REQUEST, timeGeneratedRequest
); |
| 505 editor.putString(OmahaBase.PREF_PERSISTED_REQUEST_ID, "persisted_id"); | 506 editor.putString(OmahaBase.PREF_PERSISTED_REQUEST_ID, "persisted_id"); |
| 506 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEXT_POST_ATTEMPT, timeSendN
ewPost); | 507 editor.putLong(OmahaBase.PREF_TIMESTAMP_FOR_NEXT_POST_ATTEMPT, timeSendN
ewPost); |
| 507 editor.apply(); | 508 editor.apply(); |
| 508 | 509 |
| 509 // Trigger Omaha. | 510 // Trigger Omaha. |
| 510 mOmahaClient = createOmahaClient(); | 511 mOmahaBase = createOmahaBase(); |
| 511 mOmahaClient.run(); | 512 mOmahaBase.run(); |
| 512 | 513 |
| 513 // Registering code shouldn't have fired. | 514 // Registering code shouldn't have fired. |
| 514 checkTimestamps(now + OmahaClient.MS_BETWEEN_REQUESTS, now, | 515 checkTimestamps(now + OmahaBase.MS_BETWEEN_REQUESTS, now, |
| 515 mDelegate.mTimestampsOnRegisterNewRequest); | 516 mDelegate.mTimestampsOnRegisterNewRequest); |
| 516 | 517 |
| 517 // Because we didn't send an install event, only one POST should have oc
curred. | 518 // Because we didn't send an install event, only one POST should have oc
curred. |
| 518 assertEquals(1, mDelegate.mPostResults.size()); | 519 assertEquals(1, mDelegate.mPostResults.size()); |
| 519 assertEquals(OmahaClient.POST_RESULT_SENT, mDelegate.mPostResults.get(0)
.intValue()); | 520 assertEquals(OmahaBase.POST_RESULT_SENT, mDelegate.mPostResults.get(0).i
ntValue()); |
| 520 assertEquals(1, mDelegate.mGenerateAndPostRequestResults.size()); | 521 assertEquals(1, mDelegate.mGenerateAndPostRequestResults.size()); |
| 521 assertTrue(mDelegate.mGenerateAndPostRequestResults.get(0)); | 522 assertTrue(mDelegate.mGenerateAndPostRequestResults.get(0)); |
| 522 | 523 |
| 523 // The next scheduled event should be the registration event. | 524 // The next scheduled event should be the registration event. |
| 524 assertEquals(mDelegate.mTimestampsOnSaveState.timestampNextRequest, | 525 assertEquals(mDelegate.mTimestampsOnSaveState.timestampNextRequest, |
| 525 mDelegate.mNextScheduledTimestamp); | 526 mDelegate.mNextScheduledTimestamp); |
| 526 checkTimestamps(now + OmahaClient.MS_BETWEEN_REQUESTS, now + OmahaClient
.MS_POST_BASE_DELAY, | 527 checkTimestamps(now + OmahaBase.MS_BETWEEN_REQUESTS, now + OmahaBase.MS_
POST_BASE_DELAY, |
| 527 mDelegate.mTimestampsOnSaveState); | 528 mDelegate.mTimestampsOnSaveState); |
| 528 } | 529 } |
| 529 | 530 |
| 530 private void checkTimestamps( | 531 private void checkTimestamps( |
| 531 long expectedRequestTimestamp, long expectedPostTimestamp, Timestamp
Pair timestamps) { | 532 long expectedRequestTimestamp, long expectedPostTimestamp, Timestamp
Pair timestamps) { |
| 532 assertEquals(expectedRequestTimestamp, timestamps.timestampNextRequest); | 533 assertEquals(expectedRequestTimestamp, timestamps.timestampNextRequest); |
| 533 assertEquals(expectedPostTimestamp, timestamps.timestampNextPost); | 534 assertEquals(expectedPostTimestamp, timestamps.timestampNextPost); |
| 534 } | 535 } |
| 535 | 536 |
| 536 /** | 537 /** |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 /** | 579 /** |
| 579 * Build a simulated response from the Omaha server indicating an update
is available. | 580 * Build a simulated response from the Omaha server indicating an update
is available. |
| 580 * The response changes based on the device type. | 581 * The response changes based on the device type. |
| 581 */ | 582 */ |
| 582 private String buildServerResponseString(boolean isOnTablet, boolean sen
dInstallEvent) { | 583 private String buildServerResponseString(boolean isOnTablet, boolean sen
dInstallEvent) { |
| 583 String response = ""; | 584 String response = ""; |
| 584 response += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; | 585 response += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; |
| 585 response += "<response protocol=\"3.0\" server=\"prod\">"; | 586 response += "<response protocol=\"3.0\" server=\"prod\">"; |
| 586 response += "<daystart elapsed_seconds=\"12345\"/>"; | 587 response += "<daystart elapsed_seconds=\"12345\"/>"; |
| 587 response += "<app appid=\""; | 588 response += "<app appid=\""; |
| 588 response += (isOnTablet | 589 response += (isOnTablet ? MockRequestGenerator.UUID_TABLET |
| 589 ? MockRequestGenerator.UUID_TABLET : MockRequestGenerator.UU
ID_PHONE); | 590 : MockRequestGenerator.UUID_PHONE); |
| 590 response += "\" status=\"ok\">"; | 591 response += "\" status=\"ok\">"; |
| 591 if (sendInstallEvent) { | 592 if (sendInstallEvent) { |
| 592 response += "<event status=\"ok\"/>"; | 593 response += "<event status=\"ok\"/>"; |
| 593 } else { | 594 } else { |
| 594 response += "<updatecheck status=\"ok\">"; | 595 response += "<updatecheck status=\"ok\">"; |
| 595 response += "<urls><url codebase=\"" + MARKET_URL + "\"/></urls>
"; | 596 response += "<urls><url codebase=\"" + MARKET_URL + "\"/></urls>
"; |
| 596 response += "<manifest version=\"" + UPDATE_VERSION + "\">"; | 597 response += "<manifest version=\"" + UPDATE_VERSION + "\">"; |
| 597 response += "<packages>"; | 598 response += "<packages>"; |
| 598 response += "<package hash=\"0\" name=\"dummy.apk\" required=\"t
rue\" size=\"0\"/>"; | 599 response += "<package hash=\"0\" name=\"dummy.apk\" required=\"t
rue\" size=\"0\"/>"; |
| 599 response += "</packages>"; | 600 response += "</packages>"; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 @Override | 634 @Override |
| 634 public void setFixedLengthStreamingMode(int contentLength) { | 635 public void setFixedLengthStreamingMode(int contentLength) { |
| 635 mContentLength = contentLength; | 636 mContentLength = contentLength; |
| 636 } | 637 } |
| 637 | 638 |
| 638 @Override | 639 @Override |
| 639 public int getResponseCode() { | 640 public int getResponseCode() { |
| 640 if (mNumTimesResponseCodeRetrieved == 0) { | 641 if (mNumTimesResponseCodeRetrieved == 0) { |
| 641 // The output stream should now have the generated XML for the r
equest. | 642 // The output stream should now have the generated XML for the r
equest. |
| 642 // Check if its length is correct. | 643 // Check if its length is correct. |
| 643 assertEquals("Expected OmahaClient to write out certain number o
f bytes", | 644 assertEquals("Expected OmahaBase to write out certain number of
bytes", |
| 644 mContentLength, mOutputStream.toByteArray().length); | 645 mContentLength, mOutputStream.toByteArray().length); |
| 645 } | 646 } |
| 646 assertTrue("Tried to retrieve response code more than twice", | 647 assertTrue("Tried to retrieve response code more than twice", |
| 647 mNumTimesResponseCodeRetrieved < 2); | 648 mNumTimesResponseCodeRetrieved < 2); |
| 648 mNumTimesResponseCodeRetrieved++; | 649 mNumTimesResponseCodeRetrieved++; |
| 649 return mHTTPResponseCode; | 650 return mHTTPResponseCode; |
| 650 } | 651 } |
| 651 | 652 |
| 652 @Override | 653 @Override |
| 653 public OutputStream getOutputStream() throws IOException { | 654 public OutputStream getOutputStream() throws IOException { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 | 688 |
| 688 public String getRequestPropertyField() { | 689 public String getRequestPropertyField() { |
| 689 return mRequestPropertyField; | 690 return mRequestPropertyField; |
| 690 } | 691 } |
| 691 | 692 |
| 692 public String getRequestPropertyValue() { | 693 public String getRequestPropertyValue() { |
| 693 return mRequestPropertyValue; | 694 return mRequestPropertyValue; |
| 694 } | 695 } |
| 695 } | 696 } |
| 696 } | 697 } |
| OLD | NEW |