OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.contextmenu; | 5 package org.chromium.chrome.browser.contextmenu; |
6 | 6 |
7 import android.support.design.widget.TabLayout; | 7 import android.support.design.widget.TabLayout; |
8 import android.support.test.filters.SmallTest; | 8 import android.support.test.filters.SmallTest; |
9 import android.util.Pair; | 9 import android.util.Pair; |
| 10 import android.view.LayoutInflater; |
10 import android.view.View; | 11 import android.view.View; |
11 import android.widget.TextView; | 12 import android.widget.TextView; |
12 | 13 |
13 import org.junit.Assert; | 14 import org.junit.Assert; |
14 import org.junit.Before; | 15 import org.junit.Before; |
15 import org.junit.Rule; | 16 import org.junit.Rule; |
16 import org.junit.Test; | 17 import org.junit.Test; |
17 import org.junit.runner.RunWith; | 18 import org.junit.runner.RunWith; |
18 | 19 |
19 import org.chromium.base.CollectionUtil; | 20 import org.chromium.base.CollectionUtil; |
(...skipping 23 matching lines...) Expand all Loading... |
43 public class TabularContextMenuUiTest { | 44 public class TabularContextMenuUiTest { |
44 @Rule | 45 @Rule |
45 public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = | 46 public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = |
46 new ChromeActivityTestRule<>(ChromeActivity.class); | 47 new ChromeActivityTestRule<>(ChromeActivity.class); |
47 | 48 |
48 private static class MockMenuParams extends ContextMenuParams { | 49 private static class MockMenuParams extends ContextMenuParams { |
49 private String mUrl = ""; | 50 private String mUrl = ""; |
50 | 51 |
51 private MockMenuParams(int mediaType, String pageUrl, String linkUrl, St
ring linkText, | 52 private MockMenuParams(int mediaType, String pageUrl, String linkUrl, St
ring linkText, |
52 String unfilteredLinkUrl, String srcUrl, String titleText, | 53 String unfilteredLinkUrl, String srcUrl, String titleText, |
53 boolean imageWasFetchedLoFi, Referrer referrer, boolean canSavem
edia) { | 54 boolean imageWasFetchedLoFi, Referrer referrer, boolean canSavem
edia, |
| 55 int touchPointXDp, int touchPointYDp) { |
54 super(mediaType, pageUrl, linkUrl, linkText, unfilteredLinkUrl, srcU
rl, titleText, | 56 super(mediaType, pageUrl, linkUrl, linkText, unfilteredLinkUrl, srcU
rl, titleText, |
55 imageWasFetchedLoFi, referrer, canSavemedia); | 57 imageWasFetchedLoFi, referrer, canSavemedia, touchPointXDp,
touchPointYDp); |
56 } | 58 } |
57 | 59 |
58 private MockMenuParams(String url) { | 60 private MockMenuParams(String url) { |
59 this(0, "", "", "", "", "", "", false, null, true); | 61 this(0, "", "", "", "", "", "", false, null, true, 0, 0); |
60 mUrl = url; | 62 mUrl = url; |
61 } | 63 } |
62 | 64 |
63 @Override | 65 @Override |
64 public String getLinkUrl() { | 66 public String getLinkUrl() { |
65 return mUrl; | 67 return mUrl; |
66 } | 68 } |
67 } | 69 } |
68 | 70 |
69 @Before | 71 @Before |
70 public void setUp() throws InterruptedException { | 72 public void setUp() throws InterruptedException { |
71 mActivityTestRule.startMainActivityOnBlankPage(); | 73 mActivityTestRule.startMainActivityOnBlankPage(); |
72 } | 74 } |
73 | 75 |
74 @Test | 76 @Test |
75 @SmallTest | 77 @SmallTest |
76 @Feature({"CustomContextMenu"}) | 78 @Feature({"CustomContextMenu"}) |
77 public void testViewDisplaysSingleItemProperly() throws ExecutionException { | 79 public void testViewDisplaysSingleItemProperly() throws ExecutionException { |
78 final TabularContextMenuUi dialog = new TabularContextMenuUi(null); | 80 final TabularContextMenuUi dialog = new TabularContextMenuUi(null); |
79 | 81 |
80 final List<Pair<Integer, List<ContextMenuItem>>> itemGroups = new ArrayL
ist<>(); | 82 final List<Pair<Integer, List<ContextMenuItem>>> itemGroups = new ArrayL
ist<>(); |
81 List<? extends ContextMenuItem> item = | 83 List<? extends ContextMenuItem> item = |
82 CollectionUtil.newArrayList(ChromeContextMenuItem.ADD_TO_CONTACT
S, | 84 CollectionUtil.newArrayList(ChromeContextMenuItem.ADD_TO_CONTACT
S, |
83 ChromeContextMenuItem.CALL, ChromeContextMenuItem.COPY_L
INK_ADDRESS); | 85 ChromeContextMenuItem.CALL, ChromeContextMenuItem.COPY_L
INK_ADDRESS); |
84 itemGroups.add( | 86 itemGroups.add( |
85 new Pair<>(R.string.contextmenu_link_title, Collections.unmodifi
ableList(item))); | 87 new Pair<>(R.string.contextmenu_link_title, Collections.unmodifi
ableList(item))); |
86 final String url = "http://google.com"; | 88 final String url = "http://google.com"; |
| 89 View tabularContextMenu = LayoutInflater.from(mActivityTestRule.getActiv
ity()) |
| 90 .inflate(R.layout.tabular_context_menu
, null); |
| 91 final TabularContextMenuViewPager pager = |
| 92 (TabularContextMenuViewPager) tabularContextMenu.findViewById(R.
id.custom_pager); |
87 View view = ThreadUtils.runOnUiThreadBlocking(new Callable<View>() { | 93 View view = ThreadUtils.runOnUiThreadBlocking(new Callable<View>() { |
88 @Override | 94 @Override |
89 public View call() { | 95 public View call() { |
90 return dialog.createPagerView( | 96 return dialog.initPagerView(mActivityTestRule.getActivity(), |
91 mActivityTestRule.getActivity(), new MockMenuParams(url)
, itemGroups); | 97 new MockMenuParams(url), itemGroups, pager); |
92 } | 98 } |
93 }); | 99 }); |
94 | 100 |
95 TabLayout layout = (TabLayout) view.findViewById(R.id.tab_layout); | 101 TabLayout layout = (TabLayout) view.findViewById(R.id.tab_layout); |
96 Assert.assertEquals(layout.getVisibility(), View.GONE); | 102 Assert.assertEquals(View.GONE, layout.getVisibility()); |
97 } | 103 } |
98 | 104 |
99 @Test | 105 @Test |
100 @SmallTest | 106 @SmallTest |
101 @Feature({"CustomContextMenu"}) | 107 @Feature({"CustomContextMenu"}) |
102 public void testViewDisplaysViewPagerForMultipleItems() throws ExecutionExce
ption { | 108 public void testViewDisplaysViewPagerForMultipleItems() throws ExecutionExce
ption { |
103 final TabularContextMenuUi dialog = new TabularContextMenuUi(null); | 109 final TabularContextMenuUi dialog = new TabularContextMenuUi(null); |
104 | 110 |
105 final List<Pair<Integer, List<ContextMenuItem>>> itemGroups = new ArrayL
ist<>(); | 111 final List<Pair<Integer, List<ContextMenuItem>>> itemGroups = new ArrayL
ist<>(); |
106 List<? extends ContextMenuItem> item = | 112 List<? extends ContextMenuItem> item = |
107 CollectionUtil.newArrayList(ChromeContextMenuItem.ADD_TO_CONTACT
S, | 113 CollectionUtil.newArrayList(ChromeContextMenuItem.ADD_TO_CONTACT
S, |
108 ChromeContextMenuItem.CALL, ChromeContextMenuItem.COPY_L
INK_ADDRESS); | 114 ChromeContextMenuItem.CALL, ChromeContextMenuItem.COPY_L
INK_ADDRESS); |
109 itemGroups.add( | 115 itemGroups.add( |
110 new Pair<>(R.string.contextmenu_link_title, Collections.unmodifi
ableList(item))); | 116 new Pair<>(R.string.contextmenu_link_title, Collections.unmodifi
ableList(item))); |
111 itemGroups.add( | 117 itemGroups.add( |
112 new Pair<>(R.string.contextmenu_link_title, Collections.unmodifi
ableList(item))); | 118 new Pair<>(R.string.contextmenu_link_title, Collections.unmodifi
ableList(item))); |
113 final String url = "http://google.com"; | 119 final String url = "http://google.com"; |
| 120 View tabularContextMenu = LayoutInflater.from(mActivityTestRule.getActiv
ity()) |
| 121 .inflate(R.layout.tabular_context_menu
, null); |
| 122 final TabularContextMenuViewPager pager = |
| 123 (TabularContextMenuViewPager) tabularContextMenu.findViewById(R.
id.custom_pager); |
114 View view = ThreadUtils.runOnUiThreadBlocking(new Callable<View>() { | 124 View view = ThreadUtils.runOnUiThreadBlocking(new Callable<View>() { |
115 @Override | 125 @Override |
116 public View call() { | 126 public View call() { |
117 return dialog.createPagerView( | 127 return dialog.initPagerView(mActivityTestRule.getActivity(), |
118 mActivityTestRule.getActivity(), new MockMenuParams(url)
, itemGroups); | 128 new MockMenuParams(url), itemGroups, pager); |
119 } | 129 } |
120 }); | 130 }); |
121 | 131 |
122 TabLayout layout = (TabLayout) view.findViewById(R.id.tab_layout); | 132 TabLayout layout = (TabLayout) view.findViewById(R.id.tab_layout); |
123 Assert.assertEquals(layout.getVisibility(), View.VISIBLE); | 133 Assert.assertEquals(View.VISIBLE, layout.getVisibility()); |
124 } | 134 } |
125 | 135 |
126 @Test | 136 @Test |
127 @SmallTest | 137 @SmallTest |
128 @Feature({"CustomContextMenu"}) | 138 @Feature({"CustomContextMenu"}) |
129 public void testURLIsShownOnContextMenu() throws ExecutionException { | 139 public void testURLIsShownOnContextMenu() throws ExecutionException { |
130 final TabularContextMenuUi dialog = new TabularContextMenuUi(null); | 140 final TabularContextMenuUi dialog = new TabularContextMenuUi(null); |
131 final List<? extends ContextMenuItem> item = | 141 final List<? extends ContextMenuItem> item = |
132 CollectionUtil.newArrayList(ChromeContextMenuItem.ADD_TO_CONTACT
S, | 142 CollectionUtil.newArrayList(ChromeContextMenuItem.ADD_TO_CONTACT
S, |
133 ChromeContextMenuItem.CALL, ChromeContextMenuItem.COPY_L
INK_ADDRESS); | 143 ChromeContextMenuItem.CALL, ChromeContextMenuItem.COPY_L
INK_ADDRESS); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 } | 206 } |
197 }); | 207 }); |
198 | 208 |
199 expectedMaxLines = Integer.MAX_VALUE; | 209 expectedMaxLines = Integer.MAX_VALUE; |
200 actualMaxLines = headerTextView.getMaxLines(); | 210 actualMaxLines = headerTextView.getMaxLines(); |
201 Assert.assertEquals( | 211 Assert.assertEquals( |
202 "Expected a different number of maximum lines when the header is
clicked.", | 212 "Expected a different number of maximum lines when the header is
clicked.", |
203 expectedMaxLines, actualMaxLines); | 213 expectedMaxLines, actualMaxLines); |
204 } | 214 } |
205 } | 215 } |
OLD | NEW |