OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 class DeviceIDTest : public OobeBaseTest, | 43 class DeviceIDTest : public OobeBaseTest, |
44 public user_manager::RemoveUserDelegate { | 44 public user_manager::RemoveUserDelegate { |
45 public: | 45 public: |
46 void SetUpCommandLine(base::CommandLine* command_line) override { | 46 void SetUpCommandLine(base::CommandLine* command_line) override { |
47 OobeBaseTest::SetUpCommandLine(command_line); | 47 OobeBaseTest::SetUpCommandLine(command_line); |
48 command_line->AppendSwitch(switches::kOobeSkipPostLogin); | 48 command_line->AppendSwitch(switches::kOobeSkipPostLogin); |
49 } | 49 } |
50 | 50 |
51 void SetUpOnMainThread() override { | 51 void SetUpOnMainThread() override { |
| 52 user_removal_loop_.reset(new base::RunLoop); |
52 OobeBaseTest::SetUpOnMainThread(); | 53 OobeBaseTest::SetUpOnMainThread(); |
53 LoadRefreshTokenToDeviceIdMap(); | 54 LoadRefreshTokenToDeviceIdMap(); |
54 } | 55 } |
55 | 56 |
56 void TearDownOnMainThread() override { | 57 void TearDownOnMainThread() override { |
57 SaveRefreshTokenToDeviceIdMap(); | 58 SaveRefreshTokenToDeviceIdMap(); |
58 OobeBaseTest::TearDownOnMainThread(); | 59 OobeBaseTest::TearDownOnMainThread(); |
59 } | 60 } |
60 | 61 |
61 std::string GetDeviceId(const AccountId& account_id) { | 62 std::string GetDeviceId(const AccountId& account_id) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 WaitForSigninScreen(); | 119 WaitForSigninScreen(); |
119 | 120 |
120 JS().ExecuteAsync(base::StringPrintf( | 121 JS().ExecuteAsync(base::StringPrintf( |
121 "chrome.send('authenticateUser', ['%s', '%s', false])", user_id.c_str(), | 122 "chrome.send('authenticateUser', ['%s', '%s', false])", user_id.c_str(), |
122 password.c_str())); | 123 password.c_str())); |
123 WaitForSessionStart(); | 124 WaitForSessionStart(); |
124 } | 125 } |
125 | 126 |
126 void RemoveUser(const AccountId& account_id) { | 127 void RemoveUser(const AccountId& account_id) { |
127 user_manager::UserManager::Get()->RemoveUser(account_id, this); | 128 user_manager::UserManager::Get()->RemoveUser(account_id, this); |
128 user_removal_loop_.Run(); | 129 user_removal_loop_->Run(); |
129 } | 130 } |
130 | 131 |
131 private: | 132 private: |
132 // user_manager::RemoveUserDelegate: | 133 // user_manager::RemoveUserDelegate: |
133 void OnBeforeUserRemoved(const AccountId& account_id) override {} | 134 void OnBeforeUserRemoved(const AccountId& account_id) override {} |
134 | 135 |
135 void OnUserRemoved(const AccountId& account_id) override { | 136 void OnUserRemoved(const AccountId& account_id) override { |
136 user_removal_loop_.Quit(); | 137 user_removal_loop_->Quit(); |
137 } | 138 } |
138 | 139 |
139 base::FilePath GetRefreshTokenToDeviceIdMapFilePath() const { | 140 base::FilePath GetRefreshTokenToDeviceIdMapFilePath() const { |
140 return base::CommandLine::ForCurrentProcess() | 141 return base::CommandLine::ForCurrentProcess() |
141 ->GetSwitchValuePath(::switches::kUserDataDir) | 142 ->GetSwitchValuePath(::switches::kUserDataDir) |
142 .Append(kRefreshTokenToDeviceIdMapFile); | 143 .Append(kRefreshTokenToDeviceIdMapFile); |
143 } | 144 } |
144 | 145 |
145 void LoadRefreshTokenToDeviceIdMap() { | 146 void LoadRefreshTokenToDeviceIdMap() { |
146 std::string file_contents; | 147 std::string file_contents; |
(...skipping 16 matching lines...) Expand all Loading... |
163 void SaveRefreshTokenToDeviceIdMap() { | 164 void SaveRefreshTokenToDeviceIdMap() { |
164 base::DictionaryValue dictionary; | 165 base::DictionaryValue dictionary; |
165 for (const auto& kv : fake_gaia_->refresh_token_to_device_id_map()) | 166 for (const auto& kv : fake_gaia_->refresh_token_to_device_id_map()) |
166 dictionary.SetStringWithoutPathExpansion(kv.first, kv.second); | 167 dictionary.SetStringWithoutPathExpansion(kv.first, kv.second); |
167 std::string json; | 168 std::string json; |
168 EXPECT_TRUE(base::JSONWriter::Write(dictionary, &json)); | 169 EXPECT_TRUE(base::JSONWriter::Write(dictionary, &json)); |
169 EXPECT_TRUE(base::WriteFile(GetRefreshTokenToDeviceIdMapFilePath(), | 170 EXPECT_TRUE(base::WriteFile(GetRefreshTokenToDeviceIdMapFilePath(), |
170 json.c_str(), json.length())); | 171 json.c_str(), json.length())); |
171 } | 172 } |
172 | 173 |
173 base::RunLoop user_removal_loop_; | 174 std::unique_ptr<base::RunLoop> user_removal_loop_; |
174 }; | 175 }; |
175 | 176 |
176 // Add the first user and check that device ID is consistent. | 177 // Add the first user and check that device ID is consistent. |
177 IN_PROC_BROWSER_TEST_F(DeviceIDTest, PRE_PRE_PRE_PRE_PRE_NewUsers) { | 178 IN_PROC_BROWSER_TEST_F(DeviceIDTest, PRE_PRE_PRE_PRE_PRE_NewUsers) { |
178 SignInOnline(kFakeUserEmail, kFakeUserPassword, kRefreshToken1, | 179 SignInOnline(kFakeUserEmail, kFakeUserPassword, kRefreshToken1, |
179 kFakeUserGaiaId); | 180 kFakeUserGaiaId); |
180 CheckDeviceIDIsConsistent(AccountId::FromUserEmail(kFakeUserEmail), | 181 CheckDeviceIDIsConsistent(AccountId::FromUserEmail(kFakeUserEmail), |
181 kRefreshToken1); | 182 kRefreshToken1); |
182 } | 183 } |
183 | 184 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 IN_PROC_BROWSER_TEST_F(DeviceIDTest, LegacyUsers) { | 290 IN_PROC_BROWSER_TEST_F(DeviceIDTest, LegacyUsers) { |
290 EXPECT_TRUE(GetDeviceId(AccountId::FromUserEmail(kFakeUserEmail)).empty()); | 291 EXPECT_TRUE(GetDeviceId(AccountId::FromUserEmail(kFakeUserEmail)).empty()); |
291 SignInOffline(kFakeUserEmail, kFakeUserPassword); | 292 SignInOffline(kFakeUserEmail, kFakeUserPassword); |
292 // Last param |auth_code| is empty, because we don't pass a device ID to GAIA | 293 // Last param |auth_code| is empty, because we don't pass a device ID to GAIA |
293 // in this case. | 294 // in this case. |
294 CheckDeviceIDIsConsistent(AccountId::FromUserEmail(kFakeUserEmail), | 295 CheckDeviceIDIsConsistent(AccountId::FromUserEmail(kFakeUserEmail), |
295 std::string()); | 296 std::string()); |
296 } | 297 } |
297 | 298 |
298 } // namespace chromeos | 299 } // namespace chromeos |
OLD | NEW |