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 5 package org.chromium.content.browser; 6 7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; 8 9 import android.os.SystemClock; 10 import android.test.suitebuilder.annotation.MediumTest; 11 12 import org.chromium.base.ThreadUtils; 13 import org.chromium.base.test.util.Feature; 14 import org.chromium.content_shell_apk.ContentShellActivity; 15 import org.chromium.content_shell_apk.ContentShellTestBase; 16 17 import java.io.File; 18 19 public 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( 37 true, "*", "record-until-full")); 38 } 39 }); 40 41 assertTrue(tracingController.isTracing()); 42 File file = new File(tracingController.getOutputPath()); 43 assertTrue(file.getName().startsWith("chrome-profile-results")); 44 45 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 46 @Override 47 public void run() { 48 tracingController.stopTracing(); 49 } 50 }); 51 52 // The tracer stops asynchronously, because it needs to wait for native code to flush and 53 // close the output file. Give it a little time. 54 long startTime = SystemClock.uptimeMillis(); 55 while (tracingController.isTracing()) { 56 if (SystemClock.uptimeMillis() > startTime + TIMEOUT_MILLIS) { 57 fail("Timed out waiting for tracing to stop."); 58 } 59 Thread.sleep(1000); 60 } 61 62 // It says it stopped, so it should have written the output file. 63 assertTrue(file.exists()); 64 assertTrue(file.delete()); 65 tracingController.destroy(); 66 } 67 } 68