/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* 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.
*/
/*
test
@bug 5039416 6404008
@summary REGRESSION: Extra mouse click dispatched after press-drag- release sequence.
@library ../../regtesthelpers
@build Util
@author andrei.dmitriev area=awt.event
@run applet ExtraMouseClick.html
*/
//**
// Here are two values of smugde used in this test (2 and 5). They should be on
// different sides from value 4 (smudge distance on both toolkits).
// Note that this test may not fail easily. But it must always pass on
// patched workspace.
//**
{
boolean dragged = false;
boolean clicked = false;
boolean pressed = false;
boolean released = false;
public void init()
{
this.setLayout (new BorderLayout ());
public void mousePressed(MouseEvent e) {
pressed = true;
}
public void mouseReleased(MouseEvent e) {
released = true;
}
public void mouseClicked(MouseEvent e) {
clicked = true;
}
});
public void mouseDragged(MouseEvent e) {
dragged = true;
}
public void mouseMoved(MouseEvent e) {
}
});
}//End init()
public void start ()
{
frame.setVisible(true);
try{
}catch(AWTException e){
throw new RuntimeException(e);
}
for (int i = 0; i< TRIALS; i++){
checkClicked();
clearFlags();
}
for (int i = 0; i< TRIALS; i++){
oneDrag(2);
clearFlags();
}
for (int i = 0; i< TRIALS; i++){
oneDrag(5);
clearFlags();
}
for (int i = 0; i< TRIALS; i++){
oneDrag(70);
clearFlags();
}
//Check that no Drag event occur in the SMUDGE area
// DragWidth and dragHeight may be equal to 1. In that case the SMUDGE rectangle
// narrowed into 1x1 pixel and we can't drag a mouse in it.
// In that case we may skip following testcase but I'd prefer if we move mouse on 1 pixel only.
// And that should pass as well.
for (int i = 0; i< TRIALS; i++){
clearFlags();
}
}else{
for (int i = 0; i< TRIALS; i++){
clearFlags();
}
}
}// start()
//drag for a short distance
for (int i = 1; i<pixels;i++){
}
throw new RuntimeException("Test failed. Clicked event follows by Dragged. Dragged = "+dragged +". Clicked = "+clicked + " : distance = "+pixels);
}
}
// by the X-axis
//drag for a short distance
for (int i = 1; i<pixelsX;i++){
}
if (dragged){
throw new RuntimeException("Test failed. Dragged event (by the X-axis) occured in SMUDGE area. Dragged = "+dragged +". Clicked = "+clicked);
}
// the same with Y-axis
for (int i = 1; i<pixelsY;i++){
}
if (dragged){
throw new RuntimeException("Test failed. Dragged event (by the Y-axis) occured in SMUDGE area. Dragged = "+dragged +". Clicked = "+clicked);
}
}
// The difference between X-system and Win32: on Win32 Dragged event start to be generated after any mouse drag.
// On X-systems Dragged event first fired when mouse has left the SMUDGE area
// by the X-axis
//drag for a short distance
for (int i = 1; i<=pixelsX;i++){
}
if (!dragged){
throw new RuntimeException("Test failed. Dragged event (by the X-axis) didn't occur in the SMUDGE area. Dragged = "+dragged);
}
// the same with Y-axis
for (int i = 1; i<=pixelsY;i++){
}
if (!dragged){
throw new RuntimeException("Test failed. Dragged event (by the Y-axis) didn't occur in the SMUDGE area. Dragged = "+dragged);
}
}
public void checkClicked(){
throw new RuntimeException("Test failed. Some of Pressed/Released/Clicked events are missed or dragged occured. Pressed/Released/Clicked/Dragged = "+pressed + ":"+released+":"+clicked +":" +dragged);
}
}
public void clearFlags(){
clicked = false;
pressed = false;
released = false;
dragged = false;
}
}// class