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

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 typedef testing::Test TranslationLoggingHelperTest;
15
16 using metrics::TranslateEventProto;
17 using sync_pb::Translation;
18
19 void EqualTranslationProto(const Translation& first,
20 const Translation& second) {
21 EXPECT_EQ(first.from_language_code(), second.from_language_code());
22 EXPECT_EQ(first.to_language_code(), second.to_language_code());
23 EXPECT_EQ(first.interaction(), second.interaction());
24 }
25
26 // Tests that UserEventSpecifics is correctly built.
27 TEST_F(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 bool needs_logging =
41 translate::ConstructTranslateEvent(translation_event, &user_specifics);
42 EXPECT_TRUE(needs_logging);
43 EqualTranslationProto(user_translation_event, user_specifics.translation());
44 }
45
46 // Tests that if user change the target language, the event is MANUAL.
47 TEST_F(TranslationLoggingHelperTest, UserManualEvent) {
48 // The event we have.
49 TranslateEventProto translation_event;
50 translation_event.set_source_language("ja");
51 translation_event.set_target_language("en");
52 translation_event.set_modified_target_language("fr");
53 translation_event.set_event_type(TranslateEventProto::USER_ACCEPT);
54 // Expected user_event.
55 Translation user_translation_event;
56 user_translation_event.set_from_language_code("ja");
57 user_translation_event.set_to_language_code("fr");
58 user_translation_event.set_interaction(Translation::MANUAL);
59 // The user event.
60 sync_pb::UserEventSpecifics user_specifics;
61 const bool needs_logging =
62 translate::ConstructTranslateEvent(translation_event, &user_specifics);
63 EXPECT_TRUE(needs_logging);
64 EqualTranslationProto(user_translation_event, user_specifics.translation());
65 }
66
67 // Tests that we don't build unnecessary events.
68 TEST_F(TranslationLoggingHelperTest, DontBuildUnnecessaryEvent) {
69 // The event we have.
70 TranslateEventProto translation_event;
71 translation_event.set_source_language("ja");
72 translation_event.set_target_language("en");
73 // The event we don't care.
74 translation_event.set_event_type(TranslateEventProto::DISABLED_BY_RANKER);
75 // The user event.
76 sync_pb::UserEventSpecifics user_specifics;
77 const bool needs_logging =
78 translate::ConstructTranslateEvent(translation_event, &user_specifics);
79 // We don't expect the event to be logged.
80 EXPECT_FALSE(needs_logging);
81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698