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

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

Issue 8515021: Move PluginPrefs to use PluginService instead of PluginList. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 1 month 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/plugin_prefs.h" 5 #include "chrome/browser/plugin_prefs.h"
6 6
7 #include "base/at_exit.h"
8 #include "base/bind.h"
9 #include "base/message_loop.h"
7 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
8 #include "chrome/test/base/testing_browser_process.h" 11 #include "chrome/test/base/testing_browser_process.h"
9 #include "chrome/test/base/testing_profile.h" 12 #include "chrome/test/base/testing_profile.h"
10 #include "chrome/test/base/testing_profile_manager.h" 13 #include "chrome/test/base/testing_profile_manager.h"
14 #include "content/browser/plugin_service.h"
11 #include "content/test/test_browser_thread.h" 15 #include "content/test/test_browser_thread.h"
12 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
13 #include "webkit/plugins/npapi/mock_plugin_list.cc" 17 #include "webkit/plugins/npapi/mock_plugin_list.cc"
14 #include "webkit/plugins/webplugininfo.h" 18 #include "webkit/plugins/webplugininfo.h"
15 19
16 using content::BrowserThread; 20 using content::BrowserThread;
17 21
18 class PluginPrefsTest : public ::testing::Test { 22 class PluginPrefsTest : public ::testing::Test {
19 public: 23 public:
20 virtual void SetUp() OVERRIDE { 24 virtual void SetUp() OVERRIDE {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 131
128 EXPECT_EQ(PluginPrefs::POLICY_ENABLED, 132 EXPECT_EQ(PluginPrefs::POLICY_ENABLED,
129 plugin_prefs_->PolicyStatusForPlugin(kGoogleEarth)); 133 plugin_prefs_->PolicyStatusForPlugin(kGoogleEarth));
130 EXPECT_EQ(PluginPrefs::NO_POLICY, 134 EXPECT_EQ(PluginPrefs::NO_POLICY,
131 plugin_prefs_->PolicyStatusForPlugin(kGoogleMars)); 135 plugin_prefs_->PolicyStatusForPlugin(kGoogleMars));
132 EXPECT_EQ(PluginPrefs::POLICY_DISABLED, 136 EXPECT_EQ(PluginPrefs::POLICY_DISABLED,
133 plugin_prefs_->PolicyStatusForPlugin(k42)); 137 plugin_prefs_->PolicyStatusForPlugin(k42));
134 } 138 }
135 139
136 TEST_F(PluginPrefsTest, DisableGlobally) { 140 TEST_F(PluginPrefsTest, DisableGlobally) {
141 base::ShadowingAtExitManager at_exit_manager_; // Destroys the PluginService.
142
137 MessageLoop message_loop; 143 MessageLoop message_loop;
138 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 144 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
139 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); 145 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop);
140 146
147 webkit::npapi::MockPluginList plugin_list(NULL, 0);
148 PluginService::GetInstance()->SetPluginListForTesting(&plugin_list);
149 PluginService::GetInstance()->Init();
150
141 TestingBrowserProcess* browser_process = 151 TestingBrowserProcess* browser_process =
142 static_cast<TestingBrowserProcess*>(g_browser_process); 152 static_cast<TestingBrowserProcess*>(g_browser_process);
143 TestingProfileManager profile_manager(browser_process); 153 TestingProfileManager profile_manager(browser_process);
144 ASSERT_TRUE(profile_manager.SetUp()); 154 ASSERT_TRUE(profile_manager.SetUp());
145 155
146 TestingProfile* profile_1 = 156 TestingProfile* profile_1 =
147 profile_manager.CreateTestingProfile("Profile 1"); 157 profile_manager.CreateTestingProfile("Profile 1");
148 PluginPrefs* plugin_prefs = PluginPrefs::GetForTestingProfile(profile_1); 158 PluginPrefs* plugin_prefs = PluginPrefs::GetForTestingProfile(profile_1);
149 ASSERT_TRUE(plugin_prefs); 159 ASSERT_TRUE(plugin_prefs);
160 plugin_prefs->SetPluginListForTesting(&plugin_list);
150 161
151 webkit::WebPluginInfo plugin(ASCIIToUTF16("Foo"), 162 webkit::WebPluginInfo plugin(ASCIIToUTF16("Foo"),
152 FilePath(FILE_PATH_LITERAL("/path/too/foo")), 163 FilePath(FILE_PATH_LITERAL("/path/too/foo")),
153 ASCIIToUTF16("1.0.0"), 164 ASCIIToUTF16("1.0.0"),
154 ASCIIToUTF16("Foo plug-in")); 165 ASCIIToUTF16("Foo plug-in"));
155 webkit::npapi::MockPluginList plugin_list(NULL, 0);
156 plugin_list.AddPluginToLoad(plugin); 166 plugin_list.AddPluginToLoad(plugin);
157 plugin_prefs->SetPluginListForTesting(&plugin_list);
158 EXPECT_TRUE(PluginPrefs::EnablePluginGlobally(false, plugin.path)); 167 EXPECT_TRUE(PluginPrefs::EnablePluginGlobally(false, plugin.path));
159 168
169 message_loop.RunAllPending();
170
160 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(plugin)); 171 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(plugin));
161 172
162 TestingProfile* profile_2 = 173 TestingProfile* profile_2 =
163 profile_manager.CreateTestingProfile("Profile 2"); 174 profile_manager.CreateTestingProfile("Profile 2");
164 PluginPrefs* plugin_prefs_2 = PluginPrefs::GetForTestingProfile(profile_2); 175 PluginPrefs* plugin_prefs_2 = PluginPrefs::GetForTestingProfile(profile_2);
165 ASSERT_TRUE(plugin_prefs); 176 ASSERT_TRUE(plugin_prefs);
166 plugin_prefs_2->SetPluginListForTesting(&plugin_list); 177 plugin_prefs_2->SetPluginListForTesting(&plugin_list);
167 EXPECT_FALSE(plugin_prefs_2->IsPluginEnabled(plugin)); 178 EXPECT_FALSE(plugin_prefs_2->IsPluginEnabled(plugin));
179
180 profile_manager.DeleteTestingProfile("Profile 1");
181 profile_manager.DeleteTestingProfile("Profile 2");
168 } 182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698