| OLD | NEW |
| 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "chrome/browser/chromeos/cros/mock_network_library.h" | 6 #include "chrome/browser/chromeos/cros/mock_network_library.h" |
| 7 #include "chrome/browser/chromeos/cros/mock_update_library.h" | 7 #include "chrome/browser/chromeos/cros/mock_update_library.h" |
| 8 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 8 #include "chrome/browser/chromeos/dbus/mock_dbus_thread_manager.h" |
| 9 #include "chrome/browser/chromeos/dbus/mock_session_manager_client.h" | 9 #include "chrome/browser/chromeos/dbus/mock_session_manager_client.h" |
| 10 #include "chrome/browser/chromeos/login/mock_screen_observer.h" | 10 #include "chrome/browser/chromeos/login/mock_screen_observer.h" |
| 11 #include "chrome/browser/chromeos/login/update_screen.h" | 11 #include "chrome/browser/chromeos/login/update_screen.h" |
| 12 #include "chrome/browser/chromeos/login/wizard_controller.h" | 12 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 13 #include "chrome/browser/chromeos/login/wizard_in_process_browser_test.h" | 13 #include "chrome/browser/chromeos/login/wizard_in_process_browser_test.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace chromeos { | 16 namespace chromeos { |
| 17 using ::testing::_; | 17 using ::testing::_; |
| 18 using ::testing::AnyNumber; | 18 using ::testing::AnyNumber; |
| 19 using ::testing::AtLeast; | 19 using ::testing::AtLeast; |
| 20 using ::testing::Return; | 20 using ::testing::Return; |
| 21 using ::testing::ReturnRef; | 21 using ::testing::ReturnRef; |
| 22 using ::testing::Invoke; | 22 using ::testing::Invoke; |
| 23 | 23 |
| 24 static void RequestUpdateCheckSuccess(UpdateCallback callback, void* userdata) { | 24 static void RequestUpdateCheckSuccess(UpdateCallback callback, void* userdata) { |
| 25 callback(userdata, chromeos::UPDATE_RESULT_SUCCESS, NULL); | 25 callback(userdata, chromeos::UPDATE_RESULT_SUCCESS, NULL); |
| 26 } | 26 } |
| 27 | 27 |
| 28 class UpdateScreenTest : public WizardInProcessBrowserTest { | 28 class UpdateScreenTest : public WizardInProcessBrowserTest { |
| 29 public: | 29 public: |
| 30 UpdateScreenTest() : WizardInProcessBrowserTest("update"), | 30 UpdateScreenTest() : WizardInProcessBrowserTest("update"), |
| 31 mock_session_manager_client_(NULL), | |
| 32 mock_update_library_(NULL), | 31 mock_update_library_(NULL), |
| 33 mock_network_library_(NULL) {} | 32 mock_network_library_(NULL) {} |
| 34 | 33 |
| 35 protected: | 34 protected: |
| 36 virtual void SetUpInProcessBrowserTestFixture() { | 35 virtual void SetUpInProcessBrowserTestFixture() { |
| 37 DBusThreadManager::Initialize(); | 36 MockDBusThreadManager* mock_dbus_thread_manager = |
| 37 new MockDBusThreadManager; |
| 38 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); |
| 38 WizardInProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | 39 WizardInProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 39 cros_mock_->InitStatusAreaMocks(); | 40 cros_mock_->InitStatusAreaMocks(); |
| 40 cros_mock_->SetStatusAreaMocksExpectations(); | 41 cros_mock_->SetStatusAreaMocksExpectations(); |
| 41 ASSERT_TRUE(CrosLibrary::Get()->EnsureLoaded()); | 42 ASSERT_TRUE(CrosLibrary::Get()->EnsureLoaded()); |
| 42 | 43 |
| 43 mock_session_manager_client_ = new MockSessionManagerClient(); | 44 MockSessionManagerClient* mock_session_manager_client |
| 44 DBusThreadManager::Get()->set_session_manager_client_for_testing( | 45 = mock_dbus_thread_manager->mock_session_manager_client(); |
| 45 mock_session_manager_client_); | 46 EXPECT_CALL(*mock_session_manager_client, EmitLoginPromptReady()) |
| 46 EXPECT_CALL(*mock_session_manager_client_, EmitLoginPromptReady()) | |
| 47 .Times(1); | 47 .Times(1); |
| 48 | 48 |
| 49 mock_update_library_ = new MockUpdateLibrary(); | 49 mock_update_library_ = new MockUpdateLibrary(); |
| 50 cros_mock_->test_api()->SetUpdateLibrary(mock_update_library_, true); | 50 cros_mock_->test_api()->SetUpdateLibrary(mock_update_library_, true); |
| 51 | 51 |
| 52 // UpdateScreen::StartUpdate() will be called by the WizardController | 52 // UpdateScreen::StartUpdate() will be called by the WizardController |
| 53 // just after creating the update screen, so the expectations for that | 53 // just after creating the update screen, so the expectations for that |
| 54 // should be set up here. | 54 // should be set up here. |
| 55 EXPECT_CALL(*mock_update_library_, AddObserver(_)) | 55 EXPECT_CALL(*mock_update_library_, AddObserver(_)) |
| 56 .Times(1); | 56 .Times(1); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 83 update_screen_->screen_observer_ = mock_screen_observer_.get(); | 83 update_screen_->screen_observer_ = mock_screen_observer_.get(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 virtual void TearDownInProcessBrowserTestFixture() { | 86 virtual void TearDownInProcessBrowserTestFixture() { |
| 87 update_screen_->screen_observer_ = (controller()); | 87 update_screen_->screen_observer_ = (controller()); |
| 88 cros_mock_->test_api()->SetUpdateLibrary(NULL, true); | 88 cros_mock_->test_api()->SetUpdateLibrary(NULL, true); |
| 89 WizardInProcessBrowserTest::TearDownInProcessBrowserTestFixture(); | 89 WizardInProcessBrowserTest::TearDownInProcessBrowserTestFixture(); |
| 90 DBusThreadManager::Shutdown(); | 90 DBusThreadManager::Shutdown(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 MockSessionManagerClient* mock_session_manager_client_; | |
| 94 MockUpdateLibrary* mock_update_library_; | 93 MockUpdateLibrary* mock_update_library_; |
| 95 MockNetworkLibrary* mock_network_library_; | 94 MockNetworkLibrary* mock_network_library_; |
| 96 | 95 |
| 97 scoped_ptr<MockScreenObserver> mock_screen_observer_; | 96 scoped_ptr<MockScreenObserver> mock_screen_observer_; |
| 98 UpdateScreen* update_screen_; | 97 UpdateScreen* update_screen_; |
| 99 // DBusThreadManager needs a message loop. | |
| 100 MessageLoopForUI message_loop_; | |
| 101 | 98 |
| 102 private: | 99 private: |
| 103 DISALLOW_COPY_AND_ASSIGN(UpdateScreenTest); | 100 DISALLOW_COPY_AND_ASSIGN(UpdateScreenTest); |
| 104 }; | 101 }; |
| 105 | 102 |
| 106 IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestBasic) { | 103 IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestBasic) { |
| 107 ASSERT_TRUE(update_screen_->actor_ != NULL); | 104 ASSERT_TRUE(update_screen_->actor_ != NULL); |
| 108 } | 105 } |
| 109 | 106 |
| 110 IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestNoUpdate) { | 107 IN_PROC_BROWSER_TEST_F(UpdateScreenTest, TestNoUpdate) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 EXPECT_CALL(*mock_update_library_, status()) | 209 EXPECT_CALL(*mock_update_library_, status()) |
| 213 .Times(AtLeast(1)) | 210 .Times(AtLeast(1)) |
| 214 .WillRepeatedly(ReturnRef(status)); | 211 .WillRepeatedly(ReturnRef(status)); |
| 215 EXPECT_CALL(*mock_screen_observer_, | 212 EXPECT_CALL(*mock_screen_observer_, |
| 216 OnExit(ScreenObserver::UPDATE_ERROR_UPDATING)) | 213 OnExit(ScreenObserver::UPDATE_ERROR_UPDATING)) |
| 217 .Times(1); | 214 .Times(1); |
| 218 update_screen_->UpdateStatusChanged(status); | 215 update_screen_->UpdateStatusChanged(status); |
| 219 } | 216 } |
| 220 | 217 |
| 221 } // namespace chromeos | 218 } // namespace chromeos |
| OLD | NEW |