| OLD | NEW |
| 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 "chrome/test/chromedriver/util.h" | 5 #include "chrome/test/chromedriver/util.h" |
| 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_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/test/chromedriver/key_converter.h" | 22 #include "chrome/test/chromedriver/key_converter.h" |
| 23 | 23 |
| 24 std::string GenerateId() { | 24 std::string GenerateId() { |
| 25 uint64 msb = base::RandUint64(); | 25 uint64 msb = base::RandUint64(); |
| 26 uint64 lsb = base::RandUint64(); | 26 uint64 lsb = base::RandUint64(); |
| 27 return base::StringPrintf("%016" PRIx64 "%016" PRIx64, msb, lsb); | 27 return base::StringPrintf("%016" PRIx64 "%016" PRIx64, msb, lsb); |
| 28 } | 28 } |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 Status FlattenStringArray(const base::ListValue* src, string16* dest) { | 32 Status FlattenStringArray(const base::ListValue* src, base::string16* dest) { |
| 33 string16 keys; | 33 base::string16 keys; |
| 34 for (size_t i = 0; i < src->GetSize(); ++i) { | 34 for (size_t i = 0; i < src->GetSize(); ++i) { |
| 35 string16 keys_list_part; | 35 base::string16 keys_list_part; |
| 36 if (!src->GetString(i, &keys_list_part)) | 36 if (!src->GetString(i, &keys_list_part)) |
| 37 return Status(kUnknownError, "keys should be a string"); | 37 return Status(kUnknownError, "keys should be a string"); |
| 38 for (size_t j = 0; j < keys_list_part.size(); ++j) { | 38 for (size_t j = 0; j < keys_list_part.size(); ++j) { |
| 39 if (CBU16_IS_SURROGATE(keys_list_part[j])) { | 39 if (CBU16_IS_SURROGATE(keys_list_part[j])) { |
| 40 return Status(kUnknownError, | 40 return Status(kUnknownError, |
| 41 "ChromeDriver only supports characters in the BMP"); | 41 "ChromeDriver only supports characters in the BMP"); |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 keys.append(keys_list_part); | 44 keys.append(keys_list_part); |
| 45 } | 45 } |
| 46 *dest = keys; | 46 *dest = keys; |
| 47 return Status(kOk); | 47 return Status(kOk); |
| 48 } | 48 } |
| 49 | 49 |
| 50 } // namespace | 50 } // namespace |
| 51 | 51 |
| 52 Status SendKeysOnWindow( | 52 Status SendKeysOnWindow( |
| 53 WebView* web_view, | 53 WebView* web_view, |
| 54 const base::ListValue* key_list, | 54 const base::ListValue* key_list, |
| 55 bool release_modifiers, | 55 bool release_modifiers, |
| 56 int* sticky_modifiers) { | 56 int* sticky_modifiers) { |
| 57 string16 keys; | 57 base::string16 keys; |
| 58 Status status = FlattenStringArray(key_list, &keys); | 58 Status status = FlattenStringArray(key_list, &keys); |
| 59 if (status.IsError()) | 59 if (status.IsError()) |
| 60 return status; | 60 return status; |
| 61 std::list<KeyEvent> events; | 61 std::list<KeyEvent> events; |
| 62 int sticky_modifiers_tmp = *sticky_modifiers; | 62 int sticky_modifiers_tmp = *sticky_modifiers; |
| 63 status = ConvertKeysToKeyEvents( | 63 status = ConvertKeysToKeyEvents( |
| 64 keys, release_modifiers, &sticky_modifiers_tmp, &events); | 64 keys, release_modifiers, &sticky_modifiers_tmp, &events); |
| 65 if (status.IsError()) | 65 if (status.IsError()) |
| 66 return status; | 66 return status; |
| 67 status = web_view->DispatchKeyEvents(events); | 67 status = web_view->DispatchKeyEvents(events); |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 if (first_file.empty()) | 394 if (first_file.empty()) |
| 395 return Status(kUnknownError, "contained 0 files"); | 395 return Status(kUnknownError, "contained 0 files"); |
| 396 | 396 |
| 397 base::FilePath second_file = enumerator.Next(); | 397 base::FilePath second_file = enumerator.Next(); |
| 398 if (!second_file.empty()) | 398 if (!second_file.empty()) |
| 399 return Status(kUnknownError, "contained multiple files"); | 399 return Status(kUnknownError, "contained multiple files"); |
| 400 | 400 |
| 401 *file = first_file; | 401 *file = first_file; |
| 402 return Status(kOk); | 402 return Status(kOk); |
| 403 } | 403 } |
| OLD | NEW |