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/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. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 return status; | 65 return status; |
66 base::ListValue window_ids; | 66 base::ListValue window_ids; |
67 for (std::list<WebView*>::const_iterator it = web_views.begin(); | 67 for (std::list<WebView*>::const_iterator it = web_views.begin(); |
68 it != web_views.end(); ++it) { | 68 it != web_views.end(); ++it) { |
69 window_ids.AppendString((*it)->GetId()); | 69 window_ids.AppendString((*it)->GetId()); |
70 } | 70 } |
71 value->reset(window_ids.DeepCopy()); | 71 value->reset(window_ids.DeepCopy()); |
72 return Status(kOk); | 72 return Status(kOk); |
73 } | 73 } |
74 | 74 |
75 Status ExecuteSwitchToWindow( | |
76 Session* session, | |
77 const base::DictionaryValue& params, | |
78 scoped_ptr<base::Value>* value) { | |
79 std::string name; | |
80 if (!params.GetString("name", &name) || name.empty()) | |
81 return Status(kUnknownError, "'name' must be a nonempty string"); | |
82 | |
83 std::list<WebView*> web_views; | |
84 Status status = session->chrome->GetWebViews(&web_views); | |
85 if (status.IsError()) | |
86 return status; | |
87 | |
88 // Check if any window handle matches |name|. | |
89 WebView* web_view = NULL; | |
90 for (std::list<WebView*>::const_iterator it = web_views.begin(); | |
91 it != web_views.end(); ++it) { | |
92 if ((*it)->GetId() == name) { | |
93 web_view = *it; | |
94 break; | |
95 } | |
96 } | |
97 if (!web_view) { | |
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) { | |
chrisgao (Use stgao instead)
2013/02/11 22:56:37
Should we check if two windows share the same name
craigdh
2013/02/11 23:40:12
Seems like that would be a common issue. Also what
chrisgao (Use stgao instead)
2013/02/12 01:26:02
Window handles look like: "1", "2", etc. for Linux
| |
111 web_view = *it; | |
112 break; | |
113 } | |
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); | |
chrisgao (Use stgao instead)
2013/02/11 22:56:37
Add chrome/test/chromedriver/basic_types.h
chrisgao (Use stgao instead)
2013/02/12 01:26:02
Done.
| |
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 } |
OLD | NEW |