| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/live_sync/live_sync_test.h" | 5 #include "chrome/test/live_sync/live_sync_test.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "base/task.h" | 16 #include "base/task.h" |
| 17 #include "base/test/test_timeouts.h" | 17 #include "base/test/test_timeouts.h" |
| 18 #include "base/threading/platform_thread.h" | 18 #include "base/threading/platform_thread.h" |
| 19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "chrome/browser/password_manager/encryptor.h" | 21 #include "chrome/browser/password_manager/encryptor.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/profiles/profile_manager.h" | 23 #include "chrome/browser/profiles/profile_manager.h" |
| 24 #include "chrome/browser/sync/notifier/p2p_notifier.h" |
| 24 #include "chrome/browser/sync/profile_sync_service_harness.h" | 25 #include "chrome/browser/sync/profile_sync_service_harness.h" |
| 25 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
| 26 #include "chrome/browser/ui/browser_list.h" | 27 #include "chrome/browser/ui/browser_list.h" |
| 27 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
| 28 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/test/base/testing_browser_process.h" | 30 #include "chrome/test/base/testing_browser_process.h" |
| 30 #include "chrome/test/base/ui_test_utils.h" | 31 #include "chrome/test/base/ui_test_utils.h" |
| 31 #include "chrome/test/live_sync/sync_datatype_helper.h" | 32 #include "chrome/test/live_sync/sync_datatype_helper.h" |
| 32 #include "content/browser/browser_thread.h" | 33 #include "content/browser/browser_thread.h" |
| 33 #include "content/browser/tab_contents/tab_contents.h" | 34 #include "content/browser/tab_contents/tab_contents.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 net::URLRequestContextGetter* url_request_context_getter_; | 107 net::URLRequestContextGetter* url_request_context_getter_; |
| 107 net::ProxyConfig proxy_config_; | 108 net::ProxyConfig proxy_config_; |
| 108 }; | 109 }; |
| 109 | 110 |
| 110 LiveSyncTest::LiveSyncTest(TestType test_type) | 111 LiveSyncTest::LiveSyncTest(TestType test_type) |
| 111 : sync_server_(net::TestServer::TYPE_SYNC, FilePath()), | 112 : sync_server_(net::TestServer::TYPE_SYNC, FilePath()), |
| 112 test_type_(test_type), | 113 test_type_(test_type), |
| 113 server_type_(SERVER_TYPE_UNDECIDED), | 114 server_type_(SERVER_TYPE_UNDECIDED), |
| 114 num_clients_(-1), | 115 num_clients_(-1), |
| 115 use_verifier_(true), | 116 use_verifier_(true), |
| 116 test_server_handle_(base::kNullProcessHandle), | 117 test_server_handle_(base::kNullProcessHandle) { |
| 117 enable_notifications_(true) { | |
| 118 InProcessBrowserTest::set_show_window(true); | 118 InProcessBrowserTest::set_show_window(true); |
| 119 sync_datatype_helper::AssociateWithTest(this); | 119 sync_datatype_helper::AssociateWithTest(this); |
| 120 switch (test_type_) { | 120 switch (test_type_) { |
| 121 case SINGLE_CLIENT: { | 121 case SINGLE_CLIENT: { |
| 122 num_clients_ = 1; | 122 num_clients_ = 1; |
| 123 break; | 123 break; |
| 124 } | 124 } |
| 125 case TWO_CLIENT: { | 125 case TWO_CLIENT: { |
| 126 num_clients_ = 2; | 126 num_clients_ = 2; |
| 127 break; | 127 break; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 // Create the required number of sync profiles, browsers and clients. | 280 // Create the required number of sync profiles, browsers and clients. |
| 281 for (int i = 0; i < num_clients_; ++i) { | 281 for (int i = 0; i < num_clients_; ++i) { |
| 282 profiles_.push_back(MakeProfile( | 282 profiles_.push_back(MakeProfile( |
| 283 base::StringPrintf(FILE_PATH_LITERAL("Profile%d"), i))); | 283 base::StringPrintf(FILE_PATH_LITERAL("Profile%d"), i))); |
| 284 EXPECT_FALSE(GetProfile(i) == NULL) << "GetProfile(" << i << ") failed."; | 284 EXPECT_FALSE(GetProfile(i) == NULL) << "GetProfile(" << i << ") failed."; |
| 285 | 285 |
| 286 browsers_.push_back(Browser::Create(GetProfile(i))); | 286 browsers_.push_back(Browser::Create(GetProfile(i))); |
| 287 EXPECT_FALSE(GetBrowser(i) == NULL) << "GetBrowser(" << i << ") failed."; | 287 EXPECT_FALSE(GetBrowser(i) == NULL) << "GetBrowser(" << i << ") failed."; |
| 288 | 288 |
| 289 clients_.push_back( | 289 clients_.push_back( |
| 290 new ProfileSyncServiceHarness(GetProfile(i), username_, password_, | 290 new ProfileSyncServiceHarness(GetProfile(i), username_, password_)); |
| 291 enable_notifications_)); | |
| 292 EXPECT_FALSE(GetClient(i) == NULL) << "GetClient(" << i << ") failed."; | 291 EXPECT_FALSE(GetClient(i) == NULL) << "GetClient(" << i << ") failed."; |
| 293 | 292 |
| 294 ui_test_utils::WaitForBookmarkModelToLoad( | 293 ui_test_utils::WaitForBookmarkModelToLoad( |
| 295 GetProfile(i)->GetBookmarkModel()); | 294 GetProfile(i)->GetBookmarkModel()); |
| 296 } | 295 } |
| 297 | 296 |
| 298 // Create the verifier profile. | 297 // Create the verifier profile. |
| 299 verifier_.reset(MakeProfile(FILE_PATH_LITERAL("Verifier"))); | 298 verifier_.reset(MakeProfile(FILE_PATH_LITERAL("Verifier"))); |
| 300 ui_test_utils::WaitForBookmarkModelToLoad(verifier()->GetBookmarkModel()); | 299 ui_test_utils::WaitForBookmarkModelToLoad(verifier()->GetBookmarkModel()); |
| 301 return (verifier_.get() != NULL); | 300 return (verifier_.get() != NULL); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 | 399 |
| 401 bool LiveSyncTest::SetUpLocalPythonTestServer() { | 400 bool LiveSyncTest::SetUpLocalPythonTestServer() { |
| 402 EXPECT_TRUE(sync_server_.Start()) | 401 EXPECT_TRUE(sync_server_.Start()) |
| 403 << "Could not launch local python test server."; | 402 << "Could not launch local python test server."; |
| 404 | 403 |
| 405 CommandLine* cl = CommandLine::ForCurrentProcess(); | 404 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 406 std::string sync_service_url = sync_server_.GetURL("chromiumsync").spec(); | 405 std::string sync_service_url = sync_server_.GetURL("chromiumsync").spec(); |
| 407 cl->AppendSwitchASCII(switches::kSyncServiceURL, sync_service_url); | 406 cl->AppendSwitchASCII(switches::kSyncServiceURL, sync_service_url); |
| 408 VLOG(1) << "Started local python test server at " << sync_service_url; | 407 VLOG(1) << "Started local python test server at " << sync_service_url; |
| 409 | 408 |
| 410 if (enable_notifications_) { | 409 int xmpp_port = 0; |
| 411 int xmpp_port = 0; | 410 if (!sync_server_.server_data().GetInteger("xmpp_port", &xmpp_port)) { |
| 412 if (!sync_server_.server_data().GetInteger("xmpp_port", &xmpp_port)) { | 411 LOG(ERROR) << "Could not find valid xmpp_port value"; |
| 413 LOG(ERROR) << "Could not find valid xmpp_port value"; | 412 return false; |
| 414 return false; | 413 } |
| 415 } | 414 if ((xmpp_port <= 0) || (xmpp_port > kuint16max)) { |
| 416 if ((xmpp_port <= 0) || (xmpp_port > kuint16max)) { | 415 LOG(ERROR) << "Invalid xmpp port: " << xmpp_port; |
| 417 LOG(ERROR) << "Invalid xmpp port: " << xmpp_port; | 416 return false; |
| 418 return false; | 417 } |
| 419 } | |
| 420 | 418 |
| 421 net::HostPortPair xmpp_host_port_pair(sync_server_.host_port_pair()); | 419 net::HostPortPair xmpp_host_port_pair(sync_server_.host_port_pair()); |
| 422 xmpp_host_port_pair.set_port(xmpp_port); | 420 xmpp_host_port_pair.set_port(xmpp_port); |
| 423 xmpp_port_.reset(new net::ScopedPortException(xmpp_port)); | 421 xmpp_port_.reset(new net::ScopedPortException(xmpp_port)); |
| 424 | 422 |
| 425 if (!cl->HasSwitch(switches::kSyncNotificationHost)) { | 423 if (!cl->HasSwitch(switches::kSyncNotificationHost)) { |
| 426 cl->AppendSwitchASCII(switches::kSyncNotificationHost, | 424 cl->AppendSwitchASCII(switches::kSyncNotificationHost, |
| 427 xmpp_host_port_pair.ToString()); | 425 xmpp_host_port_pair.ToString()); |
| 428 // The local XMPP server only supports insecure connections. | 426 // The local XMPP server only supports insecure connections. |
| 429 cl->AppendSwitch(switches::kSyncAllowInsecureXmppConnection); | 427 cl->AppendSwitch(switches::kSyncAllowInsecureXmppConnection); |
| 430 } | |
| 431 } | 428 } |
| 432 | 429 |
| 433 return true; | 430 return true; |
| 434 } | 431 } |
| 435 | 432 |
| 436 bool LiveSyncTest::SetUpLocalTestServer() { | 433 bool LiveSyncTest::SetUpLocalTestServer() { |
| 437 CommandLine* cl = CommandLine::ForCurrentProcess(); | 434 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 438 CommandLine::StringType server_cmdline_string = cl->GetSwitchValueNative( | 435 CommandLine::StringType server_cmdline_string = cl->GetSwitchValueNative( |
| 439 switches::kSyncServerCommandLine); | 436 switches::kSyncServerCommandLine); |
| 440 CommandLine::StringVector server_cmdline_vector; | 437 CommandLine::StringVector server_cmdline_vector; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 } | 516 } |
| 520 | 517 |
| 521 bool LiveSyncTest::EnableEncryption(int index, syncable::ModelType type) { | 518 bool LiveSyncTest::EnableEncryption(int index, syncable::ModelType type) { |
| 522 return GetClient(index)->EnableEncryptionForType(type); | 519 return GetClient(index)->EnableEncryptionForType(type); |
| 523 } | 520 } |
| 524 | 521 |
| 525 bool LiveSyncTest::IsEncrypted(int index, syncable::ModelType type) { | 522 bool LiveSyncTest::IsEncrypted(int index, syncable::ModelType type) { |
| 526 return GetClient(index)->IsTypeEncrypted(type); | 523 return GetClient(index)->IsTypeEncrypted(type); |
| 527 } | 524 } |
| 528 | 525 |
| 529 void LiveSyncTest::DisableNotifications() { | |
| 530 // TODO(akalin): It would be better to assert that the test server | |
| 531 // hasn't been started yet. That would require adding an | |
| 532 // IsStarted() method to TestServer. | |
| 533 ASSERT_TRUE(profiles_.empty()); | |
| 534 ASSERT_TRUE(clients_.empty()); | |
| 535 enable_notifications_ = false; | |
| 536 } | |
| 537 | |
| 538 bool LiveSyncTest::AwaitQuiescence() { | 526 bool LiveSyncTest::AwaitQuiescence() { |
| 539 return ProfileSyncServiceHarness::AwaitQuiescence(clients()); | 527 return ProfileSyncServiceHarness::AwaitQuiescence(clients()); |
| 540 } | 528 } |
| 541 | 529 |
| 542 bool LiveSyncTest::ServerSupportsErrorTriggering() { | 530 bool LiveSyncTest::ServerSupportsNotificationControl() { |
| 543 EXPECT_TRUE(server_type_ != SERVER_TYPE_UNDECIDED); | 531 EXPECT_NE(SERVER_TYPE_UNDECIDED, server_type_); |
| 544 | 532 |
| 545 // Supported only if we're using the python testserver. | 533 // Supported only if we're using the python testserver. |
| 546 return server_type_ == LOCAL_PYTHON_SERVER; | 534 return server_type_ == LOCAL_PYTHON_SERVER; |
| 535 } |
| 536 |
| 537 void LiveSyncTest::DisableNotifications() { |
| 538 ASSERT_TRUE(ServerSupportsNotificationControl()); |
| 539 std::string path = "chromiumsync/disablenotifications"; |
| 540 ui_test_utils::NavigateToURL(browser(), sync_server_.GetURL(path)); |
| 541 ASSERT_EQ("Notifications disabled", |
| 542 UTF16ToASCII(browser()->GetSelectedTabContents()->GetTitle())); |
| 543 } |
| 544 |
| 545 void LiveSyncTest::TriggerNotification( |
| 546 const syncable::ModelTypeSet& changed_types) { |
| 547 ASSERT_TRUE(ServerSupportsNotificationControl()); |
| 548 const std::string& data = |
| 549 sync_notifier::P2PNotificationData("from_server", |
| 550 sync_notifier::NOTIFY_ALL, |
| 551 changed_types).ToString(); |
| 552 const std::string& path = |
| 553 std::string("chromiumsync/sendnotification?channel=") + |
| 554 sync_notifier::kSyncP2PNotificationChannel + "&data=" + data; |
| 555 ui_test_utils::NavigateToURL(browser(), sync_server_.GetURL(path)); |
| 556 ASSERT_EQ("Notification sent", |
| 557 UTF16ToASCII(browser()->GetSelectedTabContents()->GetTitle())); |
| 558 } |
| 559 |
| 560 bool LiveSyncTest::ServerSupportsErrorTriggering() { |
| 561 EXPECT_NE(SERVER_TYPE_UNDECIDED, server_type_); |
| 562 |
| 563 // Supported only if we're using the python testserver. |
| 564 return server_type_ == LOCAL_PYTHON_SERVER; |
| 547 } | 565 } |
| 548 | 566 |
| 549 void LiveSyncTest::TriggerMigrationDoneError( | 567 void LiveSyncTest::TriggerMigrationDoneError( |
| 550 const syncable::ModelTypeSet& model_types) { | 568 const syncable::ModelTypeSet& model_types) { |
| 551 ASSERT_TRUE(ServerSupportsErrorTriggering()); | 569 ASSERT_TRUE(ServerSupportsErrorTriggering()); |
| 552 std::string path = "chromiumsync/migrate"; | 570 std::string path = "chromiumsync/migrate"; |
| 553 char joiner = '?'; | 571 char joiner = '?'; |
| 554 for (syncable::ModelTypeSet::const_iterator it = model_types.begin(); | 572 for (syncable::ModelTypeSet::const_iterator it = model_types.begin(); |
| 555 it != model_types.end(); ++it) { | 573 it != model_types.end(); ++it) { |
| 556 path.append(base::StringPrintf("%ctype=%d", joiner, | 574 path.append(base::StringPrintf("%ctype=%d", joiner, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 const net::ProxyConfig& proxy_config) { | 608 const net::ProxyConfig& proxy_config) { |
| 591 base::WaitableEvent done(false, false); | 609 base::WaitableEvent done(false, false); |
| 592 BrowserThread::PostTask( | 610 BrowserThread::PostTask( |
| 593 BrowserThread::IO, | 611 BrowserThread::IO, |
| 594 FROM_HERE, | 612 FROM_HERE, |
| 595 new SetProxyConfigTask(&done, | 613 new SetProxyConfigTask(&done, |
| 596 context_getter, | 614 context_getter, |
| 597 proxy_config)); | 615 proxy_config)); |
| 598 done.Wait(); | 616 done.Wait(); |
| 599 } | 617 } |
| OLD | NEW |