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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/files/file_enumerator.h" | 11 #include "base/files/file_enumerator.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
14 #include "base/format_macros.h" | 14 #include "base/format_macros.h" |
15 #include "base/memory/scoped_vector.h" | |
16 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
17 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
18 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
19 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
20 #include "base/third_party/icu/icu_utf.h" | 19 #include "base/third_party/icu/icu_utf.h" |
21 #include "base/values.h" | 20 #include "base/values.h" |
22 #include "chrome/test/chromedriver/chrome/browser_info.h" | 21 #include "chrome/test/chromedriver/chrome/browser_info.h" |
23 #include "chrome/test/chromedriver/chrome/chrome.h" | 22 #include "chrome/test/chromedriver/chrome/chrome.h" |
24 #include "chrome/test/chromedriver/chrome/status.h" | 23 #include "chrome/test/chromedriver/chrome/status.h" |
25 #include "chrome/test/chromedriver/chrome/ui_events.h" | 24 #include "chrome/test/chromedriver/chrome/ui_events.h" |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 base::FilePath second_file = enumerator.Next(); | 396 base::FilePath second_file = enumerator.Next(); |
398 if (!second_file.empty()) | 397 if (!second_file.empty()) |
399 return Status(kUnknownError, "contained multiple files"); | 398 return Status(kUnknownError, "contained multiple files"); |
400 | 399 |
401 *file = first_file; | 400 *file = first_file; |
402 return Status(kOk); | 401 return Status(kOk); |
403 } | 402 } |
404 | 403 |
405 Status NotifyCommandListenersBeforeCommand(Session* session, | 404 Status NotifyCommandListenersBeforeCommand(Session* session, |
406 const std::string& command_name) { | 405 const std::string& command_name) { |
407 for (ScopedVector<CommandListener>::const_iterator it = | 406 for (const auto& listener : session->command_listeners) { |
408 session->command_listeners.begin(); | 407 Status status = listener->BeforeCommand(command_name); |
409 it != session->command_listeners.end(); | |
410 ++it) { | |
411 Status status = (*it)->BeforeCommand(command_name); | |
412 if (status.IsError()) { | 408 if (status.IsError()) { |
413 // Do not continue if an error is encountered. Mark session for deletion, | 409 // Do not continue if an error is encountered. Mark session for deletion, |
414 // quit Chrome if necessary, and return a detailed error. | 410 // quit Chrome if necessary, and return a detailed error. |
415 if (!session->quit) { | 411 if (!session->quit) { |
416 session->quit = true; | 412 session->quit = true; |
417 std::string message = base::StringPrintf("session deleted because " | 413 std::string message = base::StringPrintf("session deleted because " |
418 "error encountered when notifying listeners of '%s' command", | 414 "error encountered when notifying listeners of '%s' command", |
419 command_name.c_str()); | 415 command_name.c_str()); |
420 if (session->chrome && !session->detach) { | 416 if (session->chrome && !session->detach) { |
421 Status quit_status = session->chrome->Quit(); | 417 Status quit_status = session->chrome->Quit(); |
422 if (quit_status.IsError()) | 418 if (quit_status.IsError()) |
423 message += ", but failed to kill browser:" + quit_status.message(); | 419 message += ", but failed to kill browser:" + quit_status.message(); |
424 } | 420 } |
425 status = Status(kUnknownError, message, status); | 421 status = Status(kUnknownError, message, status); |
426 } | 422 } |
427 if (session->chrome) { | 423 if (session->chrome) { |
428 const BrowserInfo* browser_info = session->chrome->GetBrowserInfo(); | 424 const BrowserInfo* browser_info = session->chrome->GetBrowserInfo(); |
429 status.AddDetails("Session info: " + browser_info->browser_name + "=" + | 425 status.AddDetails("Session info: " + browser_info->browser_name + "=" + |
430 browser_info->browser_version); | 426 browser_info->browser_version); |
431 } | 427 } |
432 return status; | 428 return status; |
433 } | 429 } |
434 } | 430 } |
435 return Status(kOk); | 431 return Status(kOk); |
436 } | 432 } |
OLD | NEW |