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

Unified Diff: chrome/test/chromedriver/net/net_util.cc

Issue 11415205: [chromedriver] Implement connecting to devtools and loading a page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/chromedriver/net/net_util.cc
diff --git a/chrome/test/chromedriver/net/net_util.cc b/chrome/test/chromedriver/net/net_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0d8152b1a654fa3f7f90b3514979de9df4f67fc5
--- /dev/null
+++ b/chrome/test/chromedriver/net/net_util.cc
@@ -0,0 +1,50 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop.h"
+#include "chrome/test/chromedriver/net/url_request_context_getter.h"
+#include "googleurl/src/gurl.h"
+#include "net/url_request/url_fetcher.h"
+#include "net/url_request/url_fetcher_delegate.h"
+
+namespace {
+
+class SyncUrlFetcher : public net::URLFetcherDelegate {
+ public:
+ SyncUrlFetcher() {}
+ virtual ~SyncUrlFetcher() {}
+
+ bool Fetch(const GURL& url,
+ URLRequestContextGetter* getter,
+ std::string* response) {
+ MessageLoop loop;
+ scoped_ptr<net::URLFetcher> fetcher_(
+ net::URLFetcher::Create(url, net::URLFetcher::GET, this));
+ fetcher_->SetRequestContext(getter);
+ response_ = response;
+ fetcher_->Start();
+ loop.Run();
+ return success_;
+ }
+
+ virtual void OnURLFetchComplete(const net::URLFetcher* source) {
+ success_ = (source->GetResponseCode() == 200);
+ if (success_)
+ success_ &= source->GetResponseAsString(response_);
craigdh 2012/12/04 01:41:27 Why a bit operator here? This is a logical operati
kkania 2013/02/28 21:51:58 Whoops, I don't know what I was thinking.
+ MessageLoop::current()->Quit();
+ }
+
+ private:
+ bool success_;
+ std::string* response_;
+};
+
+} // namespace
+
+bool FetchUrl(const GURL& url,
+ URLRequestContextGetter* getter,
+ std::string* response) {
+ return SyncUrlFetcher().Fetch(url, getter, response);
+}

Powered by Google App Engine
This is Rietveld 408576698