Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <string> | |
| 6 | |
| 7 #include "base/basictypes.h" | |
| 8 #include "base/command_line.h" | |
| 9 #include "base/compiler_specific.h" | |
| 10 #include "base/file_util.h" | |
| 11 #include "base/files/file_path.h" | |
| 12 #include "base/files/scoped_temp_dir.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/path_service.h" | |
| 15 #include "base/prefs/pref_service.h" | |
| 16 #include "base/strings/string_number_conversions.h" | |
| 17 #include "base/test/scoped_path_override.h" | |
| 18 #include "base/threading/sequenced_worker_pool.h" | |
| 19 #include "base/time.h" | |
| 20 #include "chrome/browser/browser_process.h" | |
| 21 #include "chrome/browser/browser_process_platform_part.h" | |
| 22 #include "chrome/browser/chromeos/app_mode/kiosk_app_update_service.h" | |
| 23 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h" | |
| 24 #include "chrome/browser/extensions/extension_test_message_listener.h" | |
| 25 #include "chrome/browser/extensions/platform_app_browsertest_util.h" | |
| 26 #include "chrome/common/chrome_switches.h" | |
| 27 #include "chrome/common/extensions/extension.h" | |
| 28 #include "chrome/common/pref_names.h" | |
| 29 #include "chromeos/chromeos_paths.h" | |
| 30 #include "chromeos/dbus/update_engine_client.h" | |
| 31 #include "content/public/browser/browser_thread.h" | |
| 32 #include "content/public/test/test_utils.h" | |
| 33 #include "testing/gtest/include/gtest/gtest.h" | |
| 34 | |
| 35 namespace chromeos { | |
| 36 | |
| 37 class KioskAppUpdateServiceTest : public extensions::PlatformAppBrowserTest { | |
| 38 public: | |
| 39 KioskAppUpdateServiceTest() : app_(NULL), update_service_(NULL) {} | |
| 40 virtual ~KioskAppUpdateServiceTest() {} | |
| 41 | |
| 42 // extensions::PlatformAppBrowserTest overrides: | |
| 43 virtual void SetUpOnMainThread() OVERRIDE { | |
| 44 extensions::PlatformAppBrowserTest::SetUpOnMainThread(); | |
| 45 | |
| 46 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
| 47 const base::FilePath& temp_dir = temp_dir_.path(); | |
| 48 | |
| 49 const base::TimeDelta uptime = base::TimeDelta::FromHours(1); | |
| 50 const std::string uptime_seconds = | |
| 51 base::DoubleToString(uptime.InSecondsF()); | |
| 52 const base::FilePath uptime_file = temp_dir.Append("uptime"); | |
| 53 ASSERT_EQ(static_cast<int>(uptime_seconds.size()), | |
| 54 file_util::WriteFile( | |
| 55 uptime_file, uptime_seconds.c_str(), uptime_seconds.size())); | |
| 56 uptime_file_override_.reset( | |
| 57 new base::ScopedPathOverride(chromeos::FILE_UPTIME, uptime_file)); | |
| 58 | |
| 59 app_ = LoadExtension( | |
| 60 test_data_dir_.AppendASCII("api_test/runtime/on_restart_required")); | |
| 61 | |
| 62 // Fake app mode command line. | |
| 63 CommandLine* command = CommandLine::ForCurrentProcess(); | |
| 64 command->AppendSwitch(switches::kForceAppMode); | |
| 65 command->AppendSwitchASCII(switches::kAppId, app_->id()); | |
| 66 | |
| 67 update_service_ = KioskAppUpdateServiceFactory::GetForProfile(profile()); | |
| 68 update_service_->set_app_id(app_->id()); | |
| 69 | |
| 70 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | |
| 71 content::RunAllPendingInMessageLoop(); | |
| 72 } | |
| 73 | |
| 74 void FireAppUpdateAvailable() { | |
| 75 update_service_->OnAppUpdateAvailable(app_->id()); | |
| 76 } | |
| 77 | |
| 78 void FireUpdatedNeedReboot() { | |
| 79 UpdateEngineClient::Status status; | |
| 80 status.status = UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT; | |
| 81 g_browser_process->platform_part()->automatic_reboot_manager()-> | |
| 82 UpdateStatusChanged(status); | |
| 83 } | |
| 84 | |
| 85 private: | |
| 86 base::ScopedTempDir temp_dir_; | |
| 87 scoped_ptr<base::ScopedPathOverride> uptime_file_override_; | |
| 88 const extensions::Extension* app_; // Not owned | |
|
bartfab (slow)
2013/06/21 18:18:13
Nit: Full stop at end of comment.
xiyuan
2013/06/21 18:33:18
Done.
| |
| 89 KioskAppUpdateService* update_service_; // Not owned | |
|
bartfab (slow)
2013/06/21 18:18:13
Nit: Full stop at end of comment.
xiyuan
2013/06/21 18:33:18
Done.
| |
| 90 | |
| 91 DISALLOW_COPY_AND_ASSIGN(KioskAppUpdateServiceTest); | |
| 92 }; | |
| 93 | |
| 94 IN_PROC_BROWSER_TEST_F(KioskAppUpdateServiceTest, AppUpdate) { | |
| 95 FireAppUpdateAvailable(); | |
| 96 | |
| 97 ExtensionTestMessageListener listener("app_update", false); | |
| 98 listener.WaitUntilSatisfied(); | |
| 99 } | |
| 100 | |
| 101 IN_PROC_BROWSER_TEST_F(KioskAppUpdateServiceTest, OsUpdate) { | |
| 102 g_browser_process->local_state()->SetBoolean(prefs::kRebootAfterUpdate, true); | |
| 103 FireUpdatedNeedReboot(); | |
| 104 | |
| 105 ExtensionTestMessageListener listener("os_update", false); | |
| 106 listener.WaitUntilSatisfied(); | |
| 107 } | |
| 108 | |
| 109 IN_PROC_BROWSER_TEST_F(KioskAppUpdateServiceTest, Periodic) { | |
| 110 g_browser_process->local_state()->SetInteger( | |
| 111 prefs::kUptimeLimit, base::TimeDelta::FromMinutes(30).InSeconds()); | |
| 112 | |
| 113 ExtensionTestMessageListener listener("periodic", false); | |
| 114 listener.WaitUntilSatisfied(); | |
| 115 } | |
| 116 | |
| 117 } // namespace chromeos | |
| OLD | NEW |