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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 EXPECT_EQ( | 136 EXPECT_EQ( |
137 1u, ArcNavigationThrottle::GetAppIndex(CreateArray(2, 1), package_name)); | 137 1u, ArcNavigationThrottle::GetAppIndex(CreateArray(2, 1), package_name)); |
138 EXPECT_EQ( | 138 EXPECT_EQ( |
139 0u, ArcNavigationThrottle::GetAppIndex(CreateArray(3, 0), package_name)); | 139 0u, ArcNavigationThrottle::GetAppIndex(CreateArray(3, 0), package_name)); |
140 EXPECT_EQ( | 140 EXPECT_EQ( |
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, TestGetDestinationPlatform) { | |
Yusuke Sato
2016/11/04 16:18:06
Thanks!
djacobo_
2016/11/04 17:43:43
Not a problem :)
| |
147 const std::string chrome_app = | |
148 ArcIntentHelperBridge::kArcIntentHelperPackageName; | |
149 const std::string non_chrome_app = "fake_package"; | |
150 | |
151 // When the CloseReason is either ERROR or DIALOG_DEACTIVATED we MUST stay in | |
152 // Chrome not taking into account the selected_app_package. | |
153 EXPECT_EQ(ArcNavigationThrottle::Platform::CHROME, | |
154 ArcNavigationThrottle::GetDestinationPlatform( | |
155 chrome_app, ArcNavigationThrottle::CloseReason::ERROR)); | |
156 EXPECT_EQ(ArcNavigationThrottle::Platform::CHROME, | |
157 ArcNavigationThrottle::GetDestinationPlatform( | |
158 non_chrome_app, ArcNavigationThrottle::CloseReason::ERROR)); | |
159 EXPECT_EQ(ArcNavigationThrottle::Platform::CHROME, | |
Yusuke Sato
2016/11/04 16:18:06
nit: could you swap L159 & L163? The order (chrome
djacobo_
2016/11/04 17:43:43
Done.
| |
160 ArcNavigationThrottle::GetDestinationPlatform( | |
161 non_chrome_app, | |
162 ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED)); | |
163 EXPECT_EQ( | |
164 ArcNavigationThrottle::Platform::CHROME, | |
165 ArcNavigationThrottle::GetDestinationPlatform( | |
166 chrome_app, ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED)); | |
167 | |
168 // Under any other CloseReason, stay in Chrome only if the package is Chrome. | |
169 // Otherwise redirect to ARC. | |
170 EXPECT_EQ( | |
171 ArcNavigationThrottle::Platform::CHROME, | |
172 ArcNavigationThrottle::GetDestinationPlatform( | |
173 chrome_app, ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED)); | |
174 EXPECT_EQ( | |
175 ArcNavigationThrottle::Platform::CHROME, | |
176 ArcNavigationThrottle::GetDestinationPlatform( | |
177 chrome_app, ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED)); | |
178 EXPECT_EQ(ArcNavigationThrottle::Platform::CHROME, | |
179 ArcNavigationThrottle::GetDestinationPlatform( | |
180 chrome_app, | |
181 ArcNavigationThrottle::CloseReason::PREFERRED_ACTIVITY_FOUND)); | |
182 | |
183 // Go to ARC on any other case. | |
184 EXPECT_EQ( | |
185 ArcNavigationThrottle::Platform::ARC, | |
186 ArcNavigationThrottle::GetDestinationPlatform( | |
187 non_chrome_app, ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED)); | |
188 EXPECT_EQ(ArcNavigationThrottle::Platform::ARC, | |
189 ArcNavigationThrottle::GetDestinationPlatform( | |
190 non_chrome_app, | |
191 ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED)); | |
192 EXPECT_EQ(ArcNavigationThrottle::Platform::ARC, | |
193 ArcNavigationThrottle::GetDestinationPlatform( | |
194 non_chrome_app, | |
195 ArcNavigationThrottle::CloseReason::PREFERRED_ACTIVITY_FOUND)); | |
196 } | |
197 | |
146 TEST(ArcNavigationThrottleTest, TestIsSwapElementsNeeded) { | 198 TEST(ArcNavigationThrottleTest, TestIsSwapElementsNeeded) { |
147 std::pair<size_t, size_t> indices; | 199 std::pair<size_t, size_t> indices; |
148 for (size_t i = 1; i <= ArcNavigationThrottle::kMaxAppResults; ++i) { | 200 for (size_t i = 1; i <= ArcNavigationThrottle::kMaxAppResults; ++i) { |
149 // When Chrome is the first element, swap is unnecessary. | 201 // When Chrome is the first element, swap is unnecessary. |
150 mojo::Array<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, 0); | 202 mojo::Array<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, 0); |
151 EXPECT_FALSE(ArcNavigationThrottle::IsSwapElementsNeededForTesting( | 203 EXPECT_FALSE(ArcNavigationThrottle::IsSwapElementsNeededForTesting( |
152 handlers, &indices)) | 204 handlers, &indices)) |
153 << i; | 205 << i; |
154 | 206 |
155 // When Chrome is within the first |kMaxAppResults| elements, swap is | 207 // When Chrome is within the first |kMaxAppResults| elements, swap is |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 for (size_t i = 0; i <= ArcNavigationThrottle::kMaxAppResults * 2; ++i) { | 241 for (size_t i = 0; i <= ArcNavigationThrottle::kMaxAppResults * 2; ++i) { |
190 // When Chrome does not exist in |handlers|, swap is unnecessary. | 242 // When Chrome does not exist in |handlers|, swap is unnecessary. |
191 mojo::Array<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, i); | 243 mojo::Array<mojom::IntentHandlerInfoPtr> handlers = CreateArray(i, i); |
192 EXPECT_FALSE(ArcNavigationThrottle::IsSwapElementsNeededForTesting( | 244 EXPECT_FALSE(ArcNavigationThrottle::IsSwapElementsNeededForTesting( |
193 handlers, &indices)) | 245 handlers, &indices)) |
194 << i; | 246 << i; |
195 } | 247 } |
196 } | 248 } |
197 | 249 |
198 } // namespace arc | 250 } // namespace arc |
OLD | NEW |