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

Side by Side Diff: chrome/browser/chromeos/extensions/device_local_account_management_policy_provider_unittest.cc

Issue 24261010: Allow explicitly whitelisted apps/extensions in public sessions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix handing of guest user ID. Created 7 years, 2 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 "chrome/browser/chromeos/extensions/device_local_account_management_pol icy_provider.h"
6
7 #include <string>
8
9 #include "base/files/file_path.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/values.h"
12 #include "chrome/common/extensions/extension.h"
13 #include "extensions/common/manifest.h"
14 #include "extensions/common/manifest_constants.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace chromeos {
18
19 namespace {
20
21 const char kWhitelistedId[] = "bpmcpldpdmajfigpchkicefoigmkfalc";
22
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");
28 std::string error;
29 return extensions::Extension::Create(base::FilePath(),
30 extensions::Manifest::INTERNAL,
31 *values,
32 extensions::Extension::NO_FLAGS,
33 id,
34 &error);
35 }
36
37 scoped_refptr<const extensions::Extension> CreateExtension(
38 const std::string& id) {
39 base::DictionaryValue values;
40 return CreateExtensionFromValues(id, &values);
41 }
42
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);
48 }
49
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);
58 }
59
60 } // namespace
61
62 TEST(DeviceLocalAccountManagementPolicyProviderTest, PublicSession) {
63 DeviceLocalAccountManagementPolicyProvider
64 provider(policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION);
65
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);
70 string16 error;
71 EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error));
72 EXPECT_EQ(string16(), error);
73 error.clear();
74
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(string16(), error);
81 error.clear();
82
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
85 // installed.
86 extension = CreateExtension(std::string());
87 ASSERT_TRUE(extension);
88 EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error));
89 EXPECT_NE(string16(), error);
90 error.clear();
91 }
92
93 TEST(DeviceLocalAccountManagementPolicyProviderTest, KioskAppSession) {
94 DeviceLocalAccountManagementPolicyProvider
95 provider(policy::DeviceLocalAccount::TYPE_KIOSK_APP);
96
97 // Verify that a platform app can be installed.
98 scoped_refptr<const extensions::Extension> extension = CreatePlatformApp();
99 ASSERT_TRUE(extension);
100 string16 error;
101 EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error));
102 EXPECT_EQ(string16(), error);
103 error.clear();
104
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
107 // session.
108 extension = CreateHostedApp();
109 ASSERT_TRUE(extension);
110 EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error));
111 EXPECT_NE(string16(), error);
112 error.clear();
113
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
116 // session.
117 extension = CreateExtension(kWhitelistedId);
118 ASSERT_TRUE(extension);
119 EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error));
120 EXPECT_NE(string16(), error);
121 error.clear();
122 }
123
124 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698