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/window_commands.h" | 5 #include "chrome/test/chromedriver/window_commands.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/test/chromedriver/basic_types.h" | 15 #include "chrome/test/chromedriver/basic_types.h" |
16 #include "chrome/test/chromedriver/chrome/chrome.h" | 16 #include "chrome/test/chromedriver/chrome/chrome.h" |
| 17 #include "chrome/test/chromedriver/chrome/devtools_client.h" |
17 #include "chrome/test/chromedriver/chrome/geoposition.h" | 18 #include "chrome/test/chromedriver/chrome/geoposition.h" |
| 19 #include "chrome/test/chromedriver/chrome/javascript_dialog_manager.h" |
18 #include "chrome/test/chromedriver/chrome/js.h" | 20 #include "chrome/test/chromedriver/chrome/js.h" |
19 #include "chrome/test/chromedriver/chrome/status.h" | 21 #include "chrome/test/chromedriver/chrome/status.h" |
20 #include "chrome/test/chromedriver/chrome/ui_events.h" | 22 #include "chrome/test/chromedriver/chrome/ui_events.h" |
21 #include "chrome/test/chromedriver/chrome/web_view.h" | 23 #include "chrome/test/chromedriver/chrome/web_view.h" |
22 #include "chrome/test/chromedriver/element_util.h" | 24 #include "chrome/test/chromedriver/element_util.h" |
23 #include "chrome/test/chromedriver/session.h" | 25 #include "chrome/test/chromedriver/session.h" |
24 #include "chrome/test/chromedriver/util.h" | 26 #include "chrome/test/chromedriver/util.h" |
25 | 27 |
26 namespace { | 28 namespace { |
27 | 29 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 return Status(kOk); | 121 return Status(kOk); |
120 } | 122 } |
121 | 123 |
122 } // namespace | 124 } // namespace |
123 | 125 |
124 Status ExecuteWindowCommand( | 126 Status ExecuteWindowCommand( |
125 const WindowCommand& command, | 127 const WindowCommand& command, |
126 Session* session, | 128 Session* session, |
127 const base::DictionaryValue& params, | 129 const base::DictionaryValue& params, |
128 scoped_ptr<base::Value>* value) { | 130 scoped_ptr<base::Value>* value) { |
129 bool is_dialog_open; | |
130 Status status = session->chrome->IsJavaScriptDialogOpen(&is_dialog_open); | |
131 if (status.IsError()) | |
132 return status; | |
133 if (is_dialog_open) | |
134 return Status(kUnexpectedAlertOpen); | |
135 | |
136 WebView* web_view = NULL; | 131 WebView* web_view = NULL; |
137 status = session->GetTargetWindow(&web_view); | 132 Status status = session->GetTargetWindow(&web_view); |
138 if (status.IsError()) | 133 if (status.IsError()) |
139 return status; | 134 return status; |
140 | 135 |
141 status = web_view->ConnectIfNecessary(); | 136 status = web_view->ConnectIfNecessary(); |
142 if (status.IsError()) | 137 if (status.IsError()) |
143 return status; | 138 return status; |
144 | 139 |
| 140 status = web_view->GetDevToolsClient()->HandleReceivedEvents(); |
| 141 if (status.IsError()) |
| 142 return status; |
| 143 |
| 144 if (web_view->GetJavaScriptDialogManager()->IsDialogOpen()) |
| 145 return Status(kUnexpectedAlertOpen); |
| 146 |
145 Status nav_status = | 147 Status nav_status = |
146 web_view->WaitForPendingNavigations(session->GetCurrentFrameId()); | 148 web_view->WaitForPendingNavigations(session->GetCurrentFrameId()); |
147 if (nav_status.IsError()) | 149 if (nav_status.IsError()) |
148 return nav_status; | 150 return nav_status; |
149 status = command.Run(session, web_view, params, value); | 151 status = command.Run(session, web_view, params, value); |
150 // Switch to main frame and retry command if subframe no longer exists. | 152 // Switch to main frame and retry command if subframe no longer exists. |
151 if (status.code() == kNoSuchExecutionContext) { | 153 if (status.code() == kNoSuchExecutionContext) { |
152 session->SwitchToTopFrame(); | 154 session->SwitchToTopFrame(); |
153 nav_status = | 155 nav_status = |
154 web_view->WaitForPendingNavigations(session->GetCurrentFrameId()); | 156 web_view->WaitForPendingNavigations(session->GetCurrentFrameId()); |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 // |accuracy| is not part of the WebDriver spec yet, so if it is not given | 748 // |accuracy| is not part of the WebDriver spec yet, so if it is not given |
747 // default to 100 meters accuracy. | 749 // default to 100 meters accuracy. |
748 geoposition.accuracy = 100; | 750 geoposition.accuracy = 100; |
749 } | 751 } |
750 | 752 |
751 Status status = web_view->OverrideGeolocation(geoposition); | 753 Status status = web_view->OverrideGeolocation(geoposition); |
752 if (status.IsOk()) | 754 if (status.IsOk()) |
753 session->overridden_geoposition.reset(new Geoposition(geoposition)); | 755 session->overridden_geoposition.reset(new Geoposition(geoposition)); |
754 return status; | 756 return status; |
755 } | 757 } |
OLD | NEW |