Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Side by Side Diff: chrome/test/chromedriver/session_commands.cc

Issue 12224106: [chromedriver] Implement command: switchToWindow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Enhance py testcase for switchToWindow. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/session_commands.h" 5 #include "chrome/test/chromedriver/session_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/logging.h" // For CHECK macros. 10 #include "base/logging.h" // For CHECK macros.
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/synchronization/lock.h" 12 #include "base/synchronization/lock.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/test/chromedriver/basic_types.h"
14 #include "chrome/test/chromedriver/chrome.h" 15 #include "chrome/test/chromedriver/chrome.h"
15 #include "chrome/test/chromedriver/session.h" 16 #include "chrome/test/chromedriver/session.h"
16 #include "chrome/test/chromedriver/session_map.h" 17 #include "chrome/test/chromedriver/session_map.h"
17 #include "chrome/test/chromedriver/status.h" 18 #include "chrome/test/chromedriver/status.h"
18 #include "chrome/test/chromedriver/web_view.h" 19 #include "chrome/test/chromedriver/web_view.h"
19 20
20 Status ExecuteSessionCommand( 21 Status ExecuteSessionCommand(
21 SessionMap* session_map, 22 SessionMap* session_map,
22 const SessionCommand& command, 23 const SessionCommand& command,
23 const base::DictionaryValue& params, 24 const base::DictionaryValue& params,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return status; 66 return status;
66 base::ListValue window_ids; 67 base::ListValue window_ids;
67 for (std::list<WebView*>::const_iterator it = web_views.begin(); 68 for (std::list<WebView*>::const_iterator it = web_views.begin();
68 it != web_views.end(); ++it) { 69 it != web_views.end(); ++it) {
69 window_ids.AppendString((*it)->GetId()); 70 window_ids.AppendString((*it)->GetId());
70 } 71 }
71 value->reset(window_ids.DeepCopy()); 72 value->reset(window_ids.DeepCopy());
72 return Status(kOk); 73 return Status(kOk);
73 } 74 }
74 75
76 Status ExecuteSwitchToWindow(
77 Session* session,
78 const base::DictionaryValue& params,
79 scoped_ptr<base::Value>* value) {
80 std::string name;
81 if (!params.GetString("name", &name) || name.empty())
82 return Status(kUnknownError, "'name' must be a nonempty string");
83
84 std::list<WebView*> web_views;
85 Status status = session->chrome->GetWebViews(&web_views);
86 if (status.IsError())
87 return status;
88
89 WebView* web_view = NULL;
90 // Check if any window handle matches |name|.
91 for (std::list<WebView*>::const_iterator it = web_views.begin();
92 it != web_views.end(); ++it) {
93 if ((*it)->GetId() == name) {
94 web_view = *it;
95 break;
96 }
97 }
98 // Check if any of the tab window names match |name|.
99 const char* kGetWindowNameScript = "function() { return window.name; }";
100 base::ListValue args;
101 for (std::list<WebView*>::const_iterator it = web_views.begin();
102 it != web_views.end(); ++it) {
103 scoped_ptr<base::Value> result;
104 status = (*it)->CallFunction("", kGetWindowNameScript, args, &result);
105 if (status.IsError())
106 return status;
107 std::string window_name;
108 if (!result->GetAsString(&window_name))
109 return Status(kUnknownError, "failed to get window name");
110 if (window_name == name) {
111 if (web_view)
112 return Status(kUnknownError, "window name or handle collision:" + name);
kkania 2013/02/12 01:33:04 i'm not sure I'd bother doing this. It's not in th
chrisgao (Use stgao instead) 2013/02/12 20:38:16 Ok. Do the same way as the old cd.
113 web_view = *it;
114 }
115 }
116
117 if (!web_view)
118 return Status(kNoSuchWindow);
119 session->window = web_view->GetId();
120 session->frame = "";
121 session->mouse_position = WebPoint(0, 0);
122 return Status(kOk);
123 }
124
75 Status ExecuteSetTimeout( 125 Status ExecuteSetTimeout(
76 Session* session, 126 Session* session,
77 const base::DictionaryValue& params, 127 const base::DictionaryValue& params,
78 scoped_ptr<base::Value>* value) { 128 scoped_ptr<base::Value>* value) {
79 int ms; 129 int ms;
80 if (!params.GetInteger("ms", &ms) || ms < 0) 130 if (!params.GetInteger("ms", &ms) || ms < 0)
81 return Status(kUnknownError, "'ms' must be a non-negative integer"); 131 return Status(kUnknownError, "'ms' must be a non-negative integer");
82 std::string type; 132 std::string type;
83 if (!params.GetString("type", &type)) 133 if (!params.GetString("type", &type))
84 return Status(kUnknownError, "'type' must be a string"); 134 return Status(kUnknownError, "'type' must be a string");
85 if (type == "implicit") 135 if (type == "implicit")
86 session->implicit_wait = ms; 136 session->implicit_wait = ms;
87 else if (type == "script") 137 else if (type == "script")
88 session->script_timeout = ms; 138 session->script_timeout = ms;
89 else if (type == "page load") 139 else if (type == "page load")
90 session->page_load_timeout = ms; 140 session->page_load_timeout = ms;
91 else 141 else
92 return Status(kUnknownError, "unknown type of timeout:" + type); 142 return Status(kUnknownError, "unknown type of timeout:" + type);
93 return Status(kOk); 143 return Status(kOk);
94 } 144 }
OLDNEW
« chrome/test/chromedriver/session_commands.h ('K') | « chrome/test/chromedriver/session_commands.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698