TracingControllerAndroidTest.java revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
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 java.io.File; 13 14import org.chromium.base.ThreadUtils; 15import org.chromium.base.test.util.Feature; 16import org.chromium.content_shell_apk.ContentShellActivity; 17import org.chromium.content_shell_apk.ContentShellTestBase; 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 } 65} 66