Exemple #1
0
 @After
 public void tearDown() throws Exception {
   if (editor != null) {
     EditorTestHelper.closeEditor(editor);
     editor = null;
   }
 }
  /**
   *
   *
   * <pre>
   * - We create a file with a function
   * - open the JS editor on it
   * - make some unsaved changes
   * - let it reconcile
   * - invoke CA to see that the unsaved contents are reflected in the CA
   * - close the editor without saving those changes
   * - wait for re-index of the underlying file to occur
   * - verify that the index now reflects underlying file's contents and not the unsaved changes.
   * </pre>
   *
   * @throws Exception
   */
  @Test
  public void testAPSTUD2944() throws Exception {
    // Create a test project and file
    project = createTestProject();
    IFile file = project.createFile("apstud2944.js", "function delete_me() {}\n");

    // open JS editor on file
    editor = (ITextEditor) EditorTestHelper.openInEditor(file, "com.aptana.editor.js", true);
    ISourceViewer viewer = ((AbstractThemeableEditor) editor).getISourceViewer();

    EditorTestHelper.joinReconciler((SourceViewer) viewer, 100L, 2000L, 100L);

    // Verify initial contents
    Index index = getIndexManager().getIndex(project.getURI());

    JSIndexQueryHelper _indexHelper = new JSIndexQueryHelper(project.getInnerProject());
    Collection<PropertyElement> projectGlobals = _indexHelper.getGlobals("apstud2944.js");
    assertContainsFunctions(projectGlobals, "delete_me");
    assertDoesntContainFunctions(projectGlobals, "foo");

    // Set the working copy contents to some new valid JS
    IDocument document = EditorTestHelper.getDocument(editor);
    document.set("function foo() { var eight = 8; }");

    // Wait for reconcile
    EditorTestHelper.joinReconciler((SourceViewer) viewer, 100L, 2000L, 100L);

    // get proposals at end of document
    this.processor = new JSContentAssistProcessor((AbstractThemeableEditor) editor);
    ICompletionProposal[] proposals = processor.computeCompletionProposals(viewer, 33, '\0', false);

    // verify that CA contains elements from unsaved JS in document!
    assertContains(proposals, "foo");
    assertDoesntContain(proposals, "delete_me");

    // TODO Verify "eight" is in CA inside foo?

    // Close the editor without saving, make sure we end up indexing underlying content again!
    EditorTestHelper.closeEditor(editor);

    Thread.sleep(1000); // FIXME Is there anyway to tell when indexing happens and is finished?

    // Now verify that our index reflects the file's contents and not the unsaved contents of the
    // editor.
    assertContainsFunctions(projectGlobals, "delete_me");
    assertDoesntContainFunctions(projectGlobals, "foo");
  }
  protected void tearDown() throws Exception {
    if (editor != null) {
      EditorTestHelper.closeEditor(editor);
      editor = null;
    }

    if (file != null) {
      if (!file.delete()) {
        file.deleteOnExit();
      }
    }

    if (project != null) {
      project.delete();
      project = null;
    }

    manager = null;
    super.tearDown();
  }