synchronized void setNewLayoutReadyListener( @Nullable ComponentTree.NewLayoutStateReadyListener listener) { if (mComponentTree != null) { mComponentTree.setNewLayoutStateReadyListener(listener); } else { mPendingNewLayoutListener = listener; } }
@Test public void testListenerInvokedForSetRootAsync() { mComponentTree.setNewLayoutStateReadyListener(mListener); mComponentTree.setSizeSpecAsync(mWidthSpec, mHeightSpec); verify(mListener, never()).onNewLayoutStateReady(any(ComponentTree.class)); // Now the background thread run the queued task. mLayoutThreadShadowLooper.runToEndOfTasks(); verify(mListener).onNewLayoutStateReady(mComponentTree); }
@Test public void testListenerInvokedForSetRoot() { mComponentTree.setNewLayoutStateReadyListener(mListener); mComponentTree.setRootAndSizeSpec(mComponent, mWidthSpec, mHeightSpec); verify(mListener).onNewLayoutStateReady(mComponentTree); }
@Test public void testListenerInvokedOnlyOnceForMultipleSetRootAsync() { mComponentTree.setNewLayoutStateReadyListener(mListener); mComponentTree.setSizeSpecAsync(mWidthSpec, mHeightSpec); mComponentTree.setSizeSpecAsync(mWidthSpec2, mHeightSpec2); verify(mListener, never()).onNewLayoutStateReady(any(ComponentTree.class)); // Now the background thread run the queued task. mLayoutThreadShadowLooper.runToEndOfTasks(); verify(mListener).onNewLayoutStateReady(mComponentTree); }
@Test public void testListenerInvokedForSetRootAsyncWhenAttached() { mComponentTree.setNewLayoutStateReadyListener(mListener); mComponentTree.setSizeSpecAsync(mWidthSpec, mHeightSpec); mComponentTree.setLithoView(new LithoView(mContext)); mComponentTree.attach(); verify(mListener, never()).onNewLayoutStateReady(any(ComponentTree.class)); // Now the background thread run the queued task. mLayoutThreadShadowLooper.runToEndOfTasks(); verify(mListener).onNewLayoutStateReady(mComponentTree); }
@Test public void testListenerNotInvokedWhenMeasureDoesntComputeALayout() { mComponentTree.setNewLayoutStateReadyListener(mListener); mComponentTree.setLithoView(new LithoView(mContext)); mComponentTree.attach(); mComponentTree.setSizeSpec(mWidthSpec, mHeightSpec); verify(mListener).onNewLayoutStateReady(mComponentTree); reset(mListener); mComponentTree.measure(mWidthSpec, mHeightSpec, new int[] {0, 0}, false); verify(mListener, never()).onNewLayoutStateReady(mComponentTree); }
@Test public void testListenerInvokedForMeasure() { mComponentTree.setNewLayoutStateReadyListener(mListener); mComponentTree.setLithoView(new LithoView(mContext)); mComponentTree.attach(); mComponentTree.setSizeSpec(mWidthSpec, mHeightSpec); verify(mListener).onNewLayoutStateReady(mComponentTree); reset(mListener); mComponentTree.measure(mWidthSpec2, mHeightSpec2, new int[] {0, 0}, false); verify(mListener).onNewLayoutStateReady(mComponentTree); }
@Test public void testListenerNotInvokedWhenNewMeasureSpecsAreCompatible() { mComponentTree.setLithoView(new LithoView(mContext)); mComponentTree.attach(); mComponentTree.setSizeSpec(mWidthSpec, mHeightSpec); mComponentTree.setNewLayoutStateReadyListener(mListener); mComponentTree.setSizeSpec(mWidthSpec, mHeightSpec); verify(mListener, never()).onNewLayoutStateReady(mComponentTree); } }
.build(); if (mPendingNewLayoutListener != null) { mComponentTree.setNewLayoutStateReadyListener(mPendingNewLayoutListener);