| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 1u, ArcNavigationThrottle::GetAppIndex(CreateArray(3, 1), package_name)); | 141 1u, ArcNavigationThrottle::GetAppIndex(CreateArray(3, 1), package_name)); |
| 142 EXPECT_EQ( | 142 EXPECT_EQ( |
| 143 2u, ArcNavigationThrottle::GetAppIndex(CreateArray(3, 2), package_name)); | 143 2u, ArcNavigationThrottle::GetAppIndex(CreateArray(3, 2), package_name)); |
| 144 } | 144 } |
| 145 | 145 |
| 146 TEST(ArcNavigationThrottleTest, TestIsSwapElementsNeeded) { | 146 TEST(ArcNavigationThrottleTest, TestIsSwapElementsNeeded) { |
| 147 std::pair<size_t, size_t> indices; | 147 std::pair<size_t, size_t> indices; |
| 148 for (size_t i = 1; i <= ArcNavigationThrottle::kMaxAppResults; ++i) { | 148 for (size_t i = 1; i <= ArcNavigationThrottle::kMaxAppResults; ++i) { |
| 149 // When Chrome is the first element, swap is unnecessary. | 149 // When Chrome is the first element, swap is unnecessary. |
| 150 mojo::Array<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, 0); | 150 mojo::Array<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, 0); |
| 151 EXPECT_FALSE(ArcNavigationThrottle::IsSwapElementsNeededForTesting( | 151 EXPECT_FALSE( |
| 152 handlers, &indices)) | 152 ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices)) |
| 153 << i; | 153 << i; |
| 154 | 154 |
| 155 // When Chrome is within the first |kMaxAppResults| elements, swap is | 155 // When Chrome is within the first |kMaxAppResults| elements, swap is |
| 156 // unnecessary. | 156 // unnecessary. |
| 157 handlers = CreateArray(i, i - 1); | 157 handlers = CreateArray(i, i - 1); |
| 158 EXPECT_FALSE(ArcNavigationThrottle::IsSwapElementsNeededForTesting( | 158 EXPECT_FALSE( |
| 159 handlers, &indices)) | 159 ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices)) |
| 160 << i; | 160 << i; |
| 161 } | 161 } |
| 162 | 162 |
| 163 for (size_t i = ArcNavigationThrottle::kMaxAppResults + 1; | 163 for (size_t i = ArcNavigationThrottle::kMaxAppResults + 1; |
| 164 i < ArcNavigationThrottle::kMaxAppResults * 2; ++i) { | 164 i < ArcNavigationThrottle::kMaxAppResults * 2; ++i) { |
| 165 // When Chrome is within the first |kMaxAppResults| elements, swap is | 165 // When Chrome is within the first |kMaxAppResults| elements, swap is |
| 166 // unnecessary. | 166 // unnecessary. |
| 167 mojo::Array<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, 0); | 167 mojo::Array<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, 0); |
| 168 EXPECT_FALSE(ArcNavigationThrottle::IsSwapElementsNeededForTesting( | 168 EXPECT_FALSE( |
| 169 handlers, &indices)) | 169 ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices)) |
| 170 << i; | 170 << i; |
| 171 | 171 |
| 172 // When Chrome is the |kMaxAppResults|-th element, swap is unnecessary. | 172 // When Chrome is the |kMaxAppResults|-th element, swap is unnecessary. |
| 173 handlers = CreateArray(i, ArcNavigationThrottle::kMaxAppResults - 1); | 173 handlers = CreateArray(i, ArcNavigationThrottle::kMaxAppResults - 1); |
| 174 EXPECT_FALSE(ArcNavigationThrottle::IsSwapElementsNeededForTesting( | 174 EXPECT_FALSE( |
| 175 handlers, &indices)) | 175 ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices)) |
| 176 << i; | 176 << i; |
| 177 | 177 |
| 178 // When Chrome is not within the first |kMaxAppResults| elements, swap is | 178 // When Chrome is not within the first |kMaxAppResults| elements, swap is |
| 179 // necessary. | 179 // necessary. |
| 180 handlers = CreateArray(i, i - 1); | 180 handlers = CreateArray(i, i - 1); |
| 181 indices.first = indices.second = 0; | 181 indices.first = indices.second = 0; |
| 182 EXPECT_TRUE(ArcNavigationThrottle::IsSwapElementsNeededForTesting(handlers, | 182 EXPECT_TRUE(ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices)) |
| 183 &indices)) | |
| 184 << i; | 183 << i; |
| 185 EXPECT_EQ(ArcNavigationThrottle::kMaxAppResults - 1u, indices.first) << i; | 184 EXPECT_EQ(ArcNavigationThrottle::kMaxAppResults - 1u, indices.first) << i; |
| 186 EXPECT_EQ(i - 1, indices.second) << i; | 185 EXPECT_EQ(i - 1, indices.second) << i; |
| 187 } | 186 } |
| 188 | 187 |
| 189 for (size_t i = 0; i <= ArcNavigationThrottle::kMaxAppResults * 2; ++i) { | 188 for (size_t i = 0; i <= ArcNavigationThrottle::kMaxAppResults * 2; ++i) { |
| 190 // When Chrome does not exist in |handlers|, swap is unnecessary. | 189 // When Chrome does not exist in |handlers|, swap is unnecessary. |
| 191 mojo::Array<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, i); | 190 mojo::Array<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, i); |
| 192 EXPECT_FALSE(ArcNavigationThrottle::IsSwapElementsNeededForTesting( | 191 EXPECT_FALSE( |
| 193 handlers, &indices)) | 192 ArcNavigationThrottle::IsSwapElementsNeeded(handlers, &indices)) |
| 194 << i; | 193 << i; |
| 195 } | 194 } |
| 196 } | 195 } |
| 197 | 196 |
| 198 } // namespace arc | 197 } // namespace arc |
| OLD | NEW |