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

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/ServiceRegistryTest.java

Issue 2191033002: Split ServiceRegistryAndroid into InterfaceRegistryAndroid and InterfaceProviderAndroid (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 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: content/public/android/javatests/src/org/chromium/content/browser/ServiceRegistryTest.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ServiceRegistryTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ServiceRegistryTest.java
deleted file mode 100644
index d26bbb755c77cb12c337fca95c63d00bab3a8f23..0000000000000000000000000000000000000000
--- a/content/public/android/javatests/src/org/chromium/content/browser/ServiceRegistryTest.java
+++ /dev/null
@@ -1,203 +0,0 @@
-// Copyright 2014 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.content.browser;
-
-import android.test.suitebuilder.annotation.SmallTest;
-
-import org.chromium.base.library_loader.LibraryLoader;
-import org.chromium.base.library_loader.LibraryProcessType;
-import org.chromium.content.browser.ServiceRegistry.ImplementationFactory;
-import org.chromium.content_shell.ShellMojoTestUtils;
-import org.chromium.content_shell_apk.ContentShellTestBase;
-import org.chromium.mojo.bindings.ConnectionErrorHandler;
-import org.chromium.mojo.bindings.InterfaceRequest;
-import org.chromium.mojo.bindings.test.mojom.math.Calculator;
-import org.chromium.mojo.system.MojoException;
-import org.chromium.mojo.system.Pair;
-import org.chromium.mojo.system.impl.CoreImpl;
-
-import java.io.Closeable;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Instrumentation tests for ServiceRegistry.
- */
-public class ServiceRegistryTest extends ContentShellTestBase {
-
- private static final long RUN_LOOP_TIMEOUT_MS = 25;
-
- private final List<Closeable> mCloseablesToClose = new ArrayList<Closeable>();
- private long mNativeTestEnvironment;
-
- static class CalcConnectionErrorHandler implements ConnectionErrorHandler {
-
- MojoException mLastMojoException;
-
- @Override
- public void onConnectionError(MojoException e) {
- mLastMojoException = e;
- }
- }
-
- static class CalcCallback implements Calculator.AddResponse, Calculator.MultiplyResponse {
-
- double mResult = 0.0;
-
- @Override
- public void call(Double result) {
- mResult = result;
- }
-
- public double getResult() {
- return mResult;
- }
- }
-
- static class CalculatorImpl implements Calculator {
-
- double mResult = 0.0;
-
- @Override
- public void close() {}
-
- @Override
- public void onConnectionError(MojoException e) {}
-
- @Override
- public void clear(ClearResponse callback) {
- mResult = 0.0;
- callback.call(mResult);
- }
-
- @Override
- public void add(double value, AddResponse callback) {
- mResult += value;
- callback.call(mResult);
- }
-
- @Override
- public void multiply(double value, MultiplyResponse callback) {
- mResult *= value;
- callback.call(mResult);
- }
- }
-
- static class CalculatorFactory implements ImplementationFactory<Calculator> {
-
- @Override
- public Calculator createImpl() {
- return new CalculatorImpl();
- }
- }
-
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized(
- getInstrumentation().getTargetContext());
- launchContentShellWithUrl("about://blank");
- mNativeTestEnvironment = ShellMojoTestUtils.setupTestEnvironment();
- }
-
- @Override
- protected void tearDown() throws Exception {
- for (Closeable c : mCloseablesToClose) {
- c.close();
- }
- ShellMojoTestUtils.tearDownTestEnvironment(mNativeTestEnvironment);
- mNativeTestEnvironment = 0;
- super.tearDown();
- }
-
- /**
- * Verifies that remote service can be requested and works.
- */
- @SmallTest
- public void testConnectToService() {
- Pair<ServiceRegistry, ServiceRegistry> registryPair =
- ShellMojoTestUtils.createServiceRegistryPair(mNativeTestEnvironment);
- ServiceRegistry serviceRegistryA = registryPair.first;
- ServiceRegistry serviceRegistryB = registryPair.second;
-
- // Add the Calculator service.
- serviceRegistryA.addService(Calculator.MANAGER, new CalculatorFactory());
-
- Pair<Calculator.Proxy, InterfaceRequest<Calculator>> requestPair =
- Calculator.MANAGER.getInterfaceRequest(CoreImpl.getInstance());
-
- mCloseablesToClose.add(requestPair.first);
- serviceRegistryB.connectToRemoteService(Calculator.MANAGER, requestPair.second);
-
- // Perform a few operations on the Calculator.
- Calculator.Proxy calculator = requestPair.first;
- CalcConnectionErrorHandler errorHandler = new CalcConnectionErrorHandler();
- calculator.getProxyHandler().setErrorHandler(errorHandler);
- CalcCallback callback = new CalcCallback();
-
- calculator.add(21, callback);
- ShellMojoTestUtils.runLoop(RUN_LOOP_TIMEOUT_MS);
- assertEquals(21.0, callback.getResult());
-
- calculator.multiply(2, callback);
- ShellMojoTestUtils.runLoop(RUN_LOOP_TIMEOUT_MS);
- assertEquals(42.0, callback.getResult());
- }
-
- /**
- * Verifies that a service can be requested only after it is added and not after it is removed.
- */
- @SmallTest
- public void testAddRemoveService() {
- Pair<ServiceRegistry, ServiceRegistry> registryPair =
- ShellMojoTestUtils.createServiceRegistryPair(mNativeTestEnvironment);
- ServiceRegistry serviceRegistryA = registryPair.first;
- ServiceRegistry serviceRegistryB = registryPair.second;
-
- // Request the Calculator service before it is added.
- Pair<Calculator.Proxy, InterfaceRequest<Calculator>> requestPair =
- Calculator.MANAGER.getInterfaceRequest(CoreImpl.getInstance());
- Calculator.Proxy calculator = requestPair.first;
- CalcConnectionErrorHandler errorHandler = new CalcConnectionErrorHandler();
- calculator.getProxyHandler().setErrorHandler(errorHandler);
- mCloseablesToClose.add(calculator);
- serviceRegistryB.connectToRemoteService(Calculator.MANAGER, requestPair.second);
-
- // Spin the message loop and verify that an error occured.
- assertNull(errorHandler.mLastMojoException);
- ShellMojoTestUtils.runLoop(RUN_LOOP_TIMEOUT_MS);
- assertNotNull(errorHandler.mLastMojoException);
-
- // Add the Calculator service and request it again.
- errorHandler.mLastMojoException = null;
- serviceRegistryA.addService(Calculator.MANAGER, new CalculatorFactory());
- requestPair = Calculator.MANAGER.getInterfaceRequest(CoreImpl.getInstance());
- calculator = requestPair.first;
- errorHandler = new CalcConnectionErrorHandler();
- mCloseablesToClose.add(calculator);
- serviceRegistryB.connectToRemoteService(Calculator.MANAGER, requestPair.second);
-
- // Spin the message loop and verify that no error occured.
- assertNull(errorHandler.mLastMojoException);
- ShellMojoTestUtils.runLoop(RUN_LOOP_TIMEOUT_MS);
- assertNull(errorHandler.mLastMojoException);
-
- // Remove the Calculator service and request it again.
- errorHandler.mLastMojoException = null;
- serviceRegistryA.removeService(Calculator.MANAGER);
- requestPair = Calculator.MANAGER.getInterfaceRequest(CoreImpl.getInstance());
- calculator = requestPair.first;
- errorHandler = new CalcConnectionErrorHandler();
- calculator.getProxyHandler().setErrorHandler(errorHandler);
- mCloseablesToClose.add(calculator);
- serviceRegistryB.connectToRemoteService(Calculator.MANAGER, requestPair.second);
-
- // Spin the message loop and verify that an error occured.
- assertNull(errorHandler.mLastMojoException);
- ShellMojoTestUtils.runLoop(RUN_LOOP_TIMEOUT_MS);
- assertNotNull(errorHandler.mLastMojoException);
- }
-}

Powered by Google App Engine
This is Rietveld 408576698