| 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/translation_logging_helper.h" | 5 #include "components/translate/core/common/translation_logging_helper.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "components/metrics/proto/translate_event.pb.h" | 10 #include "components/metrics/proto/translate_event.pb.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 user_translation_event.set_from_language_code("ja"); | 35 user_translation_event.set_from_language_code("ja"); |
| 36 user_translation_event.set_to_language_code("en"); | 36 user_translation_event.set_to_language_code("en"); |
| 37 user_translation_event.set_interaction(Translation::DECLINE); | 37 user_translation_event.set_interaction(Translation::DECLINE); |
| 38 // The user event. | 38 // The user event. |
| 39 sync_pb::UserEventSpecifics user_specifics; | 39 sync_pb::UserEventSpecifics user_specifics; |
| 40 const int64_t navigation_id = 1000000000000000LL; | 40 const int64_t navigation_id = 1000000000000000LL; |
| 41 const bool needs_logging = ConstructTranslateEvent( | 41 const bool needs_logging = ConstructTranslateEvent( |
| 42 navigation_id, translation_event, &user_specifics); | 42 navigation_id, translation_event, &user_specifics); |
| 43 EXPECT_TRUE(needs_logging); | 43 EXPECT_TRUE(needs_logging); |
| 44 EXPECT_EQ(user_specifics.navigation_id(), navigation_id); | 44 EXPECT_EQ(user_specifics.navigation_id(), navigation_id); |
| 45 EqualTranslationProto(user_translation_event, user_specifics.translation()); | 45 EqualTranslationProto(user_translation_event, |
| 46 user_specifics.translation_event()); |
| 46 } | 47 } |
| 47 | 48 |
| 48 // Tests that if user change the target language, the event is MANUAL. | 49 // Tests that if user change the target language, the event is MANUAL. |
| 49 TEST(TranslationLoggingHelperTest, UserManualEvent) { | 50 TEST(TranslationLoggingHelperTest, UserManualEvent) { |
| 50 // The event we have. | 51 // The event we have. |
| 51 TranslateEventProto translation_event; | 52 TranslateEventProto translation_event; |
| 52 translation_event.set_source_language("ja"); | 53 translation_event.set_source_language("ja"); |
| 53 translation_event.set_target_language("en"); | 54 translation_event.set_target_language("en"); |
| 54 translation_event.set_modified_target_language("fr"); | 55 translation_event.set_modified_target_language("fr"); |
| 55 translation_event.set_event_type(TranslateEventProto::USER_ACCEPT); | 56 translation_event.set_event_type(TranslateEventProto::USER_ACCEPT); |
| 56 // Expected user_event. | 57 // Expected user_event. |
| 57 Translation user_translation_event; | 58 Translation user_translation_event; |
| 58 user_translation_event.set_from_language_code("ja"); | 59 user_translation_event.set_from_language_code("ja"); |
| 59 user_translation_event.set_to_language_code("fr"); | 60 user_translation_event.set_to_language_code("fr"); |
| 60 user_translation_event.set_interaction(Translation::MANUAL); | 61 user_translation_event.set_interaction(Translation::MANUAL); |
| 61 // The user event. | 62 // The user event. |
| 62 sync_pb::UserEventSpecifics user_specifics; | 63 sync_pb::UserEventSpecifics user_specifics; |
| 63 const int64_t navigation_id = 100; | 64 const int64_t navigation_id = 100; |
| 64 const bool needs_logging = ConstructTranslateEvent( | 65 const bool needs_logging = ConstructTranslateEvent( |
| 65 navigation_id, translation_event, &user_specifics); | 66 navigation_id, translation_event, &user_specifics); |
| 66 EXPECT_TRUE(needs_logging); | 67 EXPECT_TRUE(needs_logging); |
| 67 EXPECT_EQ(user_specifics.navigation_id(), navigation_id); | 68 EXPECT_EQ(user_specifics.navigation_id(), navigation_id); |
| 68 EqualTranslationProto(user_translation_event, user_specifics.translation()); | 69 EqualTranslationProto(user_translation_event, |
| 70 user_specifics.translation_event()); |
| 69 } | 71 } |
| 70 | 72 |
| 71 // Tests that we don't build unnecessary events. | 73 // Tests that we don't build unnecessary events. |
| 72 TEST(TranslationLoggingHelperTest, DontBuildUnnecessaryEvent) { | 74 TEST(TranslationLoggingHelperTest, DontBuildUnnecessaryEvent) { |
| 73 // The event we have. | 75 // The event we have. |
| 74 TranslateEventProto translation_event; | 76 TranslateEventProto translation_event; |
| 75 translation_event.set_source_language("ja"); | 77 translation_event.set_source_language("ja"); |
| 76 translation_event.set_target_language("en"); | 78 translation_event.set_target_language("en"); |
| 77 // The event we don't care. | 79 // The event we don't care. |
| 78 translation_event.set_event_type(TranslateEventProto::DISABLED_BY_RANKER); | 80 translation_event.set_event_type(TranslateEventProto::DISABLED_BY_RANKER); |
| 79 // The user event. | 81 // The user event. |
| 80 sync_pb::UserEventSpecifics user_specifics; | 82 sync_pb::UserEventSpecifics user_specifics; |
| 81 const bool needs_logging = | 83 const bool needs_logging = |
| 82 ConstructTranslateEvent(100, translation_event, &user_specifics); | 84 ConstructTranslateEvent(100, translation_event, &user_specifics); |
| 83 // We don't expect the event to be logged. | 85 // We don't expect the event to be logged. |
| 84 EXPECT_FALSE(needs_logging); | 86 EXPECT_FALSE(needs_logging); |
| 85 } | 87 } |
| 86 | 88 |
| 87 } // namespace translate | 89 } // namespace translate |
| OLD | NEW |