 Chromium Code Reviews
 Chromium Code Reviews Issue 12226026:
  [ChromeDriver] Select the main frame if a non-existant child frame is targeted.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 12226026:
  [ChromeDriver] Select the main frame if a non-existant child frame is targeted.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" | 
| 9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" | 
| 10 #include "base/values.h" | 10 #include "base/values.h" | 
| 11 #include "chrome/test/chromedriver/chrome.h" | 11 #include "chrome/test/chromedriver/chrome.h" | 
| 12 #include "chrome/test/chromedriver/session.h" | 12 #include "chrome/test/chromedriver/session.h" | 
| 13 #include "chrome/test/chromedriver/session_map.h" | 13 #include "chrome/test/chromedriver/session_map.h" | 
| 14 #include "chrome/test/chromedriver/status.h" | 14 #include "chrome/test/chromedriver/status.h" | 
| 15 | 15 | 
| 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( | 16 Status ExecuteSessionCommand( | 
| 33 SessionMap* session_map, | 17 SessionMap* session_map, | 
| 34 const SessionCommand& command, | 18 const SessionCommand& command, | 
| 35 const base::DictionaryValue& params, | 19 const base::DictionaryValue& params, | 
| 36 const std::string& session_id, | 20 const std::string& session_id, | 
| 37 scoped_ptr<base::Value>* out_value, | 21 scoped_ptr<base::Value>* out_value, | 
| 38 std::string* out_session_id) { | 22 std::string* out_session_id) { | 
| 39 *out_session_id = session_id; | 23 *out_session_id = session_id; | 
| 40 scoped_refptr<SessionAccessor> session_accessor; | 24 scoped_refptr<SessionAccessor> session_accessor; | 
| 41 if (!session_map->Get(session_id, &session_accessor)) | 25 if (!session_map->Get(session_id, &session_accessor)) | 
| 42 return Status(kNoSuchSession, session_id); | 26 return Status(kNoSuchSession, session_id); | 
| 43 scoped_ptr<base::AutoLock> session_lock; | 27 scoped_ptr<base::AutoLock> session_lock; | 
| 44 Session* session = session_accessor->Access(&session_lock); | 28 Session* session = session_accessor->Access(&session_lock); | 
| 45 if (!session) | 29 if (!session) | 
| 46 return Status(kNoSuchSession, session_id); | 30 return Status(kNoSuchSession, session_id); | 
| 47 | 31 | 
| 48 Status nav_status = WaitForPendingNavigations(*session); | 32 Status nav_status = session->WaitForPendingNavigations(); | 
| 49 if (nav_status.IsError()) | 33 if (nav_status.IsError()) | 
| 50 return nav_status; | 34 return nav_status; | 
| 51 Status status = command.Run(session, params, out_value); | 35 Status status = command.Run(session, params, out_value); | 
| 52 nav_status = WaitForPendingNavigations(*session); | 36 // Switch to main frame and retry command if subframe no longer exists. | 
| 37 if (status.code() == kNoSuchFrame) { | |
| 
kkania
2013/02/06 23:45:26
I'm worried this might not be correct for all circ
 
craigdh
2013/02/07 00:05:37
When the inevitable bugs raise their heads assign
 | |
| 38 session->frame = ""; | |
| 39 nav_status = session->WaitForPendingNavigations(); | |
| 40 if (nav_status.IsError()) | |
| 41 return nav_status; | |
| 42 status = command.Run(session, params, out_value); | |
| 43 } | |
| 44 nav_status = session->WaitForPendingNavigations(); | |
| 53 if (status.IsOk() && nav_status.IsError() && | 45 if (status.IsOk() && nav_status.IsError() && | 
| 54 nav_status.code() != kDisconnected) | 46 nav_status.code() != kDisconnected) | 
| 55 return nav_status; | 47 return nav_status; | 
| 56 return status; | 48 return status; | 
| 57 } | 49 } | 
| OLD | NEW |