Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/session_command.h" | 5 #include "chrome/test/chromedriver/session_command.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/logging.h" | |
|
craigdh
2013/02/06 00:55:59
Not needed, I'll remove it in the next upload.
| |
| 8 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 9 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "chrome/test/chromedriver/chrome.h" | 12 #include "chrome/test/chromedriver/chrome.h" |
| 12 #include "chrome/test/chromedriver/session.h" | 13 #include "chrome/test/chromedriver/session.h" |
| 13 #include "chrome/test/chromedriver/session_map.h" | 14 #include "chrome/test/chromedriver/session_map.h" |
| 14 #include "chrome/test/chromedriver/status.h" | 15 #include "chrome/test/chromedriver/status.h" |
| 15 | 16 |
| 16 namespace { | |
| 17 | |
| 18 Status WaitForPendingNavigations(const Session& session) { | |
| 19 if (!session.chrome) | |
| 20 return Status(kOk); | |
| 21 std::string frame = session.frame; | |
| 22 if (frame == "") { | |
| 23 Status status = session.chrome->GetMainFrame(&frame); | |
| 24 if (status.IsError()) | |
| 25 return status; | |
| 26 } | |
| 27 return session.chrome->WaitForPendingNavigations(frame); | |
| 28 } | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 32 Status ExecuteSessionCommand( | 17 Status ExecuteSessionCommand( |
| 33 SessionMap* session_map, | 18 SessionMap* session_map, |
| 34 const SessionCommand& command, | 19 const SessionCommand& command, |
| 35 const base::DictionaryValue& params, | 20 const base::DictionaryValue& params, |
| 36 const std::string& session_id, | 21 const std::string& session_id, |
| 37 scoped_ptr<base::Value>* out_value, | 22 scoped_ptr<base::Value>* out_value, |
| 38 std::string* out_session_id) { | 23 std::string* out_session_id) { |
| 39 *out_session_id = session_id; | 24 *out_session_id = session_id; |
| 40 scoped_refptr<SessionAccessor> session_accessor; | 25 scoped_refptr<SessionAccessor> session_accessor; |
| 41 if (!session_map->Get(session_id, &session_accessor)) | 26 if (!session_map->Get(session_id, &session_accessor)) |
| 42 return Status(kNoSuchSession, session_id); | 27 return Status(kNoSuchSession, session_id); |
| 43 scoped_ptr<base::AutoLock> session_lock; | 28 scoped_ptr<base::AutoLock> session_lock; |
| 44 Session* session = session_accessor->Access(&session_lock); | 29 Session* session = session_accessor->Access(&session_lock); |
| 45 if (!session) | 30 if (!session) |
| 46 return Status(kNoSuchSession, session_id); | 31 return Status(kNoSuchSession, session_id); |
| 47 | 32 |
| 48 Status nav_status = WaitForPendingNavigations(*session); | 33 Status nav_status = session->WaitForPendingNavigations(); |
| 49 if (nav_status.IsError()) | 34 if (nav_status.IsError()) |
| 50 return nav_status; | 35 return nav_status; |
| 51 Status status = command.Run(session, params, out_value); | 36 Status status = command.Run(session, params, out_value); |
| 52 nav_status = WaitForPendingNavigations(*session); | 37 // Switch to main frame and retry command if subframe no longer exists. |
| 38 if (status.IsError() && status.code() == kNoSuchFrame) { | |
|
chrisgao (Use stgao instead)
2013/02/06 01:32:14
I think status.IsError() is unnecessary.
craigdh
2013/02/06 18:52:49
Done.
| |
| 39 session->frame = ""; | |
| 40 nav_status = session->WaitForPendingNavigations(); | |
| 41 if (nav_status.IsError()) | |
| 42 return nav_status; | |
| 43 status = command.Run(session, params, out_value); | |
| 44 } | |
| 45 nav_status = session->WaitForPendingNavigations(); | |
| 53 if (status.IsOk() && nav_status.IsError() && | 46 if (status.IsOk() && nav_status.IsError() && |
| 54 nav_status.code() != kDisconnected) | 47 nav_status.code() != kDisconnected) |
| 55 return nav_status; | 48 return nav_status; |
| 56 return status; | 49 return status; |
| 57 } | 50 } |
| OLD | NEW |