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

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/l10n_util_unittest.cc

Issue 2958353002: [Cleanup] Migrate the StatisticsProvider to use the TaskScheduler (Closed)
Patch Set: rewrap a line Created 3 years, 5 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/ui/webui/chromeos/login/l10n_util.h" 5 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/at_exit.h"
12 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
13 #include "base/macros.h" 12 #include "base/macros.h"
14 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
15 #include "base/memory/singleton.h"
16 #include "base/message_loop/message_loop.h"
17 #include "base/run_loop.h" 14 #include "base/run_loop.h"
18 #include "base/single_thread_task_runner.h" 15 #include "base/test/scoped_task_environment.h"
19 #include "base/values.h" 16 #include "base/values.h"
20 #include "chrome/browser/chromeos/customization/customization_document.h" 17 #include "chrome/browser/chromeos/customization/customization_document.h"
21 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" 18 #include "chrome/browser/chromeos/input_method/input_method_configuration.h"
22 #include "chrome/browser/ui/webui/chromeos/login/l10n_util_test_util.h" 19 #include "chrome/browser/ui/webui/chromeos/login/l10n_util_test_util.h"
23 #include "chromeos/system/statistics_provider.h" 20 #include "chromeos/system/statistics_provider.h"
24 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
25 #include "ui/base/ime/chromeos/component_extension_ime_manager.h" 22 #include "ui/base/ime/chromeos/component_extension_ime_manager.h"
26 23
27 namespace chromeos { 24 namespace chromeos {
28 25
29 namespace { 26 namespace {
30 27
31 class MachineStatisticsInitializer {
32 public:
33 MachineStatisticsInitializer();
34
35 static MachineStatisticsInitializer* GetInstance();
36
37 private:
38 DISALLOW_COPY_AND_ASSIGN(MachineStatisticsInitializer);
39 };
40
41 MachineStatisticsInitializer::MachineStatisticsInitializer() {
42 base::MessageLoop loop;
43 chromeos::system::StatisticsProvider::GetInstance()
44 ->StartLoadingMachineStatistics(loop.task_runner(), false);
45 base::RunLoop().RunUntilIdle();
46 }
47
48 // static
49 MachineStatisticsInitializer* MachineStatisticsInitializer::GetInstance() {
50 return base::Singleton<MachineStatisticsInitializer>::get();
51 }
52
53 void VerifyOnlyUILanguages(const base::ListValue& list) { 28 void VerifyOnlyUILanguages(const base::ListValue& list) {
54 for (size_t i = 0; i < list.GetSize(); ++i) { 29 for (size_t i = 0; i < list.GetSize(); ++i) {
55 const base::DictionaryValue* dict; 30 const base::DictionaryValue* dict;
56 ASSERT_TRUE(list.GetDictionary(i, &dict)); 31 ASSERT_TRUE(list.GetDictionary(i, &dict));
57 std::string code; 32 std::string code;
58 ASSERT_TRUE(dict->GetString("code", &code)); 33 ASSERT_TRUE(dict->GetString("code", &code));
59 EXPECT_NE("is", code) 34 EXPECT_NE("is", code)
60 << "Icelandic is an example language which has input method " 35 << "Icelandic is an example language which has input method "
61 << "but can't use it as UI language."; 36 << "but can't use it as UI language.";
62 } 37 }
(...skipping 10 matching lines...) Expand all
73 << "Wrong language code at index " << index << "."; 48 << "Wrong language code at index " << index << ".";
74 } 49 }
75 50
76 } // namespace 51 } // namespace
77 52
78 class L10nUtilTest : public testing::Test { 53 class L10nUtilTest : public testing::Test {
79 public: 54 public:
80 L10nUtilTest(); 55 L10nUtilTest();
81 ~L10nUtilTest() override; 56 ~L10nUtilTest() override;
82 57
83 // testing::Test:
84 void SetUp() override;
85 void TearDown() override;
86
87 void SetInputMethods1(); 58 void SetInputMethods1();
88 void SetInputMethods2(); 59 void SetInputMethods2();
89 60
90 private: 61 private:
91 base::ShadowingAtExitManager at_exit_manager_; 62 base::test::ScopedTaskEnvironment scoped_task_environment_;
92 63
93 MockInputMethodManagerWithInputMethods* input_manager_; 64 MockInputMethodManagerWithInputMethods* input_manager_;
94 }; 65 };
95 66
96 L10nUtilTest::L10nUtilTest() 67 L10nUtilTest::L10nUtilTest()
97 : input_manager_(new MockInputMethodManagerWithInputMethods) { 68 : input_manager_(new MockInputMethodManagerWithInputMethods) {
69 chromeos::input_method::InitializeForTesting(input_manager_);
70 input_manager_->SetComponentExtensionIMEManager(
71 base::MakeUnique<ComponentExtensionIMEManager>());
72
73 chromeos::system::StatisticsProvider::GetInstance()
74 ->StartLoadingMachineStatistics(false);
75 base::RunLoop().RunUntilIdle();
98 } 76 }
99 77
100 L10nUtilTest::~L10nUtilTest() { 78 L10nUtilTest::~L10nUtilTest() {
101 }
102
103 void L10nUtilTest::SetUp() {
104 chromeos::input_method::InitializeForTesting(input_manager_);
105 input_manager_->SetComponentExtensionIMEManager(
106 base::MakeUnique<ComponentExtensionIMEManager>());
107 MachineStatisticsInitializer::GetInstance(); // Ignore result.
108 }
109
110 void L10nUtilTest::TearDown() {
111 chromeos::input_method::Shutdown(); 79 chromeos::input_method::Shutdown();
112 } 80 }
113 81
114 void L10nUtilTest::SetInputMethods1() { 82 void L10nUtilTest::SetInputMethods1() {
115 input_manager_->AddInputMethod("xkb:us::eng", "us", "en-US"); 83 input_manager_->AddInputMethod("xkb:us::eng", "us", "en-US");
116 input_manager_->AddInputMethod("xkb:fr::fra", "fr", "fr"); 84 input_manager_->AddInputMethod("xkb:fr::fra", "fr", "fr");
117 input_manager_->AddInputMethod("xkb:be::fra", "be", "fr"); 85 input_manager_->AddInputMethod("xkb:be::fra", "be", "fr");
118 input_manager_->AddInputMethod("xkb:is::ice", "is", "is"); 86 input_manager_->AddInputMethod("xkb:is::ice", "is", "is");
119 } 87 }
120 88
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 VerifyOnlyUILanguages(*list); 189 VerifyOnlyUILanguages(*list);
222 190
223 ASSERT_LE(3u, list->GetSize()); 191 ASSERT_LE(3u, list->GetSize());
224 192
225 VerifyLanguageCode(*list, 0, "it"); 193 VerifyLanguageCode(*list, 0, "it");
226 VerifyLanguageCode(*list, 1, "de"); 194 VerifyLanguageCode(*list, 1, "de");
227 VerifyLanguageCode(*list, 2, kMostRelevantLanguagesDivider); 195 VerifyLanguageCode(*list, 2, kMostRelevantLanguagesDivider);
228 } 196 }
229 197
230 } // namespace chromeos 198 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/metrics/chromeos_metrics_provider.cc ('k') | chromeos/system/fake_statistics_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698