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