/*
 * ***********************************************************************
 *
 *  ADOBE CONFIDENTIAL
 *  ___________________
 *
 *  Copyright 2013 Adobe Systems Incorporated
 *  All Rights Reserved.
 *
 *  NOTICE:  All information contained herein is, and remains
 *  the property of Adobe Systems Incorporated and its suppliers,
 *  if any.  The intellectual and technical concepts contained
 *  herein are proprietary to Adobe Systems Incorporated and its
 *  suppliers and are protected by trade secret or copyright law.
 *  Dissemination of this information or reproduction of this material
 *  is strictly forbidden unless prior written permission is obtained
 *  from Adobe Systems Incorporated.
 *
 * ***********************************************************************
 */

package com.adobe.primetime.reference.feature.playback;

import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.adobe.primetime.reference.R;
import com.adobe.primetime.reference.feature.ads.PlaybackWithAdsEndToEndTestBase;
import com.robotium.solo.Condition;
import junit.framework.Assert;

/**
 * Play a HLS stream with play and pause operation.
 */
public class DVREndToEndTest extends PlaybackWithAdsEndToEndTestBase {

	private final String BUFFER_COMPLETE = "Buffering complete";

	public DVREndToEndTest() throws Exception {
		contentUrl = "http://d398890tia84ty.cloudfront.net/cloudfront_hls.m3u8";
	}

	/**
	 * Test player activity loads and play the video item correctly
	 */
	public void testLoadAndPlayVideo() throws InterruptedException {

		// Verify buffering on prepare stage
		Assert.assertTrue("Buffering spinner is displayed", solo.waitForView(R.id.pbBufferingSpinner));
        final ProgressBar spinner = (ProgressBar) solo.getView(R.id.pbBufferingSpinner);

        // wait for buffering to complete
        solo.waitForCondition (new Condition() {
            @Override
            public boolean isSatisfied() {
                return spinner.getVisibility() == View.INVISIBLE;
            }
        }, 10000);

		// Verify content is LIVE
		String timestamp = ((TextView) solo.getView(R.id.txtCurrentTime)).getText().toString();
		Assert.assertTrue("Timstamp display contains 'LIVE'", timestamp.contains("LIVE"));
	}
}
