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

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

Issue 331943003: [ChromeDriver] Added CommandListener interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 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
OLDNEW
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.h" 5 #include "chrome/test/chromedriver/session.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/threading/thread_local.h" 10 #include "base/threading/thread_local.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 Status Session::GetTargetWindow(WebView** web_view) { 58 Status Session::GetTargetWindow(WebView** web_view) {
59 if (!chrome) 59 if (!chrome)
60 return Status(kNoSuchWindow, "no chrome started in this session"); 60 return Status(kNoSuchWindow, "no chrome started in this session");
61 61
62 Status status = chrome->GetWebViewById(window, web_view); 62 Status status = chrome->GetWebViewById(window, web_view);
63 if (status.IsError()) 63 if (status.IsError())
64 status = Status(kNoSuchWindow, "target window already closed", status); 64 status = Status(kNoSuchWindow, "target window already closed", status);
65 return status; 65 return status;
66 } 66 }
67 67
68 Status Session::OnCommand(const std::string& command_name) {
69 // Notify listeners of the command.
70 for (ScopedVector<CommandListener>::const_iterator it =
71 command_listeners_.begin();
72 it != command_listeners_.end();
73 ++it) {
74 Status status = (*it)->OnCommand(command_name);
75 if (status.IsError())
76 return status;
77 }
78 return Status(kOk);
79 }
80
68 void Session::SwitchToTopFrame() { 81 void Session::SwitchToTopFrame() {
69 frames.clear(); 82 frames.clear();
70 } 83 }
71 84
72 void Session::SwitchToParentFrame() { 85 void Session::SwitchToParentFrame() {
73 if (!frames.empty()) 86 if (!frames.empty())
74 frames.pop_back(); 87 frames.pop_back();
75 } 88 }
76 89
77 void Session::SwitchToSubFrame(const std::string& frame_id, 90 void Session::SwitchToSubFrame(const std::string& frame_id,
78 const std::string& chromedriver_frame_id) { 91 const std::string& chromedriver_frame_id) {
79 std::string parent_frame_id; 92 std::string parent_frame_id;
80 if (!frames.empty()) 93 if (!frames.empty())
81 parent_frame_id = frames.back().frame_id; 94 parent_frame_id = frames.back().frame_id;
82 frames.push_back(FrameInfo(parent_frame_id, frame_id, chromedriver_frame_id)); 95 frames.push_back(FrameInfo(parent_frame_id, frame_id, chromedriver_frame_id));
83 } 96 }
84 97
98 void Session::AddListener(CommandListener* listener) {
99 CHECK(listener);
100 command_listeners_.push_back(listener);
101 }
102
85 std::string Session::GetCurrentFrameId() const { 103 std::string Session::GetCurrentFrameId() const {
86 if (frames.empty()) 104 if (frames.empty())
87 return std::string(); 105 return std::string();
88 return frames.back().frame_id; 106 return frames.back().frame_id;
89 } 107 }
90 108
91 std::vector<WebDriverLog*> Session::GetAllLogs() const { 109 std::vector<WebDriverLog*> Session::GetAllLogs() const {
92 std::vector<WebDriverLog*> logs; 110 std::vector<WebDriverLog*> logs;
93 for (ScopedVector<WebDriverLog>::const_iterator log = devtools_logs.begin(); 111 for (ScopedVector<WebDriverLog>::const_iterator log = devtools_logs.begin();
94 log != devtools_logs.end(); 112 log != devtools_logs.end();
(...skipping 18 matching lines...) Expand all
113 return std::string(); 131 return std::string();
114 } 132 }
115 133
116 Session* GetThreadLocalSession() { 134 Session* GetThreadLocalSession() {
117 return lazy_tls_session.Pointer()->Get(); 135 return lazy_tls_session.Pointer()->Get();
118 } 136 }
119 137
120 void SetThreadLocalSession(scoped_ptr<Session> session) { 138 void SetThreadLocalSession(scoped_ptr<Session> session) {
121 lazy_tls_session.Pointer()->Set(session.release()); 139 lazy_tls_session.Pointer()->Set(session.release());
122 } 140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698