/**
   * Invoke content assist on the given viewer at the given offset, for the given number of pages
   * and return the results of each page
   *
   * @param viewer
   * @param offset
   * @param pageCount
   * @return
   * @throws Exception
   */
  private static ICompletionProposal[][] getProposals(
      StructuredTextViewer viewer, int offset, int pageCount) throws Exception {
    // setup the viewer
    StructuredTextViewerConfigurationHTML configuration =
        new StructuredTextViewerConfigurationHTML();
    ContentAssistant contentAssistant =
        (ContentAssistant) configuration.getContentAssistant(viewer);
    viewer.configure(configuration);
    viewer.setSelectedRange(offset, 0);

    // get the processor
    String partitionTypeID = viewer.getDocument().getPartition(offset).getType();
    IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(partitionTypeID);

    // fire content assist session about to start
    Method privateFireSessionBeginEventMethod =
        ContentAssistant.class.getDeclaredMethod(
            "fireSessionBeginEvent", new Class[] {boolean.class});
    privateFireSessionBeginEventMethod.setAccessible(true);
    privateFireSessionBeginEventMethod.invoke(contentAssistant, new Object[] {Boolean.TRUE});

    // get content assist suggestions
    ICompletionProposal[][] pages = new ICompletionProposal[pageCount][];
    for (int p = 0; p < pageCount; ++p) {
      pages[p] = processor.computeCompletionProposals(viewer, offset);
    }

    // fire content assist session ending
    Method privateFireSessionEndEventMethod =
        ContentAssistant.class.getDeclaredMethod("fireSessionEndEvent", null);
    privateFireSessionEndEventMethod.setAccessible(true);
    privateFireSessionEndEventMethod.invoke(contentAssistant, null);

    return pages;
  }
  /**
   * Run a proposal test by opening the given file and invoking content assist for each expected
   * proposal count at the given line number and line character offset and then compare the number
   * of proposals for each invocation (pages) to the expected number of proposals.
   *
   * @param fileName
   * @param lineNum
   * @param lineRelativeCharOffset
   * @param expectedProposalCounts
   * @throws Exception
   */
  private static void runProposalTest(
      String fileName, int lineNum, int lineRelativeCharOffset, int[] expectedProposalCounts)
      throws Exception {

    IFile file = getFile(fileName);
    StructuredTextEditor editor = getEditor(file);
    StructuredTextViewer viewer = editor.getTextViewer();
    int offset = viewer.getDocument().getLineOffset(lineNum) + lineRelativeCharOffset;

    ICompletionProposal[][] pages = getProposals(viewer, offset, expectedProposalCounts.length);

    verifyProposalCounts(pages, expectedProposalCounts);
  }