| OLD | NEW |
| 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" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 mojo::Array<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, 0); |
| 203 EXPECT_FALSE(ArcNavigationThrottle::IsSwapElementsNeededForTesting( | 203 EXPECT_FALSE( |
| 204 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(ArcNavigationThrottle::IsSwapElementsNeededForTesting( | 210 EXPECT_FALSE( |
| 211 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 mojo::Array<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, 0); |
| 220 EXPECT_FALSE(ArcNavigationThrottle::IsSwapElementsNeededForTesting( | 220 EXPECT_FALSE( |
| 221 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(ArcNavigationThrottle::IsSwapElementsNeededForTesting( | 226 EXPECT_FALSE( |
| 227 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::IsSwapElementsNeededForTesting(handlers, | 234 EXPECT_TRUE(ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices)) |
| 235 &indices)) | |
| 236 << i; | 235 << i; |
| 237 EXPECT_EQ(ArcNavigationThrottle::kMaxAppResults - 1u, indices.first) << i; | 236 EXPECT_EQ(ArcNavigationThrottle::kMaxAppResults - 1u, indices.first) << i; |
| 238 EXPECT_EQ(i - 1, indices.second) << i; | 237 EXPECT_EQ(i - 1, indices.second) << i; |
| 239 } | 238 } |
| 240 | 239 |
| 241 for (size_t i = 0; i <= ArcNavigationThrottle::kMaxAppResults * 2; ++i) { | 240 for (size_t i = 0; i <= ArcNavigationThrottle::kMaxAppResults * 2; ++i) { |
| 242 // When Chrome does not exist in |handlers|, swap is unnecessary. | 241 // When Chrome does not exist in |handlers|, swap is unnecessary. |
| 243 mojo::Array<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, i); | 242 mojo::Array<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, i); |
| 244 EXPECT_FALSE(ArcNavigationThrottle::IsSwapElementsNeededForTesting( | 243 EXPECT_FALSE( |
| 245 handlers, &indices)) | 244 ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices)) |
| 246 << i; | 245 << i; |
| 247 } | 246 } |
| 248 } | 247 } |
| 249 | 248 |
| 250 } // namespace arc | 249 } // namespace arc |
| OLD | NEW |