OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_TEST_LIVE_SYNC_LIVE_SYNC_TEST_H_ | 5 #ifndef CHROME_TEST_LIVE_SYNC_LIVE_SYNC_TEST_H_ |
6 #define CHROME_TEST_LIVE_SYNC_LIVE_SYNC_TEST_H_ | 6 #define CHROME_TEST_LIVE_SYNC_LIVE_SYNC_TEST_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "chrome/common/chrome_paths.h" | 11 #include "chrome/common/chrome_paths.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/test/in_process_browser_test.h" | 13 #include "chrome/test/in_process_browser_test.h" |
14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
15 #include "net/socket/ssl_test_util.h" | |
16 | 15 |
17 class BookmarkModel; | 16 class BookmarkModel; |
18 class BookmarkNode; | 17 class BookmarkNode; |
19 class Profile; | 18 class Profile; |
20 namespace net { | 19 namespace net { |
21 class ScopedDefaultHostResolverProc; | 20 class ScopedDefaultHostResolverProc; |
22 } | 21 } |
23 | 22 |
24 namespace switches { | 23 namespace switches { |
25 extern const wchar_t kSyncUserForTest[]; | 24 extern const wchar_t kSyncUserForTest[]; |
(...skipping 13 matching lines...) Expand all Loading... |
39 // available. But we can verify our command line parameters and fail | 38 // available. But we can verify our command line parameters and fail |
40 // early. | 39 // early. |
41 const CommandLine* cl = CommandLine::ForCurrentProcess(); | 40 const CommandLine* cl = CommandLine::ForCurrentProcess(); |
42 username_ = WideToUTF8(cl->GetSwitchValue(switches::kSyncUserForTest)); | 41 username_ = WideToUTF8(cl->GetSwitchValue(switches::kSyncUserForTest)); |
43 password_ = WideToUTF8(cl->GetSwitchValue(switches::kSyncPasswordForTest)); | 42 password_ = WideToUTF8(cl->GetSwitchValue(switches::kSyncPasswordForTest)); |
44 ASSERT_FALSE(username_.empty()) << "Can't run live server test " | 43 ASSERT_FALSE(username_.empty()) << "Can't run live server test " |
45 << "without specifying --" << switches::kSyncUserForTest; | 44 << "without specifying --" << switches::kSyncUserForTest; |
46 ASSERT_FALSE(password_.empty()) << "Can't run live server test " | 45 ASSERT_FALSE(password_.empty()) << "Can't run live server test " |
47 << "without specifying --" << switches::kSyncPasswordForTest; | 46 << "without specifying --" << switches::kSyncPasswordForTest; |
48 | 47 |
49 // Unless a sync server was explicitly provided, run a test one locally. | |
50 // TODO(ncarter): It might be better to allow the user to specify a choice | |
51 // of sync server "providers" -- a script that could locate (or allocate) | |
52 // a sync server instance, possibly on some remote host. The provider | |
53 // would be invoked before each test. | |
54 if (!cl->HasSwitch(switches::kSyncServiceURL)) | |
55 SetUpLocalTestServer(); | |
56 | |
57 // Yield control back to the InProcessBrowserTest framework. | 48 // Yield control back to the InProcessBrowserTest framework. |
58 InProcessBrowserTest::SetUp(); | 49 InProcessBrowserTest::SetUp(); |
59 } | 50 } |
60 | 51 |
61 virtual void SetUpLocalTestServer() { | |
62 bool success = server_.Start(net::TestServerLauncher::ProtoHTTP, | |
63 server_.kHostName, server_.kOKHTTPSPort, | |
64 FilePath(), FilePath(), std::wstring()); | |
65 ASSERT_TRUE(success); | |
66 | |
67 CommandLine* cl = CommandLine::ForCurrentProcess(); | |
68 cl->AppendSwitchWithValue(switches::kSyncServiceURL, | |
69 StringPrintf("http://%s:%d/chromiumsync", server_.kHostName, | |
70 server_.kOKHTTPSPort)); | |
71 } | |
72 | |
73 // Append command line flag to enable sync. | 52 // Append command line flag to enable sync. |
74 virtual void SetUpCommandLine(CommandLine* command_line) { | 53 virtual void SetUpCommandLine(CommandLine* command_line) { |
75 } | 54 } |
76 | 55 |
77 // Helper to get a handle on a bookmark in |m| when the url is known to be | 56 // Helper to get a handle on a bookmark in |m| when the url is known to be |
78 // unique. | 57 // unique. |
79 static const BookmarkNode* GetByUniqueURL(BookmarkModel* m, const GURL& url); | 58 static const BookmarkNode* GetByUniqueURL(BookmarkModel* m, const GURL& url); |
80 | 59 |
81 // Helper to ProfileManager::CreateProfile that handles path creation. | 60 // Helper to ProfileManager::CreateProfile that handles path creation. |
82 static Profile* MakeProfile(const FilePath::CharType* name); | 61 static Profile* MakeProfile(const FilePath::CharType* name); |
83 | 62 |
84 // Utility to block (by running the current MessageLoop) until the model has | 63 // Utility to block (by running the current MessageLoop) until the model has |
85 // loaded. Note this is required instead of using m->BlockTillLoaded, as that | 64 // loaded. Note this is required instead of using m->BlockTillLoaded, as that |
86 // cannot be called from the main thread (deadlock will occur). | 65 // cannot be called from the main thread (deadlock will occur). |
87 static void BlockUntilLoaded(BookmarkModel* m); | 66 static void BlockUntilLoaded(BookmarkModel* m); |
88 | 67 |
89 protected: | 68 protected: |
90 std::string username_; | 69 std::string username_; |
91 std::string password_; | 70 std::string password_; |
92 | 71 |
93 virtual void SetUpInProcessBrowserTestFixture(); | 72 virtual void SetUpInProcessBrowserTestFixture(); |
94 virtual void TearDownInProcessBrowserTestFixture(); | 73 virtual void TearDownInProcessBrowserTestFixture(); |
95 | 74 |
96 private: | 75 private: |
97 // LiveBookmarksSyncTests need to make live DNS requests for access to | 76 // LiveBookmarksSyncTests need to make live DNS requests for access to |
98 // GAIA and sync server URLs under google.com. We use a scoped version | 77 // GAIA and sync server URLs under google.com. We use a scoped version |
99 // to override the default resolver while the test is active. | 78 // to override the default resolver while the test is active. |
100 scoped_ptr<net::ScopedDefaultHostResolverProc> mock_host_resolver_override_; | 79 scoped_ptr<net::ScopedDefaultHostResolverProc> mock_host_resolver_override_; |
101 | 80 |
102 net::TestServerLauncher server_; | |
103 | |
104 DISALLOW_COPY_AND_ASSIGN(LiveSyncTest); | 81 DISALLOW_COPY_AND_ASSIGN(LiveSyncTest); |
105 }; | 82 }; |
106 | 83 |
107 #endif // CHROME_TEST_LIVE_SYNC_LIVE_SYNC_TEST_H_ | 84 #endif // CHROME_TEST_LIVE_SYNC_LIVE_SYNC_TEST_H_ |
OLD | NEW |