From ab67c195d5d5a6a982929dd480b9c3ffbe9237eb Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Wed, 26 Mar 2014 10:18:01 -0700 Subject: [PATCH] Bug 942270 - Fix tests for quickshare. r=gbrown --- build/mobile/robocop/AndroidManifest.xml.in | 24 +++++++++++++ build/mobile/robocop/Makefile.in | 2 ++ build/mobile/robocop/RobocopShare1.java | 17 +++++++++ build/mobile/robocop/RobocopShare2.java | 17 +++++++++ .../base/tests/ContentContextMenuTest.java | 35 ++++++++++++++++--- .../tests/testPictureLinkContextMenu.java | 23 ++++++++---- 6 files changed, 107 insertions(+), 11 deletions(-) create mode 100644 build/mobile/robocop/RobocopShare1.java create mode 100644 build/mobile/robocop/RobocopShare2.java diff --git a/build/mobile/robocop/AndroidManifest.xml.in b/build/mobile/robocop/AndroidManifest.xml.in index 51a2922ef0b8..23bb32250f09 100644 --- a/build/mobile/robocop/AndroidManifest.xml.in +++ b/build/mobile/robocop/AndroidManifest.xml.in @@ -14,6 +14,30 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/mobile/robocop/Makefile.in b/build/mobile/robocop/Makefile.in index 245696671b0c..4ea7500e4f73 100644 --- a/build/mobile/robocop/Makefile.in +++ b/build/mobile/robocop/Makefile.in @@ -26,6 +26,8 @@ _JAVA_HARNESS := \ FennecNativeDriver.java \ FennecNativeElement.java \ RoboCopException.java \ + RobocopShare1.java \ + RobocopShare2.java \ RobocopUtils.java \ PaintedSurface.java \ $(NULL) diff --git a/build/mobile/robocop/RobocopShare1.java b/build/mobile/robocop/RobocopShare1.java new file mode 100644 index 000000000000..80ab3396c20e --- /dev/null +++ b/build/mobile/robocop/RobocopShare1.java @@ -0,0 +1,17 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.gecko; + +import android.os.Bundle; +import android.support.v4.app.FragmentActivity; + +public class RobocopShare1 extends FragmentActivity { + private static Bundle sArguments; + + @Override + public void onCreate(Bundle arguments) { + super.onCreate(arguments); + } +} diff --git a/build/mobile/robocop/RobocopShare2.java b/build/mobile/robocop/RobocopShare2.java new file mode 100644 index 000000000000..4874dffb76fd --- /dev/null +++ b/build/mobile/robocop/RobocopShare2.java @@ -0,0 +1,17 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.gecko; + +import android.os.Bundle; +import android.support.v4.app.FragmentActivity; + +public class RobocopShare2 extends FragmentActivity { + private static Bundle sArguments; + + @Override + public void onCreate(Bundle arguments) { + super.onCreate(arguments); + } +} diff --git a/mobile/android/base/tests/ContentContextMenuTest.java b/mobile/android/base/tests/ContentContextMenuTest.java index 19b23f0949dd..e6632073e684 100644 --- a/mobile/android/base/tests/ContentContextMenuTest.java +++ b/mobile/android/base/tests/ContentContextMenuTest.java @@ -29,7 +29,10 @@ abstract class ContentContextMenuTest extends PixelTest { protected void verifyContextMenuItems(String[] items) { // Test that the menu items are displayed - openWebContentContextMenu(items[0]); + if (!mSolo.searchText(items[0])) { + openWebContentContextMenu(items[0]); // Open the context menu if it is not already + } + for (String option:items) { mAsserter.ok(mSolo.searchText(option), "Checking that the option: " + option + " is available", "The option is available"); } @@ -46,6 +49,24 @@ abstract class ContentContextMenuTest extends PixelTest { verifyTabCount(expectedTabCount); } + protected void verifyTabs(String[] items) { + if (!mSolo.searchText(items[0])) { + openWebContentContextMenu(items[0]); + } + + for (String option:items) { + mAsserter.ok(mSolo.searchText(option), "Checking that the option: " + option + " is available", "The option is available"); + } + } + + protected void switchTabs(String tab) { + if (!mSolo.searchText(tab)) { + openWebContentContextMenu(tab); + } + mSolo.clickOnText(tab); + } + + protected void verifyCopyOption(String copyOption, final String copiedText) { if (!mSolo.searchText(copyOption)) { openWebContentContextMenu(copyOption); // Open the context menu if it is not already @@ -65,10 +86,12 @@ abstract class ContentContextMenuTest extends PixelTest { protected void verifyShareOption(String shareOption, String pageTitle) { - waitForText(pageTitle); - openWebContentContextMenu(shareOption); + waitForText(pageTitle); // Even if this fails, it won't assert + if (!mSolo.searchText(shareOption)) { + openWebContentContextMenu(shareOption); // Open the context menu if it is not already + } mSolo.clickOnText(shareOption); - mAsserter.ok(waitForText("Share via"), "Checking that the share pop-up is displayed", "The pop-up has been displayed"); + mAsserter.ok(waitForText(shareOption), "Checking that the share pop-up is displayed", "The pop-up has been displayed"); // Close the Share Link option menu and wait for the page to be focused again mActions.sendSpecialKey(Actions.SpecialKey.BACK); @@ -76,7 +99,9 @@ abstract class ContentContextMenuTest extends PixelTest { } protected void verifyBookmarkLinkOption(String bookmarkOption, String link) { - openWebContentContextMenu(bookmarkOption); + if (!mSolo.searchText(bookmarkOption)) { + openWebContentContextMenu(bookmarkOption); // Open the context menu if it is not already + } mSolo.clickOnText(bookmarkOption); mAsserter.ok(waitForText("Bookmark added"), "Waiting for the Bookmark added toaster notification", "The notification has been displayed"); mAsserter.ok(mDatabaseHelper.isBookmark(link), "Checking if the link has been added as a bookmark", "The link has been bookmarked"); diff --git a/mobile/android/base/tests/testPictureLinkContextMenu.java b/mobile/android/base/tests/testPictureLinkContextMenu.java index 6f3a704777a6..25e0e824a4d6 100644 --- a/mobile/android/base/tests/testPictureLinkContextMenu.java +++ b/mobile/android/base/tests/testPictureLinkContextMenu.java @@ -8,7 +8,10 @@ public class testPictureLinkContextMenu extends ContentContextMenuTest { private static String PICTURE_PAGE_URL; private static String BLANK_PAGE_URL; private static final String PICTURE_PAGE_TITLE = "Picture Link"; - private static final String photoMenuItems [] = { "Copy Image Location", "Share Image", "Set Image As", "Save Image", "Open Link in New Tab", "Open Link in Private Tab", "Copy Link", "Share Link", "Bookmark Link"}; + private static final String tabs [] = { "Image", "Link" }; + private static final String photoMenuItems [] = { "Copy Image Location", "Share Image", "Set Image As", "Save Image" }; + private static final String linkMenuItems [] = { "Open Link in New Tab", "Open Link in Private Tab", "Copy Link", "Share Link", "Bookmark Link"}; + private static final String linkTitle = "^Link$"; @Override protected int getTestType() { @@ -24,13 +27,21 @@ public class testPictureLinkContextMenu extends ContentContextMenuTest { verifyPageTitle(PICTURE_PAGE_TITLE); verifyContextMenuItems(photoMenuItems); + verifyTabs(tabs); verifyCopyOption(photoMenuItems[0], "Firefox.jpg"); // Test the "Copy Image Location" option verifyShareOption(photoMenuItems[1], PICTURE_PAGE_TITLE); // Test the "Share Image" option - openTabFromContextMenu(photoMenuItems[4],2); // Test the "Open in New Tab" option - expecting 2 tabs: the original and the new one - openTabFromContextMenu(photoMenuItems[5],2); // Test the "Open in Private Tab" option - expecting only 2 tabs in normal mode - verifyCopyOption(photoMenuItems[6], BLANK_PAGE_URL); // Test the "Copy Link" option - verifyShareOption(photoMenuItems[7], PICTURE_PAGE_TITLE); // Test the "Share Link" option - verifyBookmarkLinkOption(photoMenuItems[8],BLANK_PAGE_URL); // Test the "Bookmark Link" option + + switchTabs(linkTitle); + verifyContextMenuItems(linkMenuItems); + openTabFromContextMenu(linkMenuItems[0],2); // Test the "Open in New Tab" option - expecting 2 tabs: the original and the new one + switchTabs(linkTitle); + openTabFromContextMenu(linkMenuItems[1],2); // Test the "Open in Private Tab" option - expecting only 2 tabs in normal mode + switchTabs(linkTitle); + verifyCopyOption(linkMenuItems[2], BLANK_PAGE_URL); // Test the "Copy Link" option + switchTabs(linkTitle); + verifyShareOption(linkMenuItems[3], PICTURE_PAGE_TITLE); // Test the "Share Link" option + switchTabs(linkTitle); + verifyBookmarkLinkOption(linkMenuItems[4],BLANK_PAGE_URL); // Test the "Bookmark Link" option } @Override