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

Side by Side Diff: chrome/browser/plugin_prefs_unittest.cc

Issue 7848025: Store plug-in enabled/disabled state in PluginPrefs instead of WebPluginInfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: copyright Created 9 years, 3 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
« no previous file with comments | « chrome/browser/plugin_prefs.cc ('k') | chrome/browser/printing/print_preview_tab_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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/plugin_prefs.h"
6
7 #include "base/utf_string_conversions.h"
8 #include "chrome/test/base/testing_browser_process.h"
9 #include "chrome/test/base/testing_profile.h"
10 #include "chrome/test/base/testing_profile_manager.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "webkit/plugins/webplugininfo.h"
13
14 class PluginPrefsTest : public ::testing::Test {
15 public:
16 virtual void SetUp() OVERRIDE {
17 plugin_prefs_ = new PluginPrefs();
18 }
19
20 void SetPolicyEnforcedPluginPatterns(
21 const std::set<string16>& disabled,
22 const std::set<string16>& disabled_exceptions,
23 const std::set<string16>& enabled) {
24 plugin_prefs_->SetPolicyEnforcedPluginPatterns(
25 disabled, disabled_exceptions, enabled);
26 }
27
28 protected:
29 scoped_refptr<PluginPrefs> plugin_prefs_;
30 };
31
32 TEST_F(PluginPrefsTest, DisabledByPolicy) {
33 std::set<string16> disabled_plugins;
34 disabled_plugins.insert(ASCIIToUTF16("Disable this!"));
35 disabled_plugins.insert(ASCIIToUTF16("*Google*"));
36 SetPolicyEnforcedPluginPatterns(disabled_plugins,
37 std::set<string16>(),
38 std::set<string16>());
39
40 EXPECT_EQ(PluginPrefs::NO_POLICY,
41 plugin_prefs_->PolicyStatusForPlugin(ASCIIToUTF16("42")));
42 EXPECT_EQ(PluginPrefs::POLICY_DISABLED,
43 plugin_prefs_->PolicyStatusForPlugin(
44 ASCIIToUTF16("Disable this!")));
45 EXPECT_EQ(PluginPrefs::POLICY_DISABLED,
46 plugin_prefs_->PolicyStatusForPlugin(ASCIIToUTF16("Google Earth")));
47 }
48
49 TEST_F(PluginPrefsTest, EnabledByPolicy) {
50 std::set<string16> enabled_plugins;
51 enabled_plugins.insert(ASCIIToUTF16("Enable that!"));
52 enabled_plugins.insert(ASCIIToUTF16("PDF*"));
53 SetPolicyEnforcedPluginPatterns(std::set<string16>(),
54 std::set<string16>(),
55 enabled_plugins);
56
57 EXPECT_EQ(PluginPrefs::NO_POLICY,
58 plugin_prefs_->PolicyStatusForPlugin(ASCIIToUTF16("42")));
59 EXPECT_EQ(PluginPrefs::POLICY_ENABLED,
60 plugin_prefs_->PolicyStatusForPlugin(ASCIIToUTF16("Enable that!")));
61 EXPECT_EQ(PluginPrefs::POLICY_ENABLED,
62 plugin_prefs_->PolicyStatusForPlugin(ASCIIToUTF16("PDF Reader")));
63 }
64
65 TEST_F(PluginPrefsTest, EnabledAndDisabledByPolicy) {
66 const string16 k42(ASCIIToUTF16("42"));
67 const string16 kEnabled(ASCIIToUTF16("Enabled"));
68 const string16 kEnabled2(ASCIIToUTF16("Enabled 2"));
69 const string16 kEnabled3(ASCIIToUTF16("Enabled 3"));
70 const string16 kException(ASCIIToUTF16("Exception"));
71 const string16 kException2(ASCIIToUTF16("Exception 2"));
72 const string16 kGoogleMars(ASCIIToUTF16("Google Mars"));
73 const string16 kGoogleEarth(ASCIIToUTF16("Google Earth"));
74
75 std::set<string16> disabled_plugins;
76 std::set<string16> disabled_plugins_exceptions;
77 std::set<string16> enabled_plugins;
78
79 disabled_plugins.insert(kEnabled);
80 disabled_plugins_exceptions.insert(kEnabled);
81 enabled_plugins.insert(kEnabled);
82
83 disabled_plugins_exceptions.insert(kException);
84
85 disabled_plugins.insert(kEnabled2);
86 enabled_plugins.insert(kEnabled2);
87
88 disabled_plugins.insert(kException2);
89 disabled_plugins_exceptions.insert(kException2);
90
91 disabled_plugins_exceptions.insert(kEnabled3);
92 enabled_plugins.insert(kEnabled3);
93
94 SetPolicyEnforcedPluginPatterns(disabled_plugins,
95 disabled_plugins_exceptions,
96 enabled_plugins);
97
98 EXPECT_EQ(PluginPrefs::NO_POLICY, plugin_prefs_->PolicyStatusForPlugin(k42));
99
100 EXPECT_EQ(PluginPrefs::POLICY_ENABLED,
101 plugin_prefs_->PolicyStatusForPlugin(kEnabled));
102 EXPECT_EQ(PluginPrefs::POLICY_ENABLED,
103 plugin_prefs_->PolicyStatusForPlugin(kEnabled2));
104 EXPECT_EQ(PluginPrefs::POLICY_ENABLED,
105 plugin_prefs_->PolicyStatusForPlugin(kEnabled3));
106
107 EXPECT_EQ(PluginPrefs::NO_POLICY,
108 plugin_prefs_->PolicyStatusForPlugin(kException));
109 EXPECT_EQ(PluginPrefs::NO_POLICY,
110 plugin_prefs_->PolicyStatusForPlugin(kException2));
111
112 disabled_plugins.clear();
113 disabled_plugins_exceptions.clear();
114 enabled_plugins.clear();
115
116 disabled_plugins.insert(ASCIIToUTF16("*"));
117 disabled_plugins_exceptions.insert(ASCIIToUTF16("*Google*"));
118 enabled_plugins.insert(kGoogleEarth);
119
120 SetPolicyEnforcedPluginPatterns(disabled_plugins,
121 disabled_plugins_exceptions,
122 enabled_plugins);
123
124 EXPECT_EQ(PluginPrefs::POLICY_ENABLED,
125 plugin_prefs_->PolicyStatusForPlugin(kGoogleEarth));
126 EXPECT_EQ(PluginPrefs::NO_POLICY,
127 plugin_prefs_->PolicyStatusForPlugin(kGoogleMars));
128 EXPECT_EQ(PluginPrefs::POLICY_DISABLED,
129 plugin_prefs_->PolicyStatusForPlugin(k42));
130 }
131
132 TEST_F(PluginPrefsTest, DisableGlobally) {
133 MessageLoop message_loop;
134 BrowserThread ui_thread(BrowserThread::UI, &message_loop);
135 BrowserThread file_thread(BrowserThread::FILE, &message_loop);
136
137 TestingBrowserProcess* browser_process =
138 static_cast<TestingBrowserProcess*>(g_browser_process);
139 TestingProfileManager profile_manager(browser_process);
140 ASSERT_TRUE(profile_manager.SetUp());
141
142 TestingProfile* profile_1 =
143 profile_manager.CreateTestingProfile("Profile 1");
144 PluginPrefs* plugin_prefs = PluginPrefs::GetForTestingProfile(profile_1);
145 ASSERT_TRUE(plugin_prefs);
146
147 webkit::WebPluginInfo plugin(ASCIIToUTF16("Foo"),
148 FilePath(FILE_PATH_LITERAL("/path/too/foo")),
149 ASCIIToUTF16("1.0.0"),
150 ASCIIToUTF16("Foo plug-in"));
151 PluginPrefs::EnablePluginGlobally(false, plugin.path);
152
153 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(plugin));
154
155 TestingProfile* profile_2 =
156 profile_manager.CreateTestingProfile("Profile 2");
157 PluginPrefs* plugin_prefs_2 = PluginPrefs::GetForTestingProfile(profile_2);
158 ASSERT_TRUE(plugin_prefs);
159 EXPECT_FALSE(plugin_prefs_2->IsPluginEnabled(plugin));
160 }
OLDNEW
« no previous file with comments | « chrome/browser/plugin_prefs.cc ('k') | chrome/browser/printing/print_preview_tab_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698