Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(549)

Side by Side Diff: chrome/browser/chromeos/arc/intent_helper/arc_navigation_throttle_unittest.cc

Issue 2498223002: arc: enable use_new_wrapper_types for intent_helper.mojom (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include <algorithm> 5 #include <algorithm>
6 6
7 #include "chrome/browser/chromeos/arc/intent_helper/arc_navigation_throttle.h" 7 #include "chrome/browser/chromeos/arc/intent_helper/arc_navigation_throttle.h"
8 #include "components/arc/intent_helper/arc_intent_helper_bridge.h" 8 #include "components/arc/intent_helper/arc_intent_helper_bridge.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "url/gurl.h" 10 #include "url/gurl.h"
11 11
12 namespace arc { 12 namespace arc {
13 13
14 namespace { 14 namespace {
15 15
16 // Creates an array with |num_elements| handlers and makes |chrome_index|-th 16 // Creates an array with |num_elements| handlers and makes |chrome_index|-th
17 // handler "Chrome". If Chrome is not necessary, set |chrome_index| to 17 // handler "Chrome". If Chrome is not necessary, set |chrome_index| to
18 // |num_elements|. 18 // |num_elements|.
19 mojo::Array<mojom::IntentHandlerInfoPtr> CreateArray(size_t num_elements, 19 std::vector<mojom::IntentHandlerInfoPtr> CreateArray(size_t num_elements,
20 size_t chrome_index) { 20 size_t chrome_index) {
21 mojo::Array<mojom::IntentHandlerInfoPtr> handlers; 21 std::vector<mojom::IntentHandlerInfoPtr> handlers;
22 for (size_t i = 0; i < num_elements; ++i) { 22 for (size_t i = 0; i < num_elements; ++i) {
23 mojom::IntentHandlerInfoPtr handler = mojom::IntentHandlerInfo::New(); 23 mojom::IntentHandlerInfoPtr handler = mojom::IntentHandlerInfo::New();
24 handler->name = "Name"; 24 handler->name = "Name";
25 if (i == chrome_index) { 25 if (i == chrome_index) {
26 handler->package_name = 26 handler->package_name =
27 ArcIntentHelperBridge::kArcIntentHelperPackageName; 27 ArcIntentHelperBridge::kArcIntentHelperPackageName;
28 } else { 28 } else {
29 handler->package_name = "com.package"; 29 handler->package_name = "com.package";
30 } 30 }
31 handlers.push_back(std::move(handler)); 31 handlers.push_back(std::move(handler));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 0u, ArcNavigationThrottle::FindPreferredAppForTesting(CreateArray(0, 0))); 102 0u, ArcNavigationThrottle::FindPreferredAppForTesting(CreateArray(0, 0)));
103 // Test no-preferred-app cases. 103 // Test no-preferred-app cases.
104 EXPECT_EQ( 104 EXPECT_EQ(
105 1u, ArcNavigationThrottle::FindPreferredAppForTesting(CreateArray(1, 0))); 105 1u, ArcNavigationThrottle::FindPreferredAppForTesting(CreateArray(1, 0)));
106 EXPECT_EQ( 106 EXPECT_EQ(
107 2u, ArcNavigationThrottle::FindPreferredAppForTesting(CreateArray(2, 1))); 107 2u, ArcNavigationThrottle::FindPreferredAppForTesting(CreateArray(2, 1)));
108 EXPECT_EQ( 108 EXPECT_EQ(
109 3u, ArcNavigationThrottle::FindPreferredAppForTesting(CreateArray(3, 2))); 109 3u, ArcNavigationThrottle::FindPreferredAppForTesting(CreateArray(3, 2)));
110 // Add a preferred app and call the function. 110 // Add a preferred app and call the function.
111 for (size_t i = 0; i < 3; ++i) { 111 for (size_t i = 0; i < 3; ++i) {
112 mojo::Array<mojom::IntentHandlerInfoPtr> handlers = CreateArray(3, 0); 112 std::vector<mojom::IntentHandlerInfoPtr> handlers = CreateArray(3, 0);
113 handlers[i]->is_preferred = true; 113 handlers[i]->is_preferred = true;
114 EXPECT_EQ(i, ArcNavigationThrottle::FindPreferredAppForTesting(handlers)) 114 EXPECT_EQ(i, ArcNavigationThrottle::FindPreferredAppForTesting(handlers))
115 << i; 115 << i;
116 } 116 }
117 } 117 }
118 118
119 TEST(ArcNavigationThrottleTest, TestGetAppIndex) { 119 TEST(ArcNavigationThrottleTest, TestGetAppIndex) {
120 const std::string package_name = 120 const std::string package_name =
121 ArcIntentHelperBridge::kArcIntentHelperPackageName; 121 ArcIntentHelperBridge::kArcIntentHelperPackageName;
122 // Test an empty array. 122 // Test an empty array.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 EXPECT_EQ(ArcNavigationThrottle::Platform::ARC, 192 EXPECT_EQ(ArcNavigationThrottle::Platform::ARC,
193 ArcNavigationThrottle::GetDestinationPlatform( 193 ArcNavigationThrottle::GetDestinationPlatform(
194 non_chrome_app, 194 non_chrome_app,
195 ArcNavigationThrottle::CloseReason::PREFERRED_ACTIVITY_FOUND)); 195 ArcNavigationThrottle::CloseReason::PREFERRED_ACTIVITY_FOUND));
196 } 196 }
197 197
198 TEST(ArcNavigationThrottleTest, TestIsSwapElementsNeeded) { 198 TEST(ArcNavigationThrottleTest, TestIsSwapElementsNeeded) {
199 std::pair<size_t, size_t> indices; 199 std::pair<size_t, size_t> indices;
200 for (size_t i = 1; i <= ArcNavigationThrottle::kMaxAppResults; ++i) { 200 for (size_t i = 1; i <= ArcNavigationThrottle::kMaxAppResults; ++i) {
201 // When Chrome is the first element, swap is unnecessary. 201 // When Chrome is the first element, swap is unnecessary.
202 mojo::Array<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, 0); 202 std::vector<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, 0);
203 EXPECT_FALSE( 203 EXPECT_FALSE(
204 ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices)) 204 ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices))
205 << i; 205 << i;
206 206
207 // When Chrome is within the first |kMaxAppResults| elements, swap is 207 // When Chrome is within the first |kMaxAppResults| elements, swap is
208 // unnecessary. 208 // unnecessary.
209 handlers = CreateArray(i, i - 1); 209 handlers = CreateArray(i, i - 1);
210 EXPECT_FALSE( 210 EXPECT_FALSE(
211 ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices)) 211 ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices))
212 << i; 212 << i;
213 } 213 }
214 214
215 for (size_t i = ArcNavigationThrottle::kMaxAppResults + 1; 215 for (size_t i = ArcNavigationThrottle::kMaxAppResults + 1;
216 i < ArcNavigationThrottle::kMaxAppResults * 2; ++i) { 216 i < ArcNavigationThrottle::kMaxAppResults * 2; ++i) {
217 // When Chrome is within the first |kMaxAppResults| elements, swap is 217 // When Chrome is within the first |kMaxAppResults| elements, swap is
218 // unnecessary. 218 // unnecessary.
219 mojo::Array<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, 0); 219 std::vector<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, 0);
220 EXPECT_FALSE( 220 EXPECT_FALSE(
221 ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices)) 221 ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices))
222 << i; 222 << i;
223 223
224 // When Chrome is the |kMaxAppResults|-th element, swap is unnecessary. 224 // When Chrome is the |kMaxAppResults|-th element, swap is unnecessary.
225 handlers = CreateArray(i, ArcNavigationThrottle::kMaxAppResults - 1); 225 handlers = CreateArray(i, ArcNavigationThrottle::kMaxAppResults - 1);
226 EXPECT_FALSE( 226 EXPECT_FALSE(
227 ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices)) 227 ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices))
228 << i; 228 << i;
229 229
230 // When Chrome is not within the first |kMaxAppResults| elements, swap is 230 // When Chrome is not within the first |kMaxAppResults| elements, swap is
231 // necessary. 231 // necessary.
232 handlers = CreateArray(i, i - 1); 232 handlers = CreateArray(i, i - 1);
233 indices.first = indices.second = 0; 233 indices.first = indices.second = 0;
234 EXPECT_TRUE(ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices)) 234 EXPECT_TRUE(ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices))
235 << i; 235 << i;
236 EXPECT_EQ(ArcNavigationThrottle::kMaxAppResults - 1u, indices.first) << i; 236 EXPECT_EQ(ArcNavigationThrottle::kMaxAppResults - 1u, indices.first) << i;
237 EXPECT_EQ(i - 1, indices.second) << i; 237 EXPECT_EQ(i - 1, indices.second) << i;
238 } 238 }
239 239
240 for (size_t i = 0; i <= ArcNavigationThrottle::kMaxAppResults * 2; ++i) { 240 for (size_t i = 0; i <= ArcNavigationThrottle::kMaxAppResults * 2; ++i) {
241 // When Chrome does not exist in |handlers|, swap is unnecessary. 241 // When Chrome does not exist in |handlers|, swap is unnecessary.
242 mojo::Array<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, i); 242 std::vector<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, i);
243 EXPECT_FALSE( 243 EXPECT_FALSE(
244 ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices)) 244 ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices))
245 << i; 245 << i;
246 } 246 }
247 } 247 }
248 248
249 } // namespace arc 249 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698