forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Open sourced more instrumentation tests #1
Reviewed By: avaly Differential Revision: D3366104 fbshipit-source-id: 1c77b29e28726a6a105317d9f6944bbf78b707d7
- Loading branch information
Showing
3 changed files
with
343 additions
and
1 deletion.
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
ReactAndroid/src/androidTest/java/com/facebook/react/tests/CatalystMeasureLayoutTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. | ||
* All rights reserved. | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
package com.facebook.react.tests; | ||
|
||
import com.facebook.react.testing.ReactInstanceSpecForTest; | ||
import com.facebook.react.bridge.JavaScriptModule; | ||
import com.facebook.react.uimanager.UIManagerModule; | ||
import com.facebook.react.testing.AssertModule; | ||
import com.facebook.react.testing.ReactAppInstrumentationTestCase; | ||
|
||
/** | ||
* Tests for {@link UIManagerModule#measure}, {@link UIManagerModule#measureLayout}, and | ||
* {@link UIManagerModule#measureLayoutRelativeToParent}. Tests measurement for views in the | ||
* following hierarchy: | ||
* | ||
* +---------------------------------------------+ | ||
* | A | | ||
* | | | ||
* | +-----------+ +---------+ | | ||
* | | B | | D | | | ||
* | | +---+ | | | | | ||
* | | | C | | | | | | ||
* | | | | | +---------+ | | ||
* | | +---+ | | | ||
* | +-----------+ | | ||
* | | | ||
* | | | ||
* | | | ||
* +---------------------------------------------+ | ||
* | ||
* View locations and dimensions: | ||
* A - (0,0) to (500, 500) (500x500) | ||
* B - (50,80) to (250, 380) (200x300) | ||
* C - (150,150) to (200, 300) (50x150) | ||
* D - (400,100) to (450, 300) (50x200) | ||
*/ | ||
public class CatalystMeasureLayoutTest extends ReactAppInstrumentationTestCase { | ||
|
||
private static interface MeasureLayoutTestModule extends JavaScriptModule { | ||
public void verifyMeasureOnViewA(); | ||
public void verifyMeasureOnViewC(); | ||
public void verifyMeasureLayoutCRelativeToA(); | ||
public void verifyMeasureLayoutCRelativeToB(); | ||
public void verifyMeasureLayoutCRelativeToSelf(); | ||
public void verifyMeasureLayoutRelativeToParentOnViewA(); | ||
public void verifyMeasureLayoutRelativeToParentOnViewB(); | ||
public void verifyMeasureLayoutRelativeToParentOnViewC(); | ||
public void verifyMeasureLayoutDRelativeToB(); | ||
public void verifyMeasureLayoutNonExistentTag(); | ||
public void verifyMeasureLayoutNonExistentAncestor(); | ||
public void verifyMeasureLayoutRelativeToParentNonExistentTag(); | ||
} | ||
|
||
private MeasureLayoutTestModule mTestJSModule; | ||
private AssertModule mAssertModule; | ||
|
||
@Override | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
mTestJSModule = getReactContext().getJSModule(MeasureLayoutTestModule.class); | ||
} | ||
|
||
@Override | ||
protected String getReactApplicationKeyUnderTest() { | ||
return "MeasureLayoutTestApp"; | ||
} | ||
|
||
@Override | ||
protected ReactInstanceSpecForTest createReactInstanceSpecForTest() { | ||
mAssertModule = new AssertModule(); | ||
return new ReactInstanceSpecForTest() | ||
.addNativeModule(mAssertModule) | ||
.addJSModule(MeasureLayoutTestModule.class); | ||
} | ||
|
||
private void waitForBridgeIdleAndVerifyAsserts() { | ||
waitForBridgeAndUIIdle(); | ||
mAssertModule.verifyAssertsAndReset(); | ||
} | ||
|
||
public void testMeasure() { | ||
mTestJSModule.verifyMeasureOnViewA(); | ||
waitForBridgeIdleAndVerifyAsserts(); | ||
mTestJSModule.verifyMeasureOnViewC(); | ||
waitForBridgeIdleAndVerifyAsserts(); | ||
} | ||
|
||
public void testMeasureLayout() { | ||
mTestJSModule.verifyMeasureLayoutCRelativeToA(); | ||
waitForBridgeIdleAndVerifyAsserts(); | ||
mTestJSModule.verifyMeasureLayoutCRelativeToB(); | ||
waitForBridgeIdleAndVerifyAsserts(); | ||
mTestJSModule.verifyMeasureLayoutCRelativeToSelf(); | ||
waitForBridgeIdleAndVerifyAsserts(); | ||
} | ||
|
||
public void testMeasureLayoutRelativeToParent() { | ||
mTestJSModule.verifyMeasureLayoutRelativeToParentOnViewA(); | ||
waitForBridgeIdleAndVerifyAsserts(); | ||
mTestJSModule.verifyMeasureLayoutRelativeToParentOnViewB(); | ||
waitForBridgeIdleAndVerifyAsserts(); | ||
mTestJSModule.verifyMeasureLayoutRelativeToParentOnViewC(); | ||
waitForBridgeIdleAndVerifyAsserts(); | ||
} | ||
|
||
public void testMeasureLayoutCallsErrorCallbackWhenViewIsNotChildOfAncestor() { | ||
mTestJSModule.verifyMeasureLayoutDRelativeToB(); | ||
waitForBridgeIdleAndVerifyAsserts(); | ||
} | ||
|
||
public void testMeasureLayoutCallsErrorCallbackWhenViewDoesNotExist() { | ||
mTestJSModule.verifyMeasureLayoutNonExistentTag(); | ||
waitForBridgeIdleAndVerifyAsserts(); | ||
} | ||
|
||
public void testMeasureLayoutCallsErrorCallbackWhenAncestorDoesNotExist() { | ||
mTestJSModule.verifyMeasureLayoutNonExistentAncestor(); | ||
waitForBridgeIdleAndVerifyAsserts(); | ||
} | ||
|
||
public void testMeasureLayoutRelativeToParentCallsErrorCallbackWhenViewDoesNotExist() { | ||
mTestJSModule.verifyMeasureLayoutRelativeToParentNonExistentTag(); | ||
waitForBridgeIdleAndVerifyAsserts(); | ||
} | ||
} |
205 changes: 205 additions & 0 deletions
205
ReactAndroid/src/androidTest/js/MeasureLayoutTestModule.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule MeasureLayoutTestModule | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var BatchedBridge = require('BatchedBridge'); | ||
var React = require('React'); | ||
var ReactNative = require('ReactNative'); | ||
var View = require('View'); | ||
var StyleSheet = require('StyleSheet'); | ||
var UIManager = require('UIManager'); | ||
|
||
var assertEquals = require('Asserts').assertEquals; | ||
|
||
var styles = StyleSheet.create({ | ||
A: { | ||
"width": 500, | ||
"height": 500, | ||
}, | ||
B: { | ||
backgroundColor: "rgb(255, 0, 0)", | ||
"left": 50, | ||
"top": 80, | ||
"width": 200, | ||
"height": 300, | ||
}, | ||
C: { | ||
backgroundColor: "rgb(0, 255, 0)", | ||
"left": 100, | ||
"top": 70, | ||
"width": 50, | ||
"height": 150, | ||
}, | ||
D: { | ||
backgroundColor: "rgb(0, 0, 255)", | ||
"left": 400, | ||
"top": 100, | ||
"width": 50, | ||
"height": 200, | ||
}, | ||
}); | ||
|
||
var A, B, C, D; | ||
|
||
var MeasureLayoutTestApp = React.createClass({ | ||
componentDidMount: function() { | ||
A = ReactNative.findNodeHandle(this.refs.A); | ||
B = ReactNative.findNodeHandle(this.refs.B); | ||
C = ReactNative.findNodeHandle(this.refs.C); | ||
D = ReactNative.findNodeHandle(this.refs.D); | ||
}, | ||
render: function() { | ||
return ( | ||
<View ref="A" style={styles.A} collapsable={false}> | ||
<View ref="B" style={styles.B} collapsable={false}> | ||
<View ref="C" style={styles.C} collapsable={false} /> | ||
</View> | ||
<View ref="D" style={styles.D} collapsable={false} /> | ||
</View> | ||
); | ||
}, | ||
}); | ||
|
||
function shouldNotCallThisCallback() { | ||
assertEquals(false, true); | ||
} | ||
|
||
var MeasureLayoutTestModule = { | ||
MeasureLayoutTestApp: MeasureLayoutTestApp, | ||
verifyMeasureOnViewA: function() { | ||
UIManager.measure(A, function(a, b, width, height, x, y) { | ||
assertEquals(500, width); | ||
assertEquals(500, height); | ||
assertEquals(0, x); | ||
assertEquals(0, y); | ||
}); | ||
}, | ||
verifyMeasureOnViewC: function() { | ||
UIManager.measure(C, function(a, b, width, height, x, y) { | ||
assertEquals(50, width); | ||
assertEquals(150, height); | ||
assertEquals(150, x); | ||
assertEquals(150, y); | ||
}); | ||
}, | ||
verifyMeasureLayoutCRelativeToA: function() { | ||
UIManager.measureLayout( | ||
C, | ||
A, | ||
shouldNotCallThisCallback, | ||
function (x, y, width, height) { | ||
assertEquals(50, width); | ||
assertEquals(150, height); | ||
assertEquals(150, x); | ||
assertEquals(150, y); | ||
}); | ||
}, | ||
verifyMeasureLayoutCRelativeToB: function() { | ||
UIManager.measureLayout( | ||
C, | ||
B, | ||
shouldNotCallThisCallback, | ||
function (x, y, width, height) { | ||
assertEquals(50, width); | ||
assertEquals(150, height); | ||
assertEquals(100, x); | ||
assertEquals(70, y); | ||
}); | ||
}, | ||
verifyMeasureLayoutCRelativeToSelf: function() { | ||
UIManager.measureLayout( | ||
C, | ||
C, | ||
shouldNotCallThisCallback, | ||
function (x, y, width, height) { | ||
assertEquals(50, width); | ||
assertEquals(150, height); | ||
assertEquals(0, x); | ||
assertEquals(0, y); | ||
}); | ||
}, | ||
verifyMeasureLayoutRelativeToParentOnViewA: function() { | ||
UIManager.measureLayoutRelativeToParent( | ||
A, | ||
shouldNotCallThisCallback, | ||
function (x, y, width, height) { | ||
assertEquals(500, width); | ||
assertEquals(500, height); | ||
assertEquals(0, x); | ||
assertEquals(0, y); | ||
}); | ||
}, | ||
verifyMeasureLayoutRelativeToParentOnViewB: function() { | ||
UIManager.measureLayoutRelativeToParent( | ||
B, | ||
shouldNotCallThisCallback, | ||
function (x, y, width, height) { | ||
assertEquals(200, width); | ||
assertEquals(300, height); | ||
assertEquals(50, x); | ||
assertEquals(80, y); | ||
}); | ||
}, | ||
verifyMeasureLayoutRelativeToParentOnViewC: function() { | ||
UIManager.measureLayoutRelativeToParent( | ||
C, | ||
shouldNotCallThisCallback, | ||
function (x, y, width, height) { | ||
assertEquals(50, width); | ||
assertEquals(150, height); | ||
assertEquals(100, x); | ||
assertEquals(70, y); | ||
}); | ||
}, | ||
verifyMeasureLayoutDRelativeToB: function() { | ||
UIManager.measureLayout( | ||
D, | ||
B, | ||
function () { | ||
assertEquals(true, true); | ||
}, | ||
shouldNotCallThisCallback); | ||
}, | ||
verifyMeasureLayoutNonExistentTag: function() { | ||
UIManager.measureLayout( | ||
192, | ||
A, | ||
function () { | ||
assertEquals(true, true); | ||
}, | ||
shouldNotCallThisCallback); | ||
}, | ||
verifyMeasureLayoutNonExistentAncestor: function() { | ||
UIManager.measureLayout( | ||
B, | ||
192, | ||
function () { | ||
assertEquals(true, true); | ||
}, | ||
shouldNotCallThisCallback); | ||
}, | ||
verifyMeasureLayoutRelativeToParentNonExistentTag: function() { | ||
UIManager.measureLayoutRelativeToParent( | ||
192, | ||
function () { | ||
assertEquals(true, true); | ||
}, | ||
shouldNotCallThisCallback); | ||
}, | ||
}; | ||
|
||
BatchedBridge.registerCallableModule( | ||
'MeasureLayoutTestModule', | ||
MeasureLayoutTestModule | ||
); | ||
|
||
module.exports = MeasureLayoutTestModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters