Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: components/translate/core/common/translation_logging_helper_unittest.cc

Issue 2913593002: Implementation of translation event logging. (Closed)
Patch Set: fix Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/translate/core/common/translation_logging_helper.h"
6
7 #include <string>
8
9 #include "base/logging.h"
10 #include "components/metrics/proto/translate_event.pb.h"
11 #include "components/sync/protocol/user_event_specifics.pb.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 using metrics::TranslateEventProto;
15 using sync_pb::Translation;
16
17 void EqualTranslationProto(const Translation& first,
18 const Translation& second) {
19 EXPECT_EQ(first.from_language_code(), second.from_language_code());
20 EXPECT_EQ(first.to_language_code(), second.to_language_code());
21 EXPECT_EQ(first.interaction(), second.interaction());
22 }
23
24 namespace translate {
25
26 // Tests that UserEventSpecifics is correctly built.
27 TEST(TranslationLoggingHelperTest, ConstructUserEventSpecifics) {
28 // The event we have.
29 TranslateEventProto translation_event;
30 translation_event.set_source_language("ja");
31 translation_event.set_target_language("en");
32 translation_event.set_event_type(TranslateEventProto::USER_DECLINE);
33 // Expected user_event.
34 Translation user_translation_event;
35 user_translation_event.set_from_language_code("ja");
36 user_translation_event.set_to_language_code("en");
37 user_translation_event.set_interaction(Translation::DECLINE);
38 // The user event.
39 sync_pb::UserEventSpecifics user_specifics;
40 const int64_t navigation_id = 1000000000000000LL;
41 const bool needs_logging = ConstructTranslateEvent(
42 navigation_id, translation_event, &user_specifics);
43 EXPECT_TRUE(needs_logging);
44 EXPECT_EQ(user_specifics.navigation_id(), navigation_id);
45 EqualTranslationProto(user_translation_event, user_specifics.translation());
46 }
47
48 // Tests that if user change the target language, the event is MANUAL.
49 TEST(TranslationLoggingHelperTest, UserManualEvent) {
50 // The event we have.
51 TranslateEventProto translation_event;
52 translation_event.set_source_language("ja");
53 translation_event.set_target_language("en");
54 translation_event.set_modified_target_language("fr");
55 translation_event.set_event_type(TranslateEventProto::USER_ACCEPT);
56 // Expected user_event.
57 Translation user_translation_event;
58 user_translation_event.set_from_language_code("ja");
59 user_translation_event.set_to_language_code("fr");
60 user_translation_event.set_interaction(Translation::MANUAL);
61 // The user event.
62 sync_pb::UserEventSpecifics user_specifics;
63 const int64_t navigation_id = 100;
64 const bool needs_logging = ConstructTranslateEvent(
65 navigation_id, translation_event, &user_specifics);
66 EXPECT_TRUE(needs_logging);
67 EXPECT_EQ(user_specifics.navigation_id(), navigation_id);
68 EqualTranslationProto(user_translation_event, user_specifics.translation());
69 }
70
71 // Tests that we don't build unnecessary events.
72 TEST(TranslationLoggingHelperTest, DontBuildUnnecessaryEvent) {
73 // The event we have.
74 TranslateEventProto translation_event;
75 translation_event.set_source_language("ja");
76 translation_event.set_target_language("en");
77 // The event we don't care.
78 translation_event.set_event_type(TranslateEventProto::DISABLED_BY_RANKER);
79 // The user event.
80 sync_pb::UserEventSpecifics user_specifics;
81 const bool needs_logging =
82 ConstructTranslateEvent(100, translation_event, &user_specifics);
83 // We don't expect the event to be logged.
84 EXPECT_FALSE(needs_logging);
85 }
86
87 } // namespace translate
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698