TracingControllerAndroidTest.java revision 116680a4aac90f2aa7413d9095a592090648e557
1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package org.chromium.content.browser;
6
7import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
8
9import android.os.SystemClock;
10import android.test.suitebuilder.annotation.MediumTest;
11
12import org.chromium.base.ThreadUtils;
13import org.chromium.base.test.util.Feature;
14import org.chromium.content_shell_apk.ContentShellActivity;
15import org.chromium.content_shell_apk.ContentShellTestBase;
16
17import java.io.File;
18
19public class TracingControllerAndroidTest extends ContentShellTestBase {
20
21    private static final long TIMEOUT_MILLIS = scaleTimeout(30 * 1000);
22
23    @MediumTest
24    @Feature({"GPU"})
25    public void testTraceFileCreation() throws Exception {
26        ContentShellActivity activity = launchContentShellWithUrl("about:blank");
27        waitForActiveShellToBeDoneLoading();
28
29        final TracingControllerAndroid tracingController = new TracingControllerAndroid(activity);
30        assertFalse(tracingController.isTracing());
31        assertNull(tracingController.getOutputPath());
32
33        ThreadUtils.runOnUiThreadBlocking(new Runnable() {
34            @Override
35            public void run() {
36                assertTrue(tracingController.startTracing(true, "*", false));
37            }
38        });
39
40        assertTrue(tracingController.isTracing());
41        File file = new File(tracingController.getOutputPath());
42        assertTrue(file.getName().startsWith("chrome-profile-results"));
43
44        ThreadUtils.runOnUiThreadBlocking(new Runnable() {
45            @Override
46            public void run() {
47                tracingController.stopTracing();
48            }
49        });
50
51        // The tracer stops asynchronously, because it needs to wait for native code to flush and
52        // close the output file. Give it a little time.
53        long startTime = SystemClock.uptimeMillis();
54        while (tracingController.isTracing()) {
55            if (SystemClock.uptimeMillis() > startTime + TIMEOUT_MILLIS) {
56                fail("Timed out waiting for tracing to stop.");
57            }
58            Thread.sleep(1000);
59        }
60
61        // It says it stopped, so it should have written the output file.
62        assertTrue(file.exists());
63        assertTrue(file.delete());
64        tracingController.destroy();
65    }
66}
67