OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // To test, run "out/Debug//mojo_shell mojo:prediction_apptests" | 5 // To test, run "out/Debug//mojo_shell mojo:prediction_apptests" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "mojo/public/cpp/application/application_impl.h" | 9 #include "mojo/public/cpp/application/application_impl.h" |
10 #include "mojo/public/cpp/application/application_test_base.h" | 10 #include "mojo/public/cpp/application/application_test_base.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 PredictionApptest() : ApplicationTestBase() {} | 23 PredictionApptest() : ApplicationTestBase() {} |
24 | 24 |
25 ~PredictionApptest() override {} | 25 ~PredictionApptest() override {} |
26 | 26 |
27 void SetUp() override { | 27 void SetUp() override { |
28 mojo::test::ApplicationTestBase::SetUp(); | 28 mojo::test::ApplicationTestBase::SetUp(); |
29 application_impl()->ConnectToService("mojo:prediction_service", | 29 application_impl()->ConnectToService("mojo:prediction_service", |
30 &prediction_); | 30 &prediction_); |
31 } | 31 } |
32 | 32 |
33 void SetSettingsClient(bool correction, | |
34 bool offensive, | |
35 bool space_aware_gesture) { | |
36 SettingsPtr settings = Settings::New(); | |
37 settings->correction_enabled = correction; | |
38 settings->block_potentially_offensive = offensive; | |
39 settings->space_aware_gesture_enabled = space_aware_gesture; | |
40 prediction_->SetSettings(settings.Pass()); | |
41 } | |
42 | |
43 std::vector<std::string> GetPredictionListClient( | 33 std::vector<std::string> GetPredictionListClient( |
44 const mojo::Array<mojo::String>& prev_words, | 34 mojo::Array<PrevWordInfoPtr>& prev_words, |
45 const mojo::String& cur_word) { | 35 const mojo::String& cur_word) { |
46 PredictionInfoPtr prediction_info = PredictionInfo::New(); | 36 PredictionInfoPtr prediction_info = PredictionInfo::New(); |
47 prediction_info->previous_words = prev_words.Clone().Pass(); | 37 prediction_info->previous_words = prev_words.Pass(); |
48 prediction_info->current_word = cur_word; | 38 prediction_info->current_word = cur_word; |
49 | 39 |
50 std::vector<std::string> prediction_list; | 40 std::vector<std::string> prediction_list; |
51 prediction_->GetPredictionList( | 41 prediction_->GetPredictionList( |
52 prediction_info.Pass(), | 42 prediction_info.Pass(), |
53 base::Bind(&GetPredictionListAndEnd, &prediction_list)); | 43 base::Bind(&GetPredictionListAndEnd, &prediction_list)); |
54 base::MessageLoop::current()->Run(); | 44 base::MessageLoop::current()->Run(); |
55 return prediction_list; | 45 return prediction_list; |
56 } | 46 } |
57 | 47 |
58 private: | 48 private: |
59 PredictionServicePtr prediction_; | 49 PredictionServicePtr prediction_; |
60 | 50 |
61 DISALLOW_COPY_AND_ASSIGN(PredictionApptest); | 51 DISALLOW_COPY_AND_ASSIGN(PredictionApptest); |
62 }; | 52 }; |
63 | 53 |
64 TEST_F(PredictionApptest, PredictCat) { | 54 TEST_F(PredictionApptest, CurrentSpellcheck) { |
65 SetSettingsClient(true, true, true); | 55 mojo::Array<PrevWordInfoPtr> prev_words = |
66 mojo::Array<mojo::String> prev_words; | 56 mojo::Array<PrevWordInfoPtr>::New(0); |
67 prev_words.push_back("dog"); | 57 std::string prediction = GetPredictionListClient(prev_words, "tgis")[0]; |
68 std::string prediction_cat = GetPredictionListClient(prev_words, "d")[0]; | 58 EXPECT_EQ(prediction, "this"); |
69 EXPECT_EQ(prediction_cat, "cat"); | 59 |
| 60 mojo::Array<PrevWordInfoPtr> prev_words1 = |
| 61 mojo::Array<PrevWordInfoPtr>::New(0); |
| 62 std::string prediction1 = GetPredictionListClient(prev_words1, "aplle")[0]; |
| 63 EXPECT_EQ(prediction1, "Apple"); |
| 64 } |
| 65 |
| 66 TEST_F(PredictionApptest, CurrentSuggest) { |
| 67 mojo::Array<PrevWordInfoPtr> prev_words = |
| 68 mojo::Array<PrevWordInfoPtr>::New(0); |
| 69 std::string prediction = GetPredictionListClient(prev_words, "peac")[0]; |
| 70 EXPECT_EQ(prediction, "peace"); |
| 71 |
| 72 mojo::Array<PrevWordInfoPtr> prev_words1 = |
| 73 mojo::Array<PrevWordInfoPtr>::New(0); |
| 74 std::string prediction1 = GetPredictionListClient(prev_words1, "fil")[0]; |
| 75 EXPECT_EQ(prediction1, "film"); |
| 76 |
| 77 mojo::Array<PrevWordInfoPtr> prev_words2 = |
| 78 mojo::Array<PrevWordInfoPtr>::New(0); |
| 79 std::string prediction2 = GetPredictionListClient(prev_words2, "entert")[0]; |
| 80 EXPECT_EQ(prediction2, "entertainment"); |
| 81 } |
| 82 |
| 83 TEST_F(PredictionApptest, CurrentSuggestCont) { |
| 84 mojo::Array<PrevWordInfoPtr> prev_words = |
| 85 mojo::Array<PrevWordInfoPtr>::New(0); |
| 86 std::string prediction = GetPredictionListClient(prev_words, "a")[0]; |
| 87 EXPECT_EQ(prediction, "and"); |
| 88 |
| 89 mojo::Array<PrevWordInfoPtr> prev_words1 = |
| 90 mojo::Array<PrevWordInfoPtr>::New(0); |
| 91 std::string prediction1 = GetPredictionListClient(prev_words1, "ab")[0]; |
| 92 EXPECT_EQ(prediction1, "an"); |
| 93 } |
| 94 |
| 95 TEST_F(PredictionApptest, CurrentSuggestUp) { |
| 96 mojo::Array<PrevWordInfoPtr> prev_words = |
| 97 mojo::Array<PrevWordInfoPtr>::New(0); |
| 98 std::string prediction = GetPredictionListClient(prev_words, "Beau")[0]; |
| 99 EXPECT_EQ(prediction, "Beat"); |
| 100 |
| 101 mojo::Array<PrevWordInfoPtr> prev_words1 = |
| 102 mojo::Array<PrevWordInfoPtr>::New(0); |
| 103 std::string prediction1 = GetPredictionListClient(prev_words1, "THis")[0]; |
| 104 EXPECT_EQ(prediction1, "This"); |
| 105 } |
| 106 |
| 107 TEST_F(PredictionApptest, CurrentNoSuggest) { |
| 108 mojo::Array<PrevWordInfoPtr> prev_words = |
| 109 mojo::Array<PrevWordInfoPtr>::New(0); |
| 110 std::string prediction = GetPredictionListClient( |
| 111 prev_words, |
| 112 "hjlahflgfagfdafaffgruhgadfhjklghadflkghjalkdfjkldfhrshrtshtsrhkra")[0]; |
| 113 EXPECT_EQ(prediction, "homage offered a faded rugged should had dough"); |
| 114 } |
| 115 |
| 116 TEST_F(PredictionApptest, EmptyCurrent) { |
| 117 PrevWordInfoPtr prev_word = PrevWordInfo::New(); |
| 118 prev_word->word = "This"; |
| 119 prev_word->is_beginning_of_sentence = true; |
| 120 mojo::Array<PrevWordInfoPtr> prev_words = |
| 121 mojo::Array<PrevWordInfoPtr>::New(0); |
| 122 prev_words.push_back(prev_word.Pass()); |
| 123 EXPECT_EQ((int)GetPredictionListClient(prev_words, "").size(), 0); |
70 } | 124 } |
71 | 125 |
72 } // namespace prediction | 126 } // namespace prediction |
OLD | NEW |