javauis/lcdui_qt/tsrc/uitestsrc/t_uirobot/stringitem/HyperLinkTest.java
changeset 23 98ccebc37403
parent 21 2a9601315dfc
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description: 
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 package t_uirobot.stringitem;
    17 package t_uirobot.stringitem;
    18 
    18 
    19 import j2meunit.framework.*;
    19 import j2meunit.framework.*;
    30  * Short description of the module test:
    30  * Short description of the module test:
    31  * <li> UI-robot based test to test hyperlink. <br>
    31  * <li> UI-robot based test to test hyperlink. <br>
    32  * <br>
    32  * <br>
    33  * Created: 2008-10-20
    33  * Created: 2008-10-20
    34  */
    34  */
    35 public class HyperLinkTest extends ItemUITestBase {
    35 public class HyperLinkTest extends ItemUITestBase
       
    36 {
    36 
    37 
    37     /**
    38     /**
    38      * Constructor.
    39      * Constructor.
    39      */
    40      */
    40     public HyperLinkTest() {
    41     public HyperLinkTest()
       
    42     {
    41     }
    43     }
    42 
    44 
    43     /**
    45     /**
    44      * Constructor.
    46      * Constructor.
    45      *
    47      *
    46      * @param sTestName Test name.
    48      * @param sTestName Test name.
    47      * @param rTestMethod Test method.
    49      * @param rTestMethod Test method.
    48      */
    50      */
    49     public HyperLinkTest(String sTestName, TestMethod rTestMethod) {
    51     public HyperLinkTest(String sTestName, TestMethod rTestMethod)
       
    52     {
    50         super(sTestName, rTestMethod);
    53         super(sTestName, rTestMethod);
    51     }
    54     }
    52 
    55 
    53     /**
    56     /**
    54      * Creates the test suite. You need to add a new aSuite.addTest entry for
    57      * Creates the test suite. You need to add a new aSuite.addTest entry for
    55      * any new test methods, otherwise they won't be run.
    58      * any new test methods, otherwise they won't be run.
    56      *
    59      *
    57      * @return New testsuite.
    60      * @return New testsuite.
    58      */
    61      */
    59     public Test suite() {
    62     public Test suite()
       
    63     {
    60         TestSuite aSuite = new TestSuite();
    64         TestSuite aSuite = new TestSuite();
    61 
    65 
    62         aSuite.addTest(new HyperLinkTest("testCommands",
    66         aSuite.addTest(new HyperLinkTest("testCommands",
    63                 new TestMethod() {
    67                                          new TestMethod()
    64                     public void run(TestCase tc) {
    68         {
    65                         ((HyperLinkTest) tc).testCommands();
    69             public void run(TestCase tc)
    66                     }
    70             {
    67                 }));
    71                 ((HyperLinkTest) tc).testCommands();
       
    72             }
       
    73         }));
    68 
    74 
    69         aSuite.addTest(new HyperLinkTest("testAppearanceModeChangePlain",
    75         aSuite.addTest(new HyperLinkTest("testAppearanceModeChangePlain",
    70                 new TestMethod() {
    76                                          new TestMethod()
    71                     public void run(TestCase tc) {
    77         {
    72                         ((HyperLinkTest) tc).
    78             public void run(TestCase tc)
    73                         testAppearanceModeChange(StringItem.PLAIN);
    79             {
    74                     }
    80                 ((HyperLinkTest) tc).
    75                 }));
    81                 testAppearanceModeChange(StringItem.PLAIN);
       
    82             }
       
    83         }));
    76 
    84 
    77         aSuite.addTest(new HyperLinkTest("testAppearanceModeChangeButton",
    85         aSuite.addTest(new HyperLinkTest("testAppearanceModeChangeButton",
    78                 new TestMethod() {
    86                                          new TestMethod()
    79                     public void run(TestCase tc) {
    87         {
    80                         ((HyperLinkTest) tc).
    88             public void run(TestCase tc)
    81                         testAppearanceModeChange(StringItem.BUTTON);
    89             {
    82                     }
    90                 ((HyperLinkTest) tc).
    83                 }));
    91                 testAppearanceModeChange(StringItem.BUTTON);
       
    92             }
       
    93         }));
    84 
    94 
    85         aSuite.addTest(new HyperLinkTest("testAppearanceModeChangeHyperlink",
    95         aSuite.addTest(new HyperLinkTest("testAppearanceModeChangeHyperlink",
    86                 new TestMethod() {
    96                                          new TestMethod()
    87                     public void run(TestCase tc) {
    97         {
    88                         ((HyperLinkTest) tc).
    98             public void run(TestCase tc)
    89                         testAppearanceModeChange(StringItem.HYPERLINK);
    99             {
    90                     }
   100                 ((HyperLinkTest) tc).
    91                 }));
   101                 testAppearanceModeChange(StringItem.HYPERLINK);
       
   102             }
       
   103         }));
    92 
   104 
    93         aSuite.addTest(new HyperLinkTest("testFocusInAppearanceModeChangePlain",
   105         aSuite.addTest(new HyperLinkTest("testFocusInAppearanceModeChangePlain",
    94                 new TestMethod() {
   106                                          new TestMethod()
    95                     public void run(TestCase tc) {
   107         {
    96                         ((HyperLinkTest) tc).
   108             public void run(TestCase tc)
    97                         testFocusInAppearanceModeChange(StringItem.PLAIN);
   109             {
    98                     }
   110                 ((HyperLinkTest) tc).
    99                 }));
   111                 testFocusInAppearanceModeChange(StringItem.PLAIN);
       
   112             }
       
   113         }));
   100 
   114 
   101         aSuite.addTest(new HyperLinkTest(
   115         aSuite.addTest(new HyperLinkTest(
   102                 "testFocusInAppearanceModeChangeButton",
   116                            "testFocusInAppearanceModeChangeButton",
   103                 new TestMethod() {
   117                            new TestMethod()
   104                     public void run(TestCase tc) {
   118         {
   105                         ((HyperLinkTest) tc).
   119             public void run(TestCase tc)
   106                         testFocusInAppearanceModeChange(StringItem.BUTTON);
   120             {
   107                     }
   121                 ((HyperLinkTest) tc).
   108                 }));
   122                 testFocusInAppearanceModeChange(StringItem.BUTTON);
       
   123             }
       
   124         }));
   109 
   125 
   110         aSuite.addTest(new HyperLinkTest(
   126         aSuite.addTest(new HyperLinkTest(
   111                 "testFocusInAppearanceModeChangeHyperlink",
   127                            "testFocusInAppearanceModeChangeHyperlink",
   112                 new TestMethod() {
   128                            new TestMethod()
   113                     public void run(TestCase tc) {
   129         {
   114                         ((HyperLinkTest) tc).
   130             public void run(TestCase tc)
   115                         testFocusInAppearanceModeChange(StringItem.HYPERLINK);
   131             {
   116                     }
   132                 ((HyperLinkTest) tc).
   117                 }));
   133                 testFocusInAppearanceModeChange(StringItem.HYPERLINK);
       
   134             }
       
   135         }));
   118 
   136 
   119         aSuite.addTest(new HyperLinkTest("testLongHyperlinkWithLSK",
   137         aSuite.addTest(new HyperLinkTest("testLongHyperlinkWithLSK",
   120                 new TestMethod() {
   138                                          new TestMethod()
   121                     public void run(TestCase tc) {
   139         {
   122                         ((HyperLinkTest) tc).testLongHyperlink(Key.CBA1);
   140             public void run(TestCase tc)
   123                     }
   141             {
   124                 }));
   142                 ((HyperLinkTest) tc).testLongHyperlink(Key.CBA1);
       
   143             }
       
   144         }));
   125 
   145 
   126         aSuite.addTest(new HyperLinkTest("testLongHyperlinkWithMSK",
   146         aSuite.addTest(new HyperLinkTest("testLongHyperlinkWithMSK",
   127                 new TestMethod() {
   147                                          new TestMethod()
   128                     public void run(TestCase tc) {
   148         {
   129                         ((HyperLinkTest) tc).testLongHyperlink(Key.Select);
   149             public void run(TestCase tc)
   130                     }
   150             {
   131                 }));
   151                 ((HyperLinkTest) tc).testLongHyperlink(Key.Select);
       
   152             }
       
   153         }));
   132 
   154 
   133         return aSuite;
   155         return aSuite;
   134     }
   156     }
   135 
   157 
   136     /**
   158     /**
   137 	 * Tests the basic functionality of command added to Hyperlink.
   159      * Tests the basic functionality of command added to Hyperlink.
   138 	 */
   160      */
   139 	public void testCommands() {
   161     public void testCommands()
   140 		StringItem hyperlink = new StringItem("label", "url",
   162     {
   141 				StringItem.HYPERLINK);
   163         StringItem hyperlink = new StringItem("label", "url",
   142 
   164                                               StringItem.HYPERLINK);
   143 		testCommand(hyperlink);
   165 
   144 
   166         testCommand(hyperlink);
   145 		// Because focus transfer in case of hyperlink is different than
   167 
   146 		// in normal cases it is good to test that commands works when
   168         // Because focus transfer in case of hyperlink is different than
   147 		// moving focus from previous item to hyperlink as well as when
   169         // in normal cases it is good to test that commands works when
   148 		// moving focus from next item:
   170         // moving focus from previous item to hyperlink as well as when
   149 		form.deleteAll();
   171         // moving focus from next item:
   150 		StringItem button1 = new StringItem(null, "button1", StringItem.BUTTON);
   172         form.deleteAll();
   151 		StringItem button2 = new StringItem(null, "button2", StringItem.BUTTON);
   173         StringItem button1 = new StringItem(null, "button1", StringItem.BUTTON);
   152 		Command dummyCommand = new Command("dummy", "", Command.ITEM, 0);
   174         StringItem button2 = new StringItem(null, "button2", StringItem.BUTTON);
   153 		button1.addCommand(dummyCommand);
   175         Command dummyCommand = new Command("dummy", "", Command.ITEM, 0);
   154 		button2.addCommand(dummyCommand);
   176         button1.addCommand(dummyCommand);
   155 		button1.setItemCommandListener(this);
   177         button2.addCommand(dummyCommand);
   156 		button2.setItemCommandListener(this);
   178         button1.setItemCommandListener(this);
   157 
   179         button2.setItemCommandListener(this);
   158 		// Some typical url-characters are replaced with 'x'-chars to avoid
   180 
   159 		// some problems in eSWT/AVKON implementation. Those problems should
   181         // Some typical url-characters are replaced with 'x'-chars to avoid
   160 		// go away when using QT-based eSWT.
   182         // some problems in eSWT/AVKON implementation. Those problems should
   161 
   183         // go away when using QT-based eSWT.
   162 		Command ok = new Command("Ok", "", Command.ITEM, 0);
   184 
   163 
   185         Command ok = new Command("Ok", "", Command.ITEM, 0);
   164 		StringItem hyperlink3 = new StringItem(null,
   186 
   165 				"xxxx://this.link.should.be.wrapped.to.many"
   187         StringItem hyperlink3 = new StringItem(null,
   166 						+ ".lines.info/index.php?wrapped=truexi=hope",
   188                                                "xxxx://this.link.should.be.wrapped.to.many"
   167 				StringItem.HYPERLINK);
   189                                                + ".lines.info/index.php?wrapped=truexi=hope",
   168 		hyperlink3.addCommand(ok);
   190                                                StringItem.HYPERLINK);
   169 		hyperlink3.setItemCommandListener(this);
   191         hyperlink3.addCommand(ok);
   170 
   192         hyperlink3.setItemCommandListener(this);
   171 		form.append(button1);
   193 
   172 		form.append(hyperlink3);
   194         form.append(button1);
   173 		form.append(button2);
   195         form.append(hyperlink3);
   174 
   196         form.append(button2);
   175 		block(CHANGE_DISPLAYABLE_DELAY);
   197 
   176 
   198         block(CHANGE_DISPLAYABLE_DELAY);
   177 		key(Key.RightArrow);
   199 
   178 		key(Key.CBA1);
   200         key(Key.RightArrow);
   179 		assertItemCmdListener("hyperlink focus transfer test, case 1", ok,
   201         key(Key.CBA1);
   180 				hyperlink3);
   202         assertItemCmdListener("hyperlink focus transfer test, case 1", ok,
   181 
   203                               hyperlink3);
   182 		key(Key.RightArrow);
   204 
   183 		key(Key.LeftArrow);
   205         key(Key.RightArrow);
   184 		key(Key.CBA1);
   206         key(Key.LeftArrow);
   185 		assertItemCmdListener("hyperlink focus transfer test, case 2", ok,
   207         key(Key.CBA1);
   186 				hyperlink3);
   208         assertItemCmdListener("hyperlink focus transfer test, case 2", ok,
   187 	}
   209                               hyperlink3);
   188 
   210     }
   189 	/**
   211 
   190 	 * Tests that commands are working as expected when commands
   212     /**
   191 	 * are added or removed dynamically.
   213      * Tests that commands are working as expected when commands
   192 	 *
   214      * are added or removed dynamically.
   193 	 * @param mode Appearancemode of StringItem.
   215      *
   194 	 */
   216      * @param mode Appearancemode of StringItem.
   195 	public void testAppearanceModeChange(int mode) {
   217      */
   196 		switch (mode) {
   218     public void testAppearanceModeChange(int mode)
   197 		case StringItem.PLAIN:
   219     {
   198 			print("Running test with appearance mode PLAIN.");
   220         switch(mode)
   199 			break;
   221         {
   200 		case StringItem.BUTTON:
   222         case StringItem.PLAIN:
   201 			print("Running test with appearance mode BUTTON.");
   223             print("Running test with appearance mode PLAIN.");
   202 			break;
   224             break;
   203 		case StringItem.HYPERLINK:
   225         case StringItem.BUTTON:
   204 			print("Running test with appearance mode HYPERLINK.");
   226             print("Running test with appearance mode BUTTON.");
   205 			break;
   227             break;
   206 		default:
   228         case StringItem.HYPERLINK:
   207 			fail("Invalid test (incorrect appearance mode).");
   229             print("Running test with appearance mode HYPERLINK.");
   208 			break;
   230             break;
   209 		}
   231         default:
   210 
   232             fail("Invalid test (incorrect appearance mode).");
   211 		StringItem stringItem = new StringItem("label", "url", mode);
   233             break;
   212 		Command ok = new Command("Ok", "", Command.ITEM, 0);
   234         }
   213 
   235 
   214 		form.append(stringItem);
   236         StringItem stringItem = new StringItem("label", "url", mode);
   215 		stringItem.addCommand(ok);
   237         Command ok = new Command("Ok", "", Command.ITEM, 0);
   216 		stringItem.setItemCommandListener(this);
   238 
   217 
   239         form.append(stringItem);
   218 		setCurrent(form);
   240         stringItem.addCommand(ok);
   219 
   241         stringItem.setItemCommandListener(this);
   220 		// Remove command and make sure the command is not working anymore:
   242 
   221 		stringItem.removeCommand(ok);
   243         setCurrent(form);
   222 		block(CHANGE_DISPLAYABLE_DELAY);
   244 
   223 
   245         // Remove command and make sure the command is not working anymore:
   224 		key(Key.CBA1);
   246         stringItem.removeCommand(ok);
   225 		assertItemCmdListener("cmd activated after removing", null, null);
   247         block(CHANGE_DISPLAYABLE_DELAY);
   226 
   248 
   227 		// Add command again and verify it works:
   249         key(Key.CBA1);
   228 		stringItem.addCommand(ok);
   250         assertItemCmdListener("cmd activated after removing", null, null);
   229 		block(CHANGE_DISPLAYABLE_DELAY);
   251 
   230 
   252         // Add command again and verify it works:
   231 		key(Key.CBA1);
   253         stringItem.addCommand(ok);
   232 		assertItemCmdListener("", ok, stringItem);
   254         block(CHANGE_DISPLAYABLE_DELAY);
   233 	}
   255 
   234 
   256         key(Key.CBA1);
   235 	/**
   257         assertItemCmdListener("", ok, stringItem);
   236 	 * Tests that focus transfer works when commands are added/removed
   258     }
   237 	 * dynamically.
   259 
   238 	 *
   260     /**
   239 	 * @param mode Appearancemode of StringItem.
   261      * Tests that focus transfer works when commands are added/removed
   240 	 */
   262      * dynamically.
   241 	public void testFocusInAppearanceModeChange(int mode) {
   263      *
   242 		switch (mode) {
   264      * @param mode Appearancemode of StringItem.
   243 		case StringItem.PLAIN:
   265      */
   244 			print("Running test with appearance mode PLAIN.");
   266     public void testFocusInAppearanceModeChange(int mode)
   245 			break;
   267     {
   246 		case StringItem.BUTTON:
   268         switch(mode)
   247 			print("Running test with appearance mode BUTTON.");
   269         {
   248 			break;
   270         case StringItem.PLAIN:
   249 		case StringItem.HYPERLINK:
   271             print("Running test with appearance mode PLAIN.");
   250 			print("Running test with appearance mode HYPERLINK.");
   272             break;
   251 			break;
   273         case StringItem.BUTTON:
   252 		default:
   274             print("Running test with appearance mode BUTTON.");
   253 			fail("Invalid test (incorrect appearance mode).");
   275             break;
   254 			break;
   276         case StringItem.HYPERLINK:
   255 		}
   277             print("Running test with appearance mode HYPERLINK.");
   256 
   278             break;
   257 		StringItem stringItem = new StringItem(null, "url", mode);
   279         default:
   258 
   280             fail("Invalid test (incorrect appearance mode).");
   259 		StringItem button1 = new StringItem(null, "button1", Item.BUTTON);
   281             break;
   260 		StringItem button2 = new StringItem(null, "button2", Item.BUTTON);
   282         }
   261 
   283 
   262 		Command ok = new Command("giamcc1", "", Command.ITEM, 0);
   284         StringItem stringItem = new StringItem(null, "url", mode);
   263 		Command buttonCommand1 = new Command("giamcc12", "", Command.ITEM, 0);
   285 
   264 		Command buttonCommand2 = new Command("giamcc13", "", Command.ITEM, 0);
   286         StringItem button1 = new StringItem(null, "button1", Item.BUTTON);
   265 
   287         StringItem button2 = new StringItem(null, "button2", Item.BUTTON);
   266 		form.append(button1);
   288 
   267 		form.append(stringItem);
   289         Command ok = new Command("giamcc1", "", Command.ITEM, 0);
   268 		form.append(button2);
   290         Command buttonCommand1 = new Command("giamcc12", "", Command.ITEM, 0);
   269 
   291         Command buttonCommand2 = new Command("giamcc13", "", Command.ITEM, 0);
   270 		// Set listener but do not add commands yet:
   292 
   271 		stringItem.setItemCommandListener(this);
   293         form.append(button1);
   272 		button1.addCommand(buttonCommand1);
   294         form.append(stringItem);
   273 		button2.addCommand(buttonCommand2);
   295         form.append(button2);
   274 		button1.setItemCommandListener(this);
   296 
   275 		button2.setItemCommandListener(this);
   297         // Set listener but do not add commands yet:
   276 
   298         stringItem.setItemCommandListener(this);
   277 		setCurrent(form);
   299         button1.addCommand(buttonCommand1);
   278 
   300         button2.addCommand(buttonCommand2);
   279 		// At this point there are two buttons and plain stringItem
   301         button1.setItemCommandListener(this);
   280 		// in middle of them. Focus is in first button.
   302         button2.setItemCommandListener(this);
   281 		// Move to second button, add command to StringItem, move
   303 
   282 		// to StringItem and verify command works:
   304         setCurrent(form);
   283 		key(Key.RightArrow);
   305 
   284 
   306         // At this point there are two buttons and plain stringItem
   285 		stringItem.addCommand(ok);
   307         // in middle of them. Focus is in first button.
   286 		block(CHANGE_DISPLAYABLE_DELAY);
   308         // Move to second button, add command to StringItem, move
   287 
   309         // to StringItem and verify command works:
   288 		key(Key.LeftArrow);
   310         key(Key.RightArrow);
   289 
   311 
   290 		assertItemCmdListener("case1", ok, stringItem);
   312         stringItem.addCommand(ok);
   291 
   313         block(CHANGE_DISPLAYABLE_DELAY);
   292 		// Now remove command from StringItem. Test assumes that in this
   314 
   293 		// case focus is moved to next item which is the second button.
   315         key(Key.LeftArrow);
   294 		// Verify that happens and also make sure it is possible to move
   316 
   295 		// to first button also:
   317         assertItemCmdListener("case1", ok, stringItem);
   296 		stringItem.removeCommand(ok);
   318 
   297 		block(CHANGE_DISPLAYABLE_DELAY);
   319         // Now remove command from StringItem. Test assumes that in this
   298 
   320         // case focus is moved to next item which is the second button.
   299 		key(Key.CBA1);
   321         // Verify that happens and also make sure it is possible to move
   300 		assertItemCmdListener("case2", buttonCommand2, button2);
   322         // to first button also:
   301 
   323         stringItem.removeCommand(ok);
   302 		key(Key.LeftArrow);
   324         block(CHANGE_DISPLAYABLE_DELAY);
   303 
   325 
   304 		key(Key.CBA1);
   326         key(Key.CBA1);
   305 		assertItemCmdListener("case3", buttonCommand1, button1);
   327         assertItemCmdListener("case2", buttonCommand2, button2);
   306 
   328 
   307 		// Now add command back to StringItem again and make sure it
   329         key(Key.LeftArrow);
   308 		// works:
   330 
   309 		stringItem.addCommand(ok);
   331         key(Key.CBA1);
   310 		block(CHANGE_DISPLAYABLE_DELAY);
   332         assertItemCmdListener("case3", buttonCommand1, button1);
   311 
   333 
   312 		key(Key.RightArrow);
   334         // Now add command back to StringItem again and make sure it
   313 
   335         // works:
   314 		key(Key.CBA1);
   336         stringItem.addCommand(ok);
   315 		assertItemCmdListener("case4", ok, stringItem);
   337         block(CHANGE_DISPLAYABLE_DELAY);
   316 
   338 
   317 		// And verify also the functionality of second button after
   339         key(Key.RightArrow);
   318 		// these changes:
   340 
   319 		key(Key.RightArrow);
   341         key(Key.CBA1);
   320 
   342         assertItemCmdListener("case4", ok, stringItem);
   321 		key(Key.CBA1);
   343 
   322 		assertItemCmdListener("case5", buttonCommand2, button2);
   344         // And verify also the functionality of second button after
   323 	}
   345         // these changes:
   324 
   346         key(Key.RightArrow);
   325 	/**
   347 
   326 	 * Tests that Hyperlink works as expected when its size exceeds
   348         key(Key.CBA1);
   327 	 * screen height.
   349         assertItemCmdListener("case5", buttonCommand2, button2);
   328 	 *
   350     }
   329 	 * @param key Keycode which is used to verify the hyperlink command
   351 
   330 	 *      works.
   352     /**
   331 	 */
   353      * Tests that Hyperlink works as expected when its size exceeds
   332 	public void testLongHyperlink(int key) {
   354      * screen height.
   333 		StringItem stringItem = new StringItem(
   355      *
   334 				"label",
   356      * @param key Keycode which is used to verify the hyperlink command
   335 				"The quick brown fox jumps over the lazy dog and realizes"
   357      *      works.
   336 						+ " that this hyperlink text is repeated several times to make"
   358      */
   337 						+ " sure the size of the hyperlink exceeds screen height. "
   359     public void testLongHyperlink(int key)
   338 						+ "The quick brown fox jumps over the lazy dog and realizes"
   360     {
   339 						+ " that this hyperlink text is repeated several times to make"
   361         StringItem stringItem = new StringItem(
   340 						+ " sure the size of the hyperlink exceeds screen height. "
   362             "label",
   341 						+ "The quick brown fox jumps over the lazy dog and realizes"
   363             "The quick brown fox jumps over the lazy dog and realizes"
   342 						+ " that this hyperlink text is repeated several times to make"
   364             + " that this hyperlink text is repeated several times to make"
   343 						+ " sure the size of the hyperlink exceeds screen height. ",
   365             + " sure the size of the hyperlink exceeds screen height. "
   344 				StringItem.HYPERLINK);
   366             + "The quick brown fox jumps over the lazy dog and realizes"
   345 
   367             + " that this hyperlink text is repeated several times to make"
   346 		Command ok = new Command("lhlc1", "", Command.ITEM, 0);
   368             + " sure the size of the hyperlink exceeds screen height. "
   347 
   369             + "The quick brown fox jumps over the lazy dog and realizes"
   348 		StringItem button1 = new StringItem(null, "button1", Item.BUTTON);
   370             + " that this hyperlink text is repeated several times to make"
   349 		Command buttonCommand1 = new Command("lhlc2", "", Command.ITEM, 0);
   371             + " sure the size of the hyperlink exceeds screen height. ",
   350 
   372             StringItem.HYPERLINK);
   351 		form.append(stringItem);
   373 
   352 		stringItem.addCommand(ok);
   374         Command ok = new Command("lhlc1", "", Command.ITEM, 0);
   353 		stringItem.setItemCommandListener(this);
   375 
   354 
   376         StringItem button1 = new StringItem(null, "button1", Item.BUTTON);
   355 		form.append(button1);
   377         Command buttonCommand1 = new Command("lhlc2", "", Command.ITEM, 0);
   356 		button1.addCommand(buttonCommand1);
   378 
   357 		button1.setItemCommandListener(this);
   379         form.append(stringItem);
   358 
   380         stringItem.addCommand(ok);
   359 		setCurrent(form);
   381         stringItem.setItemCommandListener(this);
   360 
   382 
   361 		//TODO: When running all tests and the key is LSK and in following loop
   383         form.append(button1);
   362 		//the i is 0, latestCommand is buttonCommand1 and latestItem is null.
   384         button1.addCommand(buttonCommand1);
   363 		//If button is not added to the form then the latestCommand also
   385         button1.setItemCommandListener(this);
   364 		//will be null.
   386 
   365 		//Problem has something to do with timing, because
   387         setCurrent(form);
   366 		//adding debugprints to this test will sometimes make it pass.
   388 
   367 		//For example following delay will make the test pass:
   389         //TODO: When running all tests and the key is LSK and in following loop
   368 		block(CHANGE_DISPLAYABLE_DELAY);
   390         //the i is 0, latestCommand is buttonCommand1 and latestItem is null.
   369 
   391         //If button is not added to the form then the latestCommand also
   370 		// Scroll down and after each keydown-press make sure the hyperlink
   392         //will be null.
   371 		// is still focused:
   393         //Problem has something to do with timing, because
   372 		final int rounds = 10;
   394         //adding debugprints to this test will sometimes make it pass.
   373 		final int roundsInHyperlink = 3;
   395         //For example following delay will make the test pass:
   374 		for (int i = 0; i < rounds; i++) {
   396         block(CHANGE_DISPLAYABLE_DELAY);
   375 			key(key);
   397 
   376 
   398         // Scroll down and after each keydown-press make sure the hyperlink
   377 			if (i < roundsInHyperlink) {
   399         // is still focused:
   378 				// Code assumes that it takes at least three
   400         final int rounds = 10;
   379 				// keypresses to reach button which is located below hyperlink:
   401         final int roundsInHyperlink = 3;
   380 				assertItemCmdListener("clicking hyperlink. i=" + i, ok,
   402         for(int i = 0; i < rounds; i++)
   381 						stringItem);
   403         {
   382 			} else if (i >= (rounds - 1)) {
   404             key(key);
   383 				// After 10 keypresses button should be focused:
   405 
   384 				assertItemCmdListener("clicking button. i=" + i,
   406             if(i < roundsInHyperlink)
   385 						buttonCommand1, button1);
   407             {
   386 			}
   408                 // Code assumes that it takes at least three
   387 
   409                 // keypresses to reach button which is located below hyperlink:
   388 			key(Key.RightArrow);
   410                 assertItemCmdListener("clicking hyperlink. i=" + i, ok,
   389 			block(CHANGE_DISPLAYABLE_DELAY);
   411                                       stringItem);
   390 		}
   412             }
   391 	}
   413             else if(i >= (rounds - 1))
       
   414             {
       
   415                 // After 10 keypresses button should be focused:
       
   416                 assertItemCmdListener("clicking button. i=" + i,
       
   417                                       buttonCommand1, button1);
       
   418             }
       
   419 
       
   420             key(Key.RightArrow);
       
   421             block(CHANGE_DISPLAYABLE_DELAY);
       
   422         }
       
   423     }
   392 
   424 
   393 }
   425 }