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(new Context
MenuHelper()); |
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(new Context
MenuHelper()); |
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(new Context
MenuHelper()); |
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, it
em.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(new Context
MenuHelper()); |
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, 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 } |
OLD | NEW |