| 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/utf_string_conversions.h" | 8 #include "base/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" |
| 11 #include "chrome/browser/sync/profile_sync_service_mock.h" | 11 #include "chrome/browser/sync/profile_sync_service_mock.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/test/base/browser_with_test_window_test.h" | 13 #include "chrome/test/base/browser_with_test_window_test.h" |
| 14 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
| 15 #include "content/test/test_browser_thread.h" | 15 #include "content/test/test_browser_thread.h" |
| 16 #include "testing/gmock/include/gmock/gmock-actions.h" | 16 #include "testing/gmock/include/gmock/gmock-actions.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 using ::testing::NiceMock; | |
| 21 using ::testing::Return; | 20 using ::testing::Return; |
| 22 using ::testing::ReturnRef; | 21 using ::testing::ReturnRef; |
| 23 using ::testing::_; | 22 using ::testing::NiceMock; |
| 24 using content::BrowserThread; | 23 using content::BrowserThread; |
| 25 | 24 |
| 26 namespace { | 25 namespace { |
| 27 | 26 |
| 28 class BrowserMock: public Browser { | 27 class BrowserMock: public Browser { |
| 29 public: | 28 public: |
| 30 explicit BrowserMock(Type type, Profile* profile) : Browser(type, profile) {} | 29 explicit BrowserMock(Type type, Profile* profile) : Browser(type, profile) {} |
| 31 | 30 |
| 32 MOCK_METHOD2(ExecuteCommandWithDisposition, | 31 MOCK_METHOD1(ExecuteCommand, void(int command_id)); |
| 33 void(int command_id, WindowOpenDisposition)); | |
| 34 }; | 32 }; |
| 35 | 33 |
| 36 // Same as BrowserWithTestWindowTest, but uses MockBrowser to test calls to | 34 // Same as BrowserWithTestWindowTest, but uses MockBrowser to test calls to |
| 37 // ExecuteCommand method. | 35 // ExecuteCommand method. |
| 38 class SyncGlobalErrorTest : public BrowserWithTestWindowTest { | 36 class SyncGlobalErrorTest : public BrowserWithTestWindowTest { |
| 39 public: | 37 public: |
| 40 SyncGlobalErrorTest() {} | 38 SyncGlobalErrorTest() {} |
| 41 virtual ~SyncGlobalErrorTest() {} | 39 virtual ~SyncGlobalErrorTest() {} |
| 42 | 40 |
| 43 virtual void SetUp() OVERRIDE { | 41 virtual void SetUp() OVERRIDE { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 EXPECT_NE(error->GetBubbleViewAcceptButtonLabel().empty(), is_error); | 80 EXPECT_NE(error->GetBubbleViewAcceptButtonLabel().empty(), is_error); |
| 83 | 81 |
| 84 // We never have a cancel button. | 82 // We never have a cancel button. |
| 85 EXPECT_TRUE(error->GetBubbleViewCancelButtonLabel().empty()); | 83 EXPECT_TRUE(error->GetBubbleViewCancelButtonLabel().empty()); |
| 86 // We always return a hardcoded title. | 84 // We always return a hardcoded title. |
| 87 EXPECT_FALSE(error->GetBubbleViewTitle().empty()); | 85 EXPECT_FALSE(error->GetBubbleViewTitle().empty()); |
| 88 | 86 |
| 89 #if defined(OS_CHROMEOS) | 87 #if defined(OS_CHROMEOS) |
| 90 if (error_state != GoogleServiceAuthError::NONE) { | 88 if (error_state != GoogleServiceAuthError::NONE) { |
| 91 // In CrOS sign-in/sign-out is made to fix the error. | 89 // In CrOS sign-in/sign-out is made to fix the error. |
| 92 EXPECT_CALL(*static_cast<BrowserMock*>(browser), | 90 EXPECT_CALL(*static_cast<BrowserMock*>(browser), ExecuteCommand(IDC_EXIT)); |
| 93 ExecuteCommandWithDisposition(IDC_EXIT, _)); | |
| 94 error->ExecuteMenuItem(browser); | 91 error->ExecuteMenuItem(browser); |
| 95 } | 92 } |
| 96 #else | 93 #else |
| 97 // Test message handler. | 94 // Test message handler. |
| 98 if (is_error) { | 95 if (is_error) { |
| 99 EXPECT_CALL(*service, ShowErrorUI()); | 96 EXPECT_CALL(*service, ShowErrorUI()); |
| 100 error->ExecuteMenuItem(browser); | 97 error->ExecuteMenuItem(browser); |
| 101 EXPECT_CALL(*service, ShowErrorUI()); | 98 EXPECT_CALL(*service, ShowErrorUI()); |
| 102 error->BubbleViewAcceptButtonPressed(browser); | 99 error->BubbleViewAcceptButtonPressed(browser); |
| 103 error->BubbleViewDidClose(browser); | 100 error->BubbleViewDidClose(browser); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true }, | 149 { GoogleServiceAuthError::HOSTED_NOT_ALLOWED, true }, |
| 153 }; | 150 }; |
| 154 | 151 |
| 155 for (size_t i = 0; i < sizeof(table)/sizeof(*table); ++i) { | 152 for (size_t i = 0; i < sizeof(table)/sizeof(*table); ++i) { |
| 156 VerifySyncGlobalErrorResult(&service, browser(), &error, | 153 VerifySyncGlobalErrorResult(&service, browser(), &error, |
| 157 table[i].error_state, true, table[i].is_error); | 154 table[i].error_state, true, table[i].is_error); |
| 158 VerifySyncGlobalErrorResult(&service, browser(), &error, | 155 VerifySyncGlobalErrorResult(&service, browser(), &error, |
| 159 table[i].error_state, false, false); | 156 table[i].error_state, false, false); |
| 160 } | 157 } |
| 161 } | 158 } |
| OLD | NEW |