spellcheck_provider_mac_unittest.cc 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <tuple>
  5. #include <vector>
  6. #include "base/run_loop.h"
  7. #include "base/strings/utf_string_conversions.h"
  8. #include "components/spellcheck/common/spellcheck_result.h"
  9. #include "components/spellcheck/renderer/spellcheck_provider_test.h"
  10. #include "testing/gtest/include/gtest/gtest.h"
  11. namespace {
  12. class SpellCheckProviderMacTest : public SpellCheckProviderTest {};
  13. TEST_F(SpellCheckProviderMacTest, SingleRoundtripSuccess) {
  14. FakeTextCheckingResult completion;
  15. provider_.RequestTextChecking(
  16. u"hello ", std::make_unique<FakeTextCheckingCompletion>(&completion));
  17. EXPECT_EQ(completion.completion_count_, 0U);
  18. EXPECT_EQ(provider_.text_check_requests_.size(), 1U);
  19. EXPECT_EQ(provider_.pending_text_request_size(), 1U);
  20. const auto& text = provider_.text_check_requests_.back().first;
  21. auto& callback = provider_.text_check_requests_.back().second;
  22. EXPECT_EQ(text, u"hello ");
  23. EXPECT_TRUE(callback);
  24. std::vector<SpellCheckResult> fake_results;
  25. std::move(callback).Run(fake_results);
  26. base::RunLoop().RunUntilIdle();
  27. EXPECT_EQ(completion.completion_count_, 1U);
  28. EXPECT_EQ(provider_.pending_text_request_size(), 0U);
  29. provider_.text_check_requests_.clear();
  30. }
  31. TEST_F(SpellCheckProviderMacTest, TwoRoundtripSuccess) {
  32. FakeTextCheckingResult completion1;
  33. provider_.RequestTextChecking(
  34. u"hello ", std::make_unique<FakeTextCheckingCompletion>(&completion1));
  35. FakeTextCheckingResult completion2;
  36. provider_.RequestTextChecking(
  37. u"bye ", std::make_unique<FakeTextCheckingCompletion>(&completion2));
  38. EXPECT_EQ(completion1.completion_count_, 0U);
  39. EXPECT_EQ(completion2.completion_count_, 0U);
  40. EXPECT_EQ(provider_.text_check_requests_.size(), 2U);
  41. EXPECT_EQ(provider_.pending_text_request_size(), 2U);
  42. const auto& text1 = provider_.text_check_requests_[0].first;
  43. auto& callback1 = provider_.text_check_requests_[0].second;
  44. EXPECT_EQ(text1, u"hello ");
  45. EXPECT_TRUE(callback1);
  46. const auto& text2 = provider_.text_check_requests_[1].first;
  47. auto& callback2 = provider_.text_check_requests_[1].second;
  48. EXPECT_EQ(text2, u"bye ");
  49. EXPECT_TRUE(callback2);
  50. std::vector<SpellCheckResult> fake_results;
  51. std::move(callback1).Run(fake_results);
  52. base::RunLoop().RunUntilIdle();
  53. EXPECT_EQ(completion1.completion_count_, 1U);
  54. EXPECT_EQ(completion2.completion_count_, 0U);
  55. EXPECT_EQ(provider_.pending_text_request_size(), 1U);
  56. std::move(callback2).Run(fake_results);
  57. base::RunLoop().RunUntilIdle();
  58. EXPECT_EQ(completion1.completion_count_, 1U);
  59. EXPECT_EQ(completion2.completion_count_, 1U);
  60. EXPECT_EQ(provider_.pending_text_request_size(), 0U);
  61. provider_.text_check_requests_.clear();
  62. }
  63. } // namespace