Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2047)

Unified Diff: mojo/android/javatests/src/org/chromium/mojo/bindings/InterfaceControlMessageTest.java

Issue 1127293003: Update mojo sdk to rev f84766d3b6420b7cf6a113d9d65d73cb5fe18d90 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: formatting Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/android/javatests/src/org/chromium/mojo/bindings/InterfaceControlMessageTest.java
diff --git a/mojo/android/javatests/src/org/chromium/mojo/bindings/InterfaceControlMessageTest.java b/mojo/android/javatests/src/org/chromium/mojo/bindings/InterfaceControlMessageTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..c101675186b5148ba45dfa63f1bcafdda827ff4e
--- /dev/null
+++ b/mojo/android/javatests/src/org/chromium/mojo/bindings/InterfaceControlMessageTest.java
@@ -0,0 +1,129 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.mojo.bindings;
+
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.chromium.mojo.MojoTestCase;
+import org.chromium.mojo.bindings.Callbacks.Callback1;
+import org.chromium.mojo.bindings.test.mojom.sample.Enum;
+import org.chromium.mojo.bindings.test.mojom.sample.IntegerAccessor;
+import org.chromium.mojo.system.MojoException;
+
+import java.io.Closeable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Tests for interface control messages.
+ */
+public class InterfaceControlMessageTest extends MojoTestCase {
+ private final List<Closeable> mCloseablesToClose = new ArrayList<Closeable>();
+
+ /**
+ * See mojo/public/interfaces/bindings/tests/sample_interfaces.mojom.
+ */
+ class IntegerAccessorImpl extends SideEffectFreeCloseable implements IntegerAccessor {
+ private long mValue = 0;
+ private int mEnum = 0;
+ private boolean mEncounteredError = false;
+
+ /**
+ * @see ConnectionErrorHandler#onConnectionError(MojoException)
+ */
+ @Override
+ public void onConnectionError(MojoException e) {
+ mEncounteredError = true;
+ }
+
+ /**
+ * @see IntegerAccessor#getInteger(IntegerAccessor.GetIntegerResponse)
+ */
+ @Override
+ public void getInteger(GetIntegerResponse response) {
+ response.call(mValue, mEnum);
+ }
+
+ /**
+ * @see IntegerAccessor#setInteger(long, int)
+ */
+ @Override
+ public void setInteger(long value, int enumValue) {
+ mValue = value;
+ mEnum = enumValue;
+ }
+
+ public long getValue() {
+ return mValue;
+ }
+
+ public boolean encounteredError() {
+ return mEncounteredError;
+ }
+ }
+
+ /**
+ * @see MojoTestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ // Close the elements in the reverse order they were added. This is needed because it is an
+ // error to close the handle of a proxy without closing the proxy first.
+ Collections.reverse(mCloseablesToClose);
+ for (Closeable c : mCloseablesToClose) {
+ c.close();
+ }
+ super.tearDown();
+ }
+
+ @SmallTest
+ public void testQueryVersion() {
+ IntegerAccessor.Proxy p = BindingsTestUtils.newProxyOverPipe(
+ IntegerAccessor.MANAGER, new IntegerAccessorImpl(), mCloseablesToClose);
+ assertEquals(0, p.getProxyHandler().getVersion());
+ p.getProxyHandler().queryVersion(new Callback1<Integer>() {
+ @Override
+ public void call(Integer version) {
+ assertEquals(3, version.intValue());
+ }
+ });
+ runLoopUntilIdle();
+ assertEquals(3, p.getProxyHandler().getVersion());
+ }
+
+ @SmallTest
+ public void testRequireVersion() {
+ IntegerAccessorImpl impl = new IntegerAccessorImpl();
+ IntegerAccessor.Proxy p = BindingsTestUtils.newProxyOverPipe(
+ IntegerAccessor.MANAGER, impl, mCloseablesToClose);
+
+ assertEquals(0, p.getProxyHandler().getVersion());
+
+ p.getProxyHandler().requireVersion(1);
+ assertEquals(1, p.getProxyHandler().getVersion());
+ p.setInteger(123, Enum.VALUE);
+ runLoopUntilIdle();
+ assertFalse(impl.encounteredError());
+ assertEquals(123, impl.getValue());
+
+ p.getProxyHandler().requireVersion(3);
+ assertEquals(3, p.getProxyHandler().getVersion());
+ p.setInteger(456, Enum.VALUE);
+ runLoopUntilIdle();
+ assertFalse(impl.encounteredError());
+ assertEquals(456, impl.getValue());
+
+ // Require a version that is not supported by the implementation side.
+ p.getProxyHandler().requireVersion(4);
+ // getVersion() is updated synchronously.
+ assertEquals(4, p.getProxyHandler().getVersion());
+ p.setInteger(789, Enum.VALUE);
+ runLoopUntilIdle();
+ assertTrue(impl.encounteredError());
+ // The call to setInteger() after requireVersion() is ignored.
+ assertEquals(456, impl.getValue());
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698