mobile/android/base/tests/testBookmarksPanel.java

branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
equal deleted inserted replaced
-1:000000000000 0:f980da7087bb
1 package org.mozilla.gecko.tests;
2
3 import org.json.JSONException;
4 import org.json.JSONObject;
5 import org.mozilla.gecko.Actions;
6 import org.mozilla.gecko.Element;
7 import org.mozilla.gecko.R;
8
9 public class testBookmarksPanel extends AboutHomeTest {
10 public void testBookmarksPanel() {
11 final String BOOKMARK_URL = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_01_URL);
12 JSONObject data = null;
13
14 // Add a mobile bookmark
15 mDatabaseHelper.addOrUpdateMobileBookmark(StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE, BOOKMARK_URL);
16
17 openAboutHomeTab(AboutHomeTabs.BOOKMARKS);
18
19 // Check that the default bookmarks are displayed
20 for (String url : StringHelper.DEFAULT_BOOKMARKS_URLS) {
21 isBookmarkDisplayed(url);
22 }
23
24 // Open the context menu for the first bookmark in the list
25 openBookmarkContextMenu(StringHelper.DEFAULT_BOOKMARKS_URLS[0]);
26
27 // Test that the options are all displayed
28 for (String contextMenuOption : StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS) {
29 mAsserter.ok(mSolo.searchText(contextMenuOption), "Checking that the context menu option is present", contextMenuOption + " is present");
30 }
31
32 // Test that "Open in New Tab" works
33 final Element tabCount = mDriver.findElement(getActivity(), R.id.tabs_counter);
34 final int tabCountInt = Integer.parseInt(tabCount.getText());
35 Actions.EventExpecter tabEventExpecter = mActions.expectGeckoEvent("Tab:Added");
36 mSolo.clickOnText(StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS[0]);
37 try {
38 data = new JSONObject(tabEventExpecter.blockForEventData());
39 } catch (JSONException e) {
40 mAsserter.ok(false, "exception getting event data", e.toString());
41 }
42 tabEventExpecter.unregisterListener();
43 mAsserter.ok(mSolo.searchText(StringHelper.TITLE_PLACE_HOLDER), "Checking that the tab is not changed", "The tab was not changed");
44 // extra check here on the Tab:Added message to be sure the right tab opened
45 int tabID = 0;
46 try {
47 mAsserter.is(StringHelper.ABOUT_FIREFOX_URL, data.getString("uri"), "Checking tab uri");
48 tabID = data.getInt("tabID");
49 } catch (JSONException e) {
50 mAsserter.ok(false, "exception accessing event data", e.toString());
51 }
52 // close tab so about:firefox can be selected again
53 closeTab(tabID);
54
55 // Test that "Open in Private Tab" works
56 openBookmarkContextMenu(StringHelper.DEFAULT_BOOKMARKS_URLS[0]);
57 tabEventExpecter = mActions.expectGeckoEvent("Tab:Added");
58 mSolo.clickOnText(StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS[1]);
59 try {
60 data = new JSONObject(tabEventExpecter.blockForEventData());
61 } catch (JSONException e) {
62 mAsserter.ok(false, "exception getting event data", e.toString());
63 }
64 tabEventExpecter.unregisterListener();
65 mAsserter.ok(mSolo.searchText(StringHelper.TITLE_PLACE_HOLDER), "Checking that the tab is not changed", "The tab was not changed");
66 // extra check here on the Tab:Added message to be sure the right tab opened, again
67 try {
68 mAsserter.is(StringHelper.ABOUT_FIREFOX_URL, data.getString("uri"), "Checking tab uri");
69 } catch (JSONException e) {
70 mAsserter.ok(false, "exception accessing event data", e.toString());
71 }
72
73 // Test that "Edit" works
74 String[] editedBookmarkValues = new String[] { "New bookmark title", "www.NewBookmark.url", "newBookmarkKeyword" };
75 editBookmark(BOOKMARK_URL, editedBookmarkValues);
76 checkBookmarkEdit(editedBookmarkValues[1], editedBookmarkValues);
77
78 // Test that "Remove" works
79 openBookmarkContextMenu(editedBookmarkValues[1]);
80 mSolo.clickOnText(StringHelper.BOOKMARK_CONTEXT_MENU_ITEMS[3]);
81 waitForText("Bookmark removed");
82 mAsserter.ok(!mDatabaseHelper.isBookmark(editedBookmarkValues[1]), "Checking that the bookmark was removed", "The bookmark was removed");
83 }
84
85 /**
86 * @param bookmarkUrl URL of the bookmark to edit
87 * @param values String array with the new values for all fields
88 */
89 private void editBookmark(String bookmarkUrl, String[] values) {
90 openBookmarkContextMenu(bookmarkUrl);
91 mSolo.clickOnText("Edit");
92 waitForText("Edit Bookmark");
93
94 // Update the fields with the new values
95 for (int i = 0; i < values.length; i++) {
96 mSolo.clearEditText(i);
97 mSolo.clickOnEditText(i);
98 mActions.sendKeys(values[i]);
99 }
100
101 mSolo.clickOnButton("OK");
102 waitForText("Bookmark updated");
103 }
104
105 /**
106 * @param bookmarkUrl String with the original url
107 * @param values String array with the new values for all fields
108 */
109 private void checkBookmarkEdit(String bookmarkUrl, String[] values) {
110 openBookmarkContextMenu(bookmarkUrl);
111 mSolo.clickOnText("Edit");
112 waitForText("Edit Bookmark");
113
114 // Check the values of the fields
115 for (String value : values) {
116 mAsserter.ok(mSolo.searchText(value), "Checking that the value is correct", "The value = " + value + " is correct");
117 }
118
119 mSolo.clickOnButton("Cancel");
120 waitForText("BOOKMARKS");
121 }
122 }

mercurial