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

Side by Side Diff: chrome/browser/chromeos/app_mode/kiosk_app_update_service_browsertest.cc

Issue 727363002: Fire notifications when reboot is requested, not scheduled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@managed_cros
Patch Set: Addressed comments. Created 6 years, 1 month 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/chromeos/app_mode/kiosk_app_update_service.h" 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_update_service.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/files/scoped_temp_dir.h" 14 #include "base/files/scoped_temp_dir.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/prefs/pref_service.h" 16 #include "base/prefs/pref_service.h"
17 #include "base/run_loop.h"
17 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
18 #include "base/test/scoped_path_override.h" 19 #include "base/test/scoped_path_override.h"
19 #include "base/threading/sequenced_worker_pool.h" 20 #include "base/threading/sequenced_worker_pool.h"
20 #include "base/time/time.h" 21 #include "base/time/time.h"
21 #include "chrome/browser/apps/app_browsertest_util.h" 22 #include "chrome/browser/apps/app_browsertest_util.h"
22 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/browser_process_platform_part.h" 24 #include "chrome/browser/browser_process_platform_part.h"
24 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h" 25 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h"
26 #include "chrome/browser/chromeos/system/automatic_reboot_manager_observer.h"
25 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/common/chrome_switches.h" 28 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
28 #include "chromeos/chromeos_paths.h" 30 #include "chromeos/chromeos_paths.h"
29 #include "chromeos/dbus/update_engine_client.h" 31 #include "chromeos/dbus/update_engine_client.h"
30 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
31 #include "content/public/test/test_utils.h" 33 #include "content/public/test/test_utils.h"
32 #include "extensions/common/extension.h" 34 #include "extensions/common/extension.h"
33 #include "extensions/test/extension_test_message_listener.h" 35 #include "extensions/test/extension_test_message_listener.h"
34 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
35 37
36 namespace chromeos { 38 namespace chromeos {
37 39
38 class KioskAppUpdateServiceTest : public extensions::PlatformAppBrowserTest { 40 class KioskAppUpdateServiceTest
41 : public extensions::PlatformAppBrowserTest,
42 public system::AutomaticRebootManagerObserver {
39 public: 43 public:
40 KioskAppUpdateServiceTest() : app_(NULL), update_service_(NULL) {} 44 KioskAppUpdateServiceTest()
41 virtual ~KioskAppUpdateServiceTest() {} 45 : app_(NULL),
46 update_service_(NULL),
47 automatic_reboot_manager_(NULL) {}
48
49 ~KioskAppUpdateServiceTest() override {}
42 50
43 // extensions::PlatformAppBrowserTest overrides: 51 // extensions::PlatformAppBrowserTest overrides:
44 virtual void SetUpOnMainThread() override { 52 void SetUpOnMainThread() override {
45 extensions::PlatformAppBrowserTest::SetUpOnMainThread(); 53 extensions::PlatformAppBrowserTest::SetUpOnMainThread();
46 54
47 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 55 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
48 const base::FilePath& temp_dir = temp_dir_.path(); 56 const base::FilePath& temp_dir = temp_dir_.path();
49 57
50 const base::TimeDelta uptime = base::TimeDelta::FromHours(1); 58 const base::TimeDelta uptime = base::TimeDelta::FromHours(1);
51 const std::string uptime_seconds = 59 const std::string uptime_seconds =
52 base::DoubleToString(uptime.InSecondsF()); 60 base::DoubleToString(uptime.InSecondsF());
53 const base::FilePath uptime_file = temp_dir.Append("uptime"); 61 const base::FilePath uptime_file = temp_dir.Append("uptime");
54 ASSERT_EQ(static_cast<int>(uptime_seconds.size()), 62 ASSERT_EQ(static_cast<int>(uptime_seconds.size()),
55 base::WriteFile( 63 base::WriteFile(
56 uptime_file, uptime_seconds.c_str(), uptime_seconds.size())); 64 uptime_file, uptime_seconds.c_str(), uptime_seconds.size()));
57 uptime_file_override_.reset( 65 uptime_file_override_.reset(
58 new base::ScopedPathOverride(chromeos::FILE_UPTIME, uptime_file)); 66 new base::ScopedPathOverride(chromeos::FILE_UPTIME, uptime_file));
59 67
60 app_ = LoadExtension( 68 app_ = LoadExtension(
61 test_data_dir_.AppendASCII("api_test/runtime/on_restart_required")); 69 test_data_dir_.AppendASCII("api_test/runtime/on_restart_required"));
62 70
63 // Fake app mode command line. 71 // Fake app mode command line.
64 CommandLine* command = CommandLine::ForCurrentProcess(); 72 CommandLine* command = CommandLine::ForCurrentProcess();
65 command->AppendSwitch(switches::kForceAppMode); 73 command->AppendSwitch(switches::kForceAppMode);
66 command->AppendSwitchASCII(switches::kAppId, app_->id()); 74 command->AppendSwitchASCII(switches::kAppId, app_->id());
67 75
76 automatic_reboot_manager_ =
77 g_browser_process->platform_part()->automatic_reboot_manager();
78 automatic_reboot_manager_->AddObserver(this);
79 }
80
81 // system::AutomaticRebootManagerObserver:
82 void OnRebootRequested(
83 system::AutomaticRebootManagerObserver::Reason) override {
84 if (run_loop_)
85 run_loop_->Quit();
86 }
87
88 void WillDestroyAutomaticRebootManager() override {
89 automatic_reboot_manager_->RemoveObserver(this);
90 }
91
92 void CreateKioskAppUpdateService() {
93 EXPECT_FALSE(update_service_);
68 update_service_ = KioskAppUpdateServiceFactory::GetForProfile(profile()); 94 update_service_ = KioskAppUpdateServiceFactory::GetForProfile(profile());
69 update_service_->set_app_id(app_->id()); 95 update_service_->Init(app_->id());
70 96
71 content::RunAllBlockingPoolTasksUntilIdle(); 97 content::RunAllBlockingPoolTasksUntilIdle();
72 } 98 }
73 99
74 void FireAppUpdateAvailable() { 100 void FireAppUpdateAvailable() {
75 update_service_->OnAppUpdateAvailable(app_); 101 update_service_->OnAppUpdateAvailable(app_);
76 } 102 }
77 103
78 void FireUpdatedNeedReboot() { 104 void FireUpdatedNeedReboot() {
79 UpdateEngineClient::Status status; 105 UpdateEngineClient::Status status;
80 status.status = UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT; 106 status.status = UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT;
81 g_browser_process->platform_part()->automatic_reboot_manager()-> 107 run_loop_.reset(new base::RunLoop);
82 UpdateStatusChanged(status); 108 automatic_reboot_manager_->UpdateStatusChanged(status);
109 run_loop_->Run();
110 }
111
112 void RequestPeriodicReboot() {
113 run_loop_.reset(new base::RunLoop);
114 g_browser_process->local_state()->SetInteger(
115 prefs::kUptimeLimit, base::TimeDelta::FromMinutes(30).InSeconds());
116 run_loop_->Run();
83 } 117 }
84 118
85 private: 119 private:
86 base::ScopedTempDir temp_dir_; 120 base::ScopedTempDir temp_dir_;
87 scoped_ptr<base::ScopedPathOverride> uptime_file_override_; 121 scoped_ptr<base::ScopedPathOverride> uptime_file_override_;
88 const extensions::Extension* app_; // Not owned. 122 const extensions::Extension* app_; // Not owned.
89 KioskAppUpdateService* update_service_; // Not owned. 123 KioskAppUpdateService* update_service_; // Not owned.
124 system::AutomaticRebootManager* automatic_reboot_manager_; // Not owned.
125 scoped_ptr<base::RunLoop> run_loop_;
90 126
91 DISALLOW_COPY_AND_ASSIGN(KioskAppUpdateServiceTest); 127 DISALLOW_COPY_AND_ASSIGN(KioskAppUpdateServiceTest);
92 }; 128 };
93 129
130 // Verifies that the app is notified a reboot is required when an app update
131 // becomes available.
94 IN_PROC_BROWSER_TEST_F(KioskAppUpdateServiceTest, AppUpdate) { 132 IN_PROC_BROWSER_TEST_F(KioskAppUpdateServiceTest, AppUpdate) {
95 FireAppUpdateAvailable(); 133 CreateKioskAppUpdateService();
96 134
97 ExtensionTestMessageListener listener("app_update", false); 135 ExtensionTestMessageListener listener("app_update", false);
136 FireAppUpdateAvailable();
98 listener.WaitUntilSatisfied(); 137 listener.WaitUntilSatisfied();
99 } 138 }
100 139
140 // Verifies that the app is notified a reboot is required when an OS update is
141 // applied while Chrome is running and the policy to reboot after update is
142 // enabled.
101 IN_PROC_BROWSER_TEST_F(KioskAppUpdateServiceTest, OsUpdate) { 143 IN_PROC_BROWSER_TEST_F(KioskAppUpdateServiceTest, OsUpdate) {
144 CreateKioskAppUpdateService();
145
146 g_browser_process->local_state()->SetBoolean(prefs::kRebootAfterUpdate, true);
147 ExtensionTestMessageListener listener("os_update", false);
148 FireUpdatedNeedReboot();
149 listener.WaitUntilSatisfied();
150 }
151
152 // Verifies that the app is notified a reboot is required when a periodic reboot
153 // is requested while Chrome is running.
154 IN_PROC_BROWSER_TEST_F(KioskAppUpdateServiceTest, Periodic) {
155 CreateKioskAppUpdateService();
156
157 ExtensionTestMessageListener listener("periodic", false);
158 RequestPeriodicReboot();
159 listener.WaitUntilSatisfied();
160 }
161
162 // Verifies that the app is notified a reboot is required when an OS update was
163 // applied before Chrome was started and the policy to reboot after update is
164 // enabled.
165 IN_PROC_BROWSER_TEST_F(KioskAppUpdateServiceTest, StartAfterOsUpdate) {
102 g_browser_process->local_state()->SetBoolean(prefs::kRebootAfterUpdate, true); 166 g_browser_process->local_state()->SetBoolean(prefs::kRebootAfterUpdate, true);
103 FireUpdatedNeedReboot(); 167 FireUpdatedNeedReboot();
104 168
105 ExtensionTestMessageListener listener("os_update", false); 169 ExtensionTestMessageListener listener("os_update", false);
170 CreateKioskAppUpdateService();
106 listener.WaitUntilSatisfied(); 171 listener.WaitUntilSatisfied();
107 } 172 }
108 173
109 IN_PROC_BROWSER_TEST_F(KioskAppUpdateServiceTest, Periodic) { 174 // Verifies that the app is notified a reboot is required when a periodic reboot
110 g_browser_process->local_state()->SetInteger( 175 // was requested before Chrome was started.
111 prefs::kUptimeLimit, base::TimeDelta::FromMinutes(30).InSeconds()); 176 IN_PROC_BROWSER_TEST_F(KioskAppUpdateServiceTest, StartAfterPeriodic) {
177 RequestPeriodicReboot();
112 178
113 ExtensionTestMessageListener listener("periodic", false); 179 ExtensionTestMessageListener listener("periodic", false);
180 CreateKioskAppUpdateService();
114 listener.WaitUntilSatisfied(); 181 listener.WaitUntilSatisfied();
115 } 182 }
116 183
117 } // namespace chromeos 184 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698