-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
8246195: ListViewSkin/Behavior: misbehavior on switching skin
Reviewed-by: arapte
- Loading branch information
Showing
7 changed files
with
260 additions
and
17 deletions.
There are no files selected for viewing
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
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
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
160 changes: 160 additions & 0 deletions
160
...ontrols/src/test/java/test/com/sun/javafx/scene/control/behavior/BehaviorCleanupTest.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,160 @@ | ||
/* | ||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package test.com.sun.javafx.scene.control.behavior; | ||
|
||
import java.lang.ref.WeakReference; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import com.sun.javafx.scene.control.behavior.BehaviorBase; | ||
import com.sun.javafx.scene.control.behavior.ListCellBehavior; | ||
|
||
import static javafx.collections.FXCollections.*; | ||
import static org.junit.Assert.*; | ||
import static test.com.sun.javafx.scene.control.infrastructure.ControlSkinFactory.*; | ||
|
||
import javafx.scene.control.ListView; | ||
|
||
/** | ||
* Test for misbehavior of individual implementations that turned | ||
* up in binch testing. | ||
* | ||
*/ | ||
public class BehaviorCleanupTest { | ||
|
||
// ---------- ListView | ||
|
||
/** | ||
* Test cleanup of listener to itemsProperty. | ||
*/ | ||
@Test | ||
public void testListViewBehaviorDisposeSetItems() { | ||
ListView<String> listView = new ListView<>(observableArrayList("one", "two")); | ||
WeakReference<BehaviorBase<?>> weakRef = new WeakReference<>(createBehavior(listView)); | ||
weakRef.get().dispose(); | ||
int last = 1; | ||
ListCellBehavior.setAnchor(listView, last, false); | ||
listView.setItems(observableArrayList("other", "again")); | ||
assertEquals("sanity: anchor unchanged", last, listView.getProperties().get("anchor")); | ||
listView.getItems().remove(0); | ||
assertEquals("anchor must not be updated on items modification when disposed", | ||
last, listView.getProperties().get("anchor")); | ||
} | ||
|
||
@Test | ||
public void testListViewBehaviorSetItems() { | ||
ListView<String> listView = new ListView<>(observableArrayList("one", "two")); | ||
createBehavior(listView); | ||
int last = 1; | ||
ListCellBehavior.setAnchor(listView, last, false); | ||
listView.setItems(observableArrayList("other", "again")); | ||
assertEquals("sanity: anchor unchanged", last, listView.getProperties().get("anchor")); | ||
listView.getItems().remove(0); | ||
assertEquals("anchor must be updated on items modification", | ||
last -1, listView.getProperties().get("anchor")); | ||
} | ||
|
||
/** | ||
* Test cleanup of itemsList listener in ListViewBehavior. | ||
*/ | ||
@Test | ||
public void testListViewBehaviorDisposeRemoveItem() { | ||
ListView<String> listView = new ListView<>(observableArrayList("one", "two")); | ||
WeakReference<BehaviorBase<?>> weakRef = new WeakReference<>(createBehavior(listView)); | ||
weakRef.get().dispose(); | ||
int last = 1; | ||
ListCellBehavior.setAnchor(listView, last, false); | ||
listView.getItems().remove(0); | ||
assertEquals("anchor must not be updated on items modification when disposed", | ||
last, | ||
listView.getProperties().get("anchor")); | ||
} | ||
|
||
@Test | ||
public void testListViewBehaviorRemoveItem() { | ||
ListView<String> listView = new ListView<>(observableArrayList("one", "two")); | ||
createBehavior(listView); | ||
int last = 1; | ||
ListCellBehavior.setAnchor(listView, last, false); | ||
assertEquals("behavior must set anchor on select", last, listView.getProperties().get("anchor")); | ||
listView.getItems().remove(0); | ||
assertEquals("anchor must be updated on items modification", | ||
last -1, listView.getProperties().get("anchor")); | ||
} | ||
|
||
/** | ||
* Test cleanup of selection listeners in ListViewBehavior. | ||
*/ | ||
@Test | ||
public void testListViewBehaviorDisposeSelect() { | ||
ListView<String> listView = new ListView<>(observableArrayList("one", "two")); | ||
WeakReference<BehaviorBase<?>> weakRef = new WeakReference<>(createBehavior(listView)); | ||
listView.getSelectionModel().select(1); | ||
weakRef.get().dispose(); | ||
listView.getSelectionModel().select(0); | ||
assertNull("anchor must remain cleared on selecting when disposed", | ||
listView.getProperties().get("anchor")); | ||
} | ||
|
||
@Test | ||
public void testListViewBehaviorSelect() { | ||
ListView<String> listView = new ListView<>(observableArrayList("one", "two")); | ||
createBehavior(listView); | ||
int last = 1; | ||
listView.getSelectionModel().select(last); | ||
assertEquals("anchor must be set", last, listView.getProperties().get("anchor")); | ||
} | ||
|
||
@Test | ||
public void testListViewBehaviorDispose() { | ||
ListView<String> listView = new ListView<>(observableArrayList("one", "two")); | ||
WeakReference<BehaviorBase<?>> weakRef = new WeakReference<>(createBehavior(listView)); | ||
listView.getSelectionModel().select(1); | ||
weakRef.get().dispose(); | ||
assertNull("anchor must be cleared after dispose", listView.getProperties().get("anchor")); | ||
} | ||
|
||
//------------------ setup/cleanup | ||
|
||
@After | ||
public void cleanup() { | ||
Thread.currentThread().setUncaughtExceptionHandler(null); | ||
} | ||
|
||
@Before | ||
public void setup() { | ||
Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> { | ||
if (throwable instanceof RuntimeException) { | ||
throw (RuntimeException)throwable; | ||
} else { | ||
Thread.currentThread().getThreadGroup().uncaughtException(thread, throwable); | ||
} | ||
}); | ||
} | ||
|
||
} |
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
Oops, something went wrong.