OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 static std::vector<content::WebPluginInfo> GetPlugins() { | 130 static std::vector<content::WebPluginInfo> GetPlugins() { |
131 std::vector<content::WebPluginInfo> plugins; | 131 std::vector<content::WebPluginInfo> plugins; |
132 scoped_refptr<content::MessageLoopRunner> runner = | 132 scoped_refptr<content::MessageLoopRunner> runner = |
133 new content::MessageLoopRunner; | 133 new content::MessageLoopRunner; |
134 content::PluginService::GetInstance()->GetPlugins( | 134 content::PluginService::GetInstance()->GetPlugins( |
135 base::Bind(&GetPluginsInfoCallback, &plugins, runner->QuitClosure())); | 135 base::Bind(&GetPluginsInfoCallback, &plugins, runner->QuitClosure())); |
136 runner->Run(); | 136 runner->Run(); |
137 return plugins; | 137 return plugins; |
138 } | 138 } |
139 | 139 |
140 static void EnableFlash(bool enable, Profile* profile) { | |
141 std::vector<base::FilePath> paths; | |
142 GetFlashPath(&paths); | |
143 ASSERT_FALSE(paths.empty()); | |
144 | |
145 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile).get(); | |
146 scoped_refptr<content::MessageLoopRunner> runner = | |
147 new content::MessageLoopRunner; | |
148 scoped_refptr<CallbackBarrier> callback_barrier( | |
149 new CallbackBarrier(runner->QuitClosure())); | |
150 for (std::vector<base::FilePath>::iterator iter = paths.begin(); | |
151 iter != paths.end(); ++iter) { | |
152 plugin_prefs->EnablePlugin(enable, *iter, | |
153 callback_barrier->CreateCallback()); | |
154 } | |
155 runner->Run(); | |
156 } | |
157 | |
158 static void EnsureFlashProcessCount(int expected) { | 140 static void EnsureFlashProcessCount(int expected) { |
159 int actual = 0; | 141 int actual = 0; |
160 scoped_refptr<content::MessageLoopRunner> runner = | 142 scoped_refptr<content::MessageLoopRunner> runner = |
161 new content::MessageLoopRunner; | 143 new content::MessageLoopRunner; |
162 BrowserThread::PostTask( | 144 BrowserThread::PostTask( |
163 BrowserThread::IO, | 145 BrowserThread::IO, |
164 FROM_HERE, | 146 FROM_HERE, |
165 base::Bind(&CountPluginProcesses, &actual, runner->QuitClosure())); | 147 base::Bind(&CountPluginProcesses, &actual, runner->QuitClosure())); |
166 runner->Run(); | 148 runner->Run(); |
167 ASSERT_EQ(expected, actual); | 149 ASSERT_EQ(expected, actual); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // Try an incognito window. | 207 // Try an incognito window. |
226 ASSERT_NO_FATAL_FAILURE(LoadAndWait(CreateIncognitoBrowser(), url, true)); | 208 ASSERT_NO_FATAL_FAILURE(LoadAndWait(CreateIncognitoBrowser(), url, true)); |
227 EnsureFlashProcessCount(1); | 209 EnsureFlashProcessCount(1); |
228 | 210 |
229 // Now kill Flash process and verify it reloads. | 211 // Now kill Flash process and verify it reloads. |
230 CrashFlash(); | 212 CrashFlash(); |
231 EnsureFlashProcessCount(0); | 213 EnsureFlashProcessCount(0); |
232 | 214 |
233 ASSERT_NO_FATAL_FAILURE(LoadAndWait(browser(), url, true)); | 215 ASSERT_NO_FATAL_FAILURE(LoadAndWait(browser(), url, true)); |
234 EnsureFlashProcessCount(1); | 216 EnsureFlashProcessCount(1); |
235 | |
236 // Now try disabling it. | |
237 EnableFlash(false, profile); | |
238 CrashFlash(); | |
239 | |
240 ASSERT_NO_FATAL_FAILURE(LoadAndWait(browser(), url, false)); | |
241 EnsureFlashProcessCount(0); | |
242 | |
243 // Now enable it again. | |
244 EnableFlash(true, profile); | |
245 ASSERT_NO_FATAL_FAILURE(LoadAndWait(browser(), url, true)); | |
246 EnsureFlashProcessCount(1); | |
247 } | 217 } |
248 | 218 |
249 #if defined(OFFICIAL_BUILD) | 219 #if defined(OFFICIAL_BUILD) |
250 // Verify that the official builds have the known set of plugins. | 220 // Verify that the official builds have the known set of plugins. |
251 IN_PROC_BROWSER_TEST_F(ChromePluginTest, InstalledPlugins) { | 221 IN_PROC_BROWSER_TEST_F(ChromePluginTest, InstalledPlugins) { |
252 const char* expected[] = { | 222 const char* expected[] = { |
253 "Chrome PDF Viewer", | 223 "Chrome PDF Viewer", |
254 "Shockwave Flash", | 224 "Shockwave Flash", |
255 "Native Client", | 225 "Native Client", |
256 }; | 226 }; |
257 | 227 |
258 std::vector<content::WebPluginInfo> plugins = GetPlugins(); | 228 std::vector<content::WebPluginInfo> plugins = GetPlugins(); |
259 for (size_t i = 0; i < arraysize(expected); ++i) { | 229 for (size_t i = 0; i < arraysize(expected); ++i) { |
260 size_t j = 0; | 230 size_t j = 0; |
261 for (; j < plugins.size(); ++j) { | 231 for (; j < plugins.size(); ++j) { |
262 if (plugins[j].name == base::ASCIIToUTF16(expected[i])) | 232 if (plugins[j].name == base::ASCIIToUTF16(expected[i])) |
263 break; | 233 break; |
264 } | 234 } |
265 ASSERT_TRUE(j != plugins.size()) << "Didn't find " << expected[i]; | 235 ASSERT_TRUE(j != plugins.size()) << "Didn't find " << expected[i]; |
266 } | 236 } |
267 } | 237 } |
268 #endif | 238 #endif |
OLD | NEW |