| 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 on_callback_.Run(); | 147 on_callback_.Run(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 blink::mojom::ShareServicePtr share_service_; | 150 blink::mojom::ShareServicePtr share_service_; |
| 151 std::unique_ptr<ShareServiceTestImpl> share_service_helper_; | 151 std::unique_ptr<ShareServiceTestImpl> share_service_helper_; |
| 152 base::Closure on_callback_; | 152 base::Closure on_callback_; |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 } // namespace | 155 } // namespace |
| 156 | 156 |
| 157 #if defined(OS_LINUX) || defined(OS_WIN) | |
| 158 | |
| 159 // Basic test to check the Share method calls the callback with the expected | 157 // Basic test to check the Share method calls the callback with the expected |
| 160 // parameters. | 158 // parameters. |
| 161 TEST_F(ShareServiceImplUnittest, ShareCallbackParams) { | 159 TEST_F(ShareServiceImplUnittest, ShareCallbackParams) { |
| 162 share_service_helper_->set_picker_result( | 160 share_service_helper_->set_picker_result( |
| 163 base::Optional<std::string>(kManifestUrlLow)); | 161 base::Optional<std::string>(kManifestUrlLow)); |
| 164 | 162 |
| 165 share_service_helper_->AddShareTargetToPrefs(kManifestUrlLow, kTargetName, | 163 share_service_helper_->AddShareTargetToPrefs(kManifestUrlLow, kTargetName, |
| 166 kUrlTemplate); | 164 kUrlTemplate); |
| 167 share_service_helper_->AddShareTargetToPrefs(kManifestUrlHigh, kTargetName, | 165 share_service_helper_->AddShareTargetToPrefs(kManifestUrlHigh, kTargetName, |
| 168 kUrlTemplate); | 166 kUrlTemplate); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 256 |
| 259 base::RunLoop run_loop; | 257 base::RunLoop run_loop; |
| 260 on_callback_ = run_loop.QuitClosure(); | 258 on_callback_ = run_loop.QuitClosure(); |
| 261 | 259 |
| 262 const GURL url(kUrlSpec); | 260 const GURL url(kUrlSpec); |
| 263 share_service_->Share(kTitle, kText, url, callback); | 261 share_service_->Share(kTitle, kText, url, callback); |
| 264 | 262 |
| 265 run_loop.Run(); | 263 run_loop.Run(); |
| 266 } | 264 } |
| 267 | 265 |
| 268 #endif // defined(OS_LINUX) || defined(OS_WIN) | |
| 269 | |
| 270 // Replace various numbers of placeholders in various orders. Placeholders are | 266 // Replace various numbers of placeholders in various orders. Placeholders are |
| 271 // adjacent to eachother; there are no padding characters. | 267 // adjacent to eachother; there are no padding characters. |
| 272 TEST_F(ShareServiceImplUnittest, ReplacePlaceholders) { | 268 TEST_F(ShareServiceImplUnittest, ReplacePlaceholders) { |
| 273 const GURL url(kUrlSpec); | 269 const GURL url(kUrlSpec); |
| 274 std::string url_template_filled; | 270 std::string url_template_filled; |
| 275 bool succeeded; | 271 bool succeeded; |
| 276 | 272 |
| 277 // No placeholders | 273 // No placeholders |
| 278 std::string url_template = "blank"; | 274 std::string url_template = "blank"; |
| 279 succeeded = ShareServiceImpl::ReplacePlaceholders(url_template, kTitle, kText, | 275 succeeded = ShareServiceImpl::ReplacePlaceholders(url_template, kTitle, kText, |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 EXPECT_TRUE(succeeded); | 459 EXPECT_TRUE(succeeded); |
| 464 EXPECT_EQ("%C3%A9", url_template_filled); | 460 EXPECT_EQ("%C3%A9", url_template_filled); |
| 465 | 461 |
| 466 // U+1F4A9 | 462 // U+1F4A9 |
| 467 url_template = "{title}"; | 463 url_template = "{title}"; |
| 468 succeeded = ShareServiceImpl::ReplacePlaceholders( | 464 succeeded = ShareServiceImpl::ReplacePlaceholders( |
| 469 url_template, "\xf0\x9f\x92\xa9", kText, url, &url_template_filled); | 465 url_template, "\xf0\x9f\x92\xa9", kText, url, &url_template_filled); |
| 470 EXPECT_TRUE(succeeded); | 466 EXPECT_TRUE(succeeded); |
| 471 EXPECT_EQ("%F0%9F%92%A9", url_template_filled); | 467 EXPECT_EQ("%F0%9F%92%A9", url_template_filled); |
| 472 } | 468 } |
| OLD | NEW |