I've tried several configurations on accessing my Gmail account (I just confirmed from gmail that IMAP is enabled, and I have accessed Gmail from my iPhone).
Among the settings I tried were:
Email address: firstname.lastname@example.org
Account name: Gmail
Account type: IMAP
Email Server: imap.gmail.com
Advanced settings: [Nothing checked]
When I click "Test Settings", I get a window that says:
Error: Generic Test Failure
Note: If you continue to save, account will be marked inactive.
Press Cancel to return to editing accounts.