Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sync_global_error.h" | 5 #include "chrome/browser/sync/sync_global_error.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/signin/signin_manager.h" | 10 #include "chrome/browser/signin/signin_manager.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 22 |
| 23 using ::testing::NiceMock; | 23 using ::testing::NiceMock; |
| 24 using ::testing::Return; | 24 using ::testing::Return; |
| 25 using ::testing::ReturnRef; | 25 using ::testing::ReturnRef; |
| 26 using ::testing::_; | 26 using ::testing::_; |
| 27 using content::BrowserThread; | 27 using content::BrowserThread; |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 #if 0 | |
| 32 // TODO(altimofeev) See below. | |
| 33 class BrowserMock: public Browser { | |
| 34 public: | |
| 35 explicit BrowserMock(Type type, Profile* profile) : Browser(type, profile) {} | |
| 36 | |
| 37 MOCK_METHOD2(ExecuteCommandWithDisposition, | |
| 38 void(int command_id, WindowOpenDisposition)); | |
| 39 }; | |
| 40 #endif | |
| 41 | |
| 42 class FakeLoginUIService: public LoginUIService { | 31 class FakeLoginUIService: public LoginUIService { |
| 43 public: | 32 public: |
| 44 FakeLoginUIService() : LoginUIService(NULL) {} | 33 FakeLoginUIService() : LoginUIService(NULL) {} |
| 45 }; | 34 }; |
| 46 | 35 |
| 47 class FakeLoginUI : public LoginUIService::LoginUI { | 36 class FakeLoginUI : public LoginUIService::LoginUI { |
| 48 public: | 37 public: |
| 49 FakeLoginUI() : focus_ui_call_count_(0) {} | 38 FakeLoginUI() : focus_ui_call_count_(0) {} |
| 50 | 39 |
| 51 virtual ~FakeLoginUI() {} | 40 virtual ~FakeLoginUI() {} |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 67 return new FakeLoginUIService(); | 56 return new FakeLoginUIService(); |
| 68 } | 57 } |
| 69 | 58 |
| 70 // Same as BrowserWithTestWindowTest, but uses MockBrowser to test calls to | 59 // Same as BrowserWithTestWindowTest, but uses MockBrowser to test calls to |
| 71 // ExecuteCommand method. | 60 // ExecuteCommand method. |
| 72 class SyncGlobalErrorTest : public BrowserWithTestWindowTest { | 61 class SyncGlobalErrorTest : public BrowserWithTestWindowTest { |
| 73 public: | 62 public: |
| 74 SyncGlobalErrorTest() {} | 63 SyncGlobalErrorTest() {} |
| 75 virtual ~SyncGlobalErrorTest() {} | 64 virtual ~SyncGlobalErrorTest() {} |
| 76 | 65 |
| 77 #if 0 | |
| 78 // TODO(altimofeev): see below. | |
| 79 virtual void SetUp() OVERRIDE { | |
| 80 testing::Test::SetUp(); | |
| 81 | |
| 82 set_profile(CreateProfile()); | |
| 83 set_browser(new BrowserMock(Browser::TYPE_TABBED, profile())); | |
| 84 set_window(new TestBrowserWindow(browser())); | |
| 85 browser()->SetWindowForTesting(window()); | |
| 86 } | |
| 87 | |
| 88 virtual void TearDown() OVERRIDE { | |
| 89 testing::Test::TearDown(); | |
| 90 } | |
| 91 #endif | |
| 92 | |
| 93 private: | 66 private: |
| 94 DISALLOW_COPY_AND_ASSIGN(SyncGlobalErrorTest); | 67 DISALLOW_COPY_AND_ASSIGN(SyncGlobalErrorTest); |
| 95 }; | 68 }; |
| 96 | 69 |
| 97 // Utility function to test that SyncGlobalError behaves correct for the given | 70 // Utility function to test that SyncGlobalError behaves correct for the given |
| 98 // error condition. | 71 // error condition. |
| 99 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, | 72 void VerifySyncGlobalErrorResult(NiceMock<ProfileSyncServiceMock>* service, |
| 100 FakeLoginUIService* login_ui_service, | 73 FakeLoginUIService* login_ui_service, |
| 101 Browser* browser, | 74 Browser* browser, |
| 102 SyncGlobalError* error, | 75 SyncGlobalError* error, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 119 EXPECT_NE(error->MenuItemCommandID(), 0); | 92 EXPECT_NE(error->MenuItemCommandID(), 0); |
| 120 EXPECT_NE(error->MenuItemLabel().empty(), is_error); | 93 EXPECT_NE(error->MenuItemLabel().empty(), is_error); |
| 121 EXPECT_NE(error->GetBubbleViewAcceptButtonLabel().empty(), is_error); | 94 EXPECT_NE(error->GetBubbleViewAcceptButtonLabel().empty(), is_error); |
| 122 | 95 |
| 123 // We never have a cancel button. | 96 // We never have a cancel button. |
| 124 EXPECT_TRUE(error->GetBubbleViewCancelButtonLabel().empty()); | 97 EXPECT_TRUE(error->GetBubbleViewCancelButtonLabel().empty()); |
| 125 // We always return a hardcoded title. | 98 // We always return a hardcoded title. |
| 126 EXPECT_FALSE(error->GetBubbleViewTitle().empty()); | 99 EXPECT_FALSE(error->GetBubbleViewTitle().empty()); |
| 127 | 100 |
| 128 #if defined(OS_CHROMEOS) | 101 #if defined(OS_CHROMEOS) |
| 102 // Check for is_error and sign-out & sign-in to recover in CrOS | |
| 129 // TODO(altimofeev): Implement this in a way that doesn't involve subclassing | 103 // TODO(altimofeev): Implement this in a way that doesn't involve subclassing |
| 130 // Browser or using GMock on browser/ui types which is | 104 // Browser or using GMock on browser/ui types which is |
| 131 // banned. Consider observing NOTIFICATION_APP_TERMINATING | 105 // banned. Consider observing NOTIFICATION_APP_TERMINATING |
| 132 // instead. | 106 // instead. |
| 133 // http://crbug.com/134675 | 107 // http://crbug.com/134675 |
|
Raghu Simha
2014/01/28 01:40:04
Technically, this is dead code too, and ought to b
| |
| 134 #else | 108 #else |
| 135 #if defined(OS_CHROMEOS) | |
| 136 if (error_state != GoogleServiceAuthError::NONE) { | |
| 137 // In CrOS sign-in/sign-out is made to fix the error. | |
| 138 EXPECT_CALL(*static_cast<BrowserMock*>(browser), | |
| 139 ExecuteCommandWithDisposition(IDC_EXIT, _)); | |
| 140 error->ExecuteMenuItem(browser); | |
| 141 } | |
| 142 #else | |
| 143 // Test message handler. | 109 // Test message handler. |
| 144 if (is_error) { | 110 if (is_error) { |
| 145 FakeLoginUI* login_ui = static_cast<FakeLoginUI*>( | 111 FakeLoginUI* login_ui = static_cast<FakeLoginUI*>( |
| 146 login_ui_service->current_login_ui()); | 112 login_ui_service->current_login_ui()); |
| 147 error->ExecuteMenuItem(browser); | 113 error->ExecuteMenuItem(browser); |
| 148 ASSERT_GT(login_ui->focus_ui_call_count(), 0); | 114 ASSERT_GT(login_ui->focus_ui_call_count(), 0); |
| 149 error->BubbleViewAcceptButtonPressed(browser); | 115 error->BubbleViewAcceptButtonPressed(browser); |
| 150 error->BubbleViewDidClose(browser); | 116 error->BubbleViewDidClose(browser); |
| 151 } | 117 } |
| 152 #endif | 118 #endif |
| 153 #endif | |
| 154 } | 119 } |
| 155 | 120 |
| 156 } // namespace | 121 } // namespace |
| 157 | 122 |
| 158 // Test that SyncGlobalError shows an error if a passphrase is required. | 123 // Test that SyncGlobalError shows an error if a passphrase is required. |
| 159 TEST_F(SyncGlobalErrorTest, PassphraseGlobalError) { | 124 TEST_F(SyncGlobalErrorTest, PassphraseGlobalError) { |
| 160 scoped_ptr<Profile> profile( | 125 scoped_ptr<Profile> profile( |
| 161 ProfileSyncServiceMock::MakeSignedInTestingProfile()); | 126 ProfileSyncServiceMock::MakeSignedInTestingProfile()); |
| 162 NiceMock<ProfileSyncServiceMock> service(profile.get()); | 127 NiceMock<ProfileSyncServiceMock> service(profile.get()); |
| 163 SigninManagerBase* signin = | 128 SigninManagerBase* signin = |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 174 .WillRepeatedly(Return(false)); | 139 .WillRepeatedly(Return(false)); |
| 175 | 140 |
| 176 EXPECT_CALL(service, IsPassphraseRequired()) | 141 EXPECT_CALL(service, IsPassphraseRequired()) |
| 177 .WillRepeatedly(Return(true)); | 142 .WillRepeatedly(Return(true)); |
| 178 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) | 143 EXPECT_CALL(service, IsPassphraseRequiredForDecryption()) |
| 179 .WillRepeatedly(Return(true)); | 144 .WillRepeatedly(Return(true)); |
| 180 VerifySyncGlobalErrorResult( | 145 VerifySyncGlobalErrorResult( |
| 181 &service, login_ui_service, browser(), &error, | 146 &service, login_ui_service, browser(), &error, |
| 182 GoogleServiceAuthError::NONE, true, true); | 147 GoogleServiceAuthError::NONE, true, true); |
| 183 } | 148 } |
| OLD | NEW |