Skip to content

Commit d6021a9

Browse files
committed
Merge branch 'main' of https://github.com/firebase/firebase-android-sdk into markduckworth/vector-type
2 parents 4f195eb + 0605925 commit d6021a9

File tree

20 files changed

+527
-152
lines changed

20 files changed

+527
-152
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.crashlytics;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
21+
import androidx.test.core.app.ApplicationProvider;
22+
import com.google.firebase.FirebaseApp;
23+
import com.google.firebase.FirebaseOptions;
24+
import com.google.firebase.crashlytics.internal.common.CrashlyticsCore;
25+
import com.google.firebase.crashlytics.internal.common.DataCollectionArbiter;
26+
import java.lang.reflect.Field;
27+
import org.junit.After;
28+
import org.junit.Before;
29+
import org.junit.Test;
30+
31+
/** Tests for the internal apis that development platform plugins call. */
32+
public class CrashlyticsPluginsTest {
33+
private static final String APP_ID = "1:1:android:1a";
34+
private static final String API_KEY = "API-KEY-API-KEY-API-KEY-API-KEY-API-KEY";
35+
private static final String PROJECT_ID = "PROJECT-ID";
36+
37+
@Before
38+
public void setUp() {
39+
FirebaseApp.initializeApp(
40+
ApplicationProvider.getApplicationContext(),
41+
new FirebaseOptions.Builder()
42+
.setApplicationId(APP_ID)
43+
.setApiKey(API_KEY)
44+
.setProjectId(PROJECT_ID)
45+
.build());
46+
}
47+
48+
@After
49+
public void tearDown() {
50+
FirebaseApp.clearInstancesForTest();
51+
}
52+
53+
@Test
54+
public void accessCrashlyticsCore() {
55+
// Both Flutter and Unity plugins access CrashlyticsCore from FirebaseCrashlytics.core field.
56+
CrashlyticsCore core = FirebaseCrashlytics.getInstance().core;
57+
assertThat(core).isNotNull();
58+
59+
// Verify the internal method logFatalException exists without reflection.
60+
Runnable logFatalException = () -> core.logFatalException(new Throwable());
61+
assertThat(logFatalException).isNotNull();
62+
63+
// Verify the internal method setInternalKey exists without reflection.
64+
Runnable setInternalKey = () -> core.setInternalKey("", "");
65+
assertThat(setInternalKey).isNotNull();
66+
}
67+
68+
@Test
69+
public void accessDataCollection() throws Exception {
70+
// The Unity plugin accesses CrashlyticsCore.dataCollectionArbiter this via reflection.
71+
CrashlyticsCore core = FirebaseCrashlytics.getInstance().core;
72+
Field field = core.getClass().getDeclaredField("dataCollectionArbiter");
73+
field.setAccessible(true); // The dataCollectionArbiter field is private in CrashlyticsCore.
74+
DataCollectionArbiter dataCollectionArbiter = (DataCollectionArbiter) field.get(core);
75+
76+
assertThat(dataCollectionArbiter).isNotNull();
77+
}
78+
}

firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/common/CrashlyticsControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
import com.google.firebase.concurrent.TestOnlyExecutors;
3838
import com.google.firebase.crashlytics.internal.CrashlyticsNativeComponent;
3939
import com.google.firebase.crashlytics.internal.CrashlyticsTestCase;
40-
import com.google.firebase.crashlytics.internal.CrashlyticsWorker;
4140
import com.google.firebase.crashlytics.internal.DevelopmentPlatformProvider;
4241
import com.google.firebase.crashlytics.internal.NativeSessionFileProvider;
4342
import com.google.firebase.crashlytics.internal.analytics.AnalyticsEventLogger;
43+
import com.google.firebase.crashlytics.internal.concurrency.CrashlyticsWorker;
4444
import com.google.firebase.crashlytics.internal.metadata.LogFileManager;
4545
import com.google.firebase.crashlytics.internal.metadata.UserMetadata;
4646
import com.google.firebase.crashlytics.internal.model.CrashlyticsReport;

firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/common/CrashlyticsCoreInitializationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
import com.google.firebase.crashlytics.internal.CrashlyticsNativeComponent;
3232
import com.google.firebase.crashlytics.internal.CrashlyticsNativeComponentDeferredProxy;
3333
import com.google.firebase.crashlytics.internal.CrashlyticsTestCase;
34-
import com.google.firebase.crashlytics.internal.CrashlyticsWorker;
3534
import com.google.firebase.crashlytics.internal.DevelopmentPlatformProvider;
3635
import com.google.firebase.crashlytics.internal.RemoteConfigDeferredProxy;
3736
import com.google.firebase.crashlytics.internal.analytics.UnavailableAnalyticsEventLogger;
3837
import com.google.firebase.crashlytics.internal.breadcrumbs.DisabledBreadcrumbSource;
38+
import com.google.firebase.crashlytics.internal.concurrency.CrashlyticsWorker;
3939
import com.google.firebase.crashlytics.internal.persistence.FileStore;
4040
import com.google.firebase.crashlytics.internal.settings.Settings;
4141
import com.google.firebase.crashlytics.internal.settings.SettingsController;

firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/common/CrashlyticsCoreTest.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
import com.google.firebase.crashlytics.internal.CrashlyticsNativeComponent;
3434
import com.google.firebase.crashlytics.internal.CrashlyticsNativeComponentDeferredProxy;
3535
import com.google.firebase.crashlytics.internal.CrashlyticsTestCase;
36-
import com.google.firebase.crashlytics.internal.CrashlyticsWorker;
3736
import com.google.firebase.crashlytics.internal.DevelopmentPlatformProvider;
3837
import com.google.firebase.crashlytics.internal.RemoteConfigDeferredProxy;
3938
import com.google.firebase.crashlytics.internal.analytics.UnavailableAnalyticsEventLogger;
4039
import com.google.firebase.crashlytics.internal.breadcrumbs.BreadcrumbHandler;
4140
import com.google.firebase.crashlytics.internal.breadcrumbs.BreadcrumbSource;
4241
import com.google.firebase.crashlytics.internal.breadcrumbs.DisabledBreadcrumbSource;
42+
import com.google.firebase.crashlytics.internal.concurrency.CrashlyticsWorker;
4343
import com.google.firebase.crashlytics.internal.metadata.UserMetadata;
4444
import com.google.firebase.crashlytics.internal.persistence.FileStore;
4545
import com.google.firebase.crashlytics.internal.settings.Settings;
@@ -70,6 +70,10 @@ public void whenAvailable(
7070

7171
private CrashlyticsCore crashlyticsCore;
7272
private BreadcrumbSource mockBreadcrumbSource;
73+
private static final CrashlyticsWorker commonWorker =
74+
new CrashlyticsWorker(TestOnlyExecutors.background());
75+
private static final CrashlyticsWorker diskWriteWorker =
76+
new CrashlyticsWorker(TestOnlyExecutors.background());
7377

7478
@Override
7579
protected void setUp() throws Exception {
@@ -93,7 +97,7 @@ public void testCustomAttributes() throws Exception {
9397

9498
final String id = "id012345";
9599
crashlyticsCore.setUserId(id);
96-
crashlyticsCore.commonWorker.await();
100+
commonWorker.await();
97101
assertEquals(id, metadata.getUserId());
98102

99103
final StringBuffer idBuffer = new StringBuffer(id);
@@ -104,13 +108,13 @@ public void testCustomAttributes() throws Exception {
104108
final String superLongId = longId + "more chars";
105109

106110
crashlyticsCore.setUserId(superLongId);
107-
crashlyticsCore.commonWorker.await();
111+
commonWorker.await();
108112
assertEquals(longId, metadata.getUserId());
109113

110114
final String key1 = "key1";
111115
final String value1 = "value1";
112116
crashlyticsCore.setCustomKey(key1, value1);
113-
crashlyticsCore.commonWorker.await();
117+
commonWorker.await();
114118
assertEquals(value1, metadata.getCustomKeys().get(key1));
115119

116120
// Adding an existing key with the same value should return false
@@ -124,7 +128,7 @@ public void testCustomAttributes() throws Exception {
124128

125129
// test truncation of custom keys and attributes
126130
crashlyticsCore.setCustomKey(superLongId, superLongValue);
127-
crashlyticsCore.commonWorker.await();
131+
commonWorker.await();
128132
assertNull(metadata.getCustomKeys().get(superLongId));
129133
assertEquals(longValue, metadata.getCustomKeys().get(longId));
130134

@@ -133,28 +137,28 @@ public void testCustomAttributes() throws Exception {
133137
final String key = "key" + i;
134138
final String value = "value" + i;
135139
crashlyticsCore.setCustomKey(key, value);
136-
crashlyticsCore.commonWorker.await();
140+
commonWorker.await();
137141
assertEquals(value, metadata.getCustomKeys().get(key));
138142
}
139143
// should be full now, extra key, value pairs will be dropped.
140144
final String key = "new key";
141145
crashlyticsCore.setCustomKey(key, "some value");
142-
crashlyticsCore.commonWorker.await();
146+
commonWorker.await();
143147
assertFalse(metadata.getCustomKeys().containsKey(key));
144148

145149
// should be able to update existing keys
146150
crashlyticsCore.setCustomKey(key1, longValue);
147-
crashlyticsCore.commonWorker.await();
151+
commonWorker.await();
148152
assertEquals(longValue, metadata.getCustomKeys().get(key1));
149153

150154
// when we set a key to null, it should still exist with an empty value
151155
crashlyticsCore.setCustomKey(key1, null);
152-
crashlyticsCore.commonWorker.await();
156+
commonWorker.await();
153157
assertEquals("", metadata.getCustomKeys().get(key1));
154158

155159
// keys and values are trimmed.
156160
crashlyticsCore.setCustomKey(" " + key1 + " ", " " + longValue + " ");
157-
crashlyticsCore.commonWorker.await();
161+
commonWorker.await();
158162
assertTrue(metadata.getCustomKeys().containsKey(key1));
159163
assertEquals(longValue, metadata.getCustomKeys().get(key1));
160164
}
@@ -205,7 +209,7 @@ public void testBulkCustomKeys() throws Exception {
205209
keysAndValues.put(intKey, String.valueOf(intValue));
206210

207211
crashlyticsCore.setCustomKeys(keysAndValues);
208-
crashlyticsCore.commonWorker.await();
212+
commonWorker.await();
209213

210214
assertEquals(stringValue, metadata.getCustomKeys().get(stringKey));
211215
assertEquals(trimmedValue, metadata.getCustomKeys().get(trimmedKey));
@@ -226,7 +230,7 @@ public void testBulkCustomKeys() throws Exception {
226230
addlKeysAndValues.put(key, value);
227231
}
228232
crashlyticsCore.setCustomKeys(addlKeysAndValues);
229-
crashlyticsCore.commonWorker.await();
233+
commonWorker.await();
230234

231235
// Ensure all keys have been set
232236
assertEquals(UserMetadata.MAX_ATTRIBUTES, metadata.getCustomKeys().size(), DELTA);
@@ -244,7 +248,7 @@ public void testBulkCustomKeys() throws Exception {
244248
extraKeysAndValues.put(key, value);
245249
}
246250
crashlyticsCore.setCustomKeys(extraKeysAndValues);
247-
crashlyticsCore.commonWorker.await();
251+
commonWorker.await();
248252

249253
// Make sure the extra keys were not added
250254
for (int i = UserMetadata.MAX_ATTRIBUTES; i < UserMetadata.MAX_ATTRIBUTES + 10; ++i) {
@@ -270,7 +274,7 @@ public void testBulkCustomKeys() throws Exception {
270274
updatedKeysAndValues.put(intKey, String.valueOf(updatedIntValue));
271275

272276
crashlyticsCore.setCustomKeys(updatedKeysAndValues);
273-
crashlyticsCore.commonWorker.await();
277+
commonWorker.await();
274278

275279
assertEquals(updatedStringValue, metadata.getCustomKeys().get(stringKey));
276280
assertFalse(Boolean.parseBoolean(metadata.getCustomKeys().get(booleanKey)));
@@ -443,8 +447,8 @@ CrashlyticsCore build(Context context) {
443447
new FileStore(context),
444448
mock(CrashlyticsAppQualitySessionsSubscriber.class),
445449
mock(RemoteConfigDeferredProxy.class),
446-
new CrashlyticsWorker(TestOnlyExecutors.background()),
447-
new CrashlyticsWorker(TestOnlyExecutors.background()));
450+
commonWorker,
451+
diskWriteWorker);
448452
return crashlyticsCore;
449453
}
450454
}

0 commit comments

Comments
 (0)