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<mojo::String>& prev_words, |
35 mojo::Array<bool>& beginning_of_sentence, | |
45 const mojo::String& cur_word) { | 36 const mojo::String& cur_word) { |
46 PredictionInfoPtr prediction_info = PredictionInfo::New(); | 37 PredictionInfoPtr prediction_info = PredictionInfo::New(); |
47 prediction_info->previous_words = prev_words.Clone().Pass(); | 38 prediction_info->previous_words = prev_words.Pass(); |
39 prediction_info->are_beginning_of_sentence = beginning_of_sentence.Pass(); | |
48 prediction_info->current_word = cur_word; | 40 prediction_info->current_word = cur_word; |
49 | 41 |
50 std::vector<std::string> prediction_list; | 42 std::vector<std::string> prediction_list; |
51 prediction_->GetPredictionList( | 43 prediction_->GetPredictionList( |
52 prediction_info.Pass(), | 44 prediction_info.Pass(), |
53 base::Bind(&GetPredictionListAndEnd, &prediction_list)); | 45 base::Bind(&GetPredictionListAndEnd, &prediction_list)); |
54 base::MessageLoop::current()->Run(); | 46 base::MessageLoop::current()->Run(); |
55 return prediction_list; | 47 return prediction_list; |
56 } | 48 } |
57 | 49 |
58 private: | 50 private: |
59 PredictionServicePtr prediction_; | 51 PredictionServicePtr prediction_; |
60 | 52 |
61 DISALLOW_COPY_AND_ASSIGN(PredictionApptest); | 53 DISALLOW_COPY_AND_ASSIGN(PredictionApptest); |
62 }; | 54 }; |
63 | 55 |
64 TEST_F(PredictionApptest, PredictCat) { | 56 TEST_F(PredictionApptest, CurrentSpellcheck) { |
65 SetSettingsClient(true, true, true); | 57 mojo::Array<mojo::String> prev_words = mojo::Array<mojo::String>::New(0); |
66 mojo::Array<mojo::String> prev_words; | 58 mojo::Array<bool> beginning_of_sentence = mojo::Array<bool>::New(0); |
67 prev_words.push_back("dog"); | 59 std::string prediction = |
68 std::string prediction_cat = GetPredictionListClient(prev_words, "d")[0]; | 60 GetPredictionListClient(prev_words, beginning_of_sentence, "tgis")[0]; |
69 EXPECT_EQ(prediction_cat, "cat"); | 61 EXPECT_EQ(prediction, "this"); |
62 | |
63 mojo::Array<mojo::String> prev_words1 = mojo::Array<mojo::String>::New(0); | |
64 mojo::Array<bool> beginning_of_sentence1 = mojo::Array<bool>::New(0); | |
65 std::string prediction1 = | |
66 GetPredictionListClient(prev_words1, beginning_of_sentence1, "aplle")[0]; | |
67 EXPECT_EQ(prediction1, "Apple"); | |
68 } | |
69 | |
70 TEST_F(PredictionApptest, CurrentSuggest) { | |
71 mojo::Array<mojo::String> prev_words = mojo::Array<mojo::String>::New(0); | |
72 mojo::Array<bool> beginning_of_sentence = mojo::Array<bool>::New(0); | |
73 std::string prediction = | |
74 GetPredictionListClient(prev_words, beginning_of_sentence, "peac")[0]; | |
75 EXPECT_EQ(prediction, "peace"); | |
76 | |
77 mojo::Array<mojo::String> prev_words1 = mojo::Array<mojo::String>::New(0); | |
78 mojo::Array<bool> beginning_of_sentence1 = mojo::Array<bool>::New(0); | |
79 std::string prediction1 = | |
80 GetPredictionListClient(prev_words1, beginning_of_sentence1, "fil")[0]; | |
81 EXPECT_EQ(prediction1, "film"); | |
82 | |
83 mojo::Array<mojo::String> prev_words2 = mojo::Array<mojo::String>::New(0); | |
84 mojo::Array<bool> beginning_of_sentence2 = mojo::Array<bool>::New(0); | |
85 std::string prediction2 = | |
86 GetPredictionListClient(prev_words2, beginning_of_sentence2, "entert")[0]; | |
87 EXPECT_EQ(prediction2, "entertainment"); | |
88 } | |
89 | |
90 TEST_F(PredictionApptest, CurrentSuggestCont) { | |
91 mojo::Array<mojo::String> prev_words = mojo::Array<mojo::String>::New(0); | |
92 mojo::Array<bool> beginning_of_sentence = mojo::Array<bool>::New(0); | |
93 std::string prediction = | |
94 GetPredictionListClient(prev_words, beginning_of_sentence, "a")[0]; | |
95 EXPECT_EQ(prediction, "and"); | |
96 | |
97 mojo::Array<mojo::String> prev_words1 = mojo::Array<mojo::String>::New(0); | |
98 mojo::Array<bool> beginning_of_sentence1 = mojo::Array<bool>::New(0); | |
99 std::string prediction1 = | |
100 GetPredictionListClient(prev_words1, beginning_of_sentence1, "ab")[0]; | |
101 EXPECT_EQ(prediction1, "an"); | |
102 } | |
103 | |
104 TEST_F(PredictionApptest, CurrentSuggestUp) { | |
105 mojo::Array<mojo::String> prev_words = mojo::Array<mojo::String>::New(0); | |
106 mojo::Array<bool> beginning_of_sentence = mojo::Array<bool>::New(0); | |
107 std::string prediction = | |
108 GetPredictionListClient(prev_words, beginning_of_sentence, "Beau")[0]; | |
109 EXPECT_EQ(prediction, "Beautiful"); | |
110 | |
111 mojo::Array<mojo::String> prev_words1 = mojo::Array<mojo::String>::New(0); | |
112 mojo::Array<bool> beginning_of_sentence1 = mojo::Array<bool>::New(0); | |
113 std::string prediction1 = | |
114 GetPredictionListClient(prev_words1, beginning_of_sentence1, "THis")[0]; | |
115 EXPECT_EQ(prediction1, "This"); | |
116 } | |
117 | |
118 TEST_F(PredictionApptest, CurrentNoSuggest) { | |
119 mojo::Array<mojo::String> prev_words = mojo::Array<mojo::String>::New(0); | |
120 mojo::Array<bool> beginning_of_sentence = mojo::Array<bool>::New(0); | |
121 std::string prediction = GetPredictionListClient( | |
122 prev_words, beginning_of_sentence, | |
123 "hjlahflgfagfdafaffgruhgadfhjklghadflkghjalkdfjkldfhrshrtshtsrhkra")[0]; | |
124 EXPECT_EQ(prediction, "hula JFK"); | |
APW
2015/07/23 20:11:28
Please add a test where the previous word is This
riajiang
2015/07/31 02:13:04
Added. Suggestions are empty tho since there's no
| |
70 } | 125 } |
71 | 126 |
72 } // namespace prediction | 127 } // namespace prediction |
OLD | NEW |