001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 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.performance;
011:
012: import org.eclipse.core.resources.IFile;
013: import org.eclipse.core.runtime.CoreException;
014: import org.eclipse.test.performance.Dimension;
015: import org.eclipse.ui.IPerspectiveDescriptor;
016: import org.eclipse.ui.IPerspectiveRegistry;
017: import org.eclipse.ui.IWorkbenchPage;
018: import org.eclipse.ui.IWorkbenchWindow;
019: import org.eclipse.ui.WorkbenchException;
020: import org.eclipse.ui.ide.IDE;
021: import org.eclipse.ui.internal.WorkbenchPlugin;
022:
023: /**
024: * Test perspective switching.
025: */
026: public class PerspectiveSwitchTest extends BasicPerformanceTest {
027:
028: private String id1;
029: private String id2;
030: private String activeEditor;
031:
032: /**
033: * Constructor.
034: *
035: * @param id
036: */
037: public PerspectiveSwitchTest(String[] ids, int tagging) {
038: super ("testPerspectiveSwitch:" + ids[0] + "," + ids[1]
039: + ",editor " + ids[2], tagging);
040: this .id1 = ids[0];
041: this .id2 = ids[1];
042: this .activeEditor = ids[2];
043: setDegradationComment("<a href=https://bugs.eclipse.org/bugs/show_bug.cgi?id=179581>See Bug 179581</a>");
044: }
045:
046: /**
047: * Test perspective switching performance.
048: */
049: protected void runTest() throws CoreException, WorkbenchException {
050: // Get the two perspectives to switch between.
051: final IPerspectiveRegistry registry = WorkbenchPlugin
052: .getDefault().getPerspectiveRegistry();
053: final IPerspectiveDescriptor perspective1 = registry
054: .findPerspectiveWithId(id1);
055: final IPerspectiveDescriptor perspective2 = registry
056: .findPerspectiveWithId(id2);
057:
058: // Don't fail if we reference an unknown perspective ID. This can be
059: // a normal occurrance since the test suites reference JDT perspectives, which
060: // might not exist. Just skip the test.
061: if (perspective1 == null) {
062: System.out.println("Unknown perspective ID: " + id1);
063: return;
064: }
065:
066: if (perspective2 == null) {
067: System.out.println("Unknown perspective ID: " + id2);
068: return;
069: }
070:
071: // Open the two perspectives and the file, in a new window.
072: // Do this outside the loop so as not to include
073: // the initial time to open, just switching.
074: IWorkbenchWindow window = openTestWindow(id1);
075: final IWorkbenchPage page = window.getActivePage();
076: assertNotNull(page);
077: page.setPerspective(perspective2);
078:
079: //IFile aFile = getProject().getFile("1." + EditorPerformanceSuite.EDITOR_FILE_EXTENSIONS[0]);
080: IFile aFile = getProject().getFile(activeEditor);
081: assertTrue(aFile.exists());
082:
083: IDE.openEditor(page, aFile, true);
084:
085: tagIfNecessary("UI - Perspective Switch",
086: Dimension.ELAPSED_PROCESS);
087:
088: exercise(new TestRunnable() {
089: public void run() throws Exception {
090: processEvents();
091:
092: startMeasuring();
093: page.setPerspective(perspective1);
094: processEvents();
095: page.setPerspective(perspective2);
096: processEvents();
097: stopMeasuring();
098: }
099: });
100:
101: commitMeasurements();
102: assertPerformance();
103: }
104: }
|