当前位置: 首页>>代码示例>>Java>>正文


Java RequiresDevice类代码示例

本文整理汇总了Java中android.support.test.filters.RequiresDevice的典型用法代码示例。如果您正苦于以下问题:Java RequiresDevice类的具体用法?Java RequiresDevice怎么用?Java RequiresDevice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RequiresDevice类属于android.support.test.filters包,在下文中一共展示了RequiresDevice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testConstruct

import android.support.test.filters.RequiresDevice; //导入依赖的package包/类
@Test
@RequiresDevice
public void testConstruct () throws Exception {
	final ConditionVariable cv = new ConditionVariable();
	Handler handler = new Handler(Looper.getMainLooper());
	handler.post(new Runnable() {
		@Override
		public void run() {
			VideoPlayerView vp = new VideoPlayerView(getInstrumentation().getTargetContext());
			assertNotNull("VideoPlayerView should not be null after constructing", vp);
			cv.open();
		}
	});

	boolean success = cv.block(30000);
	assertTrue("Condition variable was not opened properly: VideoPlayer was not created", success);
}
 
开发者ID:Unity-Technologies,项目名称:unity-ads-android,代码行数:18,代码来源:VideoViewTest.java

示例2: verifySilenceDuringPresentationStoring

import android.support.test.filters.RequiresDevice; //导入依赖的package包/类
/**
 * Verify that the "Silence during presentation" setting is correctly stored and restored
 * on activity loading.
 *
 * @throws InterruptedException If sleep times fail
 */
@Test
@LargeTest
@RequiresDevice
public void verifySilenceDuringPresentationStoring() throws InterruptedException {
    onView(withId(R.id.silenceDuringPresentation))
            .perform(click());
    Thread.sleep(1000);
    onView(withId(R.id.silenceDuringPresentation))
            .check(matches(isChecked()));

    settingsActivityRule.getActivity().onStop();
    settingsActivityRule.getActivity().finish();
    Thread.sleep(1000);
    assertThat(settingsActivityRule.getActivity().isDestroyed(), is(true));

    settingsActivityRule.launchActivity(null);
    onView(withId(R.id.silenceDuringPresentation))
            .check(matches(isChecked()))
            .perform(click());
    Thread.sleep(1000);
    onView(withId(R.id.silenceDuringPresentation))
            .check(matches(isNotChecked()));

    settingsActivityRule.getActivity().onStop();
    settingsActivityRule.getActivity().finish();
    Thread.sleep(1000);
    assertThat(settingsActivityRule.getActivity().isDestroyed(), is(true));

    settingsActivityRule.launchActivity(null);
    onView(withId(R.id.silenceDuringPresentation)).check(matches(isNotChecked()));
}
 
开发者ID:FelixWohlfrom,项目名称:Presenter-Client-Android,代码行数:38,代码来源:SettingsActivityTest.java

示例3: verifyUseVolumeKeysForNavigationStoring

import android.support.test.filters.RequiresDevice; //导入依赖的package包/类
/**
 * Verify that the "Use volume keys for navigation" setting is correctly stored and restored
 * on activity loading.
 *
 * @throws InterruptedException If sleep times fail
 */
@Test
@LargeTest
@RequiresDevice
public void verifyUseVolumeKeysForNavigationStoring() throws InterruptedException {
    onView(withId(R.id.useVolumeKeysForNavigation))
            .perform(click());
    Thread.sleep(1000);
    onView(withId(R.id.useVolumeKeysForNavigation))
            .check(matches(isNotChecked()));

    settingsActivityRule.getActivity().onStop();
    settingsActivityRule.getActivity().finish();
    Thread.sleep(1000);
    assertThat(settingsActivityRule.getActivity().isDestroyed(), is(true));

    settingsActivityRule.launchActivity(null);
    onView(withId(R.id.useVolumeKeysForNavigation))
            .check(matches(isNotChecked()))
            .perform(click());
    Thread.sleep(1000);
    onView(withId(R.id.useVolumeKeysForNavigation))
            .check(matches(isChecked()));

    settingsActivityRule.getActivity().onStop();
    settingsActivityRule.getActivity().finish();
    Thread.sleep(1000);
    assertThat(settingsActivityRule.getActivity().isDestroyed(), is(true));

    settingsActivityRule.launchActivity(null);
    onView(withId(R.id.useVolumeKeysForNavigation)).check(matches(isChecked()));
}
 
开发者ID:FelixWohlfrom,项目名称:Presenter-Client-Android,代码行数:38,代码来源:SettingsActivityTest.java

示例4: tokenizesAndroidPay

import android.support.test.filters.RequiresDevice; //导入依赖的package包/类
@RequiresDevice
@Test(timeout = 60000)
public void tokenizesAndroidPay() {
    onDevice(withText("Add Payment Method")).waitForEnabled().perform(click());

    onDevice(withText("Android Pay")).perform(click());
    onDevice(withText("CONTINUE")).perform(click());

    getNonceDetails().check(text(containsString("Underlying Card Last Two")));

    onDevice(withText("Purchase")).perform(click());
    onDevice(withTextStartingWith("created")).check(text(endsWith("authorized")));
}
 
开发者ID:braintree,项目名称:braintree-android-drop-in,代码行数:14,代码来源:DropInTest.java

示例5: testRequiresDevice

import android.support.test.filters.RequiresDevice; //导入依赖的package包/类
@Test
@RequiresDevice
public void testRequiresDevice() {
    Log.d("Test Filters", "This test requires a device");
    Activity activity = activityTestRule.getActivity();
    assertNotNull("MainActivity is not available", activity);
}
 
开发者ID:ravidsrk,项目名称:android-testing-guide,代码行数:8,代码来源:MainActivityTest.java

示例6: tokenizesAndroidPay

import android.support.test.filters.RequiresDevice; //导入依赖的package包/类
@RequiresDevice
@Test(timeout = 60000)
public void tokenizesAndroidPay() {
    onDevice(withText("Android Pay")).perform(click());
    onDevice(withText("CONTINUE")).perform(click());

    getNonceDetails().check(text(containsString("Underlying Card Last Two")));

    onDevice(withText("Create a Transaction")).perform(click());
    onDevice(withTextStartingWith("created")).check(text(endsWith("authorized")));
}
 
开发者ID:braintree,项目名称:braintree_android,代码行数:12,代码来源:DropInTest.java

示例7: testInstructionsBackcase

import android.support.test.filters.RequiresDevice; //导入依赖的package包/类
@Test
    @RequiresDevice
    public void testInstructionsBackcase() {

        goToMainScreen();

        gotoSurveyForm();

        clickExternalSourceButton(0);

        sleep(1000);

        mDevice.waitForIdle();

        TestUtil.sleep(1000);

        String id = Constants.FLUORIDE_ID.substring(
                Constants.FLUORIDE_ID.lastIndexOf("-") + 1, Constants.FLUORIDE_ID.length());

        takeScreenshot(id, -1);

        mDevice.waitForIdle();

//        onView(withText(getString(mActivityTestRule.getActivity(), R.string.instructions))).perform(click());
//
//        for (int i = 0; i < 17; i++) {
//
//            try {
//                takeScreenshot(id, i);
//
//                onView(withId(R.id.image_pageRight)).perform(click());
//
//            } catch (Exception e) {
//                TestUtil.sleep(600);
//                Espresso.pressBack();
//                break;
//            }
//        }
    }
 
开发者ID:akvo,项目名称:akvo-caddisfly,代码行数:40,代码来源:ChamberInstructions.java

示例8: testFreeChlorine

import android.support.test.filters.RequiresDevice; //导入依赖的package包/类
@Test
@RequiresDevice
public void testFreeChlorine() {
    saveCalibration("TestValidChlorine", Constants.FREE_CHLORINE_ID_2);

    onView(withId(R.id.actionSettings)).perform(click());

    onView(withText(R.string.about)).check(matches(isDisplayed()));
}
 
开发者ID:akvo,项目名称:akvo-caddisfly,代码行数:10,代码来源:ChamberTest.java

示例9: startStriptest

import android.support.test.filters.RequiresDevice; //导入依赖的package包/类
@Test
@RequiresDevice
public void startStriptest() {

    activateTestMode();

    test5in1(false);
    testSoilNitrogen(false);
    testMerckPH(false);
    testNitrate100();

    test5in1(true);
    testSoilNitrogen(true);
    testMerckPH(true);
}
 
开发者ID:akvo,项目名称:akvo-caddisfly,代码行数:16,代码来源:StriptestTest.java

示例10: testPrepare

import android.support.test.filters.RequiresDevice; //导入依赖的package包/类
@Test
@RequiresDevice
public void testPrepare () throws Exception {
	final Activity activity = waitForActivityStart(null);
	assertNotNull("Started activity should not be null!", activity);

	WebViewApp.setCurrentApp(new MockWebViewApp() {
		@Override
		public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
			super.sendEvent(eventCategory, eventId, params);

			DeviceLog.debug("Event: " + eventCategory.name() + ", " + eventId.name());

			if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PREPARED)) {
				if (CONDITION_VARIABLE != null)
					CONDITION_VARIABLE.open();
			}

			return true;
		}
	});

	final String validUrl = TestUtilities.getTestServerAddress() + "/blue_test_trailer.mp4";
	final Handler handler = new Handler(Looper.getMainLooper());

	final ConditionVariable viewAddCV = new ConditionVariable();
	handler.post(new Runnable() {
		@Override
		public void run() {
			((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW = new VideoPlayerView(getInstrumentation().getTargetContext());
			activity.addContentView(((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
			viewAddCV.open();
		}
	});
	boolean success = viewAddCV.block(3000);
	assertTrue("ConditionVariable did not open in view add", success);

	MockWebViewApp mockWebViewApp = (MockWebViewApp)WebViewApp.getCurrentApp();
	ConditionVariable prepareCV = new ConditionVariable();
	mockWebViewApp.CONDITION_VARIABLE = prepareCV;
	DeviceLog.debug("URL_GIVEN: " + validUrl);
	((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.prepare(validUrl, 1f, 0);
	success = prepareCV.block(30000);

	assertTrue("Condition Variable was not opened: PREPARE or PREPARE ERROR event was not received", success);
	assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
 
开发者ID:Unity-Technologies,项目名称:unity-ads-android,代码行数:48,代码来源:VideoViewTest.java

示例11: testPrepareAndPlay

import android.support.test.filters.RequiresDevice; //导入依赖的package包/类
@Test
@RequiresDevice
public void testPrepareAndPlay () throws Exception {
	final Activity activity = waitForActivityStart(null);

	WebViewApp.setCurrentApp(new MockWebViewApp() {
		private boolean allowEvents = true;
		@Override
		public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
			super.sendEvent(eventCategory, eventId, params);
			if ("ON_FOCUS_GAINED".equals(eventId.name()) || "ON_FOCUS_LOST".equals(eventId.name())) {
				return true;
			}
			if (allowEvents) {
				EVENT_CATEGORIES.add(eventCategory);
				EVENTS.add(eventId);
				EVENT_PARAMS = params;
				EVENT_COUNT++;

				DeviceLog.debug(eventId.name());

				if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PREPARED)) {
					VIDEOPLAYER_VIEW.play();
				}
				if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.COMPLETED)) {
					allowEvents = false;
					CONDITION_VARIABLE.open();
				}
			}

			return true;
		}
	});

	final String validUrl = TestUtilities.getTestServerAddress() + "/blue_test_trailer.mp4";
	final Handler handler = new Handler(Looper.getMainLooper());

	final ConditionVariable viewAddCV = new ConditionVariable();
	handler.post(new Runnable() {
		@Override
		public void run() {
			((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW = new VideoPlayerView(getInstrumentation().getTargetContext());
			activity.addContentView(((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
			viewAddCV.open();
		}
	});
	boolean success = viewAddCV.block(3000);
	assertTrue("ConditionVariable did not open in view add", success);

	final MockWebViewApp mockWebViewApp = (MockWebViewApp)WebViewApp.getCurrentApp();
	ConditionVariable cv = new ConditionVariable();
	mockWebViewApp.CONDITION_VARIABLE = cv;
	DeviceLog.debug("URL_GIVEN: " + validUrl);
	((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.prepare(validUrl, 1f, 0);
	success = cv.block(30000);

	assertTrue("Condition Variable was not opened: COMPLETED or PREPARE ERROR event was not received", success);
	assertEquals("Event category should be videoplayer category", WebViewEventCategory.VIDEOPLAYER, mockWebViewApp.EVENT_CATEGORIES.get(0));
	assertEquals("Event ID should be completed", VideoPlayerEvent.COMPLETED, mockWebViewApp.EVENTS.get(mockWebViewApp.EVENTS.size() - 1));
	assertEquals("The video url and the url received from the completed event should be the same", validUrl, mockWebViewApp.EVENT_PARAMS[0]);
	assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
 
开发者ID:Unity-Technologies,项目名称:unity-ads-android,代码行数:63,代码来源:VideoViewTest.java

示例12: testPrepareAndPlayNonExistingUrl

import android.support.test.filters.RequiresDevice; //导入依赖的package包/类
@Test
@RequiresDevice
public void testPrepareAndPlayNonExistingUrl () throws Exception {
	final Activity activity = waitForActivityStart(null);

	WebViewApp.setCurrentApp(new MockWebViewApp() {
		private boolean allowEvents = true;
		@Override
		public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
			super.sendEvent(eventCategory, eventId, params);
			if ("ON_FOCUS_GAINED".equals(eventId.name()) || "ON_FOCUS_LOST".equals(eventId.name())) {
				return true;
			}
			if (allowEvents) {
				EVENT_CATEGORIES.add(eventCategory);
				EVENTS.add(eventId);
				EVENT_PARAMS = params;
				EVENT_COUNT++;

				DeviceLog.debug(eventId.name());

				if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PREPARED)) {
					VIDEOPLAYER_VIEW.play();
				}
				if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.GENERIC_ERROR)) {
					allowEvents = false;
					CONDITION_VARIABLE.open();
				}
			}

			return true;
		}
	});

	final String invalidUrl = TestUtilities.getTestServerAddress() + "/blue_test_trailer-invalid.mp4";
	final Handler handler = new Handler(Looper.getMainLooper());

	final ConditionVariable viewAddCV = new ConditionVariable();
	handler.post(new Runnable() {
		@Override
		public void run() {
			((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW = new VideoPlayerView(getInstrumentation().getTargetContext());
			activity.addContentView(((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
			viewAddCV.open();
		}
	});
	boolean success = viewAddCV.block(3000);
	assertTrue("ConditionVariable did not open in view add", success);

	final MockWebViewApp mockWebViewApp = (MockWebViewApp)WebViewApp.getCurrentApp();
	ConditionVariable cv = new ConditionVariable();
	mockWebViewApp.CONDITION_VARIABLE = cv;
	DeviceLog.debug("URL_GIVEN: " + invalidUrl);
	((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.prepare(invalidUrl, 1f, 0);
	success = cv.block(30000);

	assertTrue("Condition Variable was not opened: VIDEOPLAYER GENERIC ERROR or PREPARE ERROR was not received", success);
	assertEquals("Event category should be videoplayer category", WebViewEventCategory.VIDEOPLAYER, mockWebViewApp.EVENT_CATEGORIES.get(0));
	assertEquals("Event ID should be generic error", VideoPlayerEvent.GENERIC_ERROR, mockWebViewApp.EVENTS.get(0));
	assertEquals("The video url and the url received from the completed event should be the same", invalidUrl, mockWebViewApp.EVENT_PARAMS[0]);
	assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
 
开发者ID:Unity-Technologies,项目名称:unity-ads-android,代码行数:63,代码来源:VideoViewTest.java

示例13: testPreparePlaySeekToPause

import android.support.test.filters.RequiresDevice; //导入依赖的package包/类
@Test
@RequiresDevice
public void testPreparePlaySeekToPause () throws Exception {
	final Activity activity = waitForActivityStart(null);

	WebViewApp.setCurrentApp(new MockWebViewApp() {
		private boolean allowEvents = true;
		@Override
		public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
			super.sendEvent(eventCategory, eventId, params);

			if ("ON_FOCUS_GAINED".equals(eventId.name()) || "ON_FOCUS_LOST".equals(eventId.name())) {
				return true;
			}

			EVENT_CATEGORIES.add(eventCategory);
			EVENTS.add(eventId);
			EVENT_PARAMS = params;
			EVENT_COUNT++;

			if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PREPARED)) {
				VIDEOPLAYER_VIEW.play();
			}
			if (!EVENT_TRIGGERED && eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PROGRESS)) {
				EVENT_TRIGGERED = true;
				VIDEOPLAYER_VIEW.seekTo(4080);
				VIDEOPLAYER_VIEW.pause();
				CONDITION_VARIABLE.open();
				allowEvents = false;
			}

			return true;
		}
	});

	final String validUrl = TestUtilities.getTestServerAddress() + "/blue_test_trailer.mp4";
	final Handler handler = new Handler(Looper.getMainLooper());
	final ConditionVariable viewAddCV = new ConditionVariable();
	handler.post(new Runnable() {
		@Override
		public void run() {
			((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW = new VideoPlayerView(getInstrumentation().getTargetContext());
			activity.addContentView(((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
			viewAddCV.open();
		}
	});
	boolean success = viewAddCV.block(3000);
	assertTrue("ConditionVariable did not open in view add", success);

	final MockWebViewApp mockWebViewApp = (MockWebViewApp)WebViewApp.getCurrentApp();
	ConditionVariable cv = new ConditionVariable();
	mockWebViewApp.CONDITION_VARIABLE = cv;
	DeviceLog.debug("URL_GIVEN: " + validUrl);
	((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.prepare(validUrl, 1f, 0);
	success = cv.block(30000);

	assertTrue("Condition Variable was not opened: PROGRESS or PREPARE ERROR event was not received", success);
	assertTrue("Current position should be over 300ms", mockWebViewApp.VIDEOPLAYER_VIEW.getCurrentPosition() > 300);
	int diff = Math.abs(4080 - mockWebViewApp.VIDEOPLAYER_VIEW.getCurrentPosition());
	DeviceLog.debug("Difference: " + diff);
	assertTrue("Difference between expected position and actual position should be less than 300ms", diff < 300);
	assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
 
开发者ID:Unity-Technologies,项目名称:unity-ads-android,代码行数:64,代码来源:VideoViewTest.java

示例14: testPreparePlayStop

import android.support.test.filters.RequiresDevice; //导入依赖的package包/类
@Test
@RequiresDevice
public void testPreparePlayStop () throws Exception {
	final Activity activity = waitForActivityStart(null);

	WebViewApp.setCurrentApp(new MockWebViewApp() {
		@Override
		public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
			super.sendEvent(eventCategory, eventId, params);

			if ("ON_FOCUS_GAINED".equals(eventId.name()) || "ON_FOCUS_LOST".equals(eventId.name())) {
				return true;
			}

			EVENT_CATEGORIES.add(eventCategory);
			EVENTS.add(eventId);
			EVENT_PARAMS = params;
			EVENT_COUNT++;

			if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PREPARED)) {
				VIDEOPLAYER_VIEW.play();
			}
			if (!EVENT_TRIGGERED && eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PROGRESS)) {
				if (EVENT_COUNT > 8) {
					EVENT_TRIGGERED = true;
					VIDEOPLAYER_VIEW.stop();
					CONDITION_VARIABLE.open();
				}
			}

			return true;
		}
	});

	final String validUrl = TestUtilities.getTestServerAddress() + "/blue_test_trailer.mp4";

	final Handler handler = new Handler(Looper.getMainLooper());
	final ConditionVariable viewAddCV = new ConditionVariable();
	handler.post(new Runnable() {
		@Override
		public void run() {
			((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW = new VideoPlayerView(getInstrumentation().getTargetContext());
			activity.addContentView(((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
			viewAddCV.open();
		}
	});
	boolean success = viewAddCV.block(3000);
	assertTrue("ConditionVariable did not open in view add", success);

	final MockWebViewApp mockWebViewApp = (MockWebViewApp)WebViewApp.getCurrentApp();
	ConditionVariable cv = new ConditionVariable();
	mockWebViewApp.CONDITION_VARIABLE = cv;
	((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.prepare(validUrl, 1f, 0);
	success = cv.block(30000);

	assertTrue("Condition Variable was not opened: PREPARED or PREPARE ERROR event was not received", success);
	assertFalse("Videoplayer shoudn't be in isPlaying state", mockWebViewApp.VIDEOPLAYER_VIEW.isPlaying());
	assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
 
开发者ID:Unity-Technologies,项目名称:unity-ads-android,代码行数:60,代码来源:VideoViewTest.java

示例15: testPreparePlaySetVolumePause

import android.support.test.filters.RequiresDevice; //导入依赖的package包/类
@Test
@RequiresDevice
public void testPreparePlaySetVolumePause () throws Exception {
	final Activity activity = waitForActivityStart(null);

	WebViewApp.setCurrentApp(new MockWebViewApp() {
		@Override
		public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
			super.sendEvent(eventCategory, eventId, params);

			if ("ON_FOCUS_GAINED".equals(eventId.name()) || "ON_FOCUS_LOST".equals(eventId.name())) {
				return true;
			}

			EVENT_CATEGORIES.add(eventCategory);
			EVENTS.add(eventId);
			EVENT_PARAMS = params;
			EVENT_COUNT++;

			if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PREPARED)) {
				VIDEOPLAYER_VIEW.play();
			}
			if (!EVENT_TRIGGERED && eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PROGRESS)) {
				if (EVENT_COUNT > 8) {
					EVENT_TRIGGERED = true;
					VIDEOPLAYER_VIEW.setVolume(0.666f);
					VIDEOPLAYER_VIEW.pause();
					CONDITION_VARIABLE.open();
				}
			}

			return true;
		}
	});

	final String validUrl = TestUtilities.getTestServerAddress() + "/blue_test_trailer.mp4";

	final Handler handler = new Handler(Looper.getMainLooper());
	final ConditionVariable viewAddCV = new ConditionVariable();
	handler.post(new Runnable() {
		@Override
		public void run() {
			((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW = new VideoPlayerView(getInstrumentation().getTargetContext());
			activity.addContentView(((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
			viewAddCV.open();
		}
	});
	boolean success = viewAddCV.block(3000);
	assertTrue("ConditionVariable did not open in view add", success);

	final MockWebViewApp mockWebViewApp = (MockWebViewApp)WebViewApp.getCurrentApp();
	ConditionVariable cv = new ConditionVariable();
	mockWebViewApp.CONDITION_VARIABLE = cv;
	((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.prepare(validUrl, 1f, 0);
	success = cv.block(30000);

	assertTrue("Condition Variable was not opened: PREPARED or PREPARE ERROR event was not received", success);
	assertFalse("Videoplayer shouldn't be in isPlaying state", mockWebViewApp.VIDEOPLAYER_VIEW.isPlaying());
	assertEquals("getVolume should return the same value as what was set as volume", 0.666f, mockWebViewApp.VIDEOPLAYER_VIEW.getVolume());
	assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
 
开发者ID:Unity-Technologies,项目名称:unity-ads-android,代码行数:62,代码来源:VideoViewTest.java


注:本文中的android.support.test.filters.RequiresDevice类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。