Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: chrome/browser/ui/webui/help/version_updater_chromeos_unittest.cc

Issue 578293002: Fixed channel switch when user decides to switch to another channel in (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/memory/scoped_ptr.h"
10 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
11 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
12 #include "chromeos/dbus/dbus_thread_manager.h"
13 #include "chromeos/dbus/fake_update_engine_client.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 using ::testing::AtLeast;
18 using ::testing::Return;
19
20 namespace chromeos {
21
22 namespace {
23
24 void CheckNotification(VersionUpdater::Status /* status */,
25 int /* progress */,
26 const base::string16& /* message */) {
27 }
28
29 } // namespace
30
31 class VersionUpdaterCrosTest : public ::testing::Test {
32 protected:
33 VersionUpdaterCrosTest()
34 : version_updater_(VersionUpdater::Create()),
35 fake_update_engine_client_(NULL),
36 mock_user_manager_(new MockUserManager()),
37 user_manager_enabler_(mock_user_manager_) {
38 VersionUpdaterCros* version_updater =
39 static_cast<VersionUpdaterCros*>(version_updater_.get());
40 version_updater->set_can_update_for_testing(true);
41 }
42
43 virtual ~VersionUpdaterCrosTest() {}
44
45 virtual void SetUp() OVERRIDE {
46 fake_update_engine_client_ = new FakeUpdateEngineClient();
47 scoped_ptr<DBusThreadManagerSetter> dbus_setter =
48 DBusThreadManager::GetSetterForTesting();
49 dbus_setter->SetUpdateEngineClient(
50 scoped_ptr<UpdateEngineClient>(fake_update_engine_client_).Pass());
51
52 EXPECT_CALL(*mock_user_manager_, IsCurrentUserOwner())
53 .WillRepeatedly(Return(false));
54 EXPECT_CALL(*mock_user_manager_, Shutdown()).Times(AtLeast(0));
55 }
56
57 scoped_ptr<VersionUpdater> version_updater_;
58 FakeUpdateEngineClient* fake_update_engine_client_; // Not owned.
59
60 MockUserManager* mock_user_manager_; // Not owned.
61 ScopedUserManagerEnabler user_manager_enabler_;
62 };
63
64 // The test checks following behaviour:
65 // 1. The device is currently on the dev channel and an user decides to switch
66 // to the beta channel.
67 // 2. In the middle of channel switch the user decides to switch to the stable
68 // channel.
69 // 3. Update engine reports an error because downloading channel (beta) is not
70 // equal
71 // to the target channel (stable).
72 // 4. When update engine becomes idle downloading of the stable channel is
73 // initiated.
74 TEST_F(VersionUpdaterCrosTest, TwoOverlappingSetChannelRequests) {
75 version_updater_->SetChannel("beta-channel", true);
76
77 {
78 UpdateEngineClient::Status status;
79 status.status = UpdateEngineClient::UPDATE_STATUS_IDLE;
80 fake_update_engine_client_->set_default_status(status);
81 fake_update_engine_client_->NotifyObserversThatStatusChanged(status);
82 }
83
84 EXPECT_EQ(0, fake_update_engine_client_->request_update_check_call_count());
85
86 // IDLE -> DOWNLOADING transition after update check.
87 version_updater_->CheckForUpdate(base::Bind(&CheckNotification));
88 EXPECT_EQ(1, fake_update_engine_client_->request_update_check_call_count());
89
90 {
91 UpdateEngineClient::Status status;
92 status.status = UpdateEngineClient::UPDATE_STATUS_DOWNLOADING;
93 status.download_progress = 0.1;
94 fake_update_engine_client_->set_default_status(status);
95 fake_update_engine_client_->NotifyObserversThatStatusChanged(status);
96 }
97
98 version_updater_->SetChannel("stable-channel", true);
99
100 // DOWNLOADING -> REPORTING_ERROR_EVENT transition since target channel is not
101 // equal to downloading channel now.
102 {
103 UpdateEngineClient::Status status;
104 status.status = UpdateEngineClient::UPDATE_STATUS_REPORTING_ERROR_EVENT;
105 fake_update_engine_client_->set_default_status(status);
106 fake_update_engine_client_->NotifyObserversThatStatusChanged(status);
107 }
108
109 version_updater_->CheckForUpdate(base::Bind(&CheckNotification));
110 EXPECT_EQ(1, fake_update_engine_client_->request_update_check_call_count());
111
112 // REPORTING_ERROR_EVENT -> IDLE transition, update check should be
113 // automatically scheduled.
114 {
115 UpdateEngineClient::Status status;
116 status.status = UpdateEngineClient::UPDATE_STATUS_IDLE;
117 fake_update_engine_client_->set_default_status(status);
118 fake_update_engine_client_->NotifyObserversThatStatusChanged(status);
119 }
120
121 EXPECT_EQ(2, fake_update_engine_client_->request_update_check_call_count());
122 }
123
124 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698