001: /*******************************************************************************
002: * Copyright (c) 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - Initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.tests.browser.internal;
011:
012: import junit.framework.Test;
013: import junit.framework.TestCase;
014: import org.eclipse.jface.dialogs.Dialog;
015: import org.eclipse.swt.layout.GridData;
016: import org.eclipse.swt.widgets.Composite;
017: import org.eclipse.swt.widgets.Control;
018: import org.eclipse.swt.widgets.Display;
019: import org.eclipse.swt.widgets.Shell;
020: import org.eclipse.ui.PlatformUI;
021: import org.eclipse.ui.internal.browser.BrowserViewer;
022:
023: public class ToolbarBrowserTestCase extends TestCase {
024: protected static Dialog dialog;
025: protected static Shell shell;
026: protected static BrowserViewer browser;
027:
028: class TestToolbarBrowser extends BrowserViewer {
029:
030: public TestToolbarBrowser(Composite parent, int style) {
031: super (parent, style);
032: }
033:
034: public void testProtectedMethods() {
035: super .addToHistory("www.eclispe.org");
036: super .updateBackNextBusy();
037: super .updateHistory();
038: super .updateLocation();
039: }
040: }
041:
042: public static Test suite() {
043: return new OrderedTestSuite(ToolbarBrowserTestCase.class,
044: "ToolbarBrowserTestCase");
045: }
046:
047: public void test00Open() throws Exception {
048: shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
049: .getShell();
050: dialog = new Dialog(shell) {
051: protected Control createDialogArea(Composite parent) {
052: Composite composite = (Composite) super
053: .createDialogArea(parent);
054:
055: browser = new BrowserViewer(composite,
056: BrowserViewer.LOCATION_BAR
057: | BrowserViewer.BUTTON_BAR);
058: GridData data = new GridData(GridData.FILL_BOTH);
059: data.widthHint = 400;
060: data.heightHint = 400;
061: browser.setLayoutData(data);
062:
063: return composite;
064: }
065: };
066: dialog.setBlockOnOpen(false);
067: dialog.open();
068:
069: boolean b = Display.getCurrent().readAndDispatch();
070: while (b)
071: b = Display.getCurrent().readAndDispatch();
072: }
073:
074: public void test01SetURL() throws Exception {
075: runLoopTimer(5);
076: browser.setURL("http://www.eclipse.org");
077: runLoopTimer(10);
078: }
079:
080: public void test02Home() throws Exception {
081: browser.home();
082: runLoopTimer(2);
083: }
084:
085: public void test03SetURL() throws Exception {
086: browser.setURL("http://www.eclipse.org/webtools/index.html");
087: runLoopTimer(10);
088: }
089:
090: public void test04IsBackEnabled() throws Exception {
091: assertTrue(browser.isBackEnabled());
092: }
093:
094: public void test05Back() throws Exception {
095: assertTrue(browser.back());
096: runLoopTimer(5);
097: }
098:
099: public void test06IsForwardEnabled() throws Exception {
100: assertTrue(browser.isForwardEnabled());
101: }
102:
103: public void test07Forward() throws Exception {
104: assertTrue(browser.forward());
105: runLoopTimer(5);
106: }
107:
108: public void test08Refresh() throws Exception {
109: browser.refresh();
110: }
111:
112: public void test09GetBrowser() throws Exception {
113: assertNotNull(browser.getBrowser());
114: }
115:
116: public void test10Stop() throws Exception {
117: browser.stop();
118: }
119:
120: public void test11GetURL() throws Exception {
121: assertNotNull(browser.getURL());
122: }
123:
124: public void test12SetFocus() throws Exception {
125: browser.setFocus();
126: }
127:
128: public void test13Close() throws Exception {
129: dialog.close();
130: }
131:
132: TestToolbarBrowser ttb = null;
133:
134: public void test14ProtectedMethods() {
135: shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
136: .getShell();
137: dialog = new Dialog(shell) {
138: protected Control createDialogArea(Composite parent) {
139: Composite composite = (Composite) super
140: .createDialogArea(parent);
141:
142: ttb = new TestToolbarBrowser(composite,
143: BrowserViewer.LOCATION_BAR
144: | BrowserViewer.BUTTON_BAR);
145: GridData data = new GridData(GridData.FILL_BOTH);
146: data.widthHint = 400;
147: data.heightHint = 400;
148: ttb.setLayoutData(data);
149:
150: return composite;
151: }
152: };
153: dialog.setBlockOnOpen(false);
154: dialog.open();
155:
156: ttb.testProtectedMethods();
157: dialog.close();
158: }
159:
160: public void test15Listeners() {
161: BrowserViewer.IBackNextListener listener = new BrowserViewer.IBackNextListener() {
162: public void updateBackNextBusy() {
163: // ignore
164: }
165: };
166:
167: listener.updateBackNextBusy();
168: }
169:
170: public void test16Listeners() {
171: BrowserViewer.ILocationListener listener = new BrowserViewer.ILocationListener() {
172: public void locationChanged(String url) {
173: // ignore
174: }
175:
176: public void historyChanged(String[] history2) {
177: // ignore
178: }
179: };
180:
181: listener.locationChanged(null);
182: listener.historyChanged(null);
183: }
184:
185: void runLoopTimer(final int seconds) {
186: final boolean[] exit = { false };
187: new Thread() {
188: public void run() {
189: try {
190: Thread.sleep(seconds * 1000);
191: } catch (Exception e) {
192: // ignore
193: }
194: exit[0] = true;
195: // wake up the event loop
196: Display display = Display.getDefault();
197: if (!display.isDisposed()) {
198: display.asyncExec(new Runnable() {
199: public void run() {
200: if (!shell.isDisposed())
201: shell.redraw();
202: }
203: });
204: }
205: }
206: }.start();
207: shell.open();
208: Display display = Display.getCurrent();
209: while (!exit[0] && !shell.isDisposed())
210: if (!display.readAndDispatch())
211: display.sleep();
212: }
213: }
|