Remove JS console plugin
Summary: This is to unblock our mobile lab build target that adds Flipper to a redex-able build. Redex currently crashes when it tries to optimise Rhino. This could probably be fixed but we don't have any real use-cases for the console plugin right now. It should be fairly easy to unland this even partially if we want to revive this in the future. Reviewed By: danielbuechele Differential Revision: D15044539 fbshipit-source-id: f0857274aa046f5be935a342cf91b6a390fcb3dc
This commit is contained in:
committed by
Facebook Github Bot
parent
8684812907
commit
84e4b916ee
@@ -1,48 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*/
|
||||
package com.facebook.flipper.plugins.console;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.hasItem;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import com.facebook.flipper.core.FlipperObject;
|
||||
import com.facebook.flipper.testing.FlipperConnectionMock;
|
||||
import com.facebook.flipper.testing.FlipperResponderMock;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ConsoleSonarPluginTest {
|
||||
|
||||
FlipperConnectionMock connection;
|
||||
FlipperResponderMock responder;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
JavascriptEnvironment jsEnvironment = new JavascriptEnvironment();
|
||||
final ConsoleFlipperPlugin plugin = new ConsoleFlipperPlugin(jsEnvironment);
|
||||
connection = new FlipperConnectionMock();
|
||||
responder = new FlipperResponderMock();
|
||||
plugin.onConnect(connection);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleExpressionShouldEvaluateCorrectly() throws Exception {
|
||||
|
||||
receiveScript("2 + 2");
|
||||
assertThat(
|
||||
responder.successes,
|
||||
hasItem(new FlipperObject.Builder().put("value", 4).put("type", "json").build()));
|
||||
}
|
||||
|
||||
private void receiveScript(String a) throws Exception {
|
||||
FlipperObject getValue = new FlipperObject.Builder().put("command", a).build();
|
||||
connection.receivers.get("executeCommand").onReceive(getValue, responder);
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*/
|
||||
package com.facebook.flipper.plugins.console;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mozilla.javascript.ContextFactory;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class JavascriptSessionTest {
|
||||
|
||||
ContextFactory mContextFactory = new ContextFactory();
|
||||
|
||||
@Test
|
||||
public void testSimpleExpressionsEvaluate() throws Exception {
|
||||
JavascriptSession session =
|
||||
new JavascriptSession(mContextFactory, Collections.<String, Object>emptyMap());
|
||||
JSONObject json = session.evaluateCommand("2+2-1");
|
||||
assertEquals(3, json.getInt("value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStatePersistsBetweenCommands() throws Exception {
|
||||
JavascriptSession session =
|
||||
new JavascriptSession(mContextFactory, Collections.<String, Object>emptyMap());
|
||||
session.evaluateCommand("var x = 10;");
|
||||
JSONObject json = session.evaluateCommand("x");
|
||||
assertEquals(10, json.getInt("value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVariablesGetBoundCorrectly() throws Exception {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("a", 2);
|
||||
data.put("b", 2);
|
||||
JavascriptSession session = new JavascriptSession(mContextFactory, data);
|
||||
JSONObject json = session.evaluateCommand("a+b");
|
||||
assertEquals("json", json.getString("type"));
|
||||
assertEquals(4, json.getInt("value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNumberEvaluation() throws Exception {
|
||||
assertEquals(4, evaluateWithNoGlobals("4").getInt("value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringEvaluation() throws Exception {
|
||||
assertEquals("hello", evaluateWithNoGlobals("\"hello\"").getString("value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJavaObjectEvaluation() throws Exception {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("object", new HashMap<String, String>());
|
||||
JavascriptSession session = new JavascriptSession(mContextFactory, data);
|
||||
JSONObject json = session.evaluateCommand("object");
|
||||
assertEquals("javaObject", json.getString("type"));
|
||||
assertEquals("{}", json.getJSONObject("value").getString("toString"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJavaMethodEvaluation() throws Exception {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("object", new HashMap<String, String>());
|
||||
JavascriptSession session = new JavascriptSession(mContextFactory, data);
|
||||
JSONObject json = session.evaluateCommand("object.get");
|
||||
assertEquals("method", json.getString("type"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsFunctionEvaluation() throws Exception {
|
||||
JSONObject json = evaluateWithNoGlobals("function() {}");
|
||||
assertEquals("function", json.getString("type"));
|
||||
assertEquals("function(){}", removeWhitespace(json.getString("value")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullEvaluation() throws Exception {
|
||||
assertEquals("null", evaluateWithNoGlobals("null").getString("type"));
|
||||
assertEquals("null", evaluateWithNoGlobals("undefined").getString("type"));
|
||||
}
|
||||
|
||||
private static String removeWhitespace(String input) {
|
||||
return input.replaceAll("\\s", "");
|
||||
}
|
||||
|
||||
private JSONObject evaluateWithNoGlobals(String input) throws Exception {
|
||||
JavascriptSession session =
|
||||
new JavascriptSession(mContextFactory, new HashMap<String, Object>());
|
||||
return session.evaluateCommand(input);
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,6 @@ import com.facebook.flipper.core.FlipperArray;
|
||||
import com.facebook.flipper.core.FlipperConnection;
|
||||
import com.facebook.flipper.core.FlipperDynamic;
|
||||
import com.facebook.flipper.core.FlipperObject;
|
||||
import com.facebook.flipper.plugins.console.iface.NullScriptingEnvironment;
|
||||
import com.facebook.flipper.plugins.console.iface.ScriptingEnvironment;
|
||||
import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin.TouchOverlayView;
|
||||
import com.facebook.flipper.plugins.inspector.descriptors.ApplicationDescriptor;
|
||||
import com.facebook.flipper.testing.FlipperConnectionMock;
|
||||
@@ -45,7 +43,6 @@ public class InspectorFlipperPluginTest {
|
||||
private MockApplicationDescriptor mApplicationDescriptor;
|
||||
private DescriptorMapping mDescriptorMapping;
|
||||
private ApplicationWrapper mApp;
|
||||
private ScriptingEnvironment mScriptingEnvironment;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@@ -57,14 +54,13 @@ public class InspectorFlipperPluginTest {
|
||||
mApplicationDescriptor = new MockApplicationDescriptor();
|
||||
mDescriptorMapping.register(ApplicationWrapper.class, mApplicationDescriptor);
|
||||
mDescriptorMapping.register(TestNode.class, new TestNodeDescriptor());
|
||||
mScriptingEnvironment = new NullScriptingEnvironment();
|
||||
mApp = Mockito.spy(new ApplicationWrapper(app));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnConnect() throws Exception {
|
||||
final InspectorFlipperPlugin plugin =
|
||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, mScriptingEnvironment, null);
|
||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, null);
|
||||
final FlipperConnection connection = new FlipperConnectionMock();
|
||||
|
||||
plugin.onConnect(connection);
|
||||
@@ -74,7 +70,7 @@ public class InspectorFlipperPluginTest {
|
||||
@Test
|
||||
public void testOnDisconnect() throws Exception {
|
||||
final InspectorFlipperPlugin plugin =
|
||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, mScriptingEnvironment, null);
|
||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, null);
|
||||
final FlipperConnection connection = new FlipperConnectionMock();
|
||||
|
||||
plugin.onConnect(connection);
|
||||
@@ -85,7 +81,7 @@ public class InspectorFlipperPluginTest {
|
||||
@Test
|
||||
public void testGetRoot() throws Exception {
|
||||
final InspectorFlipperPlugin plugin =
|
||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, mScriptingEnvironment, null);
|
||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, null);
|
||||
final FlipperResponderMock responder = new FlipperResponderMock();
|
||||
final FlipperConnectionMock connection = new FlipperConnectionMock();
|
||||
plugin.onConnect(connection);
|
||||
@@ -112,7 +108,7 @@ public class InspectorFlipperPluginTest {
|
||||
@Test
|
||||
public void testGetNodes() throws Exception {
|
||||
final InspectorFlipperPlugin plugin =
|
||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, mScriptingEnvironment, null);
|
||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, null);
|
||||
final FlipperResponderMock responder = new FlipperResponderMock();
|
||||
final FlipperConnectionMock connection = new FlipperConnectionMock();
|
||||
plugin.onConnect(connection);
|
||||
@@ -149,7 +145,7 @@ public class InspectorFlipperPluginTest {
|
||||
@Test
|
||||
public void testGetNodesThatDontExist() throws Exception {
|
||||
final InspectorFlipperPlugin plugin =
|
||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, mScriptingEnvironment, null);
|
||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, null);
|
||||
final FlipperResponderMock responder = new FlipperResponderMock();
|
||||
final FlipperConnectionMock connection = new FlipperConnectionMock();
|
||||
plugin.onConnect(connection);
|
||||
@@ -175,7 +171,7 @@ public class InspectorFlipperPluginTest {
|
||||
@Test
|
||||
public void testSetData() throws Exception {
|
||||
final InspectorFlipperPlugin plugin =
|
||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, mScriptingEnvironment, null);
|
||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, null);
|
||||
final FlipperConnectionMock connection = new FlipperConnectionMock();
|
||||
final FlipperResponderMock responder = new FlipperResponderMock();
|
||||
plugin.onConnect(connection);
|
||||
@@ -211,7 +207,7 @@ public class InspectorFlipperPluginTest {
|
||||
@Test
|
||||
public void testSetHighlighted() throws Exception {
|
||||
final InspectorFlipperPlugin plugin =
|
||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, mScriptingEnvironment, null);
|
||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, null);
|
||||
final FlipperConnectionMock connection = new FlipperConnectionMock();
|
||||
final FlipperResponderMock responder = new FlipperResponderMock();
|
||||
plugin.onConnect(connection);
|
||||
@@ -240,7 +236,7 @@ public class InspectorFlipperPluginTest {
|
||||
@Test
|
||||
public void testHitTest() throws Exception {
|
||||
final InspectorFlipperPlugin plugin =
|
||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, mScriptingEnvironment, null);
|
||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, null);
|
||||
final FlipperConnectionMock connection = new FlipperConnectionMock();
|
||||
plugin.onConnect(connection);
|
||||
|
||||
@@ -278,7 +274,7 @@ public class InspectorFlipperPluginTest {
|
||||
@Test
|
||||
public void testSetSearchActive() throws Exception {
|
||||
final InspectorFlipperPlugin plugin =
|
||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, mScriptingEnvironment, null);
|
||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, null);
|
||||
final FlipperConnectionMock connection = new FlipperConnectionMock();
|
||||
final FlipperResponderMock responder = new FlipperResponderMock();
|
||||
plugin.onConnect(connection);
|
||||
@@ -300,7 +296,7 @@ public class InspectorFlipperPluginTest {
|
||||
@Test
|
||||
public void testNullChildThrows() throws Exception {
|
||||
final InspectorFlipperPlugin plugin =
|
||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, mScriptingEnvironment, null);
|
||||
new InspectorFlipperPlugin(mApp, mDescriptorMapping, null);
|
||||
final FlipperResponderMock responder = new FlipperResponderMock();
|
||||
final FlipperConnectionMock connection = new FlipperConnectionMock();
|
||||
plugin.onConnect(connection);
|
||||
|
||||
Reference in New Issue
Block a user