summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2017-08-23 07:30:37 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2017-08-23 07:30:37 +0000
commit19d64a8dbbfe03c5db61fe14f15ffc953455328e (patch)
tree2ab3179c51fa233bae230337ce7083bf163499cf
parent7e5d3b3cd3a5e49ffc3520f613808228a131433e (diff)
parent20540dc9a8b32a7fc467be7964d2db56db578e8a (diff)
downloadplatform_testing-19d64a8dbbfe03c5db61fe14f15ffc953455328e.tar.gz
release-request-cff6d9b6-a564-4d17-99cb-c2d0bb282758-for-git_oc-mr1-release-4293817 snap-temp-L12800000095933585
Change-Id: Ic9746748bbc5793a2a04b5a1bca974b0aa1207be
-rw-r--r--tests/functional/systemmetrics/AndroidManifest.xml1
-rw-r--r--tests/functional/systemmetrics/src/com/android/systemmetrics/functional/AppStartTests.java97
-rw-r--r--tests/functional/systemmetrics/src/com/android/systemmetrics/functional/ReportedDrawnActivity.java29
3 files changed, 103 insertions, 24 deletions
diff --git a/tests/functional/systemmetrics/AndroidManifest.xml b/tests/functional/systemmetrics/AndroidManifest.xml
index aacbb8038..319d067ec 100644
--- a/tests/functional/systemmetrics/AndroidManifest.xml
+++ b/tests/functional/systemmetrics/AndroidManifest.xml
@@ -19,6 +19,7 @@
<application>
<uses-library android:name="android.test.runner" />
+ <activity android:name=".ReportedDrawnActivity"/>
</application>
<uses-sdk
diff --git a/tests/functional/systemmetrics/src/com/android/systemmetrics/functional/AppStartTests.java b/tests/functional/systemmetrics/src/com/android/systemmetrics/functional/AppStartTests.java
index 43c6681ff..57ef432b0 100644
--- a/tests/functional/systemmetrics/src/com/android/systemmetrics/functional/AppStartTests.java
+++ b/tests/functional/systemmetrics/src/com/android/systemmetrics/functional/AppStartTests.java
@@ -16,28 +16,49 @@
package com.android.systemmetrics.functional;
+import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION;
+import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_DELAY_MS;
+import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_DEVICE_UPTIME_SECONDS;
+import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_PROCESS_RUNNING;
+import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_REPORTED_DRAWN;
+import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_REPORTED_DRAWN_MS;
+import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_STARTING_WINDOW_DELAY_MS;
+import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_WINDOWS_DRAWN_DELAY_MS;
+import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_CLASS_NAME;
+import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_TRANSITION_COLD_LAUNCH;
+import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_TRANSITION_REPORTED_DRAWN_NO_BUNDLE;
+import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_TRANSITION_WARM_LAUNCH;
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
import android.content.Context;
import android.content.Intent;
import android.metrics.LogMaker;
import android.metrics.MetricsReader;
import android.os.SystemClock;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.MediumTest;
import android.support.test.metricshelper.MetricsAsserts;
+import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.Until;
-import android.telecom.Log;
-import android.test.InstrumentationTestCase;
-import android.test.suitebuilder.annotation.MediumTest;
import android.text.TextUtils;
-import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
import java.util.Queue;
/**
* runtest --path platform_testing/tests/functional/systemmetrics/
*/
-public class AppStartTests extends InstrumentationTestCase {
+@MediumTest
+@RunWith(AndroidJUnit4.class)
+public class AppStartTests {
private static final String LOG_TAG = AppStartTests.class.getSimpleName();
private static final String SETTINGS_PACKAGE = "com.android.settings";
private static final int LONG_TIMEOUT_MS = 2000;
@@ -46,28 +67,26 @@ public class AppStartTests extends InstrumentationTestCase {
private MetricsReader mMetricsReader;
private int mPreUptime;
- @Override
+ @Before
public void setUp() throws Exception {
- super.setUp();
- mDevice = UiDevice.getInstance(getInstrumentation());
- mContext = getInstrumentation().getContext();
+ mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+ mContext = InstrumentationRegistry.getTargetContext();
mDevice.setOrientationNatural();
mMetricsReader = new MetricsReader();
mMetricsReader.checkpoint(); // clear out old logs
mPreUptime = (int) (SystemClock.uptimeMillis() / 1000);
}
- @Override
+ @After
public void tearDown() throws Exception {
- super.tearDown();
mDevice.unfreezeRotation();
- mDevice.pressHome();
+ mContext.startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));
+ mDevice.waitForIdle();
}
- @MediumTest
+ @Test
public void testStartApp() throws Exception {
- Context context = getInstrumentation().getContext();
- Intent intent = context.getPackageManager().getLaunchIntentForPackage(SETTINGS_PACKAGE);
+ Intent intent = mContext.getPackageManager().getLaunchIntentForPackage(SETTINGS_PACKAGE);
// Clear out any previous instances
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -79,41 +98,71 @@ public class AppStartTests extends InstrumentationTestCase {
assertTrue("packageName is empty", !TextUtils.isEmpty(packageName));
- context.startActivity(intent);
+ mContext.startActivity(intent);
mDevice.wait(Until.hasObject(By.pkg(SETTINGS_PACKAGE).depth(0)), LONG_TIMEOUT_MS);
int postUptime = (int) (SystemClock.uptimeMillis() / 1000);
Queue<LogMaker> startLogs = MetricsAsserts.findMatchingLogs(mMetricsReader,
- new LogMaker(MetricsEvent.APP_TRANSITION));
+ new LogMaker(APP_TRANSITION));
boolean found = false;
for (LogMaker log : startLogs) {
String actualClassName = (String) log.getTaggedData(
- MetricsEvent.FIELD_CLASS_NAME);
+ FIELD_CLASS_NAME);
String actualPackageName = log.getPackageName();
if (className.equals(actualClassName) && packageName.equals(actualPackageName)) {
found = true;
int startUptime = ((Number)
- log.getTaggedData(MetricsEvent.APP_TRANSITION_DEVICE_UPTIME_SECONDS))
+ log.getTaggedData(APP_TRANSITION_DEVICE_UPTIME_SECONDS))
.intValue();
assertTrue("must be either cold or warm launch",
- MetricsEvent.TYPE_TRANSITION_COLD_LAUNCH == log.getType()
- || MetricsEvent.TYPE_TRANSITION_WARM_LAUNCH == log.getType());
+ TYPE_TRANSITION_COLD_LAUNCH == log.getType()
+ || TYPE_TRANSITION_WARM_LAUNCH == log.getType());
assertTrue("reported uptime should be after the app was started",
mPreUptime <= startUptime);
assertTrue("reported uptime should be before assertion time",
startUptime <= postUptime);
assertNotNull("log should have delay",
- log.getTaggedData(MetricsEvent.APP_TRANSITION_DELAY_MS));
+ log.getTaggedData(APP_TRANSITION_DELAY_MS));
assertEquals("transition should be started because of starting window",
1 /* APP_TRANSITION_STARTING_WINDOW */, log.getSubtype());
assertNotNull("log should have starting window delay",
- log.getTaggedData(MetricsEvent.APP_TRANSITION_STARTING_WINDOW_DELAY_MS));
+ log.getTaggedData(APP_TRANSITION_STARTING_WINDOW_DELAY_MS));
assertNotNull("log should have windows drawn delay",
- log.getTaggedData(MetricsEvent.APP_TRANSITION_WINDOWS_DRAWN_DELAY_MS));
+ log.getTaggedData(APP_TRANSITION_WINDOWS_DRAWN_DELAY_MS));
}
}
assertTrue("did not find the app start start log for: "
+ intent.getComponent().flattenToShortString(), found);
}
+
+ @Test
+ public void testReportedDrawn() throws Exception {
+ Intent intent = new Intent(mContext, ReportedDrawnActivity.class).setFlags(
+ Intent.FLAG_ACTIVITY_NEW_TASK);
+ mContext.startActivity(intent);
+ mDevice.wait(Until.hasObject(By.pkg(mContext.getPackageName()).depth(0)), LONG_TIMEOUT_MS);
+
+ String className = intent.getComponent().getClassName();
+ String packageName = intent.getComponent().getPackageName();
+
+ // Sleep until activity under test has reported drawn (after 500ms)
+ SystemClock.sleep(1000);
+ Queue<LogMaker> startLogs = MetricsAsserts.findMatchingLogs(mMetricsReader,
+ new LogMaker(APP_TRANSITION_REPORTED_DRAWN));
+ boolean found = false;
+ for (LogMaker log : startLogs) {
+ String actualClassName = (String) log.getTaggedData(
+ FIELD_CLASS_NAME);
+ String actualPackageName = log.getPackageName();
+ if (className.equals(actualClassName) && packageName.equals(actualPackageName)) {
+ found = true;
+ assertTrue((long) log.getTaggedData(APP_TRANSITION_REPORTED_DRAWN_MS) > 500L);
+ assertEquals((int) log.getTaggedData(APP_TRANSITION_PROCESS_RUNNING), 1);
+ assertEquals(TYPE_TRANSITION_REPORTED_DRAWN_NO_BUNDLE, log.getType());
+ }
+ }
+ assertTrue("did not find the app start start log for: "
+ + intent.getComponent().flattenToShortString(), found);
+ }
}
diff --git a/tests/functional/systemmetrics/src/com/android/systemmetrics/functional/ReportedDrawnActivity.java b/tests/functional/systemmetrics/src/com/android/systemmetrics/functional/ReportedDrawnActivity.java
new file mode 100644
index 000000000..b1cdaae0a
--- /dev/null
+++ b/tests/functional/systemmetrics/src/com/android/systemmetrics/functional/ReportedDrawnActivity.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * 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.android.systemmetrics.functional;
+
+import android.app.Activity;
+import android.os.Handler;
+
+public class ReportedDrawnActivity extends Activity {
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ new Handler().postDelayed(this::reportFullyDrawn, 500);
+ }
+}