gt:         for (int i = 1; i <= 20; i++) {
context: /*
   * Copyright (c) 2014, 2018, 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.
   *
   * 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.
   */
  
  
  import java.awt.*;
  import java.awt.event.*;
  import java.lang.reflect.InvocationTargetException;
  import javax.swing.SwingUtilities;
  import java.io.*;
  
  /**
   * AWT Mixing test for HierarchyBoundsListener ancestors.
   * <p>See <a href="https://bugs.openjdk.java.net/browse/JDK-6768230">CR6768230</a> for details.
   */
  /*
   * @test
   * @key headful
   * @bug 6768230
   * @summary Mixing test for HierarchyBoundsListener ancestors
   * @build FrameBorderCounter
   * @run main HierarchyBoundsListenerMixingTest
   */
  public class HierarchyBoundsListenerMixingTest {
  
      protected void prepareControls() {
          dummy = new Frame();
          dummy.setSize(100, 100);
          dummy.setLocation(0, 350);
          dummy.setVisible(true);
  
          frame = new Frame("Test Frame");
          frame.setLayout(new FlowLayout());
  
          panel = new Panel();
          button = new Button("Button");
          label = new Label("Label");
          list = new List();
          list.add("One");
          list.add("Two");
          list.add("Three");
          choice = new Choice();
          choice.add("Red");
          choice.add("Orange");
          choice.add("Yellow");
          checkbox = new Checkbox("Checkbox");
          scrollbar = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 255);
          textfield = new TextField(15);
          textarea = new TextArea(5, 15);
  
          components = new Component[] {
              panel, button, label, list, choice, checkbox, scrollbar, textfield, textarea
          };
          ancestorResized = new boolean[components.length];
          ancestorMoved = new boolean[components.length];
  
          frame.addWindowListener(new WindowAdapter() {
              @Override
              public void windowClosing(WindowEvent event) {
                  System.err.println("User closed the window");
              }
          });
  
          HierarchyBoundsListener listener = new HierarchyBoundsListenerImpl();
          for (int i = 0; i < components.length; i++) {
              components[i].addHierarchyBoundsListener(listener);
              frame.add(components[i]);
          }
          frame.setBounds(100, 100, 300, 300);
          frame.setVisible(true);
      }
  
      private int frameBorderCounter() {
          String JAVA_HOME = System.getProperty("java.home");
  
          try {
              Process p = Runtime.getRuntime().exec(JAVA_HOME + "/bin/java FrameBorderCounter");
              try {
                  p.waitFor();
              } catch (InterruptedException e) {
                  e.printStackTrace();
                  throw new RuntimeException(e);
              }
              if (p.exitValue() != 0) {
                  throw new RuntimeException("FrameBorderCounter exited with not null code!\n" + readInputStream(p.getErrorStream()));
              }
              return Integer.parseInt(readInputStream(p.getInputStream()).trim());
          } catch (IOException e) {
              e.printStackTrace();
              throw new RuntimeException(e);
          }
      }
  
      private String readInputStream(InputStream is) throws IOException {
          byte[] buffer = new byte[4096];
          int len = 0;
          StringBuilder sb = new StringBuilder();
          try (InputStreamReader isr = new InputStreamReader(is)) {
              while ((len = is.read(buffer)) > 0) {
                  sb.append(new String(buffer, 0, len));
              }
          }
          return sb.toString();
      }
  
      protected boolean performTest() {
          int BORDER_SHIFT = frameBorderCounter();
          BORDER_SHIFT = Math.abs(BORDER_SHIFT) == 1 ? BORDER_SHIFT : BORDER_SHIFT / 2;
          Robot robot = null;
          try {
              robot = new Robot();
              Thread.sleep(delay * 10);
          } catch (Exception e) {
              e.printStackTrace();
              throw new RuntimeException("Robot creation exception.");
          }
  
          robot.mouseMove((int) components[0].getLocationOnScreen().x + components[0].getSize().width / 2,
                          (int) components[0].getLocationOnScreen().y + components[0].getSize().height / 2);
          robot.delay(delay);
          robot.mousePress(InputEvent.BUTTON1_MASK);
          robot.delay(delay);
          robot.mouseRelease(InputEvent.BUTTON1_MASK);
          robot.delay(delay);
  
          resetValues();
          try {
              EventQueue.invokeAndWait(new Runnable() {
                  public void run() {
                      frame.setSize(new Dimension(frame.getSize().width + 10, frame.getSize().height + 10));
                      frame.invalidate();
                      frame.validate();
                  }
              });
          } catch (Exception e) {
              e.printStackTrace();
              passed = false;
          }
          if (! resizeTriggered) {
              synchronized (resizeLock) {
                  try {
                      resizeLock.wait(delay * 10);
                  } catch (Exception e) {
                  }
              }
          }
          for (int i = 0; i < components.length; i++) {
              if (! ancestorResized[i]) {
                  System.err.println("FAIL: Frame resized using API call. " +
                                     "Ancestor resized event did not occur for " + components[i].getClass());
                  passed = false;
              }
          }
          if (moveCount > 0) {
              System.err.println("FAIL: Ancestor moved event occured when Frame resized using API");
              passed = false;
          }
          robot.delay(delay * 5);
  
          resetValues();
          int x = (int) frame.getLocationOnScreen().x;
          int y = (int) frame.getLocationOnScreen().y;
          int w = frame.getSize().width;
          int h = frame.getSize().height;
  
          robot.mouseMove(x + w + BORDER_SHIFT, y + h / 2);
          robot.delay(delay);
          robot.mousePress(InputEvent.BUTTON1_MASK);
          robot.delay(delay);
          for (int i = 0; i < 20; i++) {
              robot.mouseMove(x + w + i + BORDER_SHIFT, y + h / 2);
              robot.delay(50);
          }
          robot.delay(delay);
          robot.mouseRelease(InputEvent.BUTTON1_MASK);
  
          if (! resizeTriggered) {
              synchronized (resizeLock) {
                  try {
                      resizeLock.wait(delay * 10);
                  } catch (Exception e) {
                  }
              }
          }
  
          for (int i = 0; i < components.length; i++) {
              if (! ancestorResized[i]) {
                  System.err.println("FAIL: Frame resized using mouse action. " +
                                     "Ancestor resized event did not occur for " +
                                     components[i].getClass());
                  passed = false;
              }
          }
          if (moveCount > 0) {
              System.err.println("FAIL: Ancestor moved event occured when Frame resized using mouse");
              passed = false;
          }
  
          resetValues();
          try {
              EventQueue.invokeAndWait(new Runnable() {
                  public void run() {
                      frame.setLocation(frame.getLocation().x + 20, frame.getLocation().y + 20);
                      frame.invalidate();
                      frame.validate();
                  }
              });
          } catch (Exception e) {
              e.printStackTrace();
              passed = false;
          }
          if (! moveTriggered) {
              synchronized (moveLock) {
                  try {
                      moveLock.wait(delay * 10);
                  } catch (Exception e) {
                  }
              }
          }
          for (int i = 0; i < components.length; i++) {
              if (! ancestorMoved[i]) {
                  System.err.println("FAIL: Frame moved using API call. " +
                                     "Ancestor moved event did not occur for " + components[i].getClass());
                  passed = false;
              }
          }
          if (resizeCount > 0) {
              System.err.println("FAIL: Ancestor resized event occured when Frame moved using API");
              passed = false;
          }
          robot.delay(delay * 10);
  
          resetValues();
          x = (int) frame.getLocationOnScreen().x;
          y = (int) frame.getLocationOnScreen().y;
          w = frame.getSize().width;
          h = frame.getSize().height;
  
          //Click on the dummy frame so that the test frame loses focus. This is to workaround
          //a bug in Linux AS.
          robot.mouseMove((int) dummy.getLocationOnScreen().x + dummy.getSize().width / 2,
                          (int) dummy.getLocationOnScreen().y + dummy.getSize().height / 2);
          robot.delay(delay);
          robot.mousePress(InputEvent.BUTTON1_MASK);
          robot.delay(delay);
          robot.mouseRelease(InputEvent.BUTTON1_MASK);
          robot.delay(delay);
  
          robot.mouseMove(x + w / 2, y + 10);
          robot.delay(delay);
          robot.mousePress(InputEvent.BUTTON1_MASK);
          robot.delay(delay);
  