// Path: customtabs/tests/src/android/support/customtabs/trusted/TestBrowser.java
// public class TestBrowser extends AppCompatActivity {
// 
//     private final CountDownLatch mResumeLatch = new CountDownLatch(1);
// 
//     @Override
//     protected void onCreate(@Nullable Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//     }
// 
//     @Override
//     protected void onResume() {
//         super.onResume();
//         mResumeLatch.countDown();
//     }
// 
//     /**
//      * Waits until onResume. Returns whether has reached onResume until timeout.
//      * If already resumed, returns "true" immediately.
//      */
//     public boolean waitForResume(int timeoutMillis) {
//         assert Thread.currentThread() != Looper.getMainLooper().getThread() : "Deadlock!";
//         try {
//             return mResumeLatch.await(timeoutMillis, TimeUnit.MILLISECONDS);
//         } catch (InterruptedException e) {
//             return false;
//         }
//     }
// }


import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import android.app.Instrumentation;
import android.os.Handler;
import android.os.Looper;
import android.support.customtabs.trusted.TestBrowser;
import android.support.test.InstrumentationRegistry;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
// Copyright 2019 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package android.support.customtabs.testutil;





/**
 * Utilities for testing Custom Tabs.
 */
public class TestUtil {

    /**
     * Waits until {@link TestBrowser} is launched and resumed, and returns it.
     *
     * @param launchRunnable Runnable that should start the activity.
     */
    public static TestBrowser getBrowserActivityWhenLaunched(Runnable launchRunnable) {
        Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
        Instrumentation.ActivityMonitor monitor
                = instrumentation.addMonitor(TestBrowser.class.getName(), null, false);

        launchRunnable.run();
// Path: customtabs/tests/src/android/support/customtabs/trusted/TestBrowser.java
// public class TestBrowser extends AppCompatActivity {
// 
//     private final CountDownLatch mResumeLatch = new CountDownLatch(1);
// 
//     @Override
//     protected void onCreate(@Nullable Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
//     }
// 
//     @Override
//     protected void onResume() {
//         super.onResume();
//         mResumeLatch.countDown();
//     }
// 
//     /**
//      * Waits until onResume. Returns whether has reached onResume until timeout.
//      * If already resumed, returns "true" immediately.
//      */
//     public boolean waitForResume(int timeoutMillis) {
//         assert Thread.currentThread() != Looper.getMainLooper().getThread() : "Deadlock!";
//         try {
//             return mResumeLatch.await(timeoutMillis, TimeUnit.MILLISECONDS);
//         } catch (InterruptedException e) {
//             return false;
//         }
//     }
// }


// Path: customtabs/tests/src/android/support/customtabs/testutil/TestUtil.java
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import android.app.Instrumentation;
import android.os.Handler;
import android.os.Looper;
import android.support.customtabs.trusted.TestBrowser;
import android.support.test.InstrumentationRegistry;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

// Copyright 2019 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package android.support.customtabs.testutil;





/**
 * Utilities for testing Custom Tabs.
 */
public class TestUtil {

    /**
     * Waits until {@link TestBrowser} is launched and resumed, and returns it.
     *
     * @param launchRunnable Runnable that should start the activity.
     */
    public static TestBrowser getBrowserActivityWhenLaunched(Runnable launchRunnable) {
        Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
        Instrumentation.ActivityMonitor monitor
                = instrumentation.addMonitor(TestBrowser.class.getName(), null, false);

        launchRunnable.run();
        TestBrowser activity =