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/chrome/javascript_dialog_manager.h" | 5 #include "chrome/test/chromedriver/chrome/javascript_dialog_manager.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/test/chromedriver/chrome/devtools_client.h" | 8 #include "chrome/test/chromedriver/chrome/devtools_client.h" |
9 #include "chrome/test/chromedriver/chrome/status.h" | 9 #include "chrome/test/chromedriver/chrome/status.h" |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 Status JavaScriptDialogManager::HandleDialog(bool accept, | 30 Status JavaScriptDialogManager::HandleDialog(bool accept, |
31 const std::string* text) { | 31 const std::string* text) { |
32 if (!IsDialogOpen()) | 32 if (!IsDialogOpen()) |
33 return Status(kNoAlertOpen); | 33 return Status(kNoAlertOpen); |
34 | 34 |
35 base::DictionaryValue params; | 35 base::DictionaryValue params; |
36 params.SetBoolean("accept", accept); | 36 params.SetBoolean("accept", accept); |
37 if (text) | 37 if (text) |
38 params.SetString("promptText", *text); | 38 params.SetString("promptText", *text); |
39 Status status = client_->SendCommand("Page.handleJavaScriptDialog", params); | 39 Status status = client_->SendCommand("Page.handleJavaScriptDialog", params); |
40 if (status.IsError()) | 40 if (status.IsError()) { |
41 return status; | 41 // Retry once to work around |
| 42 // https://bugs.chromium.org/p/chromedriver/issues/detail?id=1500 |
| 43 status = client_->SendCommand("Page.handleJavaScriptDialog", params); |
| 44 if (status.IsError()) |
| 45 return status; |
| 46 } |
42 | 47 |
43 // Remove a dialog from the queue. Need to check the queue is not empty here, | 48 // Remove a dialog from the queue. Need to check the queue is not empty here, |
44 // because it could have been cleared during waiting for the command | 49 // because it could have been cleared during waiting for the command |
45 // response. | 50 // response. |
46 if (unhandled_dialog_queue_.size()) | 51 if (unhandled_dialog_queue_.size()) |
47 unhandled_dialog_queue_.pop_front(); | 52 unhandled_dialog_queue_.pop_front(); |
48 return Status(kOk); | 53 return Status(kOk); |
49 } | 54 } |
50 | 55 |
51 Status JavaScriptDialogManager::OnConnected(DevToolsClient* client) { | 56 Status JavaScriptDialogManager::OnConnected(DevToolsClient* client) { |
(...skipping 11 matching lines...) Expand all Loading... |
63 return Status(kUnknownError, "dialog event missing or invalid 'message'"); | 68 return Status(kUnknownError, "dialog event missing or invalid 'message'"); |
64 | 69 |
65 unhandled_dialog_queue_.push_back(message); | 70 unhandled_dialog_queue_.push_back(message); |
66 } else if (method == "Page.javascriptDialogClosed") { | 71 } else if (method == "Page.javascriptDialogClosed") { |
67 // Inspector only sends this event when all dialogs have been closed. | 72 // Inspector only sends this event when all dialogs have been closed. |
68 // Clear the unhandled queue in case the user closed a dialog manually. | 73 // Clear the unhandled queue in case the user closed a dialog manually. |
69 unhandled_dialog_queue_.clear(); | 74 unhandled_dialog_queue_.clear(); |
70 } | 75 } |
71 return Status(kOk); | 76 return Status(kOk); |
72 } | 77 } |
OLD | NEW |