summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-08 06:48:50 +0000
committerxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-08 06:48:50 +0000
commit11c823cbb31d113dd3841b31f325b0054c515913 (patch)
tree9bf3888891127be67c487d357c2248c481cb6325 /chrome
parentfb7aea60e15a728c3156797455ba75f00d75423c (diff)
downloadchromium_src-11c823cbb31d113dd3841b31f325b0054c515913.zip
chromium_src-11c823cbb31d113dd3841b31f325b0054c515913.tar.gz
chromium_src-11c823cbb31d113dd3841b31f325b0054c515913.tar.bz2
Implement chrome.runtime.restart for cros kiosk app.
This allows an app running in ChromeOS kiosk mode to restart the device. BUG=287727 Review URL: https://codereview.chromium.org/25944003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@227474 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/apps/app_browsertest.cc79
-rw-r--r--chrome/browser/extensions/api/runtime/runtime_api.cc19
-rw-r--r--chrome/browser/extensions/api/runtime/runtime_api.h9
-rw-r--r--chrome/browser/extensions/extension_function_histogram_value.h1
-rw-r--r--chrome/browser/extensions/extension_function_registry.cc1
-rw-r--r--chrome/browser/extensions/extension_messages_apitest.cc1
-rw-r--r--chrome/common/extensions/api/runtime.json7
-rw-r--r--chrome/test/data/extensions/platform_apps/restart_device/main.html10
-rw-r--r--chrome/test/data/extensions/platform_apps/restart_device/main.js10
-rw-r--r--chrome/test/data/extensions/platform_apps/restart_device/manifest.json10
-rw-r--r--chrome/test/data/extensions/platform_apps/restart_device/test.js7
11 files changed, 154 insertions, 0 deletions
diff --git a/chrome/browser/apps/app_browsertest.cc b/chrome/browser/apps/app_browsertest.cc
index 2f38d17..6a1d9f1 100644
--- a/chrome/browser/apps/app_browsertest.cc
+++ b/chrome/browser/apps/app_browsertest.cc
@@ -46,6 +46,15 @@
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "url/gurl.h"
+#if defined(OS_CHROMEOS)
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/chromeos/login/mock_user_manager.h"
+#include "chrome/browser/chromeos/login/user_manager.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/dbus/fake_power_manager_client.h"
+#include "chromeos/dbus/mock_dbus_thread_manager_without_gmock.h"
+#endif
+
using apps::ShellWindow;
using apps::ShellWindowRegistry;
using content::WebContents;
@@ -1140,6 +1149,76 @@ IN_PROC_BROWSER_TEST_F(PlatformAppIncognitoBrowserTest, IncognitoComponentApp) {
}
}
+class RestartDeviceTest : public PlatformAppBrowserTest {
+ public:
+ RestartDeviceTest()
+ : power_manager_client_(NULL),
+ mock_user_manager_(NULL) {}
+ virtual ~RestartDeviceTest() {}
+
+ // PlatformAppBrowserTest overrides
+ virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
+ PlatformAppBrowserTest::SetUpInProcessBrowserTestFixture();
+
+ chromeos::MockDBusThreadManagerWithoutGMock* dbus_manager =
+ new chromeos::MockDBusThreadManagerWithoutGMock;
+ chromeos::DBusThreadManager::InitializeForTesting(dbus_manager);
+ power_manager_client_ = dbus_manager->fake_power_manager_client();
+ }
+
+ virtual void SetUpOnMainThread() OVERRIDE {
+ PlatformAppBrowserTest::SetUpOnMainThread();
+
+ mock_user_manager_ = new chromeos::MockUserManager;
+ user_manager_enabler_.reset(
+ new chromeos::ScopedUserManagerEnabler(mock_user_manager_));
+
+ EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn())
+ .WillRepeatedly(testing::Return(true));
+ EXPECT_CALL(*mock_user_manager_, IsLoggedInAsKioskApp())
+ .WillRepeatedly(testing::Return(true));
+ }
+
+ virtual void CleanUpOnMainThread() OVERRIDE {
+ user_manager_enabler_.reset();
+ PlatformAppBrowserTest::CleanUpOnMainThread();
+ }
+
+ virtual void TearDownInProcessBrowserTestFixture() OVERRIDE {
+ chromeos::DBusThreadManager::Shutdown();
+ PlatformAppBrowserTest::TearDownInProcessBrowserTestFixture();
+ }
+
+ int request_restart_call_count() const {
+ return power_manager_client_->request_restart_call_count();
+ }
+
+ private:
+ chromeos::FakePowerManagerClient* power_manager_client_;
+ chromeos::MockUserManager* mock_user_manager_;
+ scoped_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_;
+
+ DISALLOW_COPY_AND_ASSIGN(RestartDeviceTest);
+};
+
+// Tests that chrome.runtime.restart would request device restart in
+// ChromeOS kiosk mode.
+IN_PROC_BROWSER_TEST_F(RestartDeviceTest, Restart) {
+ ASSERT_EQ(0, request_restart_call_count());
+
+ ExtensionTestMessageListener launched_listener("Launched", true);
+ const Extension* extension = LoadAndLaunchPlatformApp("restart_device");
+ ASSERT_TRUE(extension);
+ ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
+
+ launched_listener.Reply("restart");
+ ExtensionTestMessageListener restart_requested_listener("restartRequested",
+ false);
+ ASSERT_TRUE(restart_requested_listener.WaitUntilSatisfied());
+
+ EXPECT_EQ(1, request_restart_call_count());
+}
+
#endif // defined(OS_CHROMEOS)
diff --git a/chrome/browser/extensions/api/runtime/runtime_api.cc b/chrome/browser/extensions/api/runtime/runtime_api.cc
index 5966e8a..1af8642 100644
--- a/chrome/browser/extensions/api/runtime/runtime_api.cc
+++ b/chrome/browser/extensions/api/runtime/runtime_api.cc
@@ -35,6 +35,12 @@
#include "url/gurl.h"
#include "webkit/browser/fileapi/isolated_context.h"
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/login/user_manager.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/dbus/power_manager_client.h"
+#endif
+
namespace GetPlatformInfo = extensions::api::runtime::GetPlatformInfo;
namespace extensions {
@@ -356,6 +362,19 @@ void RuntimeRequestUpdateCheckFunction::ReplyUpdateFound(
SendResponse(true);
}
+bool RuntimeRestartFunction::RunImpl() {
+#if defined(OS_CHROMEOS)
+ if (chromeos::UserManager::Get()->IsLoggedInAsKioskApp()) {
+ chromeos::DBusThreadManager::Get()
+ ->GetPowerManagerClient()
+ ->RequestRestart();
+ return true;
+ }
+#endif
+ SetError("Function available only for ChromeOS kiosk mode.");
+ return false;
+}
+
bool RuntimeGetPlatformInfoFunction::RunImpl() {
GetPlatformInfo::Results::PlatformInfo info;
diff --git a/chrome/browser/extensions/api/runtime/runtime_api.h b/chrome/browser/extensions/api/runtime/runtime_api.h
index d936945..10f35f2 100644
--- a/chrome/browser/extensions/api/runtime/runtime_api.h
+++ b/chrome/browser/extensions/api/runtime/runtime_api.h
@@ -109,6 +109,15 @@ class RuntimeRequestUpdateCheckFunction : public AsyncExtensionFunction,
bool did_reply_;
};
+class RuntimeRestartFunction : public SyncExtensionFunction {
+ public:
+ DECLARE_EXTENSION_FUNCTION("runtime.restart", RUNTIME_RESTART)
+
+ protected:
+ virtual ~RuntimeRestartFunction() {}
+ virtual bool RunImpl() OVERRIDE;
+};
+
class RuntimeGetPlatformInfoFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("runtime.getPlatformInfo",
diff --git a/chrome/browser/extensions/extension_function_histogram_value.h b/chrome/browser/extensions/extension_function_histogram_value.h
index 50f49eb..541b9dd 100644
--- a/chrome/browser/extensions/extension_function_histogram_value.h
+++ b/chrome/browser/extensions/extension_function_histogram_value.h
@@ -646,6 +646,7 @@ enum HistogramValue {
CAST_CHANNEL_OPEN,
CAST_CHANNEL_SEND,
CAST_CHANNEL_CLOSE,
+ RUNTIME_RESTART,
ENUM_BOUNDARY // Last entry: Add new entries above.
};
diff --git a/chrome/browser/extensions/extension_function_registry.cc b/chrome/browser/extensions/extension_function_registry.cc
index 7b476d9..48202d9 100644
--- a/chrome/browser/extensions/extension_function_registry.cc
+++ b/chrome/browser/extensions/extension_function_registry.cc
@@ -48,6 +48,7 @@ void ExtensionFunctionRegistry::ResetFunctions() {
RegisterFunction<extensions::RuntimeSetUninstallUrlFunction>();
RegisterFunction<extensions::RuntimeReloadFunction>();
RegisterFunction<extensions::RuntimeRequestUpdateCheckFunction>();
+ RegisterFunction<extensions::RuntimeRestartFunction>();
// ExperimentalIdentity.
RegisterFunction<extensions::ExperimentalIdentityGetAuthTokenFunction>();
diff --git a/chrome/browser/extensions/extension_messages_apitest.cc b/chrome/browser/extensions/extension_messages_apitest.cc
index 6222ec5..e6557df 100644
--- a/chrome/browser/extensions/extension_messages_apitest.cc
+++ b/chrome/browser/extensions/extension_messages_apitest.cc
@@ -200,6 +200,7 @@ class ExternallyConnectableMessagingTest : public ExtensionApiTest {
"getURL",
"reload",
"requestUpdateCheck",
+ "restart",
"connectNative",
"sendNativeMessage",
"onStartup",
diff --git a/chrome/common/extensions/api/runtime.json b/chrome/common/extensions/api/runtime.json
index 26fc7ac..69f53e8 100644
--- a/chrome/common/extensions/api/runtime.json
+++ b/chrome/common/extensions/api/runtime.json
@@ -162,6 +162,13 @@
]
},
{
+ "name": "restart",
+ "description": "Restart the ChromeOS device when the app runs in kiosk mode. Otherwise, it's no-op.",
+ "type": "function",
+ "nocompile": true,
+ "parameters": []
+ },
+ {
"name": "connect",
"type": "function",
"nocompile": true,
diff --git a/chrome/test/data/extensions/platform_apps/restart_device/main.html b/chrome/test/data/extensions/platform_apps/restart_device/main.html
new file mode 100644
index 0000000..8fe0840
--- /dev/null
+++ b/chrome/test/data/extensions/platform_apps/restart_device/main.html
@@ -0,0 +1,10 @@
+<!--
+ * Copyright (c) 2012 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.
+-->
+<html>
+<body>
+<script src="main.js"></script>
+</body>
+</html>
diff --git a/chrome/test/data/extensions/platform_apps/restart_device/main.js b/chrome/test/data/extensions/platform_apps/restart_device/main.js
new file mode 100644
index 0000000..15923611
--- /dev/null
+++ b/chrome/test/data/extensions/platform_apps/restart_device/main.js
@@ -0,0 +1,10 @@
+// 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.
+
+chrome.test.sendMessage('Launched', function(response) {
+ if (response == "restart") {
+ chrome.runtime.restart();
+ chrome.test.sendMessage('restartRequested');
+ }
+});
diff --git a/chrome/test/data/extensions/platform_apps/restart_device/manifest.json b/chrome/test/data/extensions/platform_apps/restart_device/manifest.json
new file mode 100644
index 0000000..4b964cf
--- /dev/null
+++ b/chrome/test/data/extensions/platform_apps/restart_device/manifest.json
@@ -0,0 +1,10 @@
+{
+ "name": "Platform App Test: runtime.restart API",
+ "version": "1",
+ "kiosk_enabled": true,
+ "app": {
+ "background": {
+ "scripts": ["test.js"]
+ }
+ }
+}
diff --git a/chrome/test/data/extensions/platform_apps/restart_device/test.js b/chrome/test/data/extensions/platform_apps/restart_device/test.js
new file mode 100644
index 0000000..2f9f855
--- /dev/null
+++ b/chrome/test/data/extensions/platform_apps/restart_device/test.js
@@ -0,0 +1,7 @@
+// 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.
+
+chrome.app.runtime.onLaunched.addListener(function() {
+ chrome.app.window.create('main.html', {}, function () {});
+});