summaryrefslogtreecommitdiffstats
path: root/chrome/test/webdriver/webdriver_util_unittest.cc
diff options
context:
space:
mode:
authorkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-05 21:53:11 +0000
committerkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-05 21:53:11 +0000
commitd1f1b75f7174b9a90365a0b1e17ce9141942a7ee (patch)
tree76c963815cd1b94a7dc71081a591f1847d2801fb /chrome/test/webdriver/webdriver_util_unittest.cc
parent66495020df687ba383fdb57997ed6349af19ebcc (diff)
downloadchromium_src-d1f1b75f7174b9a90365a0b1e17ce9141942a7ee.zip
chromium_src-d1f1b75f7174b9a90365a0b1e17ce9141942a7ee.tar.gz
chromium_src-d1f1b75f7174b9a90365a0b1e17ce9141942a7ee.tar.bz2
[chromedriver] Add command for uploading a file to a remote ChromeDriver server,
which can be used when performing a file upload using sendKeys. Unfortunately, past and current versions of some WebDriver clients, including java, only upload a zip entry and not an actual zip. This can't be parsed by chromium's zip utilities or minizip. The WebDriver clients should be changed to send an actual zip file. In the meantime, we append a central directory on to the zip entry and then unzip it. BUG=chromedriver:18 TEST=none Review URL: http://codereview.chromium.org/9515005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125004 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/webdriver/webdriver_util_unittest.cc')
-rw-r--r--chrome/test/webdriver/webdriver_util_unittest.cc31
1 files changed, 29 insertions, 2 deletions
diff --git a/chrome/test/webdriver/webdriver_util_unittest.cc b/chrome/test/webdriver/webdriver_util_unittest.cc
index c80a3d7..7c82483 100644
--- a/chrome/test/webdriver/webdriver_util_unittest.cc
+++ b/chrome/test/webdriver/webdriver_util_unittest.cc
@@ -1,17 +1,23 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <set>
#include <string>
+#include "base/base64.h"
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/scoped_temp_dir.h"
#include "chrome/test/webdriver/webdriver_util.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace webdriver {
+
TEST(RandomIDTest, CanGenerateSufficientlyRandomIDs) {
std::set<std::string> generated_ids;
for (int i = 0; i < 10000; ++i) {
- std::string id = webdriver::GenerateRandomID();
+ std::string id = GenerateRandomID();
ASSERT_EQ(32u, id.length());
ASSERT_TRUE(generated_ids.end() == generated_ids.find(id))
<< "Generated duplicate ID: " << id
@@ -19,3 +25,24 @@ TEST(RandomIDTest, CanGenerateSufficientlyRandomIDs) {
generated_ids.insert(id);
}
}
+
+TEST(ZipFileTest, ZipEntryToZipArchive) {
+ ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ std::string data;
+ // A zip entry sent from a Java WebDriver client (v2.20) that contains a
+ // file with the contents "COW\n".
+ const char* kBase64ZipEntry =
+ "UEsDBBQACAAIAJpyXEAAAAAAAAAAAAAAAAAEAAAAdGVzdHP2D+"
+ "cCAFBLBwi/wAzGBgAAAAQAAAA=";
+ ASSERT_TRUE(base::Base64Decode(kBase64ZipEntry, &data));
+ FilePath file;
+ std::string error_msg;
+ ASSERT_TRUE(UnzipSoleFile(temp_dir.path(), data, &file, &error_msg))
+ << error_msg;
+ std::string contents;
+ ASSERT_TRUE(file_util::ReadFileToString(file, &contents));
+ ASSERT_STREQ("COW\n", contents.c_str());
+}
+
+} // namespace webdriver