mobile/android/base/tests/testBookmarkFolders.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 package org.mozilla.gecko.tests;
michael@0 2
michael@0 3 import org.mozilla.gecko.sync.Utils;
michael@0 4
michael@0 5 import android.content.ContentResolver;
michael@0 6 import android.content.ContentValues;
michael@0 7 import android.net.Uri;
michael@0 8 import android.view.View;
michael@0 9 import android.widget.ListAdapter;
michael@0 10 import android.widget.ListView;
michael@0 11 import android.widget.TextView;
michael@0 12
michael@0 13 import com.jayway.android.robotium.solo.Condition;
michael@0 14
michael@0 15 public class testBookmarkFolders extends AboutHomeTest {
michael@0 16 private static String DESKTOP_BOOKMARK_URL;
michael@0 17
michael@0 18 public void testBookmarkFolders() {
michael@0 19 DESKTOP_BOOKMARK_URL = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_02_URL);
michael@0 20
michael@0 21 setUpDesktopBookmarks();
michael@0 22 checkBookmarkList();
michael@0 23 }
michael@0 24
michael@0 25 private void checkBookmarkList() {
michael@0 26 openAboutHomeTab(AboutHomeTabs.BOOKMARKS);
michael@0 27 waitForText(StringHelper.DESKTOP_FOLDER_LABEL);
michael@0 28 clickOnBookmarkFolder(StringHelper.DESKTOP_FOLDER_LABEL);
michael@0 29 waitForText(StringHelper.TOOLBAR_FOLDER_LABEL);
michael@0 30
michael@0 31 // Verify the number of folders displayed in the Desktop Bookmarks folder is correct
michael@0 32 ListView desktopFolderContent = findListViewWithTag("bookmarks");
michael@0 33 ListAdapter adapter = desktopFolderContent.getAdapter();
michael@0 34 if (mDevice.type.equals("tablet")) { // On tablets it's 4 folders and 1 view for top padding
michael@0 35 mAsserter.is(adapter.getCount(), 5, "Checking that the correct number of folders is displayed in the Desktop Bookmarks folder");
michael@0 36 } else { // On phones it's just the 4 folders
michael@0 37 mAsserter.is(adapter.getCount(), 4, "Checking that the correct number of folders is displayed in the Desktop Bookmarks folder");
michael@0 38 }
michael@0 39
michael@0 40 clickOnBookmarkFolder(StringHelper.TOOLBAR_FOLDER_LABEL);
michael@0 41
michael@0 42 // Go up in the bookmark folder hierarchy
michael@0 43 clickOnBookmarkFolder(StringHelper.TOOLBAR_FOLDER_LABEL);
michael@0 44 mAsserter.ok(waitForText(StringHelper.BOOKMARKS_MENU_FOLDER_LABEL), "Going up in the folder hierarchy", "We are back in the Desktop Bookmarks folder");
michael@0 45
michael@0 46 clickOnBookmarkFolder(StringHelper.DESKTOP_FOLDER_LABEL);
michael@0 47 mAsserter.ok(waitForText(StringHelper.DESKTOP_FOLDER_LABEL), "Going up in the folder hierarchy", "We are back in the main Bookmarks List View");
michael@0 48
michael@0 49 clickOnBookmarkFolder(StringHelper.DESKTOP_FOLDER_LABEL);
michael@0 50 clickOnBookmarkFolder(StringHelper.TOOLBAR_FOLDER_LABEL);
michael@0 51 isBookmarkDisplayed(DESKTOP_BOOKMARK_URL);
michael@0 52
michael@0 53 // Open the bookmark from a bookmark folder hierarchy
michael@0 54 loadBookmark(DESKTOP_BOOKMARK_URL);
michael@0 55 waitForText(StringHelper.ROBOCOP_BLANK_PAGE_02_TITLE);
michael@0 56 verifyPageTitle(StringHelper.ROBOCOP_BLANK_PAGE_02_TITLE);
michael@0 57 openAboutHomeTab(AboutHomeTabs.BOOKMARKS);
michael@0 58
michael@0 59 // Check that folders don't have a context menu
michael@0 60 boolean success = waitForCondition(new Condition() {
michael@0 61 @Override
michael@0 62 public boolean isSatisfied() {
michael@0 63 View desktopFolder = getBookmarkFolderView(StringHelper.DESKTOP_FOLDER_LABEL);
michael@0 64 if (desktopFolder == null) {
michael@0 65 return false;
michael@0 66 }
michael@0 67 mSolo.clickLongOnView(desktopFolder);
michael@0 68 return true; }
michael@0 69 }, MAX_WAIT_MS);
michael@0 70
michael@0 71 mAsserter.ok(success, "Trying to long click on the Desktop Bookmarks","Desktop Bookmarks folder could not be long clicked");
michael@0 72
michael@0 73 final String contextMenuString = StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS[0];
michael@0 74 mAsserter.ok(!waitForText(contextMenuString), "Folders do not have context menus", "The context menu was not opened");
michael@0 75
michael@0 76 // Even if no context menu is opened long clicking a folder still opens it. We need to close it.
michael@0 77 clickOnBookmarkFolder(StringHelper.DESKTOP_FOLDER_LABEL);
michael@0 78 }
michael@0 79
michael@0 80 private void clickOnBookmarkFolder(final String folderName) {
michael@0 81 boolean success = waitForCondition(new Condition() {
michael@0 82 @Override
michael@0 83 public boolean isSatisfied() {
michael@0 84 View bookmarksFolder = getBookmarkFolderView(folderName);
michael@0 85 if (bookmarksFolder == null) {
michael@0 86 return false;
michael@0 87 }
michael@0 88 mSolo.waitForView(bookmarksFolder);
michael@0 89 mSolo.clickOnView(bookmarksFolder);
michael@0 90 return true;
michael@0 91 }
michael@0 92 }, MAX_WAIT_MS);
michael@0 93 mAsserter.ok(success, "Trying to click on the " + folderName + " folder","The " + folderName + " folder was clicked");
michael@0 94 }
michael@0 95
michael@0 96 private View getBookmarkFolderView(String folderName) {
michael@0 97 openAboutHomeTab(AboutHomeTabs.BOOKMARKS);
michael@0 98 mSolo.hideSoftKeyboard();
michael@0 99 getInstrumentation().waitForIdleSync();
michael@0 100
michael@0 101 ListView bookmarksTabList = findListViewWithTag("bookmarks");
michael@0 102 if (!waitForNonEmptyListToLoad(bookmarksTabList)) {
michael@0 103 return null;
michael@0 104 }
michael@0 105
michael@0 106 ListAdapter adapter = bookmarksTabList.getAdapter();
michael@0 107 if (adapter == null) {
michael@0 108 return null;
michael@0 109 }
michael@0 110
michael@0 111 for (int i = 0; i < adapter.getCount(); i++ ) {
michael@0 112 View bookmarkView = bookmarksTabList.getChildAt(i);
michael@0 113 if (bookmarkView instanceof TextView) {
michael@0 114 TextView folderTextView = (TextView) bookmarkView;
michael@0 115 if (folderTextView.getText().equals(folderName)) {
michael@0 116 return bookmarkView;
michael@0 117 }
michael@0 118 }
michael@0 119 }
michael@0 120
michael@0 121 return null;
michael@0 122 }
michael@0 123
michael@0 124 // Add a bookmark in the Desktop folder so we can check the folder navigation in the bookmarks page
michael@0 125 private void setUpDesktopBookmarks() {
michael@0 126 blockForGeckoReady();
michael@0 127
michael@0 128 // Get the folder id of the StringHelper.DESKTOP_FOLDER_LABEL folder
michael@0 129 Long desktopFolderId = mDatabaseHelper.getFolderIdFromGuid("toolbar");
michael@0 130
michael@0 131 // Generate a Guid for the bookmark
michael@0 132 final String generatedGuid = Utils.generateGuid();
michael@0 133 mAsserter.ok((generatedGuid != null), "Generating a random Guid for the bookmark", "We could not generate a Guid for the bookmark");
michael@0 134
michael@0 135 // Insert the bookmark
michael@0 136 ContentResolver resolver = getActivity().getContentResolver();
michael@0 137 Uri bookmarksUri = mDatabaseHelper.buildUri(DatabaseHelper.BrowserDataType.BOOKMARKS);
michael@0 138
michael@0 139 long now = System.currentTimeMillis();
michael@0 140 ContentValues values = new ContentValues();
michael@0 141 values.put("title", StringHelper.ROBOCOP_BLANK_PAGE_02_TITLE);
michael@0 142 values.put("url", DESKTOP_BOOKMARK_URL);
michael@0 143 values.put("parent", desktopFolderId);
michael@0 144 values.put("modified", now);
michael@0 145 values.put("type", 1);
michael@0 146 values.put("guid", generatedGuid);
michael@0 147 values.put("position", 10);
michael@0 148 values.put("created", now);
michael@0 149
michael@0 150 int updated = resolver.update(bookmarksUri,
michael@0 151 values,
michael@0 152 "url = ?",
michael@0 153 new String[] { DESKTOP_BOOKMARK_URL });
michael@0 154 if (updated == 0) {
michael@0 155 Uri uri = resolver.insert(bookmarksUri, values);
michael@0 156 mAsserter.ok(true, "Inserted at: ", uri.toString());
michael@0 157 } else {
michael@0 158 mAsserter.ok(false, "Failed to insert the Desktop bookmark", "Something went wrong");
michael@0 159 }
michael@0 160 }
michael@0 161
michael@0 162 @Override
michael@0 163 public void tearDown() throws Exception {
michael@0 164 mDatabaseHelper.deleteBookmark(DESKTOP_BOOKMARK_URL);
michael@0 165 super.tearDown();
michael@0 166 }
michael@0 167 }

mercurial