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 int64_t navigation_id = 1000000000000000LL; |
27 const std::unique_ptr<sync_pb::UserEventSpecifics> user_event = | 28 const std::unique_ptr<sync_pb::UserEventSpecifics> user_event = |
28 ConstructLanguageDetectionEvent(details); | 29 ConstructLanguageDetectionEvent(navigation_id, details); |
| 30 // Expect the navigation id is correctly set. |
| 31 EXPECT_EQ(user_event->navigation_id(), navigation_id); |
29 EXPECT_EQ(user_event->language_detection().SerializeAsString(), | 32 EXPECT_EQ(user_event->language_detection().SerializeAsString(), |
30 lang_detection.SerializeAsString()); | 33 lang_detection.SerializeAsString()); |
31 } | 34 } |
32 | 35 |
33 // Tests that sync_pb::UserEventSpecifics is correctly build. | 36 // Tests that sync_pb::UserEventSpecifics is correctly build. |
34 // If adopted_language is the same as cld_language, we don't set it. | 37 // If adopted_language is the same as cld_language, we don't set it. |
35 TEST(LanguageDetectionLoggingHelperTest, DontSetAdoptedLanguage) { | 38 TEST(LanguageDetectionLoggingHelperTest, DontSetAdoptedLanguage) { |
36 LanguageDetectionDetails details; | 39 LanguageDetectionDetails details; |
37 details.cld_language = "en"; | 40 details.cld_language = "en"; |
38 details.is_cld_reliable = true; | 41 details.is_cld_reliable = true; |
39 details.adopted_language = "en"; | 42 details.adopted_language = "en"; |
40 // Expected language detection. | 43 // Expected language detection. |
41 sync_pb::LanguageDetection lang_detection; | 44 sync_pb::LanguageDetection lang_detection; |
42 auto* const lang = lang_detection.add_detected_languages(); | 45 auto* const lang = lang_detection.add_detected_languages(); |
43 lang->set_language_code(details.cld_language); | 46 lang->set_language_code(details.cld_language); |
44 lang->set_is_reliable(details.is_cld_reliable); | 47 lang->set_is_reliable(details.is_cld_reliable); |
45 const std::unique_ptr<sync_pb::UserEventSpecifics> user_event = | 48 const std::unique_ptr<sync_pb::UserEventSpecifics> user_event = |
46 ConstructLanguageDetectionEvent(details); | 49 ConstructLanguageDetectionEvent(100, details); |
| 50 // Expect the navigation id is correctly set. |
| 51 EXPECT_EQ(user_event->navigation_id(), 100); |
47 EXPECT_EQ(user_event->language_detection().SerializeAsString(), | 52 EXPECT_EQ(user_event->language_detection().SerializeAsString(), |
48 lang_detection.SerializeAsString()); | 53 lang_detection.SerializeAsString()); |
49 } | 54 } |
50 | 55 |
51 } // namespace translate | 56 } // namespace translate |
OLD | NEW |