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

Unified Diff: chrome/test/live_sync/live_sync_test.cc

Issue 3078031: Simple offline startup integration test. (Closed)
Patch Set: Disable test. Created 10 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/live_sync/live_sync_test.h ('k') | chrome/test/live_sync/offline_sync_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/live_sync/live_sync_test.cc
diff --git a/chrome/test/live_sync/live_sync_test.cc b/chrome/test/live_sync/live_sync_test.cc
index 024f6ef9c6e8f9fdfd64ceb7556ff279ceefccfd..e09573b6101259a45f3b47dde656a20b429ac30d 100644
--- a/chrome/test/live_sync/live_sync_test.cc
+++ b/chrome/test/live_sync/live_sync_test.cc
@@ -7,12 +7,26 @@
#include <vector>
#include "base/command_line.h"
+#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/string_util.h"
+#include "base/task.h"
+#include "base/waitable_event.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/profile_manager.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/net/url_fetcher.h"
+#include "chrome/common/net/url_request_context_getter.h"
+#include "chrome/test/testing_browser_process.h"
+#include "googleurl/src/gurl.h"
+#include "net/base/escape.h"
+#include "net/proxy/proxy_config.h"
+#include "net/proxy/proxy_config_service_fixed.h"
+#include "net/proxy/proxy_service.h"
+#include "net/url_request/url_request_context.h"
+#include "net/url_request/url_request_status.h"
namespace switches {
const std::string kPasswordFileForTest = "password-file-for-test";
@@ -20,6 +34,51 @@ const std::string kSyncUserForTest = "sync-user-for-test";
const std::string kSyncPasswordForTest = "sync-password-for-test";
}
+class ConfigureURLFectcherDelegate : public URLFetcher::Delegate {
+ public:
+ ConfigureURLFectcherDelegate() : success_(false) {}
+
+ virtual void OnURLFetchComplete(const URLFetcher* source,
+ const GURL& url,
+ const URLRequestStatus& status,
+ int response_code,
+ const ResponseCookies& cookies,
+ const std::string& data) {
+ if (status.status() == URLRequestStatus::SUCCESS && response_code == 200)
+ success_ = true;
+ MessageLoop::current()->Quit();
+ }
+
+ bool success() const { return success_; }
+
+ private:
+ bool success_;
+};
+
+class SetProxyConfigTask : public Task {
+ public:
+ SetProxyConfigTask(base::WaitableEvent* done,
+ URLRequestContextGetter* url_request_context_getter,
+ const net::ProxyConfig& proxy_config)
+ : done_(done),
+ url_request_context_getter_(url_request_context_getter),
+ proxy_config_(proxy_config) {
+ }
+
+ void Run() {
+ net::ProxyService* proxy_service =
+ url_request_context_getter_->GetURLRequestContext()->proxy_service();
+ proxy_service->ResetConfigService(
+ new net::ProxyConfigServiceFixed(proxy_config_));
+ done_->Signal();
+ }
+
+ private:
+ base::WaitableEvent* done_;
+ URLRequestContextGetter* url_request_context_getter_;
+ net::ProxyConfig proxy_config_;
+};
+
void LiveSyncTest::SetUp() {
// At this point, the browser hasn't been launched, and no services are
// available. But we can verify our command line parameters and fail
@@ -198,3 +257,53 @@ void LiveSyncTest::TearDownLocalTestServer() {
bool success = server_.Stop();
ASSERT_TRUE(success);
}
+
+
+void LiveSyncTest::EnableNetwork(Profile* profile) {
+ SetProxyConfig(profile->GetRequestContext(),
+ net::ProxyConfig::CreateDirect());
+}
+
+void LiveSyncTest::DisableNetwork(Profile* profile) {
+ // Set the current proxy configuration to a nonexistent proxy to
+ // effectively disable networking.
+ net::ProxyConfig config;
+ config.proxy_rules().ParseFromString("http=127.0.0.1:0");
+ SetProxyConfig(profile->GetRequestContext(), config);
+}
+
+bool LiveSyncTest::EnsureSyncServerConfiguration() {
+ const CommandLine* cl = CommandLine::ForCurrentProcess();
+ if (!cl->HasSwitch(switches::kSyncServiceURL))
+ return true;
+
+ return ConfigureSyncServer("user_email", username_);
+}
+
+void LiveSyncTest::SetProxyConfig(URLRequestContextGetter* context_getter,
+ const net::ProxyConfig& proxy_config) {
+ base::WaitableEvent done(false, false);
+ ChromeThread::PostTask(
+ ChromeThread::IO,
+ FROM_HERE,
+ new SetProxyConfigTask(&done,
+ context_getter,
+ proxy_config));
+ done.Wait();
+}
+
+bool LiveSyncTest::ConfigureSyncServer(const std::string& name,
+ const std::string& value) {
+ std::string url = StringPrintf("http://%s:%d/chromiumsync/configure",
+ server_.kHostName,
+ server_.kOKHTTPSPort);
+ std::string data = EscapePath(name) + "=" + EscapePath(value);
+ ConfigureURLFectcherDelegate delegate;
+ scoped_ptr<URLFetcher> fetcher(
+ URLFetcher::Create(0, GURL(url), URLFetcher::POST, &delegate));
+ fetcher->set_request_context(Profile::GetDefaultRequestContext());
+ fetcher->set_upload_data("application/x-www-form-urlencoded", data);
+ fetcher->Start();
+ MessageLoop::current()->Run();
+ return delegate.success();
+}
« no previous file with comments | « chrome/test/live_sync/live_sync_test.h ('k') | chrome/test/live_sync/offline_sync_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698