OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "components/translate/core/common/language_detection_logging_helper.h" | 5 #include "components/translate/core/common/language_detection_logging_helper.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "components/sync/protocol/user_event_specifics.pb.h" | 9 #include "components/sync/protocol/user_event_specifics.pb.h" |
10 #include "components/translate/core/common/language_detection_details.h" | 10 #include "components/translate/core/common/language_detection_details.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace translate { | 13 namespace translate { |
14 | 14 |
15 // Tests that sync_pb::UserEventSpecifics is correctly build. | 15 // Tests that sync_pb::UserEventSpecifics is correctly build. |
16 TEST(LanguageDetectionLoggingHelperTest, ConstructUserEventSpecifics) { | 16 TEST(LanguageDetectionLoggingHelperTest, ConstructUserEventSpecifics) { |
17 LanguageDetectionDetails details; | 17 LanguageDetectionDetails details; |
18 details.cld_language = "en"; | 18 details.cld_language = "en"; |
19 details.is_cld_reliable = false; | 19 details.is_cld_reliable = false; |
20 details.adopted_language = "ja"; | 20 details.adopted_language = "ja"; |
21 // Expected language detection. | 21 // Expected language detection. |
22 sync_pb::LanguageDetection lang_detection; | 22 sync_pb::LanguageDetection lang_detection; |
23 auto* const lang = lang_detection.add_detected_languages(); | 23 auto* const lang = lang_detection.add_detected_languages(); |
24 lang->set_language_code(details.cld_language); | 24 lang->set_language_code(details.cld_language); |
25 lang->set_is_reliable(details.is_cld_reliable); | 25 lang->set_is_reliable(details.is_cld_reliable); |
26 lang_detection.set_adopted_language_code(details.adopted_language); | 26 lang_detection.set_adopted_language_code(details.adopted_language); |
27 const std::unique_ptr<sync_pb::UserEventSpecifics> user_event = | 27 const std::unique_ptr<sync_pb::UserEventSpecifics> user_event = |
28 ConstructLanguageDetectionEvent(details); | 28 ConstructLanguageDetectionEvent(100, details); |
skym
2017/06/02 21:22:40
Probably should have a test case that uses a numbe
renjieliu1
2017/06/05 06:39:19
Done.
| |
29 // Expect the navigation id is correctly set. | |
30 EXPECT_EQ(user_event->navigation_id(), 100); | |
29 EXPECT_EQ(user_event->language_detection().SerializeAsString(), | 31 EXPECT_EQ(user_event->language_detection().SerializeAsString(), |
30 lang_detection.SerializeAsString()); | 32 lang_detection.SerializeAsString()); |
31 } | 33 } |
32 | 34 |
33 // Tests that sync_pb::UserEventSpecifics is correctly build. | 35 // Tests that sync_pb::UserEventSpecifics is correctly build. |
34 // If adopted_language is the same as cld_language, we don't set it. | 36 // If adopted_language is the same as cld_language, we don't set it. |
35 TEST(LanguageDetectionLoggingHelperTest, DontSetAdoptedLanguage) { | 37 TEST(LanguageDetectionLoggingHelperTest, DontSetAdoptedLanguage) { |
36 LanguageDetectionDetails details; | 38 LanguageDetectionDetails details; |
37 details.cld_language = "en"; | 39 details.cld_language = "en"; |
38 details.is_cld_reliable = true; | 40 details.is_cld_reliable = true; |
39 details.adopted_language = "en"; | 41 details.adopted_language = "en"; |
40 // Expected language detection. | 42 // Expected language detection. |
41 sync_pb::LanguageDetection lang_detection; | 43 sync_pb::LanguageDetection lang_detection; |
42 auto* const lang = lang_detection.add_detected_languages(); | 44 auto* const lang = lang_detection.add_detected_languages(); |
43 lang->set_language_code(details.cld_language); | 45 lang->set_language_code(details.cld_language); |
44 lang->set_is_reliable(details.is_cld_reliable); | 46 lang->set_is_reliable(details.is_cld_reliable); |
45 const std::unique_ptr<sync_pb::UserEventSpecifics> user_event = | 47 const std::unique_ptr<sync_pb::UserEventSpecifics> user_event = |
46 ConstructLanguageDetectionEvent(details); | 48 ConstructLanguageDetectionEvent(100, details); |
49 // Expect the navigation id is correctly set. | |
50 EXPECT_EQ(user_event->navigation_id(), 100); | |
47 EXPECT_EQ(user_event->language_detection().SerializeAsString(), | 51 EXPECT_EQ(user_event->language_detection().SerializeAsString(), |
48 lang_detection.SerializeAsString()); | 52 lang_detection.SerializeAsString()); |
49 } | 53 } |
50 | 54 |
51 } // namespace translate | 55 } // namespace translate |
OLD | NEW |