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

Side by Side Diff: chrome/browser/sync/test/integration/sync_test.cc

Issue 7919001: test cases for server directed error handling code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For trybots. Created 9 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/browser/sync/test/integration/sync_test.h" 5 #include "chrome/browser/sync/test/integration/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/notifier/p2p_notifier.h"
25 #include "chrome/browser/sync/profile_sync_service_harness.h" 25 #include "chrome/browser/sync/profile_sync_service_harness.h"
26 #include "chrome/browser/sync/protocol/sync.pb.h"
26 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" 27 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
27 #include "chrome/browser/ui/browser.h" 28 #include "chrome/browser/ui/browser.h"
28 #include "chrome/browser/ui/browser_list.h" 29 #include "chrome/browser/ui/browser_list.h"
29 #include "chrome/common/chrome_paths.h" 30 #include "chrome/common/chrome_paths.h"
30 #include "chrome/common/chrome_switches.h" 31 #include "chrome/common/chrome_switches.h"
31 #include "chrome/test/base/testing_browser_process.h" 32 #include "chrome/test/base/testing_browser_process.h"
32 #include "chrome/test/base/ui_test_utils.h" 33 #include "chrome/test/base/ui_test_utils.h"
33 #include "content/browser/browser_thread.h" 34 #include "content/browser/browser_thread.h"
34 #include "content/browser/tab_contents/tab_contents.h" 35 #include "content/browser/tab_contents/tab_contents.h"
35 #include "content/common/net/url_fetcher.h" 36 #include "content/common/net/url_fetcher.h"
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 } 604 }
604 605
605 void SyncTest::TriggerTransientError() { 606 void SyncTest::TriggerTransientError() {
606 ASSERT_TRUE(ServerSupportsErrorTriggering()); 607 ASSERT_TRUE(ServerSupportsErrorTriggering());
607 std::string path = "chromiumsync/transienterror"; 608 std::string path = "chromiumsync/transienterror";
608 ui_test_utils::NavigateToURL(browser(), sync_server_.GetURL(path)); 609 ui_test_utils::NavigateToURL(browser(), sync_server_.GetURL(path));
609 ASSERT_EQ("Transient error", 610 ASSERT_EQ("Transient error",
610 UTF16ToASCII(browser()->GetSelectedTabContents()->GetTitle())); 611 UTF16ToASCII(browser()->GetSelectedTabContents()->GetTitle()));
611 } 612 }
612 613
614 namespace {
615
616 sync_pb::ClientToServerResponse::ErrorType
617 GetClientToServerResponseErrorType(
618 browser_sync::SyncProtocolErrorType error) {
619 switch (error) {
620 case browser_sync::SYNC_SUCCESS:
621 return sync_pb::ClientToServerResponse::SUCCESS;
622 case browser_sync::NOT_MY_BIRTHDAY:
623 return sync_pb::ClientToServerResponse::NOT_MY_BIRTHDAY;
624 case browser_sync::THROTTLED:
625 return sync_pb::ClientToServerResponse::THROTTLED;
626 case browser_sync::CLEAR_PENDING:
627 return sync_pb::ClientToServerResponse::CLEAR_PENDING;
628 case browser_sync::TRANSIENT_ERROR:
629 return sync_pb::ClientToServerResponse::TRANSIENT_ERROR;
630 case browser_sync::MIGRATION_DONE:
631 return sync_pb::ClientToServerResponse::MIGRATION_DONE;
632 case browser_sync::UNKNOWN_ERROR:
633 return sync_pb::ClientToServerResponse::UNKNOWN;
634 default:
635 NOTREACHED();
636 return sync_pb::ClientToServerResponse::UNKNOWN;
637 }
638 }
639
640 sync_pb::ClientToServerResponse::Error::Action
641 GetClientToServerResponseAction(
642 const browser_sync::ClientAction& action) {
643 switch (action) {
644 case browser_sync::UPGRADE_CLIENT:
645 return sync_pb::ClientToServerResponse::Error::UPGRADE_CLIENT;
646 case browser_sync::CLEAR_USER_DATA_AND_RESYNC:
647 return sync_pb::ClientToServerResponse::Error::CLEAR_USER_DATA_AND_RESYNC;
648 case browser_sync::ENABLE_SYNC_ON_ACCOUNT:
649 return sync_pb::ClientToServerResponse::Error::ENABLE_SYNC_ON_ACCOUNT;
650 case browser_sync::STOP_AND_RESTART_SYNC:
651 return sync_pb::ClientToServerResponse::Error::STOP_AND_RESTART_SYNC;
652 case browser_sync::DISABLE_SYNC_ON_CLIENT:
653 return sync_pb::ClientToServerResponse::Error::DISABLE_SYNC_ON_CLIENT;
654 case browser_sync::UNKNOWN_ACTION:
655 return sync_pb::ClientToServerResponse::Error::UNKNOWN_ACTION;
656 default:
657 NOTREACHED();
658 return sync_pb::ClientToServerResponse::Error::UNKNOWN_ACTION;
659 }
660 }
661
662 } // namespace
663
664 void SyncTest::TriggerSyncError(const browser_sync::SyncProtocolError& error) {
665 ASSERT_TRUE(ServerSupportsErrorTriggering());
666 std::string path = "chromiumsync/error";
667 int error_type =
668 static_cast<int>(GetClientToServerResponseErrorType(
669 error.error_type));
670 int action = static_cast<int>(GetClientToServerResponseAction(
671 error.action));
672
673 path.append(base::StringPrintf("?error=%d", error_type));
674 path.append(base::StringPrintf("&action=%d", action));
675
676 path += "&error_description=" + error.error_description;
677 path += "&url=" + error.url;
678
679 ui_test_utils::NavigateToURL(browser(), sync_server_.GetURL(path));
680 std::string output = UTF16ToASCII(
681 browser()->GetSelectedTabContents()->GetTitle());
682 ASSERT_TRUE(output.find("SetError: 200") != string16::npos);
683 }
684
613 void SyncTest::TriggerSetSyncTabs() { 685 void SyncTest::TriggerSetSyncTabs() {
614 ASSERT_TRUE(ServerSupportsErrorTriggering()); 686 ASSERT_TRUE(ServerSupportsErrorTriggering());
615 std::string path = "chromiumsync/synctabs"; 687 std::string path = "chromiumsync/synctabs";
616 ui_test_utils::NavigateToURL(browser(), sync_server_.GetURL(path)); 688 ui_test_utils::NavigateToURL(browser(), sync_server_.GetURL(path));
617 ASSERT_EQ("Sync Tabs", 689 ASSERT_EQ("Sync Tabs",
618 UTF16ToASCII(browser()->GetSelectedTabContents()->GetTitle())); 690 UTF16ToASCII(browser()->GetSelectedTabContents()->GetTitle()));
619 } 691 }
620 692
621 void SyncTest::SetProxyConfig(net::URLRequestContextGetter* context_getter, 693 void SyncTest::SetProxyConfig(net::URLRequestContextGetter* context_getter,
622 const net::ProxyConfig& proxy_config) { 694 const net::ProxyConfig& proxy_config) {
623 base::WaitableEvent done(false, false); 695 base::WaitableEvent done(false, false);
624 BrowserThread::PostTask( 696 BrowserThread::PostTask(
625 BrowserThread::IO, 697 BrowserThread::IO,
626 FROM_HERE, 698 FROM_HERE,
627 new SetProxyConfigTask(&done, 699 new SetProxyConfigTask(&done,
628 context_getter, 700 context_getter,
629 proxy_config)); 701 proxy_config));
630 done.Wait(); 702 done.Wait();
631 } 703 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698