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