OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/webui/help/version_updater_chromeos.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
| 12 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 13 #include "chromeos/dbus/dbus_thread_manager.h" |
| 14 #include "chromeos/dbus/fake_update_engine_client.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 |
| 18 using ::testing::AtLeast; |
| 19 using ::testing::Return; |
| 20 |
| 21 namespace chromeos { |
| 22 |
| 23 namespace { |
| 24 |
| 25 void CheckNotification(VersionUpdater::Status /* status */, |
| 26 int /* progress */, |
| 27 const base::string16& /* message */) { |
| 28 } |
| 29 |
| 30 class VersionUpdaterCrosTestImpl : public VersionUpdaterCros { |
| 31 public: |
| 32 // VersionUpdaterCros overrides: |
| 33 virtual bool EnsureCanUpdate(const StatusCallback& /* callback */) OVERRIDE { |
| 34 return true; |
| 35 } |
| 36 }; |
| 37 |
| 38 } // namespace |
| 39 |
| 40 class VersionUpdaterCrosTest : public ::testing::Test { |
| 41 protected: |
| 42 VersionUpdaterCrosTest() |
| 43 : fake_update_engine_client_(NULL), |
| 44 mock_user_manager_(new MockUserManager()), |
| 45 user_manager_enabler_(mock_user_manager_) {} |
| 46 |
| 47 virtual ~VersionUpdaterCrosTest() {} |
| 48 |
| 49 virtual void SetUp() OVERRIDE { |
| 50 fake_update_engine_client_ = new FakeUpdateEngineClient(); |
| 51 scoped_ptr<DBusThreadManagerSetter> dbus_setter = |
| 52 DBusThreadManager::GetSetterForTesting(); |
| 53 dbus_setter->SetUpdateEngineClient( |
| 54 scoped_ptr<UpdateEngineClient>(fake_update_engine_client_).Pass()); |
| 55 |
| 56 EXPECT_CALL(*mock_user_manager_, IsCurrentUserOwner()) |
| 57 .WillRepeatedly(Return(false)); |
| 58 EXPECT_CALL(*mock_user_manager_, Shutdown()).Times(AtLeast(0)); |
| 59 } |
| 60 |
| 61 VersionUpdaterCrosTestImpl version_updater_; |
| 62 FakeUpdateEngineClient* fake_update_engine_client_; // Not owned. |
| 63 |
| 64 MockUserManager* mock_user_manager_; // Not owned. |
| 65 ScopedUserManagerEnabler user_manager_enabler_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(VersionUpdaterCrosTest); |
| 68 }; |
| 69 |
| 70 // The test checks following behaviour: |
| 71 // 1. The device is currently on the dev channel and an user decides to switch |
| 72 // to the beta channel. |
| 73 // 2. In the middle of channel switch the user decides to switch to the stable |
| 74 // channel. |
| 75 // 3. Update engine reports an error because downloading channel (beta) is not |
| 76 // equal |
| 77 // to the target channel (stable). |
| 78 // 4. When update engine becomes idle downloading of the stable channel is |
| 79 // initiated. |
| 80 TEST_F(VersionUpdaterCrosTest, TwoOverlappingSetChannelRequests) { |
| 81 version_updater_.SetChannel("beta-channel", true); |
| 82 |
| 83 { |
| 84 UpdateEngineClient::Status status; |
| 85 status.status = UpdateEngineClient::UPDATE_STATUS_IDLE; |
| 86 fake_update_engine_client_->set_default_status(status); |
| 87 fake_update_engine_client_->NotifyObserversThatStatusChanged(status); |
| 88 } |
| 89 |
| 90 EXPECT_EQ(0, fake_update_engine_client_->request_update_check_call_count()); |
| 91 |
| 92 // IDLE -> DOWNLOADING transition after update check. |
| 93 version_updater_.CheckForUpdate(base::Bind(&CheckNotification)); |
| 94 EXPECT_EQ(1, fake_update_engine_client_->request_update_check_call_count()); |
| 95 |
| 96 { |
| 97 UpdateEngineClient::Status status; |
| 98 status.status = UpdateEngineClient::UPDATE_STATUS_DOWNLOADING; |
| 99 status.download_progress = 0.1; |
| 100 fake_update_engine_client_->set_default_status(status); |
| 101 fake_update_engine_client_->NotifyObserversThatStatusChanged(status); |
| 102 } |
| 103 |
| 104 version_updater_.SetChannel("stable-channel", true); |
| 105 |
| 106 // DOWNLOADING -> REPORTING_ERROR_EVENT transition since target channel is not |
| 107 // equal to downloading channel now. |
| 108 { |
| 109 UpdateEngineClient::Status status; |
| 110 status.status = UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT; |
| 111 fake_update_engine_client_->set_default_status(status); |
| 112 fake_update_engine_client_->NotifyObserversThatStatusChanged(status); |
| 113 } |
| 114 |
| 115 version_updater_.CheckForUpdate(base::Bind(&CheckNotification)); |
| 116 EXPECT_EQ(1, fake_update_engine_client_->request_update_check_call_count()); |
| 117 |
| 118 // REPORTING_ERROR_EVENT -> IDLE transition, update check should be |
| 119 // automatically scheduled. |
| 120 { |
| 121 UpdateEngineClient::Status status; |
| 122 status.status = UpdateEngineClient::UPDATE_STATUS_IDLE; |
| 123 fake_update_engine_client_->set_default_status(status); |
| 124 fake_update_engine_client_->NotifyObserversThatStatusChanged(status); |
| 125 } |
| 126 |
| 127 EXPECT_EQ(2, fake_update_engine_client_->request_update_check_call_count()); |
| 128 } |
| 129 |
| 130 } // namespace chromeos |
OLD | NEW |