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

Side by Side Diff: chrome/browser/chromeos/login/user_image_manager_browsertest.cc

Issue 184563006: Move WriteFile and WriteFileDescriptor from file_util to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <map> 5 #include <map>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 username); 192 username);
193 } 193 }
194 194
195 // Sets bitmap |resource_id| as image for |username| and saves it to disk. 195 // Sets bitmap |resource_id| as image for |username| and saves it to disk.
196 void SaveUserImagePNG(const std::string& username, 196 void SaveUserImagePNG(const std::string& username,
197 int resource_id) { 197 int resource_id) {
198 base::FilePath image_path = GetUserImagePath(username, "png"); 198 base::FilePath image_path = GetUserImagePath(username, "png");
199 scoped_refptr<base::RefCountedStaticMemory> image_data( 199 scoped_refptr<base::RefCountedStaticMemory> image_data(
200 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( 200 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
201 resource_id, ui::SCALE_FACTOR_100P)); 201 resource_id, ui::SCALE_FACTOR_100P));
202 int written = file_util::WriteFile( 202 int written = base::WriteFile(
203 image_path, 203 image_path,
204 reinterpret_cast<const char*>(image_data->front()), 204 reinterpret_cast<const char*>(image_data->front()),
205 image_data->size()); 205 image_data->size());
206 EXPECT_EQ(static_cast<int>(image_data->size()), written); 206 EXPECT_EQ(static_cast<int>(image_data->size()), written);
207 SetOldUserImageInfo(username, User::kExternalImageIndex, image_path); 207 SetOldUserImageInfo(username, User::kExternalImageIndex, image_path);
208 } 208 }
209 209
210 // Returns the image path for user |username| with specified |extension|. 210 // Returns the image path for user |username| with specified |extension|.
211 base::FilePath GetUserImagePath(const std::string& username, 211 base::FilePath GetUserImagePath(const std::string& username,
212 const std::string& extension) { 212 const std::string& extension) {
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 ASSERT_TRUE(PathService::Get(chromeos::DIR_USER_POLICY_KEYS, 592 ASSERT_TRUE(PathService::Get(chromeos::DIR_USER_POLICY_KEYS,
593 &user_keys_dir)); 593 &user_keys_dir));
594 const std::string sanitized_username = 594 const std::string sanitized_username =
595 chromeos::CryptohomeClient::GetStubSanitizedUsername(kTestUser1); 595 chromeos::CryptohomeClient::GetStubSanitizedUsername(kTestUser1);
596 const base::FilePath user_key_file = 596 const base::FilePath user_key_file =
597 user_keys_dir.AppendASCII(sanitized_username) 597 user_keys_dir.AppendASCII(sanitized_username)
598 .AppendASCII("policy.pub"); 598 .AppendASCII("policy.pub");
599 std::vector<uint8> user_key_bits; 599 std::vector<uint8> user_key_bits;
600 ASSERT_TRUE(user_policy_.GetSigningKey()->ExportPublicKey(&user_key_bits)); 600 ASSERT_TRUE(user_policy_.GetSigningKey()->ExportPublicKey(&user_key_bits));
601 ASSERT_TRUE(base::CreateDirectory(user_key_file.DirName())); 601 ASSERT_TRUE(base::CreateDirectory(user_key_file.DirName()));
602 ASSERT_EQ(file_util::WriteFile( 602 ASSERT_EQ(base::WriteFile(
603 user_key_file, 603 user_key_file,
604 reinterpret_cast<const char*>(user_key_bits.data()), 604 reinterpret_cast<const char*>(user_key_bits.data()),
605 user_key_bits.size()), 605 user_key_bits.size()),
606 static_cast<int>(user_key_bits.size())); 606 static_cast<int>(user_key_bits.size()));
607 user_policy_.policy_data().set_username(kTestUser1); 607 user_policy_.policy_data().set_username(kTestUser1);
608 608
609 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 609 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
610 610
611 policy_image_ = test::ImageLoader(test_data_dir_.Append( 611 policy_image_ = test::ImageLoader(test_data_dir_.Append(
612 test::kUserAvatarImage2RelativePath)).Load(); 612 test::kUserAvatarImage2RelativePath)).Load();
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 853
854 saved_image = test::ImageLoader(GetUserImagePath(kTestUser1, "jpg")).Load(); 854 saved_image = test::ImageLoader(GetUserImagePath(kTestUser1, "jpg")).Load();
855 ASSERT_TRUE(saved_image); 855 ASSERT_TRUE(saved_image);
856 856
857 // Check image dimensions. Images can't be compared since JPEG is lossy. 857 // Check image dimensions. Images can't be compared since JPEG is lossy.
858 EXPECT_EQ(policy_image_->width(), saved_image->width()); 858 EXPECT_EQ(policy_image_->width(), saved_image->width());
859 EXPECT_EQ(policy_image_->height(), saved_image->height()); 859 EXPECT_EQ(policy_image_->height(), saved_image->height());
860 } 860 }
861 861
862 } // namespace chromeos 862 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/resource_loader_browsertest.cc ('k') | chrome/browser/chromeos/login/user_image_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698