Skip to content

FormEditor does not cleanup pages on tab disposal #3766

Description

@basilevs
	@Test
	public void disposeTab() throws PartInitException {
		FormEditorMock.hook = FormEditorMock.DEFAULT_HOOK;
		FormEditorMock subject = (FormEditorMock) WORKBENCH.getActiveWorkbenchWindow().getActivePage().openEditor(input,
				FormEditorMock.ID);
		dispatch(subject);
		CTabItem[] tabs = subject.leakContainer().getItems();
		assertEquals(1, tabs.length);
		FormPage page1 = addPage(subject, "page1");
		assertSame(page1, subject.findPage("page1"));
		tabs = subject.leakContainer().getItems();
		assertEquals(2, tabs.length);
		tabs[tabs.length - 1].dispose();
		dispatch(subject);
		tabs = subject.leakContainer().getItems();
		assertEquals(1, tabs.length);
		// BUG
		// assertNull(subject.findPage("page1"));
	}

	@Test
	public void maintainIntegrityOnPageClose() throws PartInitException {
		FormEditorMock.hook = new Hook() {
			@Override
			public void createContainer(FormEditorMock subject, CTabFolder container) {
				Hook.super.createContainer(subject, container);
				container.setUnselectedCloseVisible(true);
			}

			@Override
			public void createItem(FormEditorMock subject, CTabItem item) {
				Hook.super.createItem(subject, item);
				item.setShowClose(true);
			}
		};
		FormEditorMock subject = (FormEditorMock) WORKBENCH.getActiveWorkbenchWindow().getActivePage().openEditor(input,
				FormEditorMock.ID);
		FormPage page1 = addPage(subject, "page1");
		CTabFolder tabFolder = subject.leakContainer();
		CTabItem tab = tabFolder.getItem(1);
		assertTrue(tab.getShowClose());
		assertSame(page1, subject.findPage("page1"));
		Event event = new Event();
		event.type = SWT.MouseDown;
		event.button = 1;
		event.x = tab.getBounds().x + tab.getBounds().width - 9;
		event.y = tab.getBounds().y + tab.getBounds().height/2;
		tabFolder.notifyListeners(event.type, event);
		dispatch(subject);
		event.type = SWT.MouseUp;
		tabFolder.notifyListeners(event.type, event);
		dispatch(subject);
		assertEquals(1, tabFolder.getItems().length);
		// BUG
		// assertNull(subject.findPage("page1"));
	}

To reproduce, pull from #3765 and uncomment BUG lines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions