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
3 // found in the LICENSE file.
7 #include "base/base64.h"
8 #include "base/file_util.h"
9 #include "base/files/file_path.h"
10 #include "base/files/scoped_temp_dir.h"
11 #include "chrome/test/chromedriver/chrome/status.h"
12 #include "chrome/test/chromedriver/util.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 TEST(UnzipSoleFile
, Entry
) {
16 base::ScopedTempDir temp_dir
;
17 ASSERT_TRUE(temp_dir
.CreateUniqueTempDir());
19 // A zip entry sent from a Java WebDriver client (v2.20) that contains a
20 // file with the contents "COW\n".
21 const char* kBase64ZipEntry
=
22 "UEsDBBQACAAIAJpyXEAAAAAAAAAAAAAAAAAEAAAAdGVzdHP2D+"
23 "cCAFBLBwi/wAzGBgAAAAQAAAA=";
24 ASSERT_TRUE(base::Base64Decode(kBase64ZipEntry
, &data
));
26 Status status
= UnzipSoleFile(temp_dir
.path(), data
, &file
);
27 ASSERT_EQ(kOk
, status
.code()) << status
.message();
29 ASSERT_TRUE(base::ReadFileToString(file
, &contents
));
30 ASSERT_STREQ("COW\n", contents
.c_str());
33 TEST(UnzipSoleFile
, Archive
) {
34 base::ScopedTempDir temp_dir
;
35 ASSERT_TRUE(temp_dir
.CreateUniqueTempDir());
37 // A zip archive sent from a Python WebDriver client that contains a
38 // file with the contents "COW\n".
39 const char* kBase64ZipArchive
=
40 "UEsDBBQAAAAAAMROi0K/wAzGBAAAAAQAAAADAAAAbW9vQ09XClBLAQIUAxQAAAAAAMROi0K/"
41 "wAzGBAAAAAQAAAADAAAAAAAAAAAAAACggQAAAABtb29QSwUGAAAAAAEAAQAxAAAAJQAAAAA"
43 ASSERT_TRUE(base::Base64Decode(kBase64ZipArchive
, &data
));
45 Status status
= UnzipSoleFile(temp_dir
.path(), data
, &file
);
46 ASSERT_EQ(kOk
, status
.code()) << status
.message();
48 ASSERT_TRUE(base::ReadFileToString(file
, &contents
));
49 ASSERT_STREQ("COW\n", contents
.c_str());