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

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: address comments Created 8 years 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
« no previous file with comments | « chrome/test/chromedriver/net/net_util.h ('k') | chrome/test/chromedriver/net/net_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..c6aebc370818f2ef2baaf2a33e758a48387b883b
--- /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_);
+ 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);
+}
« no previous file with comments | « chrome/test/chromedriver/net/net_util.h ('k') | chrome/test/chromedriver/net/net_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698