| Index: components/cronet/android/test/javatests/src/org/chromium/cronet_test_apk/urlconnection/MessageLoopTest.java
|
| diff --git a/components/cronet/android/test/javatests/src/org/chromium/cronet_test_apk/urlconnection/MessageLoopTest.java b/components/cronet/android/test/javatests/src/org/chromium/cronet_test_apk/urlconnection/MessageLoopTest.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..450f54ae03fac7891cbd6652db977616b527ecbd
|
| --- /dev/null
|
| +++ b/components/cronet/android/test/javatests/src/org/chromium/cronet_test_apk/urlconnection/MessageLoopTest.java
|
| @@ -0,0 +1,52 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package org.chromium.cronet_test_apk.urlconnection;
|
| +
|
| +import android.test.suitebuilder.annotation.SmallTest;
|
| +
|
| +import org.chromium.base.test.util.Feature;
|
| +import org.chromium.cronet_test_apk.CronetTestBase;
|
| +import org.chromium.net.urlconnection.MessageLoop;
|
| +
|
| +import java.io.IOException;
|
| +
|
| +/**
|
| + * Tests the MessageLoop implementation.
|
| + */
|
| +public class MessageLoopTest extends CronetTestBase {
|
| +
|
| + @SmallTest
|
| + @Feature({"Cronet"})
|
| + public void testInterrupt() throws Exception {
|
| + final MessageLoop loop = new MessageLoop();
|
| + assertFalse(loop.isRunning());
|
| + Thread thread = new Thread() {
|
| + @Override
|
| + public void run() {
|
| + try {
|
| + loop.loop();
|
| + fail();
|
| + } catch (IOException e) {
|
| + // Expected interrupt.
|
| + }
|
| + }
|
| + };
|
| + thread.start();
|
| + Thread.sleep(1000);
|
| + assertTrue(loop.isRunning());
|
| + assertFalse(loop.isWaitingInterrupted());
|
| + thread.interrupt();
|
| + Thread.sleep(1000);
|
| + assertFalse(loop.isRunning());
|
| + assertTrue(loop.isWaitingInterrupted());
|
| + // Re-spinning the message loop is not allowed after interrupt.
|
| + try {
|
| + loop.loop();
|
| + fail();
|
| + } catch (IllegalStateException e) {
|
| + // Expected.
|
| + }
|
| + }
|
| +}
|
|
|