Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / test / chromedriver / util_unittest.cc
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.
4
5 #include <string>
6
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"
14
15 TEST(UnzipSoleFile, Entry) {
16   base::ScopedTempDir temp_dir;
17   ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
18   std::string data;
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));
25   base::FilePath file;
26   Status status = UnzipSoleFile(temp_dir.path(), data, &file);
27   ASSERT_EQ(kOk, status.code()) << status.message();
28   std::string contents;
29   ASSERT_TRUE(base::ReadFileToString(file, &contents));
30   ASSERT_STREQ("COW\n", contents.c_str());
31 }
32
33 TEST(UnzipSoleFile, Archive) {
34   base::ScopedTempDir temp_dir;
35   ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
36   std::string data;
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"
42       "A";
43   ASSERT_TRUE(base::Base64Decode(kBase64ZipArchive, &data));
44   base::FilePath file;
45   Status status = UnzipSoleFile(temp_dir.path(), data, &file);
46   ASSERT_EQ(kOk, status.code()) << status.message();
47   std::string contents;
48   ASSERT_TRUE(base::ReadFileToString(file, &contents));
49   ASSERT_STREQ("COW\n", contents.c_str());
50 }