summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-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
6 files changed, 110 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",