001: /*******************************************************************************
002: * Copyright (c) 2004, 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.test.performance.Dimension;
013: import org.eclipse.ui.IPerspectiveDescriptor;
014: import org.eclipse.ui.IPerspectiveRegistry;
015: import org.eclipse.ui.IViewReference;
016: import org.eclipse.ui.IWorkbenchPage;
017: import org.eclipse.ui.IWorkbenchWindow;
018: import org.eclipse.ui.internal.ClosePerspectiveAction;
019: import org.eclipse.ui.internal.WorkbenchPlugin;
020:
021: /**
022: * @since 3.1
023: */
024: public class OpenClosePerspectiveTest extends BasicPerformanceTest {
025:
026: private String id;
027:
028: /**
029: * @param tagging
030: * @param testName
031: */
032: public OpenClosePerspectiveTest(String id, int tagging) {
033: super ("testOpenClosePerspectives:" + id, tagging);
034: this .id = id;
035: }
036:
037: protected void runTest() throws Throwable {
038: // Get the two perspectives to switch between.
039: final IPerspectiveRegistry registry = WorkbenchPlugin
040: .getDefault().getPerspectiveRegistry();
041: final IPerspectiveDescriptor perspective1 = registry
042: .findPerspectiveWithId(id);
043:
044: // Don't fail if we reference an unknown perspective ID. This can be
045: // a normal occurrance since the test suites reference JDT perspectives, which
046: // might not exist.
047: if (perspective1 == null) {
048: System.out.println("Unknown perspective id: " + id);
049: return;
050: }
051:
052: // create a nice clean window.
053: IWorkbenchWindow window = openTestWindow();
054: final IWorkbenchPage activePage = window.getActivePage();
055:
056: //causes creation of all views
057: activePage.setPerspective(perspective1);
058: IViewReference[] refs = activePage.getViewReferences();
059: //get the IDs now - after we close hte perspective the view refs will be partiall disposed and their IDs will be null
060: String[] ids = new String[refs.length];
061: for (int i = 0; i < refs.length; i++) {
062: ids[i] = refs[i].getId();
063: }
064: closePerspective(activePage);
065: //populate the empty perspective with all view that will be shown in the test view
066: for (int i = 0; i < ids.length; i++) {
067: activePage.showView(ids[i]);
068: }
069:
070: tagIfNecessary("UI - Open/Close " + perspective1.getLabel()
071: + " Perspective", Dimension.ELAPSED_PROCESS);
072:
073: exercise(new TestRunnable() {
074: public void run() throws Exception {
075: processEvents();
076: EditorTestHelper.calmDown(500, 30000, 500);
077:
078: startMeasuring();
079: activePage.setPerspective(perspective1);
080: processEvents();
081: closePerspective(activePage);
082: processEvents();
083: stopMeasuring();
084: }
085: });
086:
087: commitMeasurements();
088: assertPerformance();
089: }
090:
091: /**
092: * @param activePage
093: */
094: private void closePerspective(IWorkbenchPage activePage) {
095: // we dont have API to close a perspective so use the close perspective action instead.
096: ClosePerspectiveAction action = new ClosePerspectiveAction(
097: activePage.getWorkbenchWindow());
098: action.run();
099: action.dispose();
100: }
101: }
|