diff options
-rw-r--r-- | chrome/chrome_tests.gypi | 83 | ||||
-rw-r--r-- | chrome/test/webdriver/session_manager.cc | 27 | ||||
-rw-r--r-- | chrome/test/webdriver/session_manager.h | 3 | ||||
-rw-r--r-- | chrome/test/webdriver/utility_functions.cc | 11 | ||||
-rw-r--r-- | chrome/test/webdriver/utility_functions.h | 4 | ||||
-rw-r--r-- | chrome/test/webdriver/utility_functions_unittest.cc | 21 |
6 files changed, 104 insertions, 45 deletions
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 7d2f37c..7b8b036 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -696,8 +696,8 @@ # be found at: http://seleniumhq.org/docs/09_webdriver.html. # The documention of the protocol implemented is at: # http://code.google.com/p/selenium/wiki/JsonWireProtocol - 'target_name': 'chromedriver', - 'type': 'executable', + 'target_name': 'chromedriver_lib', + 'type': '<(library)', 'dependencies': [ 'browser', 'chrome', @@ -710,7 +710,6 @@ '../build/temp_gyp/googleurl.gyp:googleurl', '../net/net.gyp:net', '../skia/skia.gyp:skia', - '../testing/gmock.gyp:gmock', '../testing/gtest.gyp:gtest', '../third_party/icu/icu.gyp:icui18n', '../third_party/icu/icu.gyp:icuuc', @@ -730,7 +729,6 @@ 'test/webdriver/error_codes.h', 'test/webdriver/keymap.h', 'test/webdriver/keymap.cc', - 'test/webdriver/server.cc', 'test/webdriver/session.h', 'test/webdriver/session.cc', 'test/webdriver/session_manager.h', @@ -777,15 +775,34 @@ '../views/views.gyp:views', ], }], - ['OS=="win"', { - 'include_dirs': [ - 'third_party/wtl/include', - ], - 'dependencies': [ - 'test_support_common', - '../google_update/google_update.gyp:google_update', - '../views/views.gyp:views', + ['OS=="linux" or OS=="freebsd"', { + 'conditions': [ + ['linux_use_tcmalloc==1', { + 'dependencies': [ + '../base/allocator/allocator.gyp:allocator', + ], + }], ], + }], + ], + }, + { + 'target_name': 'chromedriver', + 'type': 'executable', + 'msvs_guid': '3F9C9B6D-BBB6-480F-B038-23BF35A432DC', + 'dependencies': [ + 'chromedriver_lib', + '../skia/skia.gyp:skia', + '../testing/gtest.gyp:gtest', + ], + 'include_dirs': [ + '..', + ], + 'sources': [ + 'test/webdriver/server.cc', + ], + 'conditions': [ + ['OS=="win"', { 'conditions': [ ['win_use_allocator_shim==1', { 'dependencies': [ @@ -808,15 +825,49 @@ }, }, }, - },], - ['OS=="linux" or OS=="freebsd"', { + }], + ] + }, + { + 'target_name': 'chromedriver_unittests', + 'type': 'executable', + 'msvs_guid': 'E24B445D-96E3-4272-BB54-AACBC6D3FE7E', + 'dependencies': [ + 'chromedriver_lib', + '../base/base.gyp:test_support_base', + '../testing/gtest.gyp:gtest', + ], + 'include_dirs': [ + '..', + ], + 'sources': [ + '../base/test/run_all_unittests.cc', + 'test/webdriver/utility_functions_unittest.cc', + ], + 'conditions': [ + ['OS=="win"', { 'conditions': [ - ['linux_use_tcmalloc==1', { + ['win_use_allocator_shim==1', { 'dependencies': [ - '../base/allocator/allocator.gyp:allocator', + '<(allocator_target)', ], }], ], + 'link_settings': { + 'libraries': [ + '-lOleAcc.lib', + '-lws2_32.lib', + ], + }, + 'configurations': { + 'Debug': { + 'msvs_settings': { + 'VCLinkerTool': { + 'LinkIncremental': '<(msvs_large_module_debug_link_mode)', + }, + }, + }, + }, }], ], }, diff --git a/chrome/test/webdriver/session_manager.cc b/chrome/test/webdriver/session_manager.cc index 30adf9e..ffa85b3 100644 --- a/chrome/test/webdriver/session_manager.cc +++ b/chrome/test/webdriver/session_manager.cc @@ -4,14 +4,10 @@ #include "chrome/test/webdriver/session_manager.h" -#include "base/command_line.h" #include "base/logging.h" -#include "base/process.h" -#include "base/process_util.h" -#include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "base/threading/thread.h" -#include "chrome/common/chrome_constants.h" +#include "chrome/test/webdriver/utility_functions.h" #if defined(OS_POSIX) #include <arpa/inet.h> @@ -108,25 +104,8 @@ bool SessionManager::SetIPAddress(const std::string& p) { #endif } -std::string SessionManager::GenerateSessionID() { - static const char text[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ"\ - "RSTUVWXYZ0123456789"; - session_generation_.Acquire(); - std::string id = ""; - count_++; // For every connection made increment the global count. - for (int i = 0; i < 32; ++i) { -#ifdef OS_POSIX - id += text[random() % (sizeof text - 1)]; -#else - id += text[rand() % (sizeof text - 1)]; -#endif - } - session_generation_.Release(); - return id; -} - Session* SessionManager::Create() { - std::string id = GenerateSessionID(); + std::string id = GenerateRandomID(); { base::AutoLock lock(map_lock_); if (map_.find(id) != map_.end()) { @@ -177,7 +156,7 @@ Session* SessionManager::GetSession(const std::string& id) const { return it->second; } -SessionManager::SessionManager() : addr_(""), port_(""), count_(0) {} +SessionManager::SessionManager() : addr_(""), port_("") {} SessionManager::~SessionManager() {} diff --git a/chrome/test/webdriver/session_manager.h b/chrome/test/webdriver/session_manager.h index 959ff84..2f977f2 100644 --- a/chrome/test/webdriver/session_manager.h +++ b/chrome/test/webdriver/session_manager.h @@ -37,19 +37,16 @@ class SessionManager { SessionManager(); ~SessionManager(); friend struct DefaultSingletonTraits<SessionManager>; - std::string GenerateSessionID(); std::string IPLookup(const std::string& nic); std::map<std::string, Session*> map_; mutable base::Lock map_lock_; - base::Lock session_generation_; // Record the address and port for the HTTP 303 See other redirect. // We save the IP and Port of the machine chromedriver is running on since // a HTTP 303, see other, resdirect is sent after a successful creation of // a session, ie: http://172.22.41.105:8080/session/DFSSE453CV588 std::string addr_; std::string port_; - int count_; DISALLOW_COPY_AND_ASSIGN(SessionManager); }; diff --git a/chrome/test/webdriver/utility_functions.cc b/chrome/test/webdriver/utility_functions.cc index 0f55bb4..659be9d 100644 --- a/chrome/test/webdriver/utility_functions.cc +++ b/chrome/test/webdriver/utility_functions.cc @@ -9,9 +9,13 @@ #include <algorithm> #include <sstream> +#include "base/basictypes.h" +#include "base/format_macros.h" #include "base/json/json_reader.h" #include "base/logging.h" +#include "base/rand_util.h" #include "base/scoped_ptr.h" +#include "base/stringprintf.h" #include "base/utf_string_conversions.h" #include "third_party/webdriver/atoms.h" @@ -82,5 +86,10 @@ bool ParseJSONDictionary(const std::string& json, DictionaryValue** dict, return true; } -} // namespace webdriver +std::string GenerateRandomID() { + uint64 msb = base::RandUint64(); + uint64 lsb = base::RandUint64(); + return base::StringPrintf("%016" PRIx64 "%016" PRIx64, msb, lsb); +} +} // namespace webdriver diff --git a/chrome/test/webdriver/utility_functions.h b/chrome/test/webdriver/utility_functions.h index a6eae86..88ec2f6 100644 --- a/chrome/test/webdriver/utility_functions.h +++ b/chrome/test/webdriver/utility_functions.h @@ -28,7 +28,9 @@ void CheckValueType(const Value::ValueType expected, const Value* const actual); bool ParseJSONDictionary(const std::string& json, DictionaryValue** dict, std::string* error); +// Generates a random, 32-character hexidecimal ID. +std::string GenerateRandomID(); + } // namespace webdriver #endif // CHROME_TEST_WEBDRIVER_UTILITY_FUNCTIONS_H_ - diff --git a/chrome/test/webdriver/utility_functions_unittest.cc b/chrome/test/webdriver/utility_functions_unittest.cc new file mode 100644 index 0000000..2563905 --- /dev/null +++ b/chrome/test/webdriver/utility_functions_unittest.cc @@ -0,0 +1,21 @@ +// Copyright (c) 2011 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 "chrome/test/webdriver/utility_functions.h" +#include "testing/gtest/include/gtest/gtest.h" + +TEST(RandomIDTest, CanGenerateSufficientlyRandomIDs) { + std::set<std::string> generated_ids; + for (int i = 0; i < 10000; ++i) { + std::string id = webdriver::GenerateRandomID(); + ASSERT_EQ(32u, id.length()); + ASSERT_TRUE(generated_ids.end() == generated_ids.find(id)) + << "Generated duplicate ID: " << id + << " on iteration " << i; + generated_ids.insert(id); + } +} |