• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java RequiresDevice类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: testSetProgressInterval

import android.support.test.filters.RequiresDevice; //导入依赖的package包/类
@Test
@RequiresDevice
public void testSetProgressInterval () 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 (eventId.equals(VideoPlayerEvent.PROGRESS)) {
				EVENT_POSITIONS.add(System.currentTimeMillis());
			}

			if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PREPARED)) {
				VIDEOPLAYER_VIEW.play();
			}
			else if (!EVENT_TRIGGERED && eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PROGRESS)) {
				if (EVENT_COUNT > 12) {
					EVENT_TRIGGERED = true;
					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.setProgressEventInterval(300);
	((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.prepare(validUrl, 1f, 0);
	success = cv.block(30000);

	assertTrue("Condition Variable was not opened: VIDEO PROGRESS or PREPARE ERROR event was not received", success);

	int failedIntervals = 0;

	for (int idx = 0; idx < EVENT_POSITIONS.size(); idx++) {
		if (idx + 1 < EVENT_POSITIONS.size()) {
			long interval = Math.abs(300 - (EVENT_POSITIONS.get(idx + 1) - EVENT_POSITIONS.get(idx)));
			DeviceLog.debug("Interval is: " + interval);

			if (interval > 80) {
				failedIntervals++;
			}

			assertFalse("Too many intervals failed to arrive in 80ms threshold (" + failedIntervals + ")", failedIntervals > 3);
		}
	}

	assertFalse("Videoplayer shouldn't be in isPlaying state", mockWebViewApp.VIDEOPLAYER_VIEW.isPlaying());
	assertEquals("getProgressInterval should return the same value as what was set", 300, mockWebViewApp.VIDEOPLAYER_VIEW.getProgressEventInterval());
	assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
 
开发者ID:Unity-Technologies,项目名称:unity-ads-android,代码行数:82,代码来源:VideoViewTest.java


示例17: testPreparePlayPause

import android.support.test.filters.RequiresDevice; //导入依赖的package包/类
@Test
@RequiresDevice
public void testPreparePlayPause () 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();
			}
			else if (!EVENT_TRIGGERED && eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.PROGRESS)) {
				if (EVENT_COUNT > 6) {
					EVENT_TRIGGERED = true;
					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: VIDEO PROGRESS or PREPARE ERROR event was not received", success);
	assertTrue("Current position should be over 300ms", mockWebViewApp.VIDEOPLAYER_VIEW.getCurrentPosition() > 300);
	assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
 
开发者ID:Unity-Technologies,项目名称:unity-ads-android,代码行数:60,代码来源:VideoViewTest.java


示例18: testInfoListener

import android.support.test.filters.RequiresDevice; //导入依赖的package包/类
@Test
@RequiresDevice
@SdkSuppress(minSdkVersion = 17)
public void testInfoListener () 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 (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.INFO)) {
				INFO_EVENTS = new ArrayList<>();
				INFO_EVENTS.add((Integer) params[1]);
			}
			if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.COMPLETED)) {
				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: 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]);
	assertNotNull("Info events should not be NULL", mockWebViewApp.INFO_EVENTS);
	assertTrue("There should be at least one INFO event received", mockWebViewApp.INFO_EVENTS.size() > 0);
	assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
 
开发者ID:Unity-Technologies,项目名称:unity-ads-android,代码行数:65,代码来源:VideoViewTest.java


示例19: testDisableInfoListener

import android.support.test.filters.RequiresDevice; //导入依赖的package包/类
@Test
@RequiresDevice
@SdkSuppress(minSdkVersion = 17)
public void testDisableInfoListener () 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 (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.INFO)) {
				INFO_EVENTS = new ArrayList<>();
				INFO_EVENTS.add((Integer) params[1]);
			}
			if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.COMPLETED)) {
				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.setInfoListenerEnabled(true);
	((MockWebViewApp)WebViewApp.getCurrentApp()).VIDEOPLAYER_VIEW.setInfoListenerEnabled(false);
	((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]);
	assertNull("No info-events shoul've been received", mockWebViewApp.INFO_EVENTS);
	assertTrue("Didn't get activity finish", waitForActivityFinish(activity));
}
 
开发者ID:Unity-Technologies,项目名称:unity-ads-android,代码行数:66,代码来源:VideoViewTest.java


示例20: testEnableInfoListener

import android.support.test.filters.RequiresDevice; //导入依赖的package包/类
@Test
@RequiresDevice
@SdkSuppress(minSdkVersion = 17)
public void testEnableInfoListener () 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 (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.INFO)) {
				INFO_EVENTS = new ArrayList<>();
				INFO_EVENTS.add((Integer) params[1]);
			}
			if (eventCategory.equals(WebViewEventCategory.VIDEOPLAYER) && eventId.equals(VideoPlayerEvent.COMPLETED)) {
				CONDITION_VARIABLE.open();
			}

			return true;
		}
	});

	final String validUrl = 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OFTableFeatureProp类代码示例发布时间:2022-05-22
下一篇:
Java RegExpResult类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap