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

Side by Side Diff: chrome/test/chromedriver/util_unittest.cc

Issue 19579005: Move ReadFileToString to the base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <string> 5 #include <string>
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
11 #include "chrome/test/chromedriver/chrome/status.h" 11 #include "chrome/test/chromedriver/chrome/status.h"
12 #include "chrome/test/chromedriver/util.h" 12 #include "chrome/test/chromedriver/util.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 TEST(UnzipSoleFile, Entry) { 15 TEST(UnzipSoleFile, Entry) {
16 base::ScopedTempDir temp_dir; 16 base::ScopedTempDir temp_dir;
17 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 17 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
18 std::string data; 18 std::string data;
19 // A zip entry sent from a Java WebDriver client (v2.20) that contains a 19 // A zip entry sent from a Java WebDriver client (v2.20) that contains a
20 // file with the contents "COW\n". 20 // file with the contents "COW\n".
21 const char* kBase64ZipEntry = 21 const char* kBase64ZipEntry =
22 "UEsDBBQACAAIAJpyXEAAAAAAAAAAAAAAAAAEAAAAdGVzdHP2D+" 22 "UEsDBBQACAAIAJpyXEAAAAAAAAAAAAAAAAAEAAAAdGVzdHP2D+"
23 "cCAFBLBwi/wAzGBgAAAAQAAAA="; 23 "cCAFBLBwi/wAzGBgAAAAQAAAA=";
24 ASSERT_TRUE(base::Base64Decode(kBase64ZipEntry, &data)); 24 ASSERT_TRUE(base::Base64Decode(kBase64ZipEntry, &data));
25 base::FilePath file; 25 base::FilePath file;
26 Status status = UnzipSoleFile(temp_dir.path(), data, &file); 26 Status status = UnzipSoleFile(temp_dir.path(), data, &file);
27 ASSERT_EQ(kOk, status.code()) << status.message(); 27 ASSERT_EQ(kOk, status.code()) << status.message();
28 std::string contents; 28 std::string contents;
29 ASSERT_TRUE(file_util::ReadFileToString(file, &contents)); 29 ASSERT_TRUE(base::ReadFileToString(file, &contents));
30 ASSERT_STREQ("COW\n", contents.c_str()); 30 ASSERT_STREQ("COW\n", contents.c_str());
31 } 31 }
32 32
33 TEST(UnzipSoleFile, Archive) { 33 TEST(UnzipSoleFile, Archive) {
34 base::ScopedTempDir temp_dir; 34 base::ScopedTempDir temp_dir;
35 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 35 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
36 std::string data; 36 std::string data;
37 // A zip archive sent from a Python WebDriver client that contains a 37 // A zip archive sent from a Python WebDriver client that contains a
38 // file with the contents "COW\n". 38 // file with the contents "COW\n".
39 const char* kBase64ZipArchive = 39 const char* kBase64ZipArchive =
40 "UEsDBBQAAAAAAMROi0K/wAzGBAAAAAQAAAADAAAAbW9vQ09XClBLAQIUAxQAAAAAAMROi0K/" 40 "UEsDBBQAAAAAAMROi0K/wAzGBAAAAAQAAAADAAAAbW9vQ09XClBLAQIUAxQAAAAAAMROi0K/"
41 "wAzGBAAAAAQAAAADAAAAAAAAAAAAAACggQAAAABtb29QSwUGAAAAAAEAAQAxAAAAJQAAAAA" 41 "wAzGBAAAAAQAAAADAAAAAAAAAAAAAACggQAAAABtb29QSwUGAAAAAAEAAQAxAAAAJQAAAAA"
42 "A"; 42 "A";
43 ASSERT_TRUE(base::Base64Decode(kBase64ZipArchive, &data)); 43 ASSERT_TRUE(base::Base64Decode(kBase64ZipArchive, &data));
44 base::FilePath file; 44 base::FilePath file;
45 Status status = UnzipSoleFile(temp_dir.path(), data, &file); 45 Status status = UnzipSoleFile(temp_dir.path(), data, &file);
46 ASSERT_EQ(kOk, status.code()) << status.message(); 46 ASSERT_EQ(kOk, status.code()) << status.message();
47 std::string contents; 47 std::string contents;
48 ASSERT_TRUE(file_util::ReadFileToString(file, &contents)); 48 ASSERT_TRUE(base::ReadFileToString(file, &contents));
49 ASSERT_STREQ("COW\n", contents.c_str()); 49 ASSERT_STREQ("COW\n", contents.c_str());
50 } 50 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/session_commands_unittest.cc ('k') | chrome/test/perf/dom_checker_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698