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.
5 #include "chrome/browser/chromeos/extensions/device_local_account_management_policy_provider.h"
9 #include "base/files/file_path.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/values.h"
12 #include "extensions/common/extension.h"
13 #include "extensions/common/manifest.h"
14 #include "extensions/common/manifest_constants.h"
15 #include "testing/gtest/include/gtest/gtest.h"
21 const char kWhitelistedId
[] = "cbkkbcmdlboombapidmoeolnmdacpkch";
23 scoped_refptr
<const extensions::Extension
> CreateExtensionFromValues(
24 const std::string
& id
,
25 base::DictionaryValue
* values
) {
26 values
->SetString(extensions::manifest_keys::kName
, "test");
27 values
->SetString(extensions::manifest_keys::kVersion
, "0.1");
29 return extensions::Extension::Create(base::FilePath(),
30 extensions::Manifest::INTERNAL
,
32 extensions::Extension::NO_FLAGS
,
37 scoped_refptr
<const extensions::Extension
> CreateExtension(
38 const std::string
& id
) {
39 base::DictionaryValue values
;
40 return CreateExtensionFromValues(id
, &values
);
43 scoped_refptr
<const extensions::Extension
> CreateHostedApp() {
44 base::DictionaryValue values
;
45 values
.Set(extensions::manifest_keys::kApp
, new base::DictionaryValue
);
46 values
.Set(extensions::manifest_keys::kWebURLs
, new base::ListValue
);
47 return CreateExtensionFromValues(std::string(), &values
);
50 scoped_refptr
<const extensions::Extension
> CreatePlatformApp() {
51 base::DictionaryValue values
;
52 values
.Set(extensions::manifest_keys::kApp
, new base::DictionaryValue
);
53 values
.Set(extensions::manifest_keys::kPlatformAppBackground
,
54 new base::DictionaryValue
);
55 values
.Set(extensions::manifest_keys::kPlatformAppBackgroundPage
,
56 new base::StringValue("background.html"));
57 return CreateExtensionFromValues(std::string(), &values
);
62 TEST(DeviceLocalAccountManagementPolicyProviderTest
, PublicSession
) {
63 DeviceLocalAccountManagementPolicyProvider
64 provider(policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION
);
66 // Verify that if an extension's type has been whitelisted for use in
67 // device-local accounts, the extension can be installed.
68 scoped_refptr
<const extensions::Extension
> extension
= CreateHostedApp();
69 ASSERT_TRUE(extension
);
71 EXPECT_TRUE(provider
.UserMayLoad(extension
.get(), &error
));
72 EXPECT_EQ(base::string16(), error
);
75 // Verify that if an extension's ID has been explicitly whitelisted for use in
76 // device-local accounts, the extension can be installed.
77 extension
= CreateExtension(kWhitelistedId
);
78 ASSERT_TRUE(extension
);
79 EXPECT_TRUE(provider
.UserMayLoad(extension
.get(), &error
));
80 EXPECT_EQ(base::string16(), error
);
83 // Verify that if neither the type nor the ID of an extension have been
84 // whitelisted for use in device-local accounts, the extension cannot be
86 extension
= CreateExtension(std::string());
87 ASSERT_TRUE(extension
);
88 EXPECT_FALSE(provider
.UserMayLoad(extension
.get(), &error
));
89 EXPECT_NE(base::string16(), error
);
93 TEST(DeviceLocalAccountManagementPolicyProviderTest
, KioskAppSession
) {
94 DeviceLocalAccountManagementPolicyProvider
95 provider(policy::DeviceLocalAccount::TYPE_KIOSK_APP
);
97 // Verify that a platform app can be installed.
98 scoped_refptr
<const extensions::Extension
> extension
= CreatePlatformApp();
99 ASSERT_TRUE(extension
);
100 base::string16 error
;
101 EXPECT_TRUE(provider
.UserMayLoad(extension
.get(), &error
));
102 EXPECT_EQ(base::string16(), error
);
105 // Verify that an extension whose type has been whitelisted for use in other
106 // types of device-local accounts cannot be installed in a single-app kiosk
108 extension
= CreateHostedApp();
109 ASSERT_TRUE(extension
);
110 EXPECT_FALSE(provider
.UserMayLoad(extension
.get(), &error
));
111 EXPECT_NE(base::string16(), error
);
114 // Verify that an extension whose ID has been whitelisted for use in other
115 // types of device-local accounts cannot be installed in a single-app kiosk
117 extension
= CreateExtension(kWhitelistedId
);
118 ASSERT_TRUE(extension
);
119 EXPECT_FALSE(provider
.UserMayLoad(extension
.get(), &error
));
120 EXPECT_NE(base::string16(), error
);
124 } // namespace chromeos