KeyboardNavigationTests_Tab.cs 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072
  1. // -----------------------------------------------------------------------
  2. // <copyright file="KeyboardNavigationTests_Tab.cs" company="Steven Kirk">
  3. // Copyright 2015 MIT Licence. See licence.md for more information.
  4. // </copyright>
  5. // -----------------------------------------------------------------------
  6. namespace Perspex.Input.UnitTests
  7. {
  8. using Perspex.Controls;
  9. using Xunit;
  10. public class KeyboardNavigationTests_Tab
  11. {
  12. [Fact]
  13. public void Next_Continue_Returns_Next_Control_In_Container()
  14. {
  15. StackPanel container;
  16. Button current;
  17. Button next;
  18. var top = new StackPanel
  19. {
  20. Children = new Controls
  21. {
  22. (container = new StackPanel
  23. {
  24. Children = new Controls
  25. {
  26. new Button { Name = "Button1" },
  27. (current = new Button { Name = "Button2" }),
  28. (next = new Button { Name = "Button3" }),
  29. }
  30. }),
  31. new StackPanel
  32. {
  33. Children = new Controls
  34. {
  35. new Button { Name = "Button4" },
  36. new Button { Name = "Button5" },
  37. new Button { Name = "Button6" },
  38. }
  39. },
  40. }
  41. };
  42. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Next);
  43. Assert.Equal(next, result);
  44. }
  45. [Fact]
  46. public void Next_Continue_Returns_First_Control_In_Next_Sibling_Container()
  47. {
  48. StackPanel container;
  49. Button current;
  50. Button next;
  51. var top = new StackPanel
  52. {
  53. Children = new Controls
  54. {
  55. (container = new StackPanel
  56. {
  57. Children = new Controls
  58. {
  59. new Button { Name = "Button1" },
  60. new Button { Name = "Button2" },
  61. (current = new Button { Name = "Button3" }),
  62. }
  63. }),
  64. new StackPanel
  65. {
  66. Children = new Controls
  67. {
  68. (next = new Button { Name = "Button4" }),
  69. new Button { Name = "Button5" },
  70. new Button { Name = "Button6" },
  71. }
  72. },
  73. }
  74. };
  75. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Next);
  76. Assert.Equal(next, result);
  77. }
  78. [Fact]
  79. public void Next_Continue_Doesnt_Enter_Panel_With_TabNavigation_None()
  80. {
  81. StackPanel container;
  82. Button current;
  83. Button next;
  84. var top = new StackPanel
  85. {
  86. Children = new Controls
  87. {
  88. (container = new StackPanel
  89. {
  90. Children = new Controls
  91. {
  92. (next = new Button { Name = "Button1" }),
  93. new Button { Name = "Button2" },
  94. (current = new Button { Name = "Button3" }),
  95. }
  96. }),
  97. new StackPanel
  98. {
  99. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.None,
  100. Children = new Controls
  101. {
  102. new StackPanel
  103. {
  104. Children = new Controls
  105. {
  106. new Button { Name = "Button4" },
  107. new Button { Name = "Button5" },
  108. new Button { Name = "Button6" },
  109. }
  110. },
  111. }
  112. }
  113. }
  114. };
  115. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Next);
  116. Assert.Equal(next, result);
  117. }
  118. [Fact]
  119. public void Next_Continue_Returns_Next_Sibling()
  120. {
  121. StackPanel container;
  122. Button current;
  123. Button next;
  124. var top = new StackPanel
  125. {
  126. Children = new Controls
  127. {
  128. (container = new StackPanel
  129. {
  130. Children = new Controls
  131. {
  132. new Button { Name = "Button1" },
  133. new Button { Name = "Button2" },
  134. (current = new Button { Name = "Button3" }),
  135. }
  136. }),
  137. (next = new Button { Name = "Button4" }),
  138. }
  139. };
  140. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Next);
  141. Assert.Equal(next, result);
  142. }
  143. [Fact]
  144. public void Next_Continue_Returns_First_Control_In_Next_Uncle_Container()
  145. {
  146. StackPanel container;
  147. Button current;
  148. Button next;
  149. var top = new StackPanel
  150. {
  151. Children = new Controls
  152. {
  153. new StackPanel
  154. {
  155. Children = new Controls
  156. {
  157. (container = new StackPanel
  158. {
  159. Children = new Controls
  160. {
  161. new Button { Name = "Button1" },
  162. new Button { Name = "Button2" },
  163. (current = new Button { Name = "Button3" }),
  164. }
  165. }),
  166. },
  167. },
  168. new StackPanel
  169. {
  170. Children = new Controls
  171. {
  172. (next = new Button { Name = "Button4" }),
  173. new Button { Name = "Button5" },
  174. new Button { Name = "Button6" },
  175. }
  176. },
  177. }
  178. };
  179. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Next);
  180. Assert.Equal(next, result);
  181. }
  182. [Fact]
  183. public void Next_Continue_Returns_Child_Of_Top_Level()
  184. {
  185. Button next;
  186. var top = new StackPanel
  187. {
  188. Children = new Controls
  189. {
  190. (next = new Button { Name = "Button1" }),
  191. }
  192. };
  193. var result = KeyboardNavigationHandler.GetNext(top, FocusNavigationDirection.Next);
  194. Assert.Equal(next, result);
  195. }
  196. [Fact]
  197. public void Next_Continue_Wraps()
  198. {
  199. StackPanel container;
  200. Button current;
  201. Button next;
  202. var top = new StackPanel
  203. {
  204. Children = new Controls
  205. {
  206. new StackPanel
  207. {
  208. Children = new Controls
  209. {
  210. (container = new StackPanel
  211. {
  212. Children = new Controls
  213. {
  214. (next = new Button { Name = "Button1" }),
  215. new Button { Name = "Button2" },
  216. new Button { Name = "Button3" },
  217. }
  218. }),
  219. },
  220. },
  221. new StackPanel
  222. {
  223. Children = new Controls
  224. {
  225. new Button { Name = "Button4" },
  226. new Button { Name = "Button5" },
  227. (current = new Button { Name = "Button6" }),
  228. }
  229. },
  230. }
  231. };
  232. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Next);
  233. Assert.Equal(next, result);
  234. }
  235. [Fact]
  236. public void Next_Cycle_Returns_Next_Control_In_Container()
  237. {
  238. StackPanel container;
  239. Button current;
  240. Button next;
  241. var top = new StackPanel
  242. {
  243. Children = new Controls
  244. {
  245. (container = new StackPanel
  246. {
  247. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle,
  248. Children = new Controls
  249. {
  250. new Button { Name = "Button1" },
  251. (current = new Button { Name = "Button2" }),
  252. (next = new Button { Name = "Button3" }),
  253. }
  254. }),
  255. new StackPanel
  256. {
  257. Children = new Controls
  258. {
  259. new Button { Name = "Button4" },
  260. new Button { Name = "Button5" },
  261. new Button { Name = "Button6" },
  262. }
  263. },
  264. }
  265. };
  266. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Next);
  267. Assert.Equal(next, result);
  268. }
  269. [Fact]
  270. public void Next_Cycle_Wraps_To_First()
  271. {
  272. StackPanel container;
  273. Button current;
  274. Button next;
  275. var top = new StackPanel
  276. {
  277. Children = new Controls
  278. {
  279. (container = new StackPanel
  280. {
  281. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle,
  282. Children = new Controls
  283. {
  284. (next = new Button { Name = "Button1" }),
  285. new Button { Name = "Button2" },
  286. (current = new Button { Name = "Button3" }),
  287. }
  288. }),
  289. new StackPanel
  290. {
  291. Children = new Controls
  292. {
  293. new Button { Name = "Button4" },
  294. new Button { Name = "Button5" },
  295. new Button { Name = "Button6" },
  296. }
  297. },
  298. }
  299. };
  300. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Next);
  301. Assert.Equal(next, result);
  302. }
  303. [Fact]
  304. public void Next_Contained_Returns_Next_Control_In_Container()
  305. {
  306. StackPanel container;
  307. Button current;
  308. Button next;
  309. var top = new StackPanel
  310. {
  311. Children = new Controls
  312. {
  313. (container = new StackPanel
  314. {
  315. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Contained,
  316. Children = new Controls
  317. {
  318. new Button { Name = "Button1" },
  319. (current = new Button { Name = "Button2" }),
  320. (next = new Button { Name = "Button3" }),
  321. }
  322. }),
  323. new StackPanel
  324. {
  325. Children = new Controls
  326. {
  327. new Button { Name = "Button4" },
  328. new Button { Name = "Button5" },
  329. new Button { Name = "Button6" },
  330. }
  331. },
  332. }
  333. };
  334. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Next);
  335. Assert.Equal(next, result);
  336. }
  337. [Fact]
  338. public void Next_Contained_Stops_At_End()
  339. {
  340. StackPanel container;
  341. Button current;
  342. Button next;
  343. var top = new StackPanel
  344. {
  345. Children = new Controls
  346. {
  347. (container = new StackPanel
  348. {
  349. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Contained,
  350. Children = new Controls
  351. {
  352. (next = new Button { Name = "Button1" }),
  353. new Button { Name = "Button2" },
  354. (current = new Button { Name = "Button3" }),
  355. }
  356. }),
  357. new StackPanel
  358. {
  359. Children = new Controls
  360. {
  361. new Button { Name = "Button4" },
  362. new Button { Name = "Button5" },
  363. new Button { Name = "Button6" },
  364. }
  365. },
  366. }
  367. };
  368. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Next);
  369. Assert.Null(result);
  370. }
  371. [Fact]
  372. public void Next_Once_Moves_To_Next_Container()
  373. {
  374. StackPanel container;
  375. Button current;
  376. Button next;
  377. var top = new StackPanel
  378. {
  379. Children = new Controls
  380. {
  381. (container = new StackPanel
  382. {
  383. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Once,
  384. Children = new Controls
  385. {
  386. new Button { Name = "Button1" },
  387. (current = new Button { Name = "Button2" }),
  388. new Button { Name = "Button3" },
  389. }
  390. }),
  391. new StackPanel
  392. {
  393. Children = new Controls
  394. {
  395. (next = new Button { Name = "Button4" }),
  396. new Button { Name = "Button5" },
  397. new Button { Name = "Button6" },
  398. }
  399. },
  400. }
  401. };
  402. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Next);
  403. Assert.Equal(next, result);
  404. }
  405. [Fact]
  406. public void Next_Once_Moves_To_Active_Element()
  407. {
  408. StackPanel container;
  409. Button current;
  410. Button next;
  411. var top = new StackPanel
  412. {
  413. Children = new Controls
  414. {
  415. (container = new StackPanel
  416. {
  417. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Once,
  418. Children = new Controls
  419. {
  420. new Button { Name = "Button1" },
  421. (next = new Button { Name = "Button2" }),
  422. new Button { Name = "Button3" },
  423. }
  424. }),
  425. new StackPanel
  426. {
  427. Children = new Controls
  428. {
  429. new Button { Name = "Button4" },
  430. new Button { Name = "Button5" },
  431. (current = new Button { Name = "Button6" }),
  432. }
  433. },
  434. }
  435. };
  436. KeyboardNavigation.SetTabOnceActiveElement(container, next);
  437. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Next);
  438. Assert.Equal(next, result);
  439. }
  440. [Fact]
  441. public void Next_None_Moves_To_Next_Container()
  442. {
  443. StackPanel container;
  444. Button current;
  445. Button next;
  446. var top = new StackPanel
  447. {
  448. Children = new Controls
  449. {
  450. (container = new StackPanel
  451. {
  452. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.None,
  453. Children = new Controls
  454. {
  455. new Button { Name = "Button1" },
  456. (current = new Button { Name = "Button2" }),
  457. new Button { Name = "Button3" },
  458. }
  459. }),
  460. new StackPanel
  461. {
  462. Children = new Controls
  463. {
  464. (next = new Button { Name = "Button4" }),
  465. new Button { Name = "Button5" },
  466. new Button { Name = "Button6" },
  467. }
  468. },
  469. }
  470. };
  471. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Next);
  472. Assert.Equal(next, result);
  473. }
  474. [Fact]
  475. public void Next_None_Skips_Container()
  476. {
  477. StackPanel container;
  478. Button current;
  479. Button next;
  480. var top = new StackPanel
  481. {
  482. Children = new Controls
  483. {
  484. (container = new StackPanel
  485. {
  486. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.None,
  487. Children = new Controls
  488. {
  489. new Button { Name = "Button1" },
  490. new Button { Name = "Button2" },
  491. new Button { Name = "Button3" },
  492. }
  493. }),
  494. new StackPanel
  495. {
  496. Children = new Controls
  497. {
  498. (next = new Button { Name = "Button4" }),
  499. new Button { Name = "Button5" },
  500. (current = new Button { Name = "Button6" }),
  501. }
  502. },
  503. }
  504. };
  505. KeyboardNavigation.SetTabOnceActiveElement(container, next);
  506. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Next);
  507. Assert.Equal(next, result);
  508. }
  509. [Fact]
  510. public void Previous_Continue_Returns_Previous_Control_In_Container()
  511. {
  512. StackPanel container;
  513. Button current;
  514. Button next;
  515. var top = new StackPanel
  516. {
  517. Children = new Controls
  518. {
  519. (container = new StackPanel
  520. {
  521. Children = new Controls
  522. {
  523. new Button { Name = "Button1" },
  524. (next = new Button { Name = "Button2" }),
  525. (current = new Button { Name = "Button3" }),
  526. }
  527. }),
  528. new StackPanel
  529. {
  530. Children = new Controls
  531. {
  532. new Button { Name = "Button4" },
  533. new Button { Name = "Button5" },
  534. new Button { Name = "Button6" },
  535. }
  536. },
  537. }
  538. };
  539. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Previous);
  540. Assert.Equal(next, result);
  541. }
  542. [Fact]
  543. public void Previous_Continue_Returns_Last_Control_In_Previous_Sibling_Container()
  544. {
  545. StackPanel container;
  546. Button current;
  547. Button next;
  548. var top = new StackPanel
  549. {
  550. Children = new Controls
  551. {
  552. (container = new StackPanel
  553. {
  554. Children = new Controls
  555. {
  556. new Button { Name = "Button1" },
  557. new Button { Name = "Button2" },
  558. (next = new Button { Name = "Button3" }),
  559. }
  560. }),
  561. new StackPanel
  562. {
  563. Children = new Controls
  564. {
  565. (current = new Button { Name = "Button4" }),
  566. new Button { Name = "Button5" },
  567. new Button { Name = "Button6" },
  568. }
  569. },
  570. }
  571. };
  572. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Previous);
  573. Assert.Equal(next, result);
  574. }
  575. [Fact]
  576. public void Previous_Continue_Returns_Last_Child_Of_Sibling()
  577. {
  578. StackPanel container;
  579. Button current;
  580. Button next;
  581. var top = new StackPanel
  582. {
  583. Children = new Controls
  584. {
  585. (container = new StackPanel
  586. {
  587. Children = new Controls
  588. {
  589. new Button { Name = "Button1" },
  590. new Button { Name = "Button2" },
  591. (next = new Button { Name = "Button3" }),
  592. }
  593. }),
  594. (current = new Button { Name = "Button4" }),
  595. }
  596. };
  597. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Previous);
  598. Assert.Equal(next, result);
  599. }
  600. [Fact]
  601. public void Previous_Continue_Returns_Last_Control_In_Previous_Nephew_Container()
  602. {
  603. StackPanel container;
  604. Button current;
  605. Button next;
  606. var top = new StackPanel
  607. {
  608. Children = new Controls
  609. {
  610. new StackPanel
  611. {
  612. Children = new Controls
  613. {
  614. (container = new StackPanel
  615. {
  616. Children = new Controls
  617. {
  618. new Button { Name = "Button1" },
  619. new Button { Name = "Button2" },
  620. (next = new Button { Name = "Button3" }),
  621. }
  622. }),
  623. },
  624. },
  625. new StackPanel
  626. {
  627. Children = new Controls
  628. {
  629. (current = new Button { Name = "Button4" }),
  630. new Button { Name = "Button5" },
  631. new Button { Name = "Button6" },
  632. }
  633. },
  634. }
  635. };
  636. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Previous);
  637. Assert.Equal(next, result);
  638. }
  639. [Fact]
  640. public void Previous_Continue_Wraps()
  641. {
  642. StackPanel container;
  643. Button current;
  644. Button next;
  645. var top = new StackPanel
  646. {
  647. Children = new Controls
  648. {
  649. new StackPanel
  650. {
  651. Children = new Controls
  652. {
  653. (container = new StackPanel
  654. {
  655. Children = new Controls
  656. {
  657. (current = new Button { Name = "Button1" }),
  658. new Button { Name = "Button2" },
  659. new Button { Name = "Button3" },
  660. }
  661. }),
  662. },
  663. },
  664. new StackPanel
  665. {
  666. Children = new Controls
  667. {
  668. new Button { Name = "Button4" },
  669. new Button { Name = "Button5" },
  670. (next = new Button { Name = "Button6" }),
  671. }
  672. },
  673. }
  674. };
  675. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Previous);
  676. Assert.Equal(next, result);
  677. }
  678. [Fact]
  679. public void Previous_Continue_Returns_Parent()
  680. {
  681. Button current;
  682. var top = new Decorator
  683. {
  684. Focusable = true,
  685. Child = current = new Button
  686. {
  687. Name = "Button",
  688. }
  689. };
  690. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Previous);
  691. Assert.Equal(top, result);
  692. }
  693. [Fact]
  694. public void Previous_Cycle_Returns_Previous_Control_In_Container()
  695. {
  696. StackPanel container;
  697. Button current;
  698. Button next;
  699. var top = new StackPanel
  700. {
  701. Children = new Controls
  702. {
  703. (container = new StackPanel
  704. {
  705. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle,
  706. Children = new Controls
  707. {
  708. (next = new Button { Name = "Button1" }),
  709. (current = new Button { Name = "Button2" }),
  710. new Button { Name = "Button3" },
  711. }
  712. }),
  713. new StackPanel
  714. {
  715. Children = new Controls
  716. {
  717. new Button { Name = "Button4" },
  718. new Button { Name = "Button5" },
  719. new Button { Name = "Button6" },
  720. }
  721. },
  722. }
  723. };
  724. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Previous);
  725. Assert.Equal(next, result);
  726. }
  727. [Fact]
  728. public void Previous_Cycle_Wraps_To_Last()
  729. {
  730. StackPanel container;
  731. Button current;
  732. Button next;
  733. var top = new StackPanel
  734. {
  735. Children = new Controls
  736. {
  737. (container = new StackPanel
  738. {
  739. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle,
  740. Children = new Controls
  741. {
  742. (current = new Button { Name = "Button1" }),
  743. new Button { Name = "Button2" },
  744. (next = new Button { Name = "Button3" }),
  745. }
  746. }),
  747. new StackPanel
  748. {
  749. Children = new Controls
  750. {
  751. new Button { Name = "Button4" },
  752. new Button { Name = "Button5" },
  753. new Button { Name = "Button6" },
  754. }
  755. },
  756. }
  757. };
  758. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Previous);
  759. Assert.Equal(next, result);
  760. }
  761. [Fact]
  762. public void Previous_Contained_Returns_Previous_Control_In_Container()
  763. {
  764. StackPanel container;
  765. Button current;
  766. Button next;
  767. var top = new StackPanel
  768. {
  769. Children = new Controls
  770. {
  771. (container = new StackPanel
  772. {
  773. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Contained,
  774. Children = new Controls
  775. {
  776. (next = new Button { Name = "Button1" }),
  777. (current = new Button { Name = "Button2" }),
  778. new Button { Name = "Button3" },
  779. }
  780. }),
  781. new StackPanel
  782. {
  783. Children = new Controls
  784. {
  785. new Button { Name = "Button4" },
  786. new Button { Name = "Button5" },
  787. new Button { Name = "Button6" },
  788. }
  789. },
  790. }
  791. };
  792. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Previous);
  793. Assert.Equal(next, result);
  794. }
  795. [Fact]
  796. public void Previous_Contained_Stops_At_Beginning()
  797. {
  798. StackPanel container;
  799. Button current;
  800. Button next;
  801. var top = new StackPanel
  802. {
  803. Children = new Controls
  804. {
  805. (container = new StackPanel
  806. {
  807. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Contained,
  808. Children = new Controls
  809. {
  810. (current = new Button { Name = "Button1" }),
  811. new Button { Name = "Button2" },
  812. (next = new Button { Name = "Button3" }),
  813. }
  814. }),
  815. new StackPanel
  816. {
  817. Children = new Controls
  818. {
  819. new Button { Name = "Button4" },
  820. new Button { Name = "Button5" },
  821. new Button { Name = "Button6" },
  822. }
  823. },
  824. }
  825. };
  826. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Previous);
  827. Assert.Null(result);
  828. }
  829. [Fact]
  830. public void Previous_Once_Moves_To_Previous_Container()
  831. {
  832. StackPanel container;
  833. Button current;
  834. Button next;
  835. var top = new StackPanel
  836. {
  837. Children = new Controls
  838. {
  839. (container = new StackPanel
  840. {
  841. Children = new Controls
  842. {
  843. new Button { Name = "Button1" },
  844. new Button { Name = "Button2" },
  845. (next = new Button { Name = "Button3" }),
  846. }
  847. }),
  848. new StackPanel
  849. {
  850. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Once,
  851. Children = new Controls
  852. {
  853. new Button { Name = "Button4" },
  854. (current = new Button { Name = "Button5" }),
  855. new Button { Name = "Button6" },
  856. }
  857. },
  858. }
  859. };
  860. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Previous);
  861. Assert.Equal(next, result);
  862. }
  863. [Fact]
  864. public void Previous_Once_Moves_To_Active_Element()
  865. {
  866. StackPanel container;
  867. Button current;
  868. Button next;
  869. var top = new StackPanel
  870. {
  871. Children = new Controls
  872. {
  873. (container = new StackPanel
  874. {
  875. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Once,
  876. Children = new Controls
  877. {
  878. new Button { Name = "Button1" },
  879. (next = new Button { Name = "Button2" }),
  880. new Button { Name = "Button3" },
  881. }
  882. }),
  883. new StackPanel
  884. {
  885. Children = new Controls
  886. {
  887. (current = new Button { Name = "Button4" }),
  888. new Button { Name = "Button5" },
  889. new Button { Name = "Button6" },
  890. }
  891. },
  892. }
  893. };
  894. KeyboardNavigation.SetTabOnceActiveElement(container, next);
  895. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Previous);
  896. Assert.Equal(next, result);
  897. }
  898. [Fact]
  899. public void Previous_Once_Moves_To_First_Element()
  900. {
  901. StackPanel container;
  902. Button current;
  903. Button next;
  904. var top = new StackPanel
  905. {
  906. Children = new Controls
  907. {
  908. (container = new StackPanel
  909. {
  910. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Once,
  911. Children = new Controls
  912. {
  913. (next = new Button { Name = "Button1" }),
  914. new Button { Name = "Button2" },
  915. new Button { Name = "Button3" },
  916. }
  917. }),
  918. new StackPanel
  919. {
  920. Children = new Controls
  921. {
  922. (current = new Button { Name = "Button4" }),
  923. new Button { Name = "Button5" },
  924. new Button { Name = "Button6" },
  925. }
  926. },
  927. }
  928. };
  929. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Previous);
  930. Assert.Equal(next, result);
  931. }
  932. [Fact]
  933. public void Previous_Contained_Doesnt_Select_Child_Control()
  934. {
  935. Decorator current;
  936. var top = new StackPanel
  937. {
  938. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Contained,
  939. Children = new Controls
  940. {
  941. (current = new Decorator
  942. {
  943. Focusable = true,
  944. Child = new Button(),
  945. })
  946. }
  947. };
  948. var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Previous);
  949. Assert.Null(result);
  950. }
  951. }
  952. }