| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; | 7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; |
| 8 | 8 |
| 9 import android.os.SystemClock; | 9 import android.os.SystemClock; |
| 10 import android.support.test.filters.MediumTest; | 10 import android.support.test.filters.MediumTest; |
| 11 | 11 |
| 12 import org.junit.Assert; |
| 13 import org.junit.Rule; |
| 14 import org.junit.Test; |
| 15 import org.junit.runner.RunWith; |
| 16 |
| 12 import org.chromium.base.ThreadUtils; | 17 import org.chromium.base.ThreadUtils; |
| 18 import org.chromium.base.test.BaseJUnit4ClassRunner; |
| 13 import org.chromium.base.test.util.DisabledTest; | 19 import org.chromium.base.test.util.DisabledTest; |
| 14 import org.chromium.base.test.util.Feature; | 20 import org.chromium.base.test.util.Feature; |
| 15 import org.chromium.content_shell_apk.ContentShellActivity; | 21 import org.chromium.content_shell_apk.ContentShellActivity; |
| 16 import org.chromium.content_shell_apk.ContentShellTestBase; | 22 import org.chromium.content_shell_apk.ContentShellActivityTestRule; |
| 17 | 23 |
| 18 import java.io.File; | 24 import java.io.File; |
| 19 | 25 |
| 20 /** | 26 /** |
| 21 * Test suite for TracingControllerAndroid. | 27 * Test suite for TracingControllerAndroid. |
| 22 */ | 28 */ |
| 23 public class TracingControllerAndroidTest extends ContentShellTestBase { | 29 @RunWith(BaseJUnit4ClassRunner.class) |
| 30 public class TracingControllerAndroidTest { |
| 31 @Rule |
| 32 public ContentShellActivityTestRule mActivityTestRule = new ContentShellActi
vityTestRule(); |
| 24 | 33 |
| 25 private static final long TIMEOUT_MILLIS = scaleTimeout(30 * 1000); | 34 private static final long TIMEOUT_MILLIS = scaleTimeout(30 * 1000); |
| 26 | 35 |
| 36 @Test |
| 27 @MediumTest | 37 @MediumTest |
| 28 @Feature({"GPU"}) | 38 @Feature({"GPU"}) |
| 29 @DisabledTest(message = "crbug.com/621956") | 39 @DisabledTest(message = "crbug.com/621956") |
| 30 public void testTraceFileCreation() throws Exception { | 40 public void testTraceFileCreation() throws Exception { |
| 31 ContentShellActivity activity = launchContentShellWithUrl("about:blank")
; | 41 ContentShellActivity activity = mActivityTestRule.launchContentShellWith
Url("about:blank"); |
| 32 waitForActiveShellToBeDoneLoading(); | 42 mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
| 33 | 43 |
| 34 final TracingControllerAndroid tracingController = new TracingController
Android(activity); | 44 final TracingControllerAndroid tracingController = new TracingController
Android(activity); |
| 35 assertFalse(tracingController.isTracing()); | 45 Assert.assertFalse(tracingController.isTracing()); |
| 36 assertNull(tracingController.getOutputPath()); | 46 Assert.assertNull(tracingController.getOutputPath()); |
| 37 | 47 |
| 38 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 48 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 39 @Override | 49 @Override |
| 40 public void run() { | 50 public void run() { |
| 41 assertTrue(tracingController.startTracing(true, "*", "record-unt
il-full")); | 51 Assert.assertTrue(tracingController.startTracing(true, "*", "rec
ord-until-full")); |
| 42 } | 52 } |
| 43 }); | 53 }); |
| 44 | 54 |
| 45 assertTrue(tracingController.isTracing()); | 55 Assert.assertTrue(tracingController.isTracing()); |
| 46 File file = new File(tracingController.getOutputPath()); | 56 File file = new File(tracingController.getOutputPath()); |
| 47 assertTrue(file.getName().startsWith("chrome-profile-results")); | 57 Assert.assertTrue(file.getName().startsWith("chrome-profile-results")); |
| 48 | 58 |
| 49 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 59 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 50 @Override | 60 @Override |
| 51 public void run() { | 61 public void run() { |
| 52 tracingController.stopTracing(); | 62 tracingController.stopTracing(); |
| 53 } | 63 } |
| 54 }); | 64 }); |
| 55 | 65 |
| 56 // The tracer stops asynchronously, because it needs to wait for native
code to flush and | 66 // The tracer stops asynchronously, because it needs to wait for native
code to flush and |
| 57 // close the output file. Give it a little time. | 67 // close the output file. Give it a little time. |
| 58 long startTime = SystemClock.uptimeMillis(); | 68 long startTime = SystemClock.uptimeMillis(); |
| 59 while (tracingController.isTracing()) { | 69 while (tracingController.isTracing()) { |
| 60 if (SystemClock.uptimeMillis() > startTime + TIMEOUT_MILLIS) { | 70 if (SystemClock.uptimeMillis() > startTime + TIMEOUT_MILLIS) { |
| 61 fail("Timed out waiting for tracing to stop."); | 71 Assert.fail("Timed out waiting for tracing to stop."); |
| 62 } | 72 } |
| 63 Thread.sleep(1000); | 73 Thread.sleep(1000); |
| 64 } | 74 } |
| 65 | 75 |
| 66 // It says it stopped, so it should have written the output file. | 76 // It says it stopped, so it should have written the output file. |
| 67 assertTrue(file.exists()); | 77 Assert.assertTrue(file.exists()); |
| 68 assertTrue(file.delete()); | 78 Assert.assertTrue(file.delete()); |
| 69 tracingController.destroy(); | 79 tracingController.destroy(); |
| 70 } | 80 } |
| 71 } | 81 } |
| OLD | NEW |