-
Notifications
You must be signed in to change notification settings - Fork 625
[Fragment Performance] e2e test app fragments #3210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cd79111
new template activity
leotianlizhan 70866c5
copyright
leotianlizhan d767612
fix appcompat theme
leotianlizhan e3f029e
WIP FTL instrumeumented tests
leotianlizhan 6f81662
rv in all fragments
leotianlizhan 6b4b6bf
automated scroll of all 3 fragments
leotianlizhan b1b6caf
remove debug code
leotianlizhan faa1015
gJF
leotianlizhan b19c6ae
copyright
leotianlizhan 0690abb
rename to slow/fast fragments
leotianlizhan 4d0b0b8
copyright
leotianlizhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...ava/com/google/firebase/testing/fireperf/FirebasePerformanceFragmentScreenTracesTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Copyright 2021 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.firebase.testing.fireperf; | ||
|
||
import static androidx.test.espresso.Espresso.onView; | ||
import static androidx.test.espresso.contrib.RecyclerViewActions.scrollToPosition; | ||
import static androidx.test.espresso.matcher.ViewMatchers.withId; | ||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import android.app.Activity; | ||
import androidx.annotation.NonNull; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.fragment.app.Fragment; | ||
import androidx.fragment.app.FragmentManager; | ||
import androidx.lifecycle.Lifecycle.State; | ||
import androidx.navigation.NavController; | ||
import androidx.navigation.Navigation; | ||
import androidx.test.core.app.ActivityScenario; | ||
import androidx.test.ext.junit.rules.ActivityScenarioRule; | ||
import androidx.test.filters.MediumTest; | ||
import androidx.test.runner.AndroidJUnit4; | ||
import com.google.firebase.testing.fireperf.ui.fast.FastFragment; | ||
import com.google.firebase.testing.fireperf.ui.home.HomeFragment; | ||
import com.google.firebase.testing.fireperf.ui.slow.SlowFragment; | ||
import java.util.Arrays; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* Scrolls a slow RecyclerView all the way to the end, which should generate slow and frozen frame | ||
* data. | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
@MediumTest | ||
public class FirebasePerformanceFragmentScreenTracesTest { | ||
|
||
@Rule | ||
public ActivityScenarioRule<FragmentActivity> activityRule = | ||
new ActivityScenarioRule<>(FragmentActivity.class); | ||
|
||
@Test | ||
public void scrollAndCycleThroughAllFragments() throws InterruptedException { | ||
activityRule | ||
.getScenario() | ||
.onActivity( | ||
activity -> { | ||
((AppCompatActivity) activity) | ||
.getSupportFragmentManager() | ||
.registerFragmentLifecycleCallbacks( | ||
new FragmentManager.FragmentLifecycleCallbacks() { | ||
@Override | ||
public void onFragmentResumed( | ||
@NonNull FragmentManager fm, @NonNull Fragment f) { | ||
super.onFragmentResumed(fm, f); | ||
notifyNavigationLock(); | ||
} | ||
}, | ||
true); | ||
}); | ||
scrollRecyclerViewToEnd(HomeFragment.NUM_LIST_ITEMS, R.id.rv_numbers_home); | ||
activityRule.getScenario().onActivity(new NavigateAction(R.id.navigation_fast)); | ||
blockUntilNavigationDone(); | ||
scrollRecyclerViewToEnd(FastFragment.NUM_LIST_ITEMS, R.id.rv_numbers_fast); | ||
activityRule.getScenario().onActivity(new NavigateAction(R.id.navigation_slow)); | ||
blockUntilNavigationDone(); | ||
scrollRecyclerViewToEnd(SlowFragment.NUM_LIST_ITEMS, R.id.rv_numbers_slow); | ||
assertThat(activityRule.getScenario().getState()) | ||
.isIn(Arrays.asList(State.CREATED, State.RESUMED)); | ||
activityRule.getScenario().moveToState(State.CREATED); | ||
} | ||
|
||
private void scrollRecyclerViewToEnd(int itemCount, int viewId) { | ||
int currItemCount = 0; | ||
|
||
while (currItemCount < itemCount) { | ||
onView(withId(viewId)).perform(scrollToPosition(currItemCount)); | ||
currItemCount += 5; | ||
} | ||
} | ||
|
||
private synchronized void blockUntilNavigationDone() throws InterruptedException { | ||
wait(); | ||
} | ||
|
||
private synchronized void notifyNavigationLock() { | ||
notify(); | ||
visumickey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
static class NavigateAction implements ActivityScenario.ActivityAction { | ||
private final int destinationId; | ||
|
||
public NavigateAction(int destinationId) { | ||
this.destinationId = destinationId; | ||
} | ||
|
||
@Override | ||
public void perform(Activity activity) { | ||
NavController navController = | ||
Navigation.findNavController(activity, R.id.nav_host_fragment_activity_fragment); | ||
navController.navigate(destinationId); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,11 +17,17 @@ | |
import static androidx.test.espresso.Espresso.onView; | ||
import static androidx.test.espresso.contrib.RecyclerViewActions.scrollToPosition; | ||
import static androidx.test.espresso.matcher.ViewMatchers.withId; | ||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import androidx.recyclerview.widget.RecyclerView; | ||
import androidx.test.filters.MediumTest; | ||
import androidx.test.platform.app.InstrumentationRegistry; | ||
import androidx.test.rule.ActivityTestRule; | ||
import androidx.test.runner.AndroidJUnit4; | ||
import androidx.test.uiautomator.By; | ||
import androidx.test.uiautomator.UiDevice; | ||
import androidx.test.uiautomator.Until; | ||
import org.junit.After; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
@@ -33,6 +39,7 @@ | |
@RunWith(AndroidJUnit4.class) | ||
@MediumTest | ||
public class FirebasePerformanceScreenTracesTest { | ||
private static final int LAUNCH_TIMEOUT = 5000; | ||
|
||
@Rule | ||
public ActivityTestRule<FirebasePerfScreenTracesActivity> activityRule = | ||
|
@@ -41,6 +48,16 @@ public class FirebasePerformanceScreenTracesTest { | |
/* initialTouchMode= */ false, | ||
/* launchActivity= */ true); | ||
|
||
@After | ||
public void pressHome_toTriggerSendScreenTrace() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we triggering an event sent for every app backgrounding? I thought we were dispatching events scheduled every 30 seconds managed by Firelog service. @jeremyjiang-dev |
||
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); | ||
boolean success = device.pressHome(); | ||
// Wait for launcher | ||
final String launcherPackage = device.getLauncherPackageName(); | ||
assertThat(launcherPackage).isNotNull(); | ||
device.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT); | ||
} | ||
|
||
@Test | ||
public void scrollRecyclerViewToEnd() { | ||
RecyclerView recyclerView = activityRule.getActivity().findViewById(R.id.rv_numbers); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,38 @@ | ||
<?xml version="1.0" encoding="utf-8"?> <!-- Copyright 2020 Google Inc. All Rights Reserved. --> | ||
|
||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="com.google.firebase.testing.fireperf"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:debuggable="true" | ||
android:label="FirePerf E2E Test App" | ||
android:usesCleartextTraffic="true" | ||
tools:ignore="HardcodedDebugMode,UnusedAttribute"> | ||
|
||
<activity | ||
android:label="FirebasePerfActivity" | ||
android:name=".FirebasePerfActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
<activity | ||
android:label="FirebasePerfScreenTracesActivity" | ||
android:name=".FirebasePerfScreenTracesActivity" /> | ||
|
||
<meta-data | ||
android:name="firebase_performance_logcat_enabled" | ||
android:value="true" /> | ||
|
||
<meta-data | ||
android:name="sessions_sampling_percentage" | ||
android:value="100.0" /> | ||
|
||
</application> | ||
|
||
</manifest> | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="com.google.firebase.testing.fireperf"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:debuggable="true" | ||
android:label="FirePerf E2E Test App" | ||
android:usesCleartextTraffic="true" | ||
tools:ignore="HardcodedDebugMode,UnusedAttribute"> | ||
<activity | ||
android:name=".FragmentActivity" | ||
android:label="@string/title_activity_fragment" | ||
android:theme="@style/Theme.MaterialComponents.DayNight.DarkActionBar" /> | ||
<activity | ||
android:name=".FirebasePerfActivity" | ||
android:label="FirebasePerfActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity | ||
android:name=".FirebasePerfScreenTracesActivity" | ||
android:label="FirebasePerfScreenTracesActivity" /> | ||
|
||
<meta-data | ||
android:name="firebase_performance_logcat_enabled" | ||
android:value="true" /> | ||
<meta-data | ||
android:name="sessions_sampling_percentage" | ||
android:value="100.0" /> | ||
</application> | ||
|
||
</manifest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...ase-perf/e2e-app/src/main/java/com/google/firebase/testing/fireperf/FragmentActivity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2021 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package com.google.firebase.testing.fireperf; | ||
|
||
import android.os.Bundle; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.navigation.NavController; | ||
import androidx.navigation.Navigation; | ||
import androidx.navigation.ui.AppBarConfiguration; | ||
import androidx.navigation.ui.NavigationUI; | ||
import com.google.android.material.bottomnavigation.BottomNavigationView; | ||
|
||
public class FragmentActivity extends AppCompatActivity { | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_fragment); | ||
BottomNavigationView navView = findViewById(R.id.nav_view); | ||
// Passing each menu ID as a set of Ids because each | ||
// menu should be considered as top level destinations. | ||
AppBarConfiguration appBarConfiguration = | ||
new AppBarConfiguration.Builder( | ||
R.id.navigation_home, R.id.navigation_fast, R.id.navigation_slow) | ||
.build(); | ||
NavController navController = | ||
Navigation.findNavController(this, R.id.nav_host_fragment_activity_fragment); | ||
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration); | ||
NavigationUI.setupWithNavController(navView, navController); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.