2012-02-16 11:32:33 -08:00
# filter substitution
package @ ANDROID_PACKAGE_NAME @ . tests ;
import @ ANDROID_PACKAGE_NAME @ . * ;
import android.util.DisplayMetrics ;
2012-09-25 09:56:34 -07:00
/ * Test the context menu on web content : Long click on a link ,
* verify that the context menu is shown and verify that some
* of the menu actions work .
* /
2013-02-26 04:46:02 -08:00
2012-09-25 09:56:34 -07:00
public class testWebContentContextMenu extends PixelTest {
2013-02-26 04:46:02 -08:00
2012-06-27 16:56:49 -07:00
@Override
protected int getTestType ( ) {
return TEST_MOCHITEST ;
2013-02-26 04:46:02 -08:00
2012-06-27 16:56:49 -07:00
}
2012-02-16 11:32:33 -08:00
public void testWebContentContextMenu ( ) {
2012-10-25 12:37:39 -07:00
blockForGeckoReady ( ) ;
2012-02-16 11:32:33 -08:00
2013-02-26 04:46:02 -08:00
String urls [ ] = { " /robocop/robocop_big_link.html " , " /robocop/robocop_big_mailto.html " , " /robocop/robocop_picture_link.html " } ;
String linkMenuItems [ ] = { " Open Link in New Tab " , " Open Link in Private Tab " , " Copy Link " , " Share Link " , " Bookmark Link " } ;
String mailtoMenuItems [ ] = { " Open With an App " , " Copy Email Address " , " Share Email Address " } ;
String photoMenuItems [ ] = { " Copy Image Location " , " Share Image " , " Set as Wallpaper " , " Save Image " } ;
verfyLinkContextMenu ( linkMenuItems , urls ) ;
verfyMailtoContextMenu ( mailtoMenuItems , urls ) ;
verfyPhotoContextMenu ( photoMenuItems , urls ) ;
}
public void openContextMenu ( int i , String urls [ ] ) {
2012-02-16 11:32:33 -08:00
DisplayMetrics dm = new DisplayMetrics ( ) ;
getActivity ( ) . getWindowManager ( ) . getDefaultDisplay ( ) . getMetrics ( dm ) ;
// The link has a 60px height, so let's try to hit the middle
float top = mDriver . getGeckoTop ( ) + 30 * dm . density ;
float left = mDriver . getGeckoLeft ( ) + mDriver . getGeckoWidth ( ) / 2 ;
2012-02-21 21:11:50 -08:00
2013-02-26 04:46:02 -08:00
String url = getAbsoluteUrl ( urls [ i ] ) ;
getInstrumentation ( ) . waitForIdleSync ( ) ;
2012-09-25 09:56:34 -07:00
loadAndPaint ( url ) ;
mAsserter . dumpLog ( " long-clicking at " + left + " , " + top ) ;
2012-02-16 11:32:33 -08:00
mSolo . clickLongOnScreen ( left , top ) ;
2013-02-26 04:46:02 -08:00
}
2012-02-16 11:32:33 -08:00
2013-02-26 04:46:02 -08:00
public void accessSection ( int i , String opt , String urls [ ] ) {
openContextMenu ( i , urls ) ;
mAsserter . ok ( mSolo . waitForText ( opt ) , " Waiting for " + opt + " option " , " The " + opt + " option is present " ) ;
mSolo . clickOnText ( opt ) ;
}
2012-02-16 11:32:33 -08:00
2013-02-26 04:46:02 -08:00
public void verfyLinkContextMenu ( String items [ ] , String urls [ ] ) {
for ( String opt : items ) {
if ( opt . equals ( " Open Link in New Tab " ) ) {
openContextMenu ( 0 , urls ) ;
mAsserter . ok ( mSolo . waitForText ( opt ) , " Waiting for " + opt + " option " , " The " + opt + " option is present " ) ;
Actions . EventExpecter tabEventExpecter = mActions . expectGeckoEvent ( " Tab:Added " ) ;
Actions . EventExpecter contentEventExpecter = mActions . expectGeckoEvent ( " DOMContentLoaded " ) ;
mSolo . clickOnText ( opt ) ;
// Wait for the new tab and page to load
tabEventExpecter . blockForEvent ( ) ;
contentEventExpecter . blockForEvent ( ) ;
2013-04-18 20:18:09 -07:00
tabEventExpecter . unregisterListener ( ) ;
contentEventExpecter . unregisterListener ( ) ;
2013-02-26 04:46:02 -08:00
// See tab count
Element tabCount = mDriver . findElement ( getActivity ( ) , " tabs_count " ) ;
String tabCountText = null ;
if ( tabCount ! = null ) {
tabCountText = tabCount . getText ( ) ;
}
mAsserter . is ( tabCountText , " 2 " , " Number of tabs has increased " ) ;
}
else {
if ( opt . equals ( " Open Link in Private Tab " ) ) {
accessSection ( 2 , opt , urls ) ;
mAsserter . ok ( mSolo . waitForText ( " New private tab opened " ) , " Waiting for private tab to open " , " The private tab is opened " ) ;
// Verifying if the private data is not listed in Awesomescreen
2013-07-18 16:02:48 -07:00
focusUrlBar ( ) ;
2013-02-26 04:46:02 -08:00
mSolo . clickOnText ( " History " ) ;
mAsserter . ok ( mSolo . waitForText ( " Browser Blank Page 01 " ) , " Looking in History for the page loaded in the normal tab " , " Fount it " ) ;
mAsserter . ok ( mSolo . waitForText ( " Browser Blank Page 02 " ) = = false , " Looking in History for the page loaded in the private tab " , " Page is not present in History " ) ;
}
else {
if ( opt . equals ( " Copy Link " ) ) {
accessSection ( 0 , opt , urls ) ;
// Verifying if the link was copied
mSolo . clickLongOnText ( " Big Link " ) ;
mAsserter . ok ( mSolo . waitForText ( " ^Paste$ " ) , " Verify if the 'Paste' option is present " , " The 'Paste' option is present " ) ;
mSolo . clickOnText ( " ^Paste$ " ) ;
mAsserter . ok ( mSolo . waitForText ( " robocop_blank_01.html " ) , " Verify link " , " The link was properly copied " ) ;
}
else {
if ( opt . equals ( " Share Link " ) ) {
accessSection ( 0 , opt , urls ) ;
// Verifying if the Share Link option menu is opened
mAsserter . ok ( mSolo . waitForText ( " Share via " ) , " Waiting for the Share Link option menu to open " , " The Share Link option menu is opened " ) ;
mActions . sendSpecialKey ( Actions . SpecialKey . BACK ) ; // Close the Share Link option menu
mSolo . waitForText ( " Big Link " ) ;
}
else {
if ( opt . equals ( " Bookmark Link " ) ) {
Navigation nav = new Navigation ( mDevice ) ;
accessSection ( 0 , opt , urls ) ;
mAsserter . is ( mSolo . waitForText ( " Bookmark added " ) , true , " Bookmark added verified " ) ;
// This waitForIdleSync improves reliability of the following loadUrl.
// TODO: understand why!
getInstrumentation ( ) . waitForIdleSync ( ) ;
// We know that the link test page points to robocop_blank_01.html, so lets
// load it and see if the page is bookmarked
String url = getAbsoluteUrl ( " /robocop/robocop_blank_01.html " ) ;
loadAndPaint ( url ) ;
// Pause briefly, to ensure that the bookmark addition, above, updates database tables and
// completes before checking that the bookmark exists.
// TODO: Find a better way to wait for completion of bookmark operations.
try { Thread . sleep ( 2000 ) ; } catch ( Exception e ) { }
// TODO: This doesn't work for some reason. We got a 'Bookmark added' and
// will check for 'Bookmark removed'
mAsserter . todo_is ( mSolo . isTextChecked ( " Bookmark " ) , true , " Page is bookmarked " ) ;
nav . bookmark ( ) ;
mAsserter . is ( mSolo . waitForText ( " Bookmark removed " ) , true , " Bookmark removal verified " ) ;
}
}
}
}
}
2012-05-22 16:25:30 -07:00
}
2013-02-26 04:46:02 -08:00
}
2012-02-21 21:11:50 -08:00
2013-02-26 04:46:02 -08:00
public void verfyMailtoContextMenu ( String items [ ] , String urls [ ] ) {
for ( String opt : items ) {
if ( opt . equals ( " Copy Email Address " ) ) {
openContextMenu ( 1 , urls ) ;
mAsserter . ok ( mSolo . waitForText ( opt ) , " Waiting for " + opt + " option " , " The " + opt + " option is present " ) ;
mSolo . clickOnText ( opt ) ;
// Verifying if the email address was copied
mSolo . clickLongOnText ( " Big Mailto " ) ;
mAsserter . ok ( mSolo . waitForText ( " ^Paste$ " ) , " Verify if the 'Paste' option is present " , " The 'Paste' option is present " ) ;
mSolo . clickOnText ( " ^Paste$ " ) ;
mAsserter . ok ( mSolo . waitForText ( " foo.bar@example.com " ) , " Verify email address " , " The email address was properly copied " ) ;
}
else {
if ( opt . equals ( " Share Email Address " ) ) {
accessSection ( 1 , opt , urls ) ;
// Verifying if the Share email address option menu is opened
mAsserter . ok ( mSolo . waitForText ( " Share via " ) , " Waiting for the Share email address option menu to open " , " The Share email address option menu is opened " ) ;
}
}
}
mActions . sendSpecialKey ( Actions . SpecialKey . BACK ) ; // Close the Share email address option menu
mSolo . waitForText ( " Big Mailto " ) ;
}
2012-02-21 21:11:50 -08:00
2013-02-26 04:46:02 -08:00
// Load a picture test page and test for allowed menu actions
public void verfyPhotoContextMenu ( String items [ ] , String urls [ ] ) {
for ( String opt : items ) {
if ( opt . equals ( " Copy Image Location " ) ) {
// This waitForIdleSync improves reliability of the following loadUrl.
// TODO: understand why!
getInstrumentation ( ) . waitForIdleSync ( ) ;
accessSection ( 2 , opt , urls ) ;
// Verifying if the photo's link was copied
mSolo . clickLongOnText ( " Picture Link " ) ;
mAsserter . ok ( mSolo . waitForText ( " ^Paste$ " ) , " Verify if the 'Paste' option is present " , " The 'Paste' option is present " ) ;
mSolo . clickOnText ( " ^Paste$ " ) ;
mAsserter . ok ( mSolo . waitForText ( " Firefox.jpg " ) , " Verify link " , " The photo's link was properly copied " ) ;
}
else {
if ( opt . equals ( " Share Image " ) ) {
accessSection ( 2 , opt , urls ) ;
// Verifying if the Share Image option menu is opened
mAsserter . ok ( mSolo . waitForText ( " Share via " ) , " Waiting for the Share Image option menu to open " , " The Share Image option menu is opened " ) ;
mActions . sendSpecialKey ( Actions . SpecialKey . BACK ) ; // Close the Share Image option menu
mSolo . waitForText ( " Picture Link " ) ;
}
else {
if ( opt . equals ( " Set as Wallpaper " ) ) {
openContextMenu ( 2 , urls ) ;
mAsserter . ok ( mSolo . waitForText ( opt ) , " Waiting for " + opt + " option " , " The " + opt + " option is present " ) ;
}
else {
if ( opt . equals ( " Save Image " ) ) {
mSolo . clickOnText ( opt ) ;
mAsserter . ok ( mSolo . waitForText ( " Download started " ) , " Verify that the download started " , " The download started " ) ;
mSolo . waitForText ( " Picture Link " ) ;
}
}
}
}
}
2012-02-16 11:32:33 -08:00
}
}