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

Side by Side Diff: chrome/installer/util/l10n_string_util_unittest.cc

Issue 2791593002: Allow installer::GetLocalizedString to return mode-specific strings. (Closed)
Patch Set: manzagop review comments Created 3 years, 8 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 "chrome/installer/util/l10n_string_util.h"
6
7 #include "base/macros.h"
8 #include "chrome/install_static/install_modes.h"
9 #include "chrome/install_static/test/scoped_install_details.h"
10 #include "chrome/installer/util/installer_util_strings.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace installer {
14
15 // Test that each mode-specific string has a distinct value among the brand's
16 // install modes.
17 TEST(GetLocalizedStringTest, DistinctStrings) {
18 static constexpr int kStringIds[] = {
19 // Generate the list of mode-specific string IDs.
20 #define HANDLE_MODE_STRING(id, ...) id,
21 DO_MODE_STRINGS
22 #undef HANDLE_MODE_STRING
23 };
24 for (int string_id : kStringIds) {
25 SCOPED_TRACE(testing::Message() << "message id: " << string_id);
26 std::set<base::string16> the_strings;
27 for (int mode_index = 0; mode_index < install_static::NUM_INSTALL_MODES;
28 ++mode_index) {
29 SCOPED_TRACE(testing::Message() << "install mode index: " << mode_index);
30 install_static::ScopedInstallDetails install_details(false, mode_index);
31 base::string16 the_string = GetLocalizedString(string_id);
32 ASSERT_FALSE(the_string.empty());
33 EXPECT_TRUE(the_strings.insert(the_string).second)
34 << the_string << " is found in more than one install mode.";
35 }
36 }
37 }
38
39 #if defined(GOOGLE_CHROME_BUILD)
40 // Test that the mode-specific string mappings are correct for Google Chrome
41 // builds.
42 TEST(GetBaseMessageIdForMode, GoogleStringIds) {
43 // The list of string ids that are mapped based on the install mode. This
44 // matches the top-level identifiers in create_string_rc.py's
45 // MODE_SPECIFIC_STRINGS data structure.
46 std::vector<int> input_ids({IDS_APP_SHORTCUTS_SUBDIR_NAME_BASE,
47 IDS_INBOUND_MDNS_RULE_DESCRIPTION_BASE,
48 IDS_INBOUND_MDNS_RULE_NAME_BASE,
49 IDS_PRODUCT_NAME_BASE});
50
51 // A map from an install mode index to its mode-specific string identifiers.
52 std::map<int, std::vector<int>> mode_to_strings;
53 mode_to_strings[install_static::STABLE_INDEX] = std::vector<int>(
54 {IDS_APP_SHORTCUTS_SUBDIR_NAME_BASE,
55 IDS_INBOUND_MDNS_RULE_DESCRIPTION_BASE, IDS_INBOUND_MDNS_RULE_NAME_BASE,
56 IDS_PRODUCT_NAME_BASE});
57 mode_to_strings[install_static::CANARY_INDEX] = std::vector<int>(
58 {IDS_APP_SHORTCUTS_SUBDIR_NAME_CANARY_BASE,
59 IDS_INBOUND_MDNS_RULE_DESCRIPTION_CANARY_BASE,
60 IDS_INBOUND_MDNS_RULE_NAME_CANARY_BASE, IDS_SXS_SHORTCUT_NAME_BASE});
61 ASSERT_EQ(install_static::NUM_INSTALL_MODES, mode_to_strings.size());
62 for (int mode_index = 0; mode_index < install_static::NUM_INSTALL_MODES;
63 ++mode_index) {
64 SCOPED_TRACE(testing::Message() << "install mode index: " << mode_index);
65 ASSERT_EQ(1, mode_to_strings.count(mode_index));
66 const auto& mode_strings = mode_to_strings[mode_index];
67 ASSERT_EQ(mode_strings.size(), input_ids.size());
68
69 install_static::ScopedInstallDetails install_details(false, mode_index);
70 for (size_t i = 0; i < input_ids.size(); ++i)
71 EXPECT_EQ(mode_strings[i], GetBaseMessageIdForMode(input_ids[i]));
72 }
73 }
74 #endif
75
76 } // namespace installer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698