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.View; | 10 import android.view.View; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 } | 54 } |
55 | 55 |
56 @Override | 56 @Override |
57 public void startMainActivity() throws InterruptedException { | 57 public void startMainActivity() throws InterruptedException { |
58 startMainActivityOnBlankPage(); | 58 startMainActivityOnBlankPage(); |
59 } | 59 } |
60 | 60 |
61 @SmallTest | 61 @SmallTest |
62 @Feature({"CustomContextMenu"}) | 62 @Feature({"CustomContextMenu"}) |
63 public void testViewDisplaysSingleItemProperly() throws ExecutionException { | 63 public void testViewDisplaysSingleItemProperly() throws ExecutionException { |
64 final TabularContextMenuUi dialog = new TabularContextMenuUi(); | 64 final TabularContextMenuUi dialog = new TabularContextMenuUi(null); |
65 | 65 |
66 final List<Pair<Integer, List<ContextMenuItem>>> itemGroups = new ArrayL
ist<>(); | 66 final List<Pair<Integer, List<ContextMenuItem>>> itemGroups = new ArrayL
ist<>(); |
67 List<ContextMenuItem> item = CollectionUtil.newArrayList(ContextMenuItem
.ADD_TO_CONTACTS, | 67 List<ContextMenuItem> item = CollectionUtil.newArrayList(ContextMenuItem
.ADD_TO_CONTACTS, |
68 ContextMenuItem.CALL, ContextMenuItem.COPY_LINK_ADDRESS); | 68 ContextMenuItem.CALL, ContextMenuItem.COPY_LINK_ADDRESS); |
69 itemGroups.add(new Pair<>(R.string.contextmenu_link_title, item)); | 69 itemGroups.add(new Pair<>(R.string.contextmenu_link_title, item)); |
70 final String url = "http://google.com"; | 70 final String url = "http://google.com"; |
71 View view = ThreadUtils.runOnUiThreadBlocking(new Callable<View>() { | 71 View view = ThreadUtils.runOnUiThreadBlocking(new Callable<View>() { |
72 @Override | 72 @Override |
73 public View call() { | 73 public View call() { |
74 return dialog.createPagerView(getActivity(), new MockMenuParams(
url), itemGroups); | 74 return dialog.createPagerView(getActivity(), new MockMenuParams(
url), itemGroups); |
75 } | 75 } |
76 }); | 76 }); |
77 | 77 |
78 TabLayout layout = (TabLayout) view.findViewById(R.id.tab_layout); | 78 TabLayout layout = (TabLayout) view.findViewById(R.id.tab_layout); |
79 assertEquals(layout.getVisibility(), View.GONE); | 79 assertEquals(layout.getVisibility(), View.GONE); |
80 } | 80 } |
81 | 81 |
82 @SmallTest | 82 @SmallTest |
83 @Feature({"CustomContextMenu"}) | 83 @Feature({"CustomContextMenu"}) |
84 public void testViewDisplaysViewPagerForMultipleItems() throws ExecutionExce
ption { | 84 public void testViewDisplaysViewPagerForMultipleItems() throws ExecutionExce
ption { |
85 final TabularContextMenuUi dialog = new TabularContextMenuUi(); | 85 final TabularContextMenuUi dialog = new TabularContextMenuUi(null); |
86 | 86 |
87 final List<Pair<Integer, List<ContextMenuItem>>> itemGroups = new ArrayL
ist<>(); | 87 final List<Pair<Integer, List<ContextMenuItem>>> itemGroups = new ArrayL
ist<>(); |
88 List<ContextMenuItem> item = CollectionUtil.newArrayList(ContextMenuItem
.ADD_TO_CONTACTS, | 88 List<ContextMenuItem> item = CollectionUtil.newArrayList(ContextMenuItem
.ADD_TO_CONTACTS, |
89 ContextMenuItem.CALL, ContextMenuItem.COPY_LINK_ADDRESS); | 89 ContextMenuItem.CALL, ContextMenuItem.COPY_LINK_ADDRESS); |
90 itemGroups.add(new Pair<>(R.string.contextmenu_link_title, item)); | 90 itemGroups.add(new Pair<>(R.string.contextmenu_link_title, item)); |
91 itemGroups.add(new Pair<>(R.string.contextmenu_link_title, item)); | 91 itemGroups.add(new Pair<>(R.string.contextmenu_link_title, item)); |
92 final String url = "http://google.com"; | 92 final String url = "http://google.com"; |
93 View view = ThreadUtils.runOnUiThreadBlocking(new Callable<View>() { | 93 View view = ThreadUtils.runOnUiThreadBlocking(new Callable<View>() { |
94 @Override | 94 @Override |
95 public View call() { | 95 public View call() { |
96 return dialog.createPagerView(getActivity(), new MockMenuParams(
url), itemGroups); | 96 return dialog.createPagerView(getActivity(), new MockMenuParams(
url), itemGroups); |
97 } | 97 } |
98 }); | 98 }); |
99 | 99 |
100 TabLayout layout = (TabLayout) view.findViewById(R.id.tab_layout); | 100 TabLayout layout = (TabLayout) view.findViewById(R.id.tab_layout); |
101 assertEquals(layout.getVisibility(), View.VISIBLE); | 101 assertEquals(layout.getVisibility(), View.VISIBLE); |
102 } | 102 } |
103 | 103 |
104 @SmallTest | 104 @SmallTest |
105 @Feature({"CustomContextMenu"}) | 105 @Feature({"CustomContextMenu"}) |
106 public void testURLIsShownOnContextMenu() throws ExecutionException { | 106 public void testURLIsShownOnContextMenu() throws ExecutionException { |
107 final TabularContextMenuUi dialog = new TabularContextMenuUi(); | 107 final TabularContextMenuUi dialog = new TabularContextMenuUi(null); |
108 final List<ContextMenuItem> item = | 108 final List<ContextMenuItem> item = |
109 CollectionUtil.newArrayList(ContextMenuItem.ADD_TO_CONTACTS, Con
textMenuItem.CALL, | 109 CollectionUtil.newArrayList(ContextMenuItem.ADD_TO_CONTACTS, Con
textMenuItem.CALL, |
110 ContextMenuItem.COPY_LINK_ADDRESS); | 110 ContextMenuItem.COPY_LINK_ADDRESS); |
111 final String expectedUrl = "http://google.com"; | 111 final String expectedUrl = "http://google.com"; |
112 View view = ThreadUtils.runOnUiThreadBlocking(new Callable<View>() { | 112 View view = ThreadUtils.runOnUiThreadBlocking(new Callable<View>() { |
113 @Override | 113 @Override |
114 public View call() { | 114 public View call() { |
115 return dialog.createContextMenuPageUi( | 115 return dialog.createContextMenuPageUi( |
116 getActivity(), new MockMenuParams(expectedUrl), item, fa
lse, item.size()); | 116 getActivity(), new MockMenuParams(expectedUrl), item, fa
lse, item.size()); |
117 } | 117 } |
118 }); | 118 }); |
119 | 119 |
120 TextView textView = (TextView) view.findViewById(R.id.context_header_tex
t); | 120 TextView textView = (TextView) view.findViewById(R.id.context_header_tex
t); |
121 assertEquals(expectedUrl, String.valueOf(textView.getText())); | 121 assertEquals(expectedUrl, String.valueOf(textView.getText())); |
122 } | 122 } |
123 | 123 |
124 @SmallTest | 124 @SmallTest |
125 @Feature({"CustomContextMenu"}) | 125 @Feature({"CustomContextMenu"}) |
126 public void testHeaderIsNotShownWhenThereIsNoParams() throws ExecutionExcept
ion { | 126 public void testHeaderIsNotShownWhenThereIsNoParams() throws ExecutionExcept
ion { |
127 final TabularContextMenuUi dialog = new TabularContextMenuUi(); | 127 final TabularContextMenuUi dialog = new TabularContextMenuUi(null); |
128 final List<ContextMenuItem> item = | 128 final List<ContextMenuItem> item = |
129 CollectionUtil.newArrayList(ContextMenuItem.ADD_TO_CONTACTS, Con
textMenuItem.CALL, | 129 CollectionUtil.newArrayList(ContextMenuItem.ADD_TO_CONTACTS, Con
textMenuItem.CALL, |
130 ContextMenuItem.COPY_LINK_ADDRESS); | 130 ContextMenuItem.COPY_LINK_ADDRESS); |
131 View view = ThreadUtils.runOnUiThreadBlocking(new Callable<View>() { | 131 View view = ThreadUtils.runOnUiThreadBlocking(new Callable<View>() { |
132 @Override | 132 @Override |
133 public View call() { | 133 public View call() { |
134 return dialog.createContextMenuPageUi( | 134 return dialog.createContextMenuPageUi( |
135 getActivity(), new MockMenuParams(""), item, false, item
.size()); | 135 getActivity(), new MockMenuParams(""), item, false, item
.size()); |
136 } | 136 } |
137 }); | 137 }); |
138 | 138 |
139 assertEquals(view.findViewById(R.id.context_header_text).getVisibility()
, View.GONE); | 139 assertEquals(view.findViewById(R.id.context_header_text).getVisibility()
, View.GONE); |
140 assertEquals(view.findViewById(R.id.context_divider).getVisibility(), Vi
ew.GONE); | 140 assertEquals(view.findViewById(R.id.context_divider).getVisibility(), Vi
ew.GONE); |
141 } | 141 } |
142 | 142 |
143 @SmallTest | 143 @SmallTest |
144 @Feature({"CustomContextMenu"}) | 144 @Feature({"CustomContextMenu"}) |
145 public void testLinkShowsMultipleLinesWhenClicked() throws ExecutionExceptio
n { | 145 public void testLinkShowsMultipleLinesWhenClicked() throws ExecutionExceptio
n { |
146 final TabularContextMenuUi dialog = new TabularContextMenuUi(); | 146 final TabularContextMenuUi dialog = new TabularContextMenuUi(null); |
147 final List<ContextMenuItem> item = | 147 final List<ContextMenuItem> item = |
148 CollectionUtil.newArrayList(ContextMenuItem.ADD_TO_CONTACTS, Con
textMenuItem.CALL, | 148 CollectionUtil.newArrayList(ContextMenuItem.ADD_TO_CONTACTS, Con
textMenuItem.CALL, |
149 ContextMenuItem.COPY_LINK_ADDRESS); | 149 ContextMenuItem.COPY_LINK_ADDRESS); |
150 View view = ThreadUtils.runOnUiThreadBlocking(new Callable<View>() { | 150 View view = ThreadUtils.runOnUiThreadBlocking(new Callable<View>() { |
151 @Override | 151 @Override |
152 public View call() { | 152 public View call() { |
153 return dialog.createContextMenuPageUi(getActivity(), | 153 return dialog.createContextMenuPageUi(getActivity(), |
154 new MockMenuParams("http://google.com"), item, false, it
em.size()); | 154 new MockMenuParams("http://google.com"), item, false, it
em.size()); |
155 } | 155 } |
156 }); | 156 }); |
(...skipping 10 matching lines...) Expand all Loading... |
167 headerTextView.callOnClick(); | 167 headerTextView.callOnClick(); |
168 } | 168 } |
169 }); | 169 }); |
170 | 170 |
171 expectedMaxLines = Integer.MAX_VALUE; | 171 expectedMaxLines = Integer.MAX_VALUE; |
172 actualMaxLines = headerTextView.getMaxLines(); | 172 actualMaxLines = headerTextView.getMaxLines(); |
173 assertEquals("Expected a different number of maximum lines when the head
er is clicked.", | 173 assertEquals("Expected a different number of maximum lines when the head
er is clicked.", |
174 expectedMaxLines, actualMaxLines); | 174 expectedMaxLines, actualMaxLines); |
175 } | 175 } |
176 } | 176 } |
OLD | NEW |