1 // Copyright 2012 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 "base/message_loop/message_loop.h"
6 #include "base/strings/string_number_conversions.h"
7 #include "base/values.h"
8 #include "chrome/browser/extensions/blacklist.h"
9 #include "chrome/browser/extensions/standard_management_policy_provider.h"
10 #include "chrome/browser/extensions/test_extension_prefs.h"
11 #include "content/public/test/test_browser_thread.h"
12 #include "extensions/browser/extension_prefs.h"
13 #include "extensions/common/manifest_constants.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 namespace extensions
{
18 class StandardManagementPolicyProviderTest
: public testing::Test
{
20 StandardManagementPolicyProviderTest()
21 : ui_thread_(content::BrowserThread::UI
, &message_loop_
),
22 file_thread_(content::BrowserThread::FILE, &message_loop_
),
23 prefs_(message_loop_
.message_loop_proxy().get()),
27 ExtensionPrefs
* prefs() {
28 return prefs_
.prefs();
31 scoped_refptr
<const Extension
> CreateExtension(Manifest::Location location
,
33 base::DictionaryValue values
;
34 values
.SetString(manifest_keys::kName
, "test");
35 values
.SetString(manifest_keys::kVersion
, "0.1");
37 scoped_refptr
<const Extension
> extension
= Extension::Create(
38 base::FilePath(), location
, values
, Extension::NO_FLAGS
, &error
);
39 CHECK(extension
.get()) << error
;
43 base::MessageLoop message_loop_
;
44 content::TestBrowserThread ui_thread_
;
45 content::TestBrowserThread file_thread_
;
47 TestExtensionPrefs prefs_
;
49 StandardManagementPolicyProvider provider_
;
52 // Tests the behavior of the ManagementPolicy provider methods for an
53 // extension required by policy.
54 TEST_F(StandardManagementPolicyProviderTest
, RequiredExtension
) {
55 scoped_refptr
<const Extension
> extension
=
56 CreateExtension(Manifest::EXTERNAL_POLICY_DOWNLOAD
, true);
58 base::string16 error16
;
59 EXPECT_TRUE(provider_
.UserMayLoad(extension
.get(), &error16
));
60 EXPECT_EQ(base::string16(), error16
);
62 // We won't check the exact wording of the error, but it should say
64 EXPECT_FALSE(provider_
.UserMayModifySettings(extension
.get(), &error16
));
65 EXPECT_NE(base::string16(), error16
);
66 EXPECT_TRUE(provider_
.MustRemainEnabled(extension
.get(), &error16
));
67 EXPECT_NE(base::string16(), error16
);
70 // Tests the behavior of the ManagementPolicy provider methods for an
71 // extension required by policy.
72 TEST_F(StandardManagementPolicyProviderTest
, NotRequiredExtension
) {
73 scoped_refptr
<const Extension
> extension
=
74 CreateExtension(Manifest::INTERNAL
, false);
76 base::string16 error16
;
77 EXPECT_TRUE(provider_
.UserMayLoad(extension
.get(), &error16
));
78 EXPECT_EQ(base::string16(), error16
);
79 EXPECT_TRUE(provider_
.UserMayModifySettings(extension
.get(), &error16
));
80 EXPECT_EQ(base::string16(), error16
);
81 EXPECT_FALSE(provider_
.MustRemainEnabled(extension
.get(), &error16
));
82 EXPECT_EQ(base::string16(), error16
);
85 } // namespace extensions