1 /*
   2  * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.jemmy.swt;
  24 
  25 import org.eclipse.swt.widgets.Control;
  26 import org.eclipse.swt.widgets.Shell;
  27 import org.eclipse.swt.widgets.TabFolder;
  28 import org.eclipse.swt.widgets.ToolBar;
  29 import org.jemmy.Point;
  30 import org.jemmy.control.Wrap;
  31 import org.jemmy.input.StringMenuOwner;
  32 import org.jemmy.input.StringPopupOwner;
  33 import org.jemmy.interfaces.Parent;
  34 import org.jemmy.interfaces.PopupOwner;
  35 import org.jemmy.interfaces.Selectable;
  36 import org.jemmy.resources.StringComparePolicy;
  37 import org.testng.annotations.AfterClass;
  38 import org.testng.annotations.AfterMethod;
  39 import org.testng.annotations.BeforeClass;
  40 import org.testng.annotations.BeforeMethod;
  41 import org.testng.annotations.Test;
  42 
  43 /**
  44  *
  45  * @author shura
  46  */
  47 public class MenuTest {
  48 
  49     public MenuTest() {
  50     }
  51 
  52     @BeforeClass
  53     public static void setUpClass() throws Exception {
  54         new Thread(new Runnable() {
  55 
  56             public void run() {
  57                 Items.main(null);
  58                         }
  59                 }).start();
  60                 Thread.sleep(2000);
  61 
  62         }
  63 
  64     @AfterClass
  65     public static void tearDownClass() throws Exception {
  66     }
  67 
  68     static Wrap<? extends Shell> shell;
  69 
  70     @BeforeMethod
  71     public void setUp() {
  72         shell = Shells.SHELLS.lookup().wrap();
  73         ((Selectable)shell.as(Parent.class, Control.class).lookup(TabFolder.class).as(Selectable.class)).selector().select("Toolbar");
  74     }
  75 
  76     @AfterMethod
  77     public void tearDown() {
  78     }
  79     String[][] menus = new String[][]{
  80         {"menu1", "item10"},
  81         {"menu0", "item00"},
  82         {"menu1", "item11"},
  83         {"menu0", "menu00", "item000"},
  84         {"menu1", "item12"},
  85         {"menu0", "item01"},};
  86 
  87     @Test
  88     public void bar() throws InterruptedException {
  89         for (String[] item : menus) {
  90             shell.as(StringMenuOwner.class).push(item);
  91             shell.waitProperty(Wrap.TEXT_PROP_NAME, item[item.length - 1] + " selected");
  92         }
  93     }
  94 
  95     @Test
  96     public void popup() throws InterruptedException {
  97         Wrap<? extends ToolBar> toolbar = shell.as(Parent.class, Control.class).
  98                 lookup(ToolBar.class).wrap();
  99         for (String[] item : menus) {
 100             toolbar.as(StringPopupOwner.class).push(PopupOwner.CENTER, item);
 101             shell.waitProperty(Wrap.TEXT_PROP_NAME, item[item.length - 1] + " selected");
 102         }
 103     }
 104 
 105     @Test
 106     public void popupPoint() throws InterruptedException {
 107         Wrap<? extends ToolBar> toolbar = shell.as(Parent.class, Control.class).
 108                 lookup(ToolBar.class).wrap();
 109         toolbar.as(StringPopupOwner.class).push(new Point(1, 1), menus[0]);
 110         toolbar.as(StringPopupOwner.class).push(new Point(1, 1), menus[3]);
 111     }
 112 
 113     @Test
 114     public void bySubString() {
 115         StringMenuOwner menu = shell.as(StringMenuOwner.class);
 116         menu.setPolicy(StringComparePolicy.SUBSTRING);
 117         menu.push("0", "menu", "");
 118         shell.waitProperty(Wrap.TEXT_PROP_NAME, "item000 selected");
 119     }
 120 }