當前位置: 首頁>>代碼示例>>Java>>正文


Java ConditionVariable.open方法代碼示例

本文整理匯總了Java中android.os.ConditionVariable.open方法的典型用法代碼示例。如果您正苦於以下問題:Java ConditionVariable.open方法的具體用法?Java ConditionVariable.open怎麽用?Java ConditionVariable.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.os.ConditionVariable的用法示例。


在下文中一共展示了ConditionVariable.open方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testInitTwoEnginesSimultaneously

import android.os.ConditionVariable; //導入方法依賴的package包/類
@SmallTest
@Feature({"Cronet"})
public void testInitTwoEnginesSimultaneously() throws Exception {
    final CronetTestFramework testFramework = startCronetTestFrameworkAndSkipLibraryInit();

    // Threads will block on runBlocker to ensure simultaneous execution.
    ConditionVariable runBlocker = new ConditionVariable(false);
    RequestThread thread1 = new RequestThread(testFramework, mUrl, runBlocker);
    RequestThread thread2 = new RequestThread(testFramework, mUrl404, runBlocker);

    thread1.start();
    thread2.start();
    runBlocker.open();
    thread1.join();
    thread2.join();
    assertEquals(200, thread1.mCallback.mResponseInfo.getHttpStatusCode());
    assertEquals(404, thread2.mCallback.mResponseInfo.getHttpStatusCode());
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:19,代碼來源:CronetUrlRequestContextTest.java

示例2: testInitAndShutdownOnMainThread

import android.os.ConditionVariable; //導入方法依賴的package包/類
@SmallTest
@Feature({"Cronet"})
public void testInitAndShutdownOnMainThread() throws Exception {
    final CronetTestFramework testFramework = startCronetTestFrameworkAndSkipLibraryInit();
    final ConditionVariable block = new ConditionVariable(false);

    // Post a task to main thread to init and shutdown on the main thread.
    Runnable blockingTask = new Runnable() {
        @Override
        public void run() {
            // Create new request context, loading the library.
            final CronetEngine cronetEngine = testFramework.initCronetEngine();
            // Shutdown right after init.
            cronetEngine.shutdown();
            // Verify that context is shutdown.
            try {
                cronetEngine.stopNetLog();
                fail("Should throw an exception.");
            } catch (Exception e) {
                assertEquals("Engine is shut down.", e.getMessage());
            }
            block.open();
        }
    };
    new Handler(Looper.getMainLooper()).post(blockingTask);
    // Wait for shutdown to complete on main thread.
    block.block();
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:29,代碼來源:CronetUrlRequestContextTest.java

示例3: maybeThrowCancelOrPause

import android.os.ConditionVariable; //導入方法依賴的package包/類
/**
 * Returns {@code false} if the callback should continue to advance the
 * stream.
 */
private boolean maybeThrowCancelOrPause(
        final BidirectionalStream stream, ConditionVariable stepBlock) {
    if (mResponseStep != mFailureStep || mFailureType == FailureType.NONE) {
        if (!mAutoAdvance) {
            stepBlock.open();
            return true;
        }
        return false;
    }

    if (mFailureType == FailureType.THROW_SYNC) {
        throw new IllegalStateException("Callback Exception.");
    }
    Runnable task = new Runnable() {
        public void run() {
            stream.cancel();
        }
    };
    if (mFailureType == FailureType.CANCEL_ASYNC
            || mFailureType == FailureType.CANCEL_ASYNC_WITHOUT_PAUSE) {
        getExecutor().execute(task);
    } else {
        task.run();
    }
    return mFailureType != FailureType.CANCEL_ASYNC_WITHOUT_PAUSE;
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:31,代碼來源:TestBidirectionalStreamCallback.java

示例4: OfflineLicenseHelper

import android.os.ConditionVariable; //導入方法依賴的package包/類
/**
 * Constructs an instance. Call {@link #release()} when the instance is no longer required.
 *
 * @param mediaDrm An underlying {@link ExoMediaDrm} for use by the manager.
 * @param callback Performs key and provisioning requests.
 * @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument
 *     to {@link MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null.
 * @see DefaultDrmSessionManager#DefaultDrmSessionManager(java.util.UUID, ExoMediaDrm,
 *     MediaDrmCallback, HashMap, Handler, EventListener)
 */
public OfflineLicenseHelper(ExoMediaDrm<T> mediaDrm, MediaDrmCallback callback,
    HashMap<String, String> optionalKeyRequestParameters) {
  handlerThread = new HandlerThread("OfflineLicenseHelper");
  handlerThread.start();
  conditionVariable = new ConditionVariable();
  EventListener eventListener = new EventListener() {
    @Override
    public void onDrmKeysLoaded() {
      conditionVariable.open();
    }

    @Override
    public void onDrmSessionManagerError(Exception e) {
      conditionVariable.open();
    }

    @Override
    public void onDrmKeysRestored() {
      conditionVariable.open();
    }

    @Override
    public void onDrmKeysRemoved() {
      conditionVariable.open();
    }
  };
  drmSessionManager = new DefaultDrmSessionManager<>(C.WIDEVINE_UUID, mediaDrm, callback,
      optionalKeyRequestParameters, new Handler(handlerThread.getLooper()), eventListener);
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:40,代碼來源:OfflineLicenseHelper.java

示例5: OfflineLicenseHelper

import android.os.ConditionVariable; //導入方法依賴的package包/類
/**
 * Constructs an instance. Call {@link #releaseResources()} when you're done with it.
 *
 * @param mediaDrm An underlying {@link ExoMediaDrm} for use by the manager.
 * @param callback Performs key and provisioning requests.
 * @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument
 *     to {@link MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null.
 * @see DefaultDrmSessionManager#DefaultDrmSessionManager(java.util.UUID, ExoMediaDrm,
 *     MediaDrmCallback, HashMap, Handler, EventListener)
 */
public OfflineLicenseHelper(ExoMediaDrm<T> mediaDrm, MediaDrmCallback callback,
    HashMap<String, String> optionalKeyRequestParameters) {
  handlerThread = new HandlerThread("OfflineLicenseHelper");
  handlerThread.start();

  conditionVariable = new ConditionVariable();
  EventListener eventListener = new EventListener() {
    @Override
    public void onDrmKeysLoaded() {
      conditionVariable.open();
    }

    @Override
    public void onDrmSessionManagerError(Exception e) {
      conditionVariable.open();
    }

    @Override
    public void onDrmKeysRestored() {
      conditionVariable.open();
    }

    @Override
    public void onDrmKeysRemoved() {
      conditionVariable.open();
    }
  };
  drmSessionManager = new DefaultDrmSessionManager<>(C.WIDEVINE_UUID, mediaDrm, callback,
      optionalKeyRequestParameters, new Handler(handlerThread.getLooper()), eventListener);
}
 
開發者ID:jcodeing,項目名稱:K-Sonic,代碼行數:41,代碼來源:OfflineLicenseHelper.java

示例6: testValidGetWithNullHeaders

import android.os.ConditionVariable; //導入方法依賴的package包/類
@Test
public void testValidGetWithNullHeaders () throws Exception {
	final ConditionVariable cv = new ConditionVariable();
	MockWebViewApp webViewApp = new MockWebViewApp() {
		@Override
		public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
			EVENT_CATEGORY = eventCategory;
			EVENT_ID = eventId;
			EVENT_PARAMS = params;
			cv.open();

			return true;
		}
	};

	WebViewApp.setCurrentApp(webViewApp);
	Invocation invocation = new Invocation();
	WebViewCallback callback = new WebViewCallback("Test_Valid_Get_No_Headers", invocation.getId());
	Request.get("1", validUrl, null, connectTimeout, readTimeout, callback);
	invocation.sendInvocationCallback();
	boolean success = cv.block(30000);

	assertTrue("ConditionVariable was not opened", success);
	assertEquals("Callback status was not OK, successfull callback was expected", CallbackStatus.OK, CALLBACK_STATUS);
	assertNull("Callback error was not NULL, successfull callback was expected", CALLBACK_ERROR);
	assertEquals("Callback params list length was expected to be 2 (callback id and request id in params)", 2, CALLBACK_PARAMS.length);
	assertEquals("Callback first param was expected to be Callback ID", callback.getCallbackId(), CALLBACK_ID);
	assertEquals("Request has changed for some reason", validUrl, EVENT_PARAMS[1]);
	assertEquals("Response code was not OK (200)", 200, EVENT_PARAMS[3]);
	assertEquals("Event ID was incorrect", WebRequestEvent.COMPLETE, EVENT_ID);
	assertEquals("Event Category was incorrect", WebViewEventCategory.REQUEST, EVENT_CATEGORY);
}
 
開發者ID:Unity-Technologies,項目名稱:unity-ads-android,代碼行數:33,代碼來源:RequestTest.java

示例7: testValidPostWithNullHeaders

import android.os.ConditionVariable; //導入方法依賴的package包/類
@Test
public void testValidPostWithNullHeaders () throws Exception {
	final ConditionVariable cv = new ConditionVariable();
	MockWebViewApp webViewApp = new MockWebViewApp() {
		@Override
		public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
			EVENT_CATEGORY = eventCategory;
			EVENT_ID = eventId;
			EVENT_PARAMS = params;
			cv.open();

			return true;
		}
	};

	WebViewApp.setCurrentApp(webViewApp);
	Invocation invocation = new Invocation();
	WebViewCallback callback = new WebViewCallback("Test_Valid_Post_No_Headers", invocation.getId());
	Request.post("1", validUrl, null, null, connectTimeout, readTimeout, callback);
	invocation.sendInvocationCallback();

	boolean success = cv.block(30000);

	assertTrue("ConditionVariable was not opened", success);
	assertEquals("Callback status was not OK, successfull callback was expected", CallbackStatus.OK, CALLBACK_STATUS);
	assertNull("Callback error was not NULL, successfull callback was expected", CALLBACK_ERROR);
	assertEquals("Callback params list length was expected to be 2 (callback id and request id in params)", 2, CALLBACK_PARAMS.length);
	assertEquals("Callback first param was expected to be Callback ID", callback.getCallbackId(), CALLBACK_ID);

	assertEquals("Request has changed for some reason", validUrl, EVENT_PARAMS[1]);
	assertEquals("Response code was not OK (200)", 200, EVENT_PARAMS[3]);
	assertEquals("Event ID was incorrect", WebRequestEvent.COMPLETE, EVENT_ID);
	assertEquals("Event Category was incorrect", WebViewEventCategory.REQUEST, EVENT_CATEGORY);
}
 
開發者ID:Unity-Technologies,項目名稱:unity-ads-android,代碼行數:35,代碼來源:RequestTest.java

示例8: testValidPostWithNullHeadersAndPostBody

import android.os.ConditionVariable; //導入方法依賴的package包/類
@Test
public void testValidPostWithNullHeadersAndPostBody () throws Exception {
	final ConditionVariable cv = new ConditionVariable();
	MockWebViewApp webViewApp = new MockWebViewApp() {
		@Override
		public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
			EVENT_CATEGORY = eventCategory;
			EVENT_ID = eventId;
			EVENT_PARAMS = params;
			cv.open();

			return true;
		}
	};

	WebViewApp.setCurrentApp(webViewApp);
	Invocation invocation = new Invocation();
	WebViewCallback callback = new WebViewCallback("Test_Valid_Post_No_Headers_Post_Body", invocation.getId());
	Request.post("1", validUrl, "Testing Testing", null, connectTimeout, readTimeout, callback);
	invocation.sendInvocationCallback();

	boolean success = cv.block(30000);

	assertTrue("ConditionVariable was not opened", success);
	assertEquals("Callback status was not OK, successfull callback was expected", CallbackStatus.OK, CALLBACK_STATUS);
	assertNull("Callback error was not NULL, successfull callback was expected", CALLBACK_ERROR);
	assertEquals("Callback params list length was expected to be 2 (callback id and request id in params)", 2, CALLBACK_PARAMS.length);
	assertEquals("Callback first param was expected to be Callback ID", callback.getCallbackId(), CALLBACK_ID);

	assertEquals("Request has changed for some reason", validUrl, EVENT_PARAMS[1]);
	assertEquals("Response code was not OK (200)", 200, EVENT_PARAMS[3]);
	assertEquals("Event ID was incorrect", WebRequestEvent.COMPLETE, EVENT_ID);
	assertEquals("Event Category was incorrect", WebViewEventCategory.REQUEST, EVENT_CATEGORY);
}
 
開發者ID:Unity-Technologies,項目名稱:unity-ads-android,代碼行數:35,代碼來源:RequestTest.java

示例9: testInvalidUrlGetWithNullHeaders

import android.os.ConditionVariable; //導入方法依賴的package包/類
@Test
public void testInvalidUrlGetWithNullHeaders () throws Exception {
	final ConditionVariable cv = new ConditionVariable();
	MockWebViewApp webViewApp = new MockWebViewApp() {
		@Override
		public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
			EVENT_CATEGORY = eventCategory;
			EVENT_ID = eventId;
			EVENT_PARAMS = params;
			cv.open();

			return true;
		}
	};

	WebViewApp.setCurrentApp(webViewApp);
	Invocation invocation = new Invocation();
	WebViewCallback callback = new WebViewCallback("Test_InvalidUrl_Get_No_Headers", invocation.getId());
	Request.get("1", invalidUrl, null, connectTimeout, readTimeout, callback);
	invocation.sendInvocationCallback();

	boolean success = cv.block(30000);

	assertTrue("ConditionVariable was not opened", success);
	assertEquals("Callback status was not OK, successfull callback was expected", CallbackStatus.OK, CALLBACK_STATUS);
	assertNull("Callback error was not NULL, successfull callback was expected", CALLBACK_ERROR);
	assertEquals("Callback params list length was expected to be 2 (callback id and request id in params)", 2, CALLBACK_PARAMS.length);
	assertEquals("Callback first param was expected to be Callback ID", callback.getCallbackId(), CALLBACK_ID);
	assertEquals("Request has changed for some reason", invalidUrl, EVENT_PARAMS[1]);
	assertEquals("Expected three (3) params in event parameters", 3, EVENT_PARAMS.length);
	assertEquals("Event ID was incorrect", WebRequestEvent.FAILED, EVENT_ID);
	assertEquals("Event Category was incorrect", WebViewEventCategory.REQUEST, EVENT_CATEGORY);
}
 
開發者ID:Unity-Technologies,項目名稱:unity-ads-android,代碼行數:34,代碼來源:RequestTest.java

示例10: testInvalidUrlPostWithNullHeaders

import android.os.ConditionVariable; //導入方法依賴的package包/類
@Test
public void testInvalidUrlPostWithNullHeaders () throws Exception {
	final ConditionVariable cv = new ConditionVariable();
	MockWebViewApp webViewApp = new MockWebViewApp() {
		@Override
		public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
			EVENT_CATEGORY = eventCategory;
			EVENT_ID = eventId;
			EVENT_PARAMS = params;
			cv.open();

			return true;
		}
	};

	WebViewApp.setCurrentApp(webViewApp);
	Invocation invocation = new Invocation();
	WebViewCallback callback = new WebViewCallback("Test_InvalidUrl_Post_No_Headers", invocation.getId());
	Request.post("1", invalidUrl, null, null, connectTimeout, readTimeout, callback);
	invocation.sendInvocationCallback();

	boolean success = cv.block(30000);

	assertTrue("ConditionVariable was not opened", success);
	assertEquals("Callback status was not OK, successfull callback was expected", CallbackStatus.OK, CALLBACK_STATUS);
	assertNull("Callback error was not NULL, successfull callback was expected", CALLBACK_ERROR);
	assertEquals("Callback params list length was expected to be 2 (callback id and request id in params)", 2, CALLBACK_PARAMS.length);
	assertEquals("Callback first param was expected to be Callback ID", callback.getCallbackId(), CALLBACK_ID);
	assertEquals("Request has changed for some reason", invalidUrl, EVENT_PARAMS[1]);
	assertEquals("Expected two (3) params in event parameters", 3, EVENT_PARAMS.length);
	assertEquals("Event ID was incorrect", WebRequestEvent.FAILED, EVENT_ID);
	assertEquals("Event Category was incorrect", WebViewEventCategory.REQUEST, EVENT_CATEGORY);
}
 
開發者ID:Unity-Technologies,項目名稱:unity-ads-android,代碼行數:34,代碼來源:RequestTest.java

示例11: testValidGetWithInvalidHeader

import android.os.ConditionVariable; //導入方法依賴的package包/類
@SdkSuppress(minSdkVersion = 16)
@Test
public void testValidGetWithInvalidHeader () throws Exception {
	final ConditionVariable cv = new ConditionVariable();
	MockWebViewApp webViewApp = new MockWebViewApp() {
		@Override
		public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
			EVENT_CATEGORY = eventCategory;
			EVENT_ID = eventId;
			EVENT_PARAMS = params;
			cv.open();

			return true;
		}
	};

	JSONArray headers = new JSONArray("[[\"C,o-n#n#e*c*t*io*n\", \"close\"]]");
	WebViewApp.setCurrentApp(webViewApp);
	Invocation invocation = new Invocation();
	WebViewCallback callback = new WebViewCallback("Test_Valid_Get_With_Invalid_Header", invocation.getId());
	Request.get("1", validUrl, headers, connectTimeout, readTimeout, callback);
	invocation.sendInvocationCallback();

	boolean success = cv.block(30000);

	assertTrue("ConditionVariable was not opened", success);
	assertEquals("Callback status was not OK, successfull callback was expected", CallbackStatus.OK, CALLBACK_STATUS);
	assertNull("Callback error was not NULL, successfull callback was expected", CALLBACK_ERROR);
	assertEquals("Callback params list length was expected to be 2 (callback id and request id in params)", 2, CALLBACK_PARAMS.length);
	assertEquals("Callback first param was expected to be Callback ID", callback.getCallbackId(), CALLBACK_ID);
	assertEquals("Request has changed for some reason", validUrl, EVENT_PARAMS[1]);
	assertEquals("Expected three (3) params in event parameters", 3, EVENT_PARAMS.length);
	assertEquals("Event Category was incorrect", WebViewEventCategory.REQUEST, EVENT_CATEGORY);
	assertEquals("Event ID was incorrect", WebRequestEvent.FAILED, EVENT_ID);
}
 
開發者ID:Unity-Technologies,項目名稱:unity-ads-android,代碼行數:36,代碼來源:RequestTest.java

示例12: testValidPostWithInvalidHeader

import android.os.ConditionVariable; //導入方法依賴的package包/類
@SdkSuppress(minSdkVersion = 16)
@Test
public void testValidPostWithInvalidHeader () throws Exception {
	final ConditionVariable cv = new ConditionVariable();
	MockWebViewApp webViewApp = new MockWebViewApp() {
		@Override
		public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
			EVENT_CATEGORY = eventCategory;
			EVENT_ID = eventId;
			EVENT_PARAMS = params;
			cv.open();

			return true;
		}
	};

	JSONArray headers = new JSONArray("[[\"C,o-n#n#e*c*t*io*n\", \"close\"]]");
	WebViewApp.setCurrentApp(webViewApp);
	Invocation invocation = new Invocation();
	WebViewCallback callback = new WebViewCallback("Test_Valid_Post_With_Invalid_Header", invocation.getId());
	Request.post("1", validUrl, null, headers, connectTimeout, readTimeout, callback);
	invocation.sendInvocationCallback();

	boolean success = cv.block(30000);

	assertTrue("ConditionVariable was not opened", success);
	assertEquals("Callback status was not OK, successfull callback was expected", CallbackStatus.OK, CALLBACK_STATUS);
	assertNull("Callback error was not NULL, successfull callback was expected", CALLBACK_ERROR);
	assertEquals("Callback params list length was expected to be 2 (callback id and request id in params)", 2, CALLBACK_PARAMS.length);
	assertEquals("Callback first param was expected to be Callback ID", callback.getCallbackId(), CALLBACK_ID);
	assertEquals("Request has changed for some reason", validUrl, EVENT_PARAMS[1]);
	assertEquals("Expected three (3) params in event parameters", 3, EVENT_PARAMS.length);
	assertEquals("Event Category was incorrect", WebViewEventCategory.REQUEST, EVENT_CATEGORY);
	assertEquals("Event ID was incorrect", WebRequestEvent.FAILED, EVENT_ID);
}
 
開發者ID:Unity-Technologies,項目名稱:unity-ads-android,代碼行數:36,代碼來源:RequestTest.java

示例13: testGetStatusForUpload

import android.os.ConditionVariable; //導入方法依賴的package包/類
@SmallTest
@Feature({"Cronet"})
// Regression test for crbug.com/606872.
@OnlyRunNativeCronet
public void testGetStatusForUpload() throws Exception {
    TestUrlRequestCallback callback = new TestUrlRequestCallback();
    UrlRequest.Builder builder = new UrlRequest.Builder(NativeTestServer.getEchoBodyURL(),
            callback, callback.getExecutor(), mTestFramework.mCronetEngine);

    final ConditionVariable block = new ConditionVariable();
    // Use a separate executor for UploadDataProvider so the upload can be
    // stalled while getStatus gets processed.
    Executor uploadProviderExecutor = Executors.newSingleThreadExecutor();
    TestUploadDataProvider dataProvider = new TestUploadDataProvider(
            TestUploadDataProvider.SuccessCallbackMode.SYNC, uploadProviderExecutor) {
        @Override
        public long getLength() throws IOException {
            // Pause the data provider.
            block.block();
            block.close();
            return super.getLength();
        }
    };
    dataProvider.addRead("test".getBytes());
    builder.setUploadDataProvider(dataProvider, uploadProviderExecutor);
    builder.addHeader("Content-Type", "useless/string");
    UrlRequest urlRequest = builder.build();
    TestStatusListener statusListener = new TestStatusListener();
    urlRequest.start();
    // Call getStatus() immediately after start(), which will post
    // startInternal() to the upload provider's executor because there is an
    // upload. When CronetUrlRequestAdapter::GetStatusOnNetworkThread is
    // executed, the |url_request_| is null.
    urlRequest.getStatus(statusListener);
    statusListener.waitUntilOnStatusCalled();
    assertTrue(statusListener.mOnStatusCalled);
    // The request should be in IDLE state because GetStatusOnNetworkThread
    // is called before |url_request_| is initialized and started.
    assertEquals(Status.IDLE, statusListener.mStatus);
    // Resume the UploadDataProvider.
    block.open();

    // Make sure the request is successful and there is no crash.
    callback.blockForDone();
    dataProvider.assertClosed();

    assertEquals(4, dataProvider.getUploadedLength());
    assertEquals(1, dataProvider.getNumReadCalls());
    assertEquals(0, dataProvider.getNumRewindCalls());

    assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
    assertEquals("test", callback.mResponseAsString);
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:54,代碼來源:GetStatusTest.java

示例14: doRelease

import android.os.ConditionVariable; //導入方法依賴的package包/類
private void doRelease(ConditionVariable conditionVariable) {
    mIoHandler.removeCallbacksAndMessages(null);
    mFinished = true;
    conditionVariable.open();
}
 
開發者ID:trevd,項目名稱:android_packages_apps_tv,代碼行數:6,代碼來源:SampleChunkIoHelper.java

示例15: testTwoReceivers

import android.os.ConditionVariable; //導入方法依賴的package包/類
@Test
public void testTwoReceivers() throws JSONException {
	final String jsonAction = "com.unity3d.ads.ACTION_JSON";
	final String jsonReceiverName = "jsonReceiver";
	final String dataSchemeAction = "com.unity3d.ads.ACTION_DATA_SCHEME";
	final String dataSchemeReceiverName = "dataSchemeReceiver";

	final String testDataScheme = "test";
	final String testDataHost = "example.net";
	final String testDataPath = "/path";

	final String testStringKey = "testString";
	final String testBoolKey = "testBoolean";
	final String testLongKey = "testLong";
	final String testStringValue = "example";
	final boolean testBoolValue = true;
	final long testLongValue = (long)1234;

	final ConditionVariable jsonCv = new ConditionVariable();
	final ConditionVariable dataSchemeCv = new ConditionVariable();

	MockWebViewApp webapp = new MockWebViewApp() {
		@Override
		public void broadcastEvent(BroadcastEvent eventId, String name, String action, String data, JSONObject extras) {
			assertEquals("Broadcast test two receivers: wrong event id", eventId, BroadcastEvent.ACTION);
			assertTrue("Broadcast test two receivers: receiver name does not match json or data scheme receiver names", name.equals(jsonReceiverName) || name.equals(dataSchemeReceiverName));

			if(name.equals(jsonReceiverName)) {
				assertEquals("Broadcast test two receivers: action does not match", jsonAction, action);
				assertEquals("Broadcast test two receivers: there should be no data in event", "", data);
				assertEquals("Broadcast test two receivers: broadcast was sent with three values in extra bundle", 3, extras.length());
				try {
					assertEquals("Broadcast test two receivers: problem with string in bundle extras", testStringValue, extras.getString(testStringKey));
					assertEquals("Broadcast test two receivers: problem with boolean in bundle extras", testBoolValue, extras.getBoolean(testBoolKey));
					assertEquals("Broadcast test two receivers: problem with long in bundle extras", testLongValue, extras.getLong(testLongKey));
				} catch(JSONException e) {
					fail("Broadcast test two receivers: JSONException: " + e.getMessage());
				}

				jsonCv.open();
			} else {
				assertEquals("Broadcast test two receivers: action does not match", dataSchemeAction, action);
				assertEquals("Broadcast test two receivers: there should be no bundle extras in this event", 0, extras.length());

				Uri testUri = Uri.parse(data);
				assertEquals("Broadcast test two receivers: data scheme does not match", testDataScheme, testUri.getScheme());
				assertEquals("Broadcast test two receivers: data host does not match", testDataHost, testUri.getHost());
				assertEquals("Broadcast test two receivers: data path does not match", testDataPath, testUri.getPath());

				dataSchemeCv.open();
			}
		}
	};
	WebViewApp.setCurrentApp(webapp);
	WebViewApp.getCurrentApp().setWebAppLoaded(true);
	SdkProperties.setInitialized(true);

	BroadcastMonitor.addBroadcastListener(jsonReceiverName, null, new String[]{jsonAction});
	BroadcastMonitor.addBroadcastListener(dataSchemeReceiverName, testDataScheme, new String[]{dataSchemeAction});

	Intent jsonIntent = new Intent();
	jsonIntent.setAction(jsonAction);
	jsonIntent.putExtra(testStringKey, testStringValue);
	jsonIntent.putExtra(testBoolKey, testBoolValue);
	jsonIntent.putExtra(testLongKey, testLongValue);
	ClientProperties.getApplicationContext().sendBroadcast(jsonIntent);

	boolean success = jsonCv.block(30000);
	assertTrue("Broadcast test two receivers: ", success);

	Intent dataIntent = new Intent();
	dataIntent.setAction(dataSchemeAction);
	dataIntent.setData(Uri.parse(testDataScheme + "://" + testDataHost + testDataPath));
	ClientProperties.getApplicationContext().sendBroadcast(dataIntent);

	boolean success2 = dataSchemeCv.block(30000);
	assertTrue("Broadcast test two receivers: ", success2);
}
 
開發者ID:Unity-Technologies,項目名稱:unity-ads-android,代碼行數:79,代碼來源:BroadcastTest.java


注:本文中的android.os.ConditionVariable.open方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。