Skip to content

Commit

Permalink
Merge pull request #893 from Microsoft/develop
Browse files Browse the repository at this point in the history
Merge develop to userid
  • Loading branch information
MatkovIvan committed Nov 23, 2018
2 parents c1b5287 + f73654a commit 3176e28
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 17 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@

* **[Fix]** Do not delete old logs when trying to add a log larger than the maximum storage capacity.
* **[Fix]** Fix error detection of `setMaxStorageSize` API if database uses custom page size.

### AppCenter

* **[Fix]** Fix minimum storage size verification to match minimum possible value.

### AppCenterCrashes

* **[Fix]** Fix a bug where crash data file could leak when the database is full.

### AppCenterPush

* **[Fix]** Fix push foreground listener after re-enabling push service.

___

## Version 1.10.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import static com.microsoft.appcenter.test.TestUtils.compareSelfNullClass;
import static java.util.Collections.singletonList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

@SuppressWarnings("unused")
public class ErrorModelTest {
Expand All @@ -41,7 +41,7 @@ private static void checkSerializationThrowsException(Log log, LogSerializer ser
checkEquals(ex.getClass(), expectedException);
return;
}
assertTrue(false);
fail();
}

private static void checkExceptions(LogSerializer serializer, ManagedErrorLog errorLog1, ManagedErrorLog errorLog2, Exception exception1, Exception exception2) throws JSONException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,7 @@ public synchronized void onActivityResumed(Activity activity) {

@Override
public void onActivityPaused(Activity activity) {
postOnUiThread(new Runnable() {

@Override
public void run() {
mActivity = null;
}
});
mActivity = null;
}

private void checkPushInActivityIntent(Activity activity) {
Expand All @@ -348,12 +342,12 @@ private void checkPushInActivityIntent(final Activity activity, final Intent int
AppCenterLog.error(LOG_TAG, "Push.checkLaunchedFromNotification: intent may not be null");
return;
}
mActivity = activity;
postOnUiThread(new Runnable() {

@Override
public void run() {
mActivity = activity;
checkPushInIntent(intent);
checkPushInIntent(activity, intent);
}
});
}
Expand All @@ -363,7 +357,7 @@ public void run() {
*
* @param intent intent to inspect.
*/
private synchronized void checkPushInIntent(Intent intent) {
private synchronized void checkPushInIntent(Activity activity, Intent intent) {
if (mInstanceListener != null) {
String googleMessageId = PushIntentUtils.getMessageId(intent);
if (googleMessageId != null && !googleMessageId.equals(mLastGoogleMessageId)
Expand All @@ -375,7 +369,7 @@ private synchronized void checkPushInIntent(Intent intent) {
AppCenterLog.info(LOG_TAG, "Clicked push message from background id=" + googleMessageId);
mLastGoogleMessageId = googleMessageId;
AppCenterLog.debug(LOG_TAG, "Push intent extras=" + intent.getExtras());
mInstanceListener.onPushNotificationReceived(mActivity, notification);
mInstanceListener.onPushNotificationReceived(activity, notification);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ public void nullTokenOnStartThenRefresh() {

@Test
public void receivedInForeground() {

PushListener pushListener = mock(PushListener.class);
Push.setListener(pushListener);
Push push = Push.getInstance();
Expand Down Expand Up @@ -383,6 +382,37 @@ public Void answer(InvocationOnMock invocation) {
verify(pushListener2).onPushNotificationReceived(eq(activity), captor.capture());
}

@Test
public void receivedInForegroundWhenInitiallyDisabled() {

/* Was disabled before start. */
when(SharedPreferencesManager.getBoolean(PUSH_ENABLED_KEY, true)).thenReturn(false);

/* Start. */
PushListener pushListener = mock(PushListener.class);
Push.setListener(pushListener);
Push push = Push.getInstance();
Channel channel = mock(Channel.class);
start(push, channel);
Activity activity = mock(Activity.class);
when(activity.getIntent()).thenReturn(mock(Intent.class));

/* Enable after activity resume. */
push.onActivityResumed(activity);
Push.setEnabled(true);

/* Mock some message. */
Intent pushIntent = createPushIntent("some title", "some message", null);
Push.getInstance().onMessageReceived(mContext, pushIntent);
ArgumentCaptor<PushNotification> captor = ArgumentCaptor.forClass(PushNotification.class);
verify(pushListener).onPushNotificationReceived(eq(activity), captor.capture());
PushNotification pushNotification = captor.getValue();
assertNotNull(pushNotification);
assertEquals("some title", pushNotification.getTitle());
assertEquals("some message", pushNotification.getMessage());
assertEquals(new HashMap<String, String>(), pushNotification.getCustomData());
}

@Test
public void receivedPushInBackgroundWithoutFirebaseWithDebugLog() {
IllegalStateException exception = new IllegalStateException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -801,4 +801,76 @@ public boolean matches(Object argument) {
}
}));
}

@Test
public void sendGzipWithHugeTextAndVerboseLogging() throws Exception {

/* Mock verbose logging. */
mockStatic(AppCenterLog.class);
when(AppCenterLog.getLogLevel()).thenReturn(Log.VERBOSE);

/* Configure mock HTTP. */
String urlString = "http://mock";
URL url = mock(URL.class);
whenNew(URL.class).withArguments(urlString).thenReturn(url);
HttpsURLConnection urlConnection = mock(HttpsURLConnection.class);
when(url.openConnection()).thenReturn(urlConnection);
when(urlConnection.getResponseCode()).thenReturn(200);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
when(urlConnection.getOutputStream()).thenReturn(buffer);
when(urlConnection.getInputStream()).thenReturn(new ByteArrayInputStream("OK".getBytes()));

/* Long mock payload. */
StringBuilder payloadBuilder = new StringBuilder();
for (int i = 0; i < 8000; i++) {
payloadBuilder.append('a');
}
final String payload = payloadBuilder.toString();

/* Compress payload for verification. */
ByteArrayOutputStream gzipBuffer = new ByteArrayOutputStream(payload.length());
GZIPOutputStream gzipStream = new GZIPOutputStream(gzipBuffer);
gzipStream.write(payload.getBytes("UTF-8"));
gzipStream.close();
byte[] compressedBytes = gzipBuffer.toByteArray();

/* Configure API client. */
HttpClient.CallTemplate callTemplate = mock(HttpClient.CallTemplate.class);
when(callTemplate.buildRequestBody()).thenReturn(payload);
DefaultHttpClient httpClient = new DefaultHttpClient();

/* Test calling code. */
String appSecret = UUIDUtils.randomUUID().toString();
UUID installId = UUIDUtils.randomUUID();
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "custom");
ServiceCallback serviceCallback = mock(ServiceCallback.class);
mockCall();
httpClient.callAsync(urlString, METHOD_POST, headers, callTemplate, serviceCallback);
verify(serviceCallback).onCallSucceeded("OK");
verifyNoMoreInteractions(serviceCallback);
verify(urlConnection).setRequestProperty("Content-Type", "custom");

/* Also verify content type was set only once, json not applied. */
verify(urlConnection).setRequestProperty(eq("Content-Type"), anyString());
verify(urlConnection).setRequestProperty("Content-Encoding", "gzip");
verify(urlConnection).setRequestMethod("POST");
verify(urlConnection).setDoOutput(true);
verify(urlConnection).disconnect();
verify(callTemplate).onBeforeCalling(eq(url), anyMapOf(String.class, String.class));
verify(callTemplate).buildRequestBody();
httpClient.close();

/* Verify payload compressed. */
assertArrayEquals(compressedBytes, buffer.toByteArray());

/* Check payload logged. */
verifyStatic();
AppCenterLog.verbose(anyString(), argThat(new ArgumentMatcher<String>() {
@Override
public boolean matches(Object argument) {
return argument.toString().contains(payload);
}
}));
}
}

0 comments on commit 3176e28

Please sign in to comment.