| OLD | NEW |
| 1 // Use of this source code is governed by a BSD-style license that can be | 1 // Use of this source code is governed by a BSD-style license that can be |
| 2 // found in the LICENSE file. | 2 // found in the LICENSE file. |
| 3 | 3 |
| 4 #include "testing/gtest/include/gtest/gtest.h" | 4 #include "testing/gtest/include/gtest/gtest.h" |
| 5 | 5 |
| 6 #include "base/json/json_writer.h" | 6 #include "base/json/json_writer.h" |
| 7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
| 9 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
| 10 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 private: | 134 private: |
| 135 // In real life, this is owned by the view that is opened by the browser. We | 135 // In real life, this is owned by the view that is opened by the browser. We |
| 136 // mock all that out, so we need to take ownership so the flow doesn't leak. | 136 // mock all that out, so we need to take ownership so the flow doesn't leak. |
| 137 scoped_ptr<SyncSetupFlow> flow_; | 137 scoped_ptr<SyncSetupFlow> flow_; |
| 138 | 138 |
| 139 bool was_show_html_dialog_called_; | 139 bool was_show_html_dialog_called_; |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 class SyncSetupWizardTest : public BrowserWithTestWindowTest { | 142 class SyncSetupWizardTest : public BrowserWithTestWindowTest { |
| 143 public: | 143 public: |
| 144 SyncSetupWizardTest() : test_window_(NULL), wizard_(NULL) { } | 144 SyncSetupWizardTest() |
| 145 : ui_thread_(ChromeThread::UI, MessageLoop::current()), |
| 146 file_thread_(ChromeThread::FILE, MessageLoop::current()), |
| 147 test_window_(NULL), |
| 148 wizard_(NULL) { } |
| 145 virtual ~SyncSetupWizardTest() { } | 149 virtual ~SyncSetupWizardTest() { } |
| 146 virtual void SetUp() { | 150 virtual void SetUp() { |
| 147 set_profile(new TestingProfileWithSyncService()); | 151 set_profile(new TestingProfileWithSyncService()); |
| 148 profile()->CreateBookmarkModel(false); | 152 profile()->CreateBookmarkModel(false); |
| 149 // Wait for the bookmarks model to load. | 153 // Wait for the bookmarks model to load. |
| 150 profile()->BlockUntilBookmarkModelLoaded(); | 154 profile()->BlockUntilBookmarkModelLoaded(); |
| 151 set_browser(new Browser(Browser::TYPE_NORMAL, profile())); | 155 set_browser(new Browser(Browser::TYPE_NORMAL, profile())); |
| 152 test_window_ = new TestBrowserWindowForWizardTest(browser()); | 156 test_window_ = new TestBrowserWindowForWizardTest(browser()); |
| 153 set_window(test_window_); | 157 set_window(test_window_); |
| 154 browser()->set_window(window()); | 158 browser()->set_window(window()); |
| 155 BrowserList::SetLastActive(browser()); | 159 BrowserList::SetLastActive(browser()); |
| 156 service_ = static_cast<ProfileSyncServiceForWizardTest*>( | 160 service_ = static_cast<ProfileSyncServiceForWizardTest*>( |
| 157 profile()->GetProfileSyncService()); | 161 profile()->GetProfileSyncService()); |
| 158 wizard_.reset(new SyncSetupWizard(service_)); | 162 wizard_.reset(new SyncSetupWizard(service_)); |
| 159 } | 163 } |
| 160 | 164 |
| 161 virtual void TearDown() { | 165 virtual void TearDown() { |
| 162 test_window_ = NULL; | 166 test_window_ = NULL; |
| 163 service_ = NULL; | 167 service_ = NULL; |
| 164 wizard_.reset(); | 168 wizard_.reset(); |
| 165 } | 169 } |
| 166 | 170 |
| 171 ChromeThread ui_thread_; |
| 172 ChromeThread file_thread_; |
| 167 TestBrowserWindowForWizardTest* test_window_; | 173 TestBrowserWindowForWizardTest* test_window_; |
| 168 scoped_ptr<SyncSetupWizard> wizard_; | 174 scoped_ptr<SyncSetupWizard> wizard_; |
| 169 ProfileSyncServiceForWizardTest* service_; | 175 ProfileSyncServiceForWizardTest* service_; |
| 170 }; | 176 }; |
| 171 | 177 |
| 172 TEST_F(SyncSetupWizardTest, InitialStepLogin) { | 178 TEST_F(SyncSetupWizardTest, InitialStepLogin) { |
| 173 DictionaryValue dialog_args; | 179 DictionaryValue dialog_args; |
| 174 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args); | 180 SyncSetupFlow::GetArgsForGaiaLogin(service_, &dialog_args); |
| 175 std::string json_start_args; | 181 std::string json_start_args; |
| 176 base::JSONWriter::Write(&dialog_args, false, &json_start_args); | 182 base::JSONWriter::Write(&dialog_args, false, &json_start_args); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 dialog_args.GetString(L"user", &actual_user); | 369 dialog_args.GetString(L"user", &actual_user); |
| 364 EXPECT_EQ(kTestUser, actual_user); | 370 EXPECT_EQ(kTestUser, actual_user); |
| 365 int error = -1; | 371 int error = -1; |
| 366 dialog_args.GetInteger(L"error", &error); | 372 dialog_args.GetInteger(L"error", &error); |
| 367 EXPECT_EQ(static_cast<int>(AUTH_ERROR_INVALID_GAIA_CREDENTIALS), error); | 373 EXPECT_EQ(static_cast<int>(AUTH_ERROR_INVALID_GAIA_CREDENTIALS), error); |
| 368 service_->set_auth_state(kTestUser, AUTH_ERROR_NONE); | 374 service_->set_auth_state(kTestUser, AUTH_ERROR_NONE); |
| 369 | 375 |
| 370 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); | 376 wizard_->Step(SyncSetupWizard::GAIA_SUCCESS); |
| 371 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); | 377 EXPECT_TRUE(test_window_->TestAndResetWasShowHTMLDialogCalled()); |
| 372 } | 378 } |
| OLD | NEW |