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

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

Issue 16844020: app_mode: Add runtime.onRestartRequired event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments in #1, add test and remove onBrowserUpdateAvailable Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
(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 "base/basictypes.h"
6 #include "base/command_line.h"
7 #include "base/compiler_specific.h"
8 #include "base/file_util.h"
9 #include "base/files/file_path.h"
10 #include "base/files/scoped_temp_dir.h"
11 #include "base/path_service.h"
12 #include "base/prefs/pref_service.h"
13 #include "base/run_loop.h"
14 #include "base/strings/string_number_conversions.h"
15 #include "base/threading/sequenced_worker_pool.h"
16 #include "chrome/browser/chromeos/app_mode/kiosk_app_update_service.h"
17 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h"
18 #include "chrome/browser/extensions/extension_test_message_listener.h"
19 #include "chrome/browser/extensions/platform_app_browsertest_util.h"
20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/extensions/extension.h"
22 #include "chrome/common/pref_names.h"
23 #include "chrome/test/base/testing_browser_process.h"
24 #include "chromeos/chromeos_paths.h"
25
26 namespace chromeos {
27
28 class KioskAppUpdateServiceTest : public extensions::PlatformAppBrowserTest {
29 public:
30 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.
31 : app_(NULL),
32 update_service_(NULL) {}
33 virtual ~KioskAppUpdateServiceTest() {}
34
35 // extensions::PlatformAppBrowserTest overrides:
36 virtual void SetUpOnMainThread() OVERRIDE {
37 extensions::PlatformAppBrowserTest::SetUpOnMainThread();
38
39 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.
40 const base::FilePath& temp_dir = temp_dir_.path();
41
42 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.
43 const std::string uptime_seconds =
bartfab (slow) 2013/06/21 06:27:58 Nit: #include <string>
xiyuan 2013/06/21 16:50:56 Done.
44 base::DoubleToString(uptime.InSecondsF());
45 const base::FilePath uptime_file = temp_dir.Append("uptime");
46 ASSERT_EQ(static_cast<int>(uptime_seconds.size()),
47 file_util::WriteFile(
48 uptime_file, uptime_seconds.c_str(), uptime_seconds.size()));
49
50 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.
51 temp_dir.Append("update_reboot_needed_uptime");
52 ASSERT_FALSE(file_util::WriteFile(
53 update_reboot_needed_uptime_file, NULL, 0));
54 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.
55 ASSERT_TRUE(
56 PathService::Override(chromeos::FILE_UPDATE_REBOOT_NEEDED_UPTIME,
57 update_reboot_needed_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());
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.
68 update_service_->set_app_id(app_->id());
69
70 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.
71 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.
72 }
73
74 void FireAppUpdateAvailable() {
75 update_service_->OnAppUpdateAvailable(app_->id());
76 }
77
78 void FireUpdateNeedReboot() {
bartfab (slow) 2013/06/21 06:27:58 Grammar nit: s/Update/Updated/
xiyuan 2013/06/21 16:50:56 Done.
79 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.
80 status.status = UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT;
81 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.
82 ->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.
83 }
84
85 private:
86 base::ScopedTempDir temp_dir_;
87 const extensions::Extension* app_; // Not owned
88 KioskAppUpdateService* update_service_; // Not owned
89
90 DISALLOW_COPY_AND_ASSIGN(KioskAppUpdateServiceTest);
91 };
92
93 IN_PROC_BROWSER_TEST_F(KioskAppUpdateServiceTest, AppUpdate) {
94 FireAppUpdateAvailable();
95
96 ExtensionTestMessageListener listener("app_update", false);
97 listener.WaitUntilSatisfied();
98 }
99
100 IN_PROC_BROWSER_TEST_F(KioskAppUpdateServiceTest, OsUpdate) {
101 g_browser_process->local_state()->SetBoolean(prefs::kRebootAfterUpdate, true);
102 FireUpdateNeedReboot();
103
104 ExtensionTestMessageListener listener("os_update", false);
105 listener.WaitUntilSatisfied();
106 }
107
108 IN_PROC_BROWSER_TEST_F(KioskAppUpdateServiceTest, Periodic) {
109 g_browser_process->local_state()->SetInteger(
110 prefs::kUptimeLimit, base::TimeDelta::FromMinutes(30).InSeconds());
111
112 ExtensionTestMessageListener listener("periodic", false);
113 listener.WaitUntilSatisfied();
114 }
115
116 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698