Chromium Code Reviews| Index: chrome/browser/chromeos/app_mode/kiosk_app_update_service_browsertest.cc |
| diff --git a/chrome/browser/chromeos/app_mode/kiosk_app_update_service_browsertest.cc b/chrome/browser/chromeos/app_mode/kiosk_app_update_service_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e879d7c988abe697401e522456b3c50d3a13d568 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/app_mode/kiosk_app_update_service_browsertest.cc |
| @@ -0,0 +1,116 @@ |
| +// Copyright 2013 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 "base/basictypes.h" |
| +#include "base/command_line.h" |
| +#include "base/compiler_specific.h" |
| +#include "base/file_util.h" |
| +#include "base/files/file_path.h" |
| +#include "base/files/scoped_temp_dir.h" |
| +#include "base/path_service.h" |
| +#include "base/prefs/pref_service.h" |
| +#include "base/run_loop.h" |
| +#include "base/strings/string_number_conversions.h" |
| +#include "base/threading/sequenced_worker_pool.h" |
| +#include "chrome/browser/chromeos/app_mode/kiosk_app_update_service.h" |
| +#include "chrome/browser/chromeos/system/automatic_reboot_manager.h" |
| +#include "chrome/browser/extensions/extension_test_message_listener.h" |
| +#include "chrome/browser/extensions/platform_app_browsertest_util.h" |
| +#include "chrome/common/chrome_switches.h" |
| +#include "chrome/common/extensions/extension.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "chrome/test/base/testing_browser_process.h" |
| +#include "chromeos/chromeos_paths.h" |
| + |
| +namespace chromeos { |
| + |
| +class KioskAppUpdateServiceTest : public extensions::PlatformAppBrowserTest { |
| + public: |
| + KioskAppUpdateServiceTest() |
|
bartfab (slow)
2013/06/21 06:27:58
Nit: No need to break this line. It should be:
Ki
xiyuan
2013/06/21 16:50:56
Done.
|
| + : app_(NULL), |
| + update_service_(NULL) {} |
| + virtual ~KioskAppUpdateServiceTest() {} |
| + |
| + // extensions::PlatformAppBrowserTest overrides: |
| + virtual void SetUpOnMainThread() OVERRIDE { |
| + extensions::PlatformAppBrowserTest::SetUpOnMainThread(); |
| + |
| + ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
|
bartfab (slow)
2013/06/21 06:27:58
Nit: #include "testing/gtest/include/gtest/gtest.h
xiyuan
2013/06/21 16:50:56
Done.
|
| + const base::FilePath& temp_dir = temp_dir_.path(); |
| + |
| + const base::TimeDelta uptime = base::TimeDelta::FromHours(1); |
|
bartfab (slow)
2013/06/21 06:27:58
Nit: #include "base/time.h"
xiyuan
2013/06/21 16:50:56
Done.
|
| + const std::string uptime_seconds = |
|
bartfab (slow)
2013/06/21 06:27:58
Nit: #include <string>
xiyuan
2013/06/21 16:50:56
Done.
|
| + base::DoubleToString(uptime.InSecondsF()); |
| + const base::FilePath uptime_file = temp_dir.Append("uptime"); |
| + ASSERT_EQ(static_cast<int>(uptime_seconds.size()), |
| + file_util::WriteFile( |
| + uptime_file, uptime_seconds.c_str(), uptime_seconds.size())); |
| + |
| + const base::FilePath update_reboot_needed_uptime_file = |
|
bartfab (slow)
2013/06/21 06:27:58
There is no need to create this file. Since the fi
xiyuan
2013/06/21 16:50:56
Done.
|
| + temp_dir.Append("update_reboot_needed_uptime"); |
| + ASSERT_FALSE(file_util::WriteFile( |
| + update_reboot_needed_uptime_file, NULL, 0)); |
| + ASSERT_TRUE(PathService::Override(chromeos::FILE_UPTIME, uptime_file)); |
|
bartfab (slow)
2013/06/21 06:27:58
Nit: Move this line up to the block of code that c
xiyuan
2013/06/21 16:50:56
Done.
|
| + ASSERT_TRUE( |
| + PathService::Override(chromeos::FILE_UPDATE_REBOOT_NEEDED_UPTIME, |
| + update_reboot_needed_uptime_file)); |
| + |
| + app_ = LoadExtension( |
| + test_data_dir_.AppendASCII("api_test/runtime/on_restart_required")); |
| + |
| + // Fake app mode command line. |
| + CommandLine* command = CommandLine::ForCurrentProcess(); |
| + command->AppendSwitch(switches::kForceAppMode); |
| + command->AppendSwitchASCII(switches::kAppId, app_->id()); |
| + |
| + update_service_ = KioskAppUpdateServiceFactory::GetForProfile(profile()); |
|
bartfab (slow)
2013/06/21 06:27:58
Nit: #include "chrome/browser/profiles/profile.h"
xiyuan
2013/06/21 16:50:56
Might not be needed since we only pass Profile* ar
bartfab (slow)
2013/06/21 18:18:12
Following the guideline to IWYU, you should includ
xiyuan
2013/06/21 18:33:18
Done.
|
| + update_service_->set_app_id(app_->id()); |
| + |
| + content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
|
bartfab (slow)
2013/06/21 06:27:58
Nit: #include "content/public/browser/browser_thre
xiyuan
2013/06/21 16:50:56
Done.
|
| + base::RunLoop().RunUntilIdle(); |
|
bartfab (slow)
2013/06/21 06:27:58
In browser tests, you should be using content::Run
xiyuan
2013/06/21 16:50:56
Done.
|
| + } |
| + |
| + void FireAppUpdateAvailable() { |
| + update_service_->OnAppUpdateAvailable(app_->id()); |
| + } |
| + |
| + void FireUpdateNeedReboot() { |
|
bartfab (slow)
2013/06/21 06:27:58
Grammar nit: s/Update/Updated/
xiyuan
2013/06/21 16:50:56
Done.
|
| + UpdateEngineClient::Status status; |
|
bartfab (slow)
2013/06/21 06:27:58
Nit: #include "chromeos/dbus/update_engine_client.
xiyuan
2013/06/21 16:50:56
Done.
|
| + status.status = UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT; |
| + g_browser_process->platform_part()->automatic_reboot_manager() |
|
bartfab (slow)
2013/06/21 06:27:58
Nit: #include "chrome/browser/browser_process_plat
xiyuan
2013/06/21 16:50:56
Done.
|
| + ->UpdateStatusChanged(status); |
|
bartfab (slow)
2013/06/21 06:27:58
Nit: Break lines after the arrow, not before it.
xiyuan
2013/06/21 16:50:56
Done.
|
| + } |
| + |
| + private: |
| + base::ScopedTempDir temp_dir_; |
| + const extensions::Extension* app_; // Not owned |
| + KioskAppUpdateService* update_service_; // Not owned |
| + |
| + DISALLOW_COPY_AND_ASSIGN(KioskAppUpdateServiceTest); |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(KioskAppUpdateServiceTest, AppUpdate) { |
| + FireAppUpdateAvailable(); |
| + |
| + ExtensionTestMessageListener listener("app_update", false); |
| + listener.WaitUntilSatisfied(); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(KioskAppUpdateServiceTest, OsUpdate) { |
| + g_browser_process->local_state()->SetBoolean(prefs::kRebootAfterUpdate, true); |
| + FireUpdateNeedReboot(); |
| + |
| + ExtensionTestMessageListener listener("os_update", false); |
| + listener.WaitUntilSatisfied(); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(KioskAppUpdateServiceTest, Periodic) { |
| + g_browser_process->local_state()->SetInteger( |
| + prefs::kUptimeLimit, base::TimeDelta::FromMinutes(30).InSeconds()); |
| + |
| + ExtensionTestMessageListener listener("periodic", false); |
| + listener.WaitUntilSatisfied(); |
| +} |
| + |
| +} // namespace chromeos |