| 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/chrome_impl.h" | 5 #include "chrome/test/chromedriver/chrome_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 ChromeImpl::ChromeImpl(base::ProcessHandle process, | 88 ChromeImpl::ChromeImpl(base::ProcessHandle process, |
| 89 URLRequestContextGetter* context_getter, | 89 URLRequestContextGetter* context_getter, |
| 90 base::ScopedTempDir* user_data_dir, | 90 base::ScopedTempDir* user_data_dir, |
| 91 int port, | 91 int port, |
| 92 const SyncWebSocketFactory& socket_factory) | 92 const SyncWebSocketFactory& socket_factory) |
| 93 : process_(process), | 93 : process_(process), |
| 94 context_getter_(context_getter), | 94 context_getter_(context_getter), |
| 95 port_(port), | 95 port_(port), |
| 96 socket_factory_(socket_factory), | 96 socket_factory_(socket_factory), |
| 97 dom_tracker_(new DomTracker()), | |
| 98 frame_tracker_(new FrameTracker()), | 97 frame_tracker_(new FrameTracker()), |
| 99 navigation_tracker_(new NavigationTracker()) { | 98 navigation_tracker_(new NavigationTracker()) { |
| 100 if (user_data_dir->IsValid()) { | 99 if (user_data_dir->IsValid()) { |
| 101 CHECK(user_data_dir_.Set(user_data_dir->Take())); | 100 CHECK(user_data_dir_.Set(user_data_dir->Take())); |
| 102 } | 101 } |
| 103 } | 102 } |
| 104 | 103 |
| 105 ChromeImpl::~ChromeImpl() { | 104 ChromeImpl::~ChromeImpl() { |
| 106 base::CloseProcessHandle(process_); | 105 base::CloseProcessHandle(process_); |
| 107 } | 106 } |
| 108 | 107 |
| 109 Status ChromeImpl::Init() { | 108 Status ChromeImpl::Init() { |
| 110 base::Time deadline = base::Time::Now() + base::TimeDelta::FromSeconds(20); | 109 base::Time deadline = base::Time::Now() + base::TimeDelta::FromSeconds(20); |
| 111 std::list<std::string> debugger_urls; | 110 std::list<std::string> debugger_urls; |
| 112 while (base::Time::Now() < deadline) { | 111 while (base::Time::Now() < deadline) { |
| 113 FetchPagesInfo(context_getter_, port_, &debugger_urls); | 112 FetchPagesInfo(context_getter_, port_, &debugger_urls); |
| 114 if (debugger_urls.empty()) | 113 if (debugger_urls.empty()) |
| 115 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); | 114 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); |
| 116 else | 115 else |
| 117 break; | 116 break; |
| 118 } | 117 } |
| 119 if (debugger_urls.empty()) | 118 if (debugger_urls.empty()) |
| 120 return Status(kUnknownError, "unable to discover open pages"); | 119 return Status(kUnknownError, "unable to discover open pages"); |
| 121 client_.reset(new DevToolsClientImpl( | 120 client_.reset(new DevToolsClientImpl( |
| 122 socket_factory_, debugger_urls.front())); | 121 socket_factory_, debugger_urls.front())); |
| 122 dom_tracker_.reset(new DomTracker(client_.get())); |
| 123 Status status = dom_tracker_->Init(); |
| 124 if (status.IsError()) |
| 125 return status; |
| 126 status = frame_tracker_->Init(client_.get()); |
| 127 if (status.IsError()) |
| 128 return status; |
| 129 status = navigation_tracker_->Init(client_.get()); |
| 130 if (status.IsError()) |
| 131 return status; |
| 123 client_->AddListener(dom_tracker_.get()); | 132 client_->AddListener(dom_tracker_.get()); |
| 124 client_->AddListener(frame_tracker_.get()); | 133 client_->AddListener(frame_tracker_.get()); |
| 125 client_->AddListener(navigation_tracker_.get()); | 134 client_->AddListener(navigation_tracker_.get()); |
| 126 | 135 return Status(kOk); |
| 127 // Perform necessary configuration of the DevTools client. | |
| 128 // Fetch the root document node so that Inspector will push DOM node | |
| 129 // information to the client. | |
| 130 base::DictionaryValue params; | |
| 131 Status status = client_->SendCommand("DOM.getDocument", params); | |
| 132 if (status.IsError()) | |
| 133 return status; | |
| 134 // Enable page domain notifications to allow tracking navigation state. | |
| 135 status = client_->SendCommand("Page.enable", params); | |
| 136 if (status.IsError()) | |
| 137 return status; | |
| 138 // Enable runtime events to allow tracking execution context creation. | |
| 139 return client_->SendCommand("Runtime.enable", params); | |
| 140 } | 136 } |
| 141 | 137 |
| 142 Status ChromeImpl::Load(const std::string& url) { | 138 Status ChromeImpl::Load(const std::string& url) { |
| 143 base::DictionaryValue params; | 139 base::DictionaryValue params; |
| 144 params.SetString("url", url); | 140 params.SetString("url", url); |
| 145 return client_->SendCommand("Page.navigate", params); | 141 return client_->SendCommand("Page.navigate", params); |
| 146 } | 142 } |
| 147 | 143 |
| 148 Status ChromeImpl::Reload() { | 144 Status ChromeImpl::Reload() { |
| 149 base::DictionaryValue params; | 145 base::DictionaryValue params; |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 } | 391 } |
| 396 if (status.IsError()) | 392 if (status.IsError()) |
| 397 return status; | 393 return status; |
| 398 | 394 |
| 399 if (!cmd_result->GetInteger("nodeId", node_id)) | 395 if (!cmd_result->GetInteger("nodeId", node_id)) |
| 400 return Status(kUnknownError, "DOM.requestNode missing int 'nodeId'"); | 396 return Status(kUnknownError, "DOM.requestNode missing int 'nodeId'"); |
| 401 return Status(kOk); | 397 return Status(kOk); |
| 402 } | 398 } |
| 403 | 399 |
| 404 } // namespace internal | 400 } // namespace internal |
| OLD | NEW |