您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

MainFrameTest.java 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.addons.ui_swing;
  23. import com.dmdirc.Main;
  24. import com.dmdirc.config.IdentityManager;
  25. import com.dmdirc.config.InvalidIdentityFileException;
  26. import com.dmdirc.harness.ui.UIClassTestRunner;
  27. import com.dmdirc.harness.ui.UITestIface;
  28. import com.dmdirc.addons.ui_swing.dialogs.FeedbackDialog;
  29. import com.dmdirc.addons.ui_swing.dialogs.NewServerDialog;
  30. import com.dmdirc.addons.ui_swing.dialogs.about.AboutDialog;
  31. import com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog;
  32. import com.dmdirc.addons.ui_swing.dialogs.aliases.AliasManagerDialog;
  33. import com.dmdirc.addons.ui_swing.dialogs.prefs.SwingPreferencesDialog;
  34. import com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileManagerDialog;
  35. import java.lang.reflect.InvocationTargetException;
  36. import javax.swing.SwingUtilities;
  37. import org.fest.swing.finder.WindowFinder;
  38. import org.fest.swing.fixture.DialogFixture;
  39. import org.fest.swing.fixture.FrameFixture;
  40. import org.junit.After;
  41. import org.junit.Before;
  42. import org.junit.BeforeClass;
  43. import org.junit.Test;
  44. import org.junit.runner.RunWith;
  45. @RunWith(UIClassTestRunner.class)
  46. public class MainFrameTest implements UITestIface {
  47. private static FrameFixture window;
  48. private DialogFixture newwin;
  49. private static SwingController controller;
  50. @BeforeClass
  51. public static void setUpClass() throws InvalidIdentityFileException {
  52. IdentityManager.load();
  53. controller = new SwingController();
  54. controller.onLoad();
  55. Main.setUI(controller);
  56. }
  57. @Before
  58. public void setUp() {
  59. if (window == null) {
  60. window = new FrameFixture(controller.getMainWindow());
  61. window.show();
  62. }
  63. }
  64. @Test
  65. public void testNewServerDialog() {
  66. window.menuItemWithPath("Server", "New Server...").click();
  67. newwin = WindowFinder.findDialog(NewServerDialog.class)
  68. .withTimeout(5000).using(window.robot);
  69. newwin.requireVisible();
  70. }
  71. @Test
  72. public void testAboutDialog() {
  73. window.menuItemWithPath("Help", "About").click();
  74. newwin = WindowFinder.findDialog(AboutDialog.class)
  75. .withTimeout(5000).using(window.robot);
  76. newwin.requireVisible();
  77. }
  78. @Test
  79. public void testFeedbackDialog() {
  80. window.menuItemWithPath("Help", "Send Feedback").click();
  81. newwin = WindowFinder.findDialog(FeedbackDialog.class)
  82. .withTimeout(5000).using(window.robot);
  83. newwin.requireVisible();
  84. }
  85. @Test
  86. public void testPreferencesDialog() {
  87. window.menuItemWithPath("Settings", "Preferences").click();
  88. newwin = WindowFinder.findDialog(SwingPreferencesDialog.class)
  89. .withTimeout(5000).using(window.robot);
  90. newwin.requireVisible();
  91. }
  92. @Test
  93. public void testProfileManagerDialog() {
  94. window.menuItemWithPath("Settings", "Profile Manager").click();
  95. newwin = WindowFinder.findDialog(ProfileManagerDialog.class)
  96. .withTimeout(5000).using(window.robot);
  97. newwin.requireVisible();
  98. }
  99. @Test
  100. public void testActionsManagerDialog() {
  101. window.menuItemWithPath("Settings", "Actions Manager").click();
  102. newwin = WindowFinder.findDialog(ActionsManagerDialog.class)
  103. .withTimeout(5000).using(window.robot);
  104. newwin.requireVisible();
  105. }
  106. @Test
  107. public void testAliasManagerDialog() {
  108. window.menuItemWithPath("Settings", "Alias Manager").click();
  109. newwin = WindowFinder.findDialog(AliasManagerDialog.class)
  110. .withTimeout(5000).using(window.robot);
  111. newwin.requireVisible();
  112. }
  113. @Test
  114. public void testChannelServerSettings() {
  115. window.menuItemWithPath("Channel", "Channel Settings").requireDisabled();
  116. }
  117. @Test
  118. public void testServerServerSettings() {
  119. window.menuItemWithPath("Server", "Server settings").requireDisabled();
  120. }
  121. @Override @After
  122. public void tearDown() throws InterruptedException, InvocationTargetException {
  123. SwingUtilities.invokeAndWait(new Runnable() {
  124. @Override
  125. public void run() {
  126. close();
  127. }
  128. });
  129. }
  130. protected void close() {
  131. if (newwin != null && newwin.target != null) {
  132. try {
  133. newwin.target.dispose();
  134. } catch (Throwable ex) {
  135. ex.printStackTrace();
  136. }
  137. }
  138. }
  139. }