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

Side by Side Diff: chrome/browser/policy/policy_browsertest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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
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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 const std::string& scheme) { 185 const std::string& scheme) {
186 return new content::URLRequestFailedJob( 186 return new content::URLRequestFailedJob(
187 request, network_delegate, net::ERR_CONNECTION_RESET); 187 request, network_delegate, net::ERR_CONNECTION_RESET);
188 } 188 }
189 189
190 // While |MakeRequestFail| is in scope URLRequests to |host| will fail. 190 // While |MakeRequestFail| is in scope URLRequests to |host| will fail.
191 class MakeRequestFail { 191 class MakeRequestFail {
192 public: 192 public:
193 // Sets up the filter on IO thread such that requests to |host| fail. 193 // Sets up the filter on IO thread such that requests to |host| fail.
194 explicit MakeRequestFail(const std::string& host) : host_(host) { 194 explicit MakeRequestFail(const std::string& host) : host_(host) {
195 BrowserThread::PostTaskAndReply( 195 BrowserThread::PostTaskAndReply(BrowserThread::IO,
196 BrowserThread::IO, FROM_HERE, 196 FROM_HERE,
197 base::Bind(MakeRequestFailOnIO, host_), 197 base::Bind(MakeRequestFailOnIO, host_),
198 MessageLoop::QuitClosure()); 198 base::MessageLoop::QuitClosure());
199 content::RunMessageLoop(); 199 content::RunMessageLoop();
200 } 200 }
201 ~MakeRequestFail() { 201 ~MakeRequestFail() {
202 BrowserThread::PostTaskAndReply( 202 BrowserThread::PostTaskAndReply(BrowserThread::IO,
203 BrowserThread::IO, FROM_HERE, 203 FROM_HERE,
204 base::Bind(UndoMakeRequestFailOnIO, host_), 204 base::Bind(UndoMakeRequestFailOnIO, host_),
205 MessageLoop::QuitClosure()); 205 base::MessageLoop::QuitClosure());
206 content::RunMessageLoop(); 206 content::RunMessageLoop();
207 } 207 }
208 208
209 private: 209 private:
210 // Filters requests to the |host| such that they fail. Run on IO thread. 210 // Filters requests to the |host| such that they fail. Run on IO thread.
211 static void MakeRequestFailOnIO(const std::string& host) { 211 static void MakeRequestFailOnIO(const std::string& host) {
212 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); 212 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance();
213 filter->AddHostnameHandler("http", host, &FailedJobFactory); 213 filter->AddHostnameHandler("http", host, &FailedJobFactory);
214 filter->AddHostnameHandler("https", host, &FailedJobFactory); 214 filter->AddHostnameHandler("https", host, &FailedJobFactory);
215 } 215 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 contents->GetRenderViewHost(), "123"); 312 contents->GetRenderViewHost(), "123");
313 int result = 0; 313 int result = 0;
314 if (!value->GetAsInteger(&result)) 314 if (!value->GetAsInteger(&result))
315 EXPECT_EQ(base::Value::TYPE_NULL, value->GetType()); 315 EXPECT_EQ(base::Value::TYPE_NULL, value->GetType());
316 return result == 123; 316 return result == 123;
317 } 317 }
318 318
319 void CopyPluginListAndQuit(std::vector<webkit::WebPluginInfo>* out, 319 void CopyPluginListAndQuit(std::vector<webkit::WebPluginInfo>* out,
320 const std::vector<webkit::WebPluginInfo>& in) { 320 const std::vector<webkit::WebPluginInfo>& in) {
321 *out = in; 321 *out = in;
322 MessageLoop::current()->QuitWhenIdle(); 322 base::MessageLoop::current()->QuitWhenIdle();
323 } 323 }
324 324
325 template<typename T> 325 template<typename T>
326 void CopyValueAndQuit(T* out, T in) { 326 void CopyValueAndQuit(T* out, T in) {
327 *out = in; 327 *out = in;
328 MessageLoop::current()->QuitWhenIdle(); 328 base::MessageLoop::current()->QuitWhenIdle();
329 } 329 }
330 330
331 void GetPluginList(std::vector<webkit::WebPluginInfo>* plugins) { 331 void GetPluginList(std::vector<webkit::WebPluginInfo>* plugins) {
332 content::PluginService* service = content::PluginService::GetInstance(); 332 content::PluginService* service = content::PluginService::GetInstance();
333 service->GetPlugins(base::Bind(CopyPluginListAndQuit, plugins)); 333 service->GetPlugins(base::Bind(CopyPluginListAndQuit, plugins));
334 content::RunMessageLoop(); 334 content::RunMessageLoop();
335 } 335 }
336 336
337 const webkit::WebPluginInfo* GetFlashPlugin( 337 const webkit::WebPluginInfo* GetFlashPlugin(
338 const std::vector<webkit::WebPluginInfo>& plugins) { 338 const std::vector<webkit::WebPluginInfo>& plugins) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 BrowserThread::IO, FROM_HERE, 438 BrowserThread::IO, FROM_HERE,
439 base::Bind(chrome_browser_net::SetUrlRequestMocksEnabled, true)); 439 base::Bind(chrome_browser_net::SetUrlRequestMocksEnabled, true));
440 } 440 }
441 441
442 // Makes URLRequestMockHTTPJobs serve data from content::DIR_TEST_DATA 442 // Makes URLRequestMockHTTPJobs serve data from content::DIR_TEST_DATA
443 // instead of chrome::DIR_TEST_DATA. 443 // instead of chrome::DIR_TEST_DATA.
444 void ServeContentTestData() { 444 void ServeContentTestData() {
445 base::FilePath root_http; 445 base::FilePath root_http;
446 PathService::Get(content::DIR_TEST_DATA, &root_http); 446 PathService::Get(content::DIR_TEST_DATA, &root_http);
447 BrowserThread::PostTaskAndReply( 447 BrowserThread::PostTaskAndReply(
448 BrowserThread::IO, FROM_HERE, 448 BrowserThread::IO,
449 FROM_HERE,
449 base::Bind(URLRequestMockHTTPJob::AddUrlHandler, root_http), 450 base::Bind(URLRequestMockHTTPJob::AddUrlHandler, root_http),
450 MessageLoop::current()->QuitWhenIdleClosure()); 451 base::MessageLoop::current()->QuitWhenIdleClosure());
451 content::RunMessageLoop(); 452 content::RunMessageLoop();
452 } 453 }
453 454
454 void SetScreenshotPolicy(bool enabled) { 455 void SetScreenshotPolicy(bool enabled) {
455 PolicyMap policies; 456 PolicyMap policies;
456 policies.Set(key::kDisableScreenshots, POLICY_LEVEL_MANDATORY, 457 policies.Set(key::kDisableScreenshots, POLICY_LEVEL_MANDATORY,
457 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(!enabled)); 458 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(!enabled));
458 UpdateProviderPolicy(policies); 459 UpdateProviderPolicy(policies);
459 } 460 }
460 461
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 web_contents->Close(); 506 web_contents->Close();
506 } 507 }
507 508
508 #if defined(OS_CHROMEOS) 509 #if defined(OS_CHROMEOS)
509 void TestScreenshotFile(bool enabled) { 510 void TestScreenshotFile(bool enabled) {
510 SetScreenshotPolicy(enabled); 511 SetScreenshotPolicy(enabled);
511 ash::Shell::GetInstance()->accelerator_controller()->PerformAction( 512 ash::Shell::GetInstance()->accelerator_controller()->PerformAction(
512 ash::TAKE_SCREENSHOT, ui::Accelerator()); 513 ash::TAKE_SCREENSHOT, ui::Accelerator());
513 514
514 // TAKE_SCREENSHOT handler posts write file task on success, wait for it. 515 // TAKE_SCREENSHOT handler posts write file task on success, wait for it.
515 BrowserThread::PostTaskAndReply( 516 BrowserThread::PostTaskAndReply(BrowserThread::IO,
516 BrowserThread::IO, 517 FROM_HERE,
517 FROM_HERE, 518 base::Bind(base::DoNothing),
518 base::Bind(base::DoNothing), 519 base::MessageLoop::QuitClosure());
519 MessageLoop::QuitClosure());
520 content::RunMessageLoop(); 520 content::RunMessageLoop();
521 } 521 }
522 #endif 522 #endif
523 523
524 ExtensionService* extension_service() { 524 ExtensionService* extension_service() {
525 extensions::ExtensionSystem* system = 525 extensions::ExtensionSystem* system =
526 extensions::ExtensionSystem::Get(browser()->profile()); 526 extensions::ExtensionSystem::Get(browser()->profile());
527 return system->extension_service(); 527 return system->extension_service();
528 } 528 }
529 529
(...skipping 20 matching lines...) Expand all
550 content::WindowedNotificationObserver observer( 550 content::WindowedNotificationObserver observer(
551 expect_success ? chrome::NOTIFICATION_EXTENSION_UNINSTALLED 551 expect_success ? chrome::NOTIFICATION_EXTENSION_UNINSTALLED
552 : chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, 552 : chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
553 content::NotificationService::AllSources()); 553 content::NotificationService::AllSources());
554 extension_service()->UninstallExtension(id, false, NULL); 554 extension_service()->UninstallExtension(id, false, NULL);
555 observer.Wait(); 555 observer.Wait();
556 } 556 }
557 557
558 void UpdateProviderPolicy(const PolicyMap& policy) { 558 void UpdateProviderPolicy(const PolicyMap& policy) {
559 provider_.UpdateChromePolicy(policy); 559 provider_.UpdateChromePolicy(policy);
560 DCHECK(MessageLoop::current()); 560 DCHECK(base::MessageLoop::current());
561 base::RunLoop loop; 561 base::RunLoop loop;
562 loop.RunUntilIdle(); 562 loop.RunUntilIdle();
563 } 563 }
564 564
565 // Sends a mouse click at the given coordinates to the current renderer. 565 // Sends a mouse click at the given coordinates to the current renderer.
566 void PerformClick(int x, int y) { 566 void PerformClick(int x, int y) {
567 content::WebContents* contents = 567 content::WebContents* contents =
568 browser()->tab_strip_model()->GetActiveWebContents(); 568 browser()->tab_strip_model()->GetActiveWebContents();
569 WebKit::WebMouseEvent click_event; 569 WebKit::WebMouseEvent click_event;
570 click_event.type = WebKit::WebInputEvent::MouseDown; 570 click_event.type = WebKit::WebInputEvent::MouseDown;
(...skipping 1401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1972 TabSpecificContentSettings* content_settings = 1972 TabSpecificContentSettings* content_settings =
1973 TabSpecificContentSettings::FromWebContents( 1973 TabSpecificContentSettings::FromWebContents(
1974 browser()->tab_strip_model()->GetActiveWebContents()); 1974 browser()->tab_strip_model()->GetActiveWebContents());
1975 MediaStreamDevicesController controller( 1975 MediaStreamDevicesController controller(
1976 browser()->profile(), 1976 browser()->profile(),
1977 content_settings, 1977 content_settings,
1978 request, 1978 request,
1979 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this)); 1979 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this));
1980 controller.DismissInfoBarAndTakeActionOnSettings(); 1980 controller.DismissInfoBarAndTakeActionOnSettings();
1981 1981
1982 MessageLoop::current()->QuitWhenIdle(); 1982 base::MessageLoop::current()->QuitWhenIdle();
1983 } 1983 }
1984 1984
1985 void FinishVideoTest() { 1985 void FinishVideoTest() {
1986 content::MediaStreamRequest request(0, 0, GURL(), 1986 content::MediaStreamRequest request(0, 0, GURL(),
1987 content::MEDIA_OPEN_DEVICE, "fake_dev", 1987 content::MEDIA_OPEN_DEVICE, "fake_dev",
1988 content::MEDIA_NO_SERVICE, 1988 content::MEDIA_NO_SERVICE,
1989 content::MEDIA_DEVICE_VIDEO_CAPTURE); 1989 content::MEDIA_DEVICE_VIDEO_CAPTURE);
1990 TabSpecificContentSettings* content_settings = 1990 TabSpecificContentSettings* content_settings =
1991 TabSpecificContentSettings::FromWebContents( 1991 TabSpecificContentSettings::FromWebContents(
1992 browser()->tab_strip_model()->GetActiveWebContents()); 1992 browser()->tab_strip_model()->GetActiveWebContents());
1993 MediaStreamDevicesController controller( 1993 MediaStreamDevicesController controller(
1994 browser()->profile(), content_settings, request, 1994 browser()->profile(), content_settings, request,
1995 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this)); 1995 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this));
1996 controller.DismissInfoBarAndTakeActionOnSettings(); 1996 controller.DismissInfoBarAndTakeActionOnSettings();
1997 1997
1998 MessageLoop::current()->QuitWhenIdle(); 1998 base::MessageLoop::current()->QuitWhenIdle();
1999 } 1999 }
2000 2000
2001 bool policy_value_; 2001 bool policy_value_;
2002 }; 2002 };
2003 2003
2004 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, 2004 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest,
2005 AudioCaptureAllowed) { 2005 AudioCaptureAllowed) {
2006 content::MediaStreamDevices audio_devices; 2006 content::MediaStreamDevices audio_devices;
2007 content::MediaStreamDevice fake_audio_device( 2007 content::MediaStreamDevice fake_audio_device(
2008 content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev", "Fake Audio Device"); 2008 content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev", "Fake Audio Device");
2009 audio_devices.push_back(fake_audio_device); 2009 audio_devices.push_back(fake_audio_device);
2010 2010
2011 PolicyMap policies; 2011 PolicyMap policies;
2012 policies.Set(key::kAudioCaptureAllowed, POLICY_LEVEL_MANDATORY, 2012 policies.Set(key::kAudioCaptureAllowed, POLICY_LEVEL_MANDATORY,
2013 POLICY_SCOPE_USER, 2013 POLICY_SCOPE_USER,
2014 base::Value::CreateBooleanValue(policy_value_)); 2014 base::Value::CreateBooleanValue(policy_value_));
2015 UpdateProviderPolicy(policies); 2015 UpdateProviderPolicy(policies);
2016 2016
2017 content::BrowserThread::PostTaskAndReply( 2017 content::BrowserThread::PostTaskAndReply(
2018 content::BrowserThread::IO, FROM_HERE, 2018 content::BrowserThread::IO, FROM_HERE,
2019 base::Bind(&MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged, 2019 base::Bind(&MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged,
2020 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), 2020 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()),
2021 audio_devices), 2021 audio_devices),
2022 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishAudioTest, 2022 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishAudioTest,
2023 this)); 2023 this));
2024 2024
2025 MessageLoop::current()->Run(); 2025 base::MessageLoop::current()->Run();
2026 } 2026 }
2027 2027
2028 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, 2028 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest,
2029 VideoCaptureAllowed) { 2029 VideoCaptureAllowed) {
2030 content::MediaStreamDevices video_devices; 2030 content::MediaStreamDevices video_devices;
2031 content::MediaStreamDevice fake_video_device( 2031 content::MediaStreamDevice fake_video_device(
2032 content::MEDIA_DEVICE_VIDEO_CAPTURE, "fake_dev", "Fake Video Device"); 2032 content::MEDIA_DEVICE_VIDEO_CAPTURE, "fake_dev", "Fake Video Device");
2033 video_devices.push_back(fake_video_device); 2033 video_devices.push_back(fake_video_device);
2034 2034
2035 PolicyMap policies; 2035 PolicyMap policies;
2036 policies.Set(key::kVideoCaptureAllowed, POLICY_LEVEL_MANDATORY, 2036 policies.Set(key::kVideoCaptureAllowed, POLICY_LEVEL_MANDATORY,
2037 POLICY_SCOPE_USER, 2037 POLICY_SCOPE_USER,
2038 base::Value::CreateBooleanValue(policy_value_)); 2038 base::Value::CreateBooleanValue(policy_value_));
2039 UpdateProviderPolicy(policies); 2039 UpdateProviderPolicy(policies);
2040 2040
2041 content::BrowserThread::PostTaskAndReply( 2041 content::BrowserThread::PostTaskAndReply(
2042 content::BrowserThread::IO, FROM_HERE, 2042 content::BrowserThread::IO, FROM_HERE,
2043 base::Bind(&MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged, 2043 base::Bind(&MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged,
2044 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), 2044 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()),
2045 video_devices), 2045 video_devices),
2046 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishVideoTest, 2046 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishVideoTest,
2047 this)); 2047 this));
2048 2048
2049 MessageLoop::current()->Run(); 2049 base::MessageLoop::current()->Run();
2050 } 2050 }
2051 2051
2052 INSTANTIATE_TEST_CASE_P(MediaStreamDevicesControllerBrowserTestInstance, 2052 INSTANTIATE_TEST_CASE_P(MediaStreamDevicesControllerBrowserTestInstance,
2053 MediaStreamDevicesControllerBrowserTest, 2053 MediaStreamDevicesControllerBrowserTest,
2054 testing::Bool()); 2054 testing::Bool());
2055 2055
2056 #if !defined(OS_CHROMEOS) 2056 #if !defined(OS_CHROMEOS)
2057 // Similar to PolicyTest but sets the proper policy before the browser is 2057 // Similar to PolicyTest but sets the proper policy before the browser is
2058 // started. 2058 // started.
2059 class PolicyVariationsServiceTest : public PolicyTest { 2059 class PolicyVariationsServiceTest : public PolicyTest {
(...skipping 16 matching lines...) Expand all
2076 GetDefaultVariationsServerURLForTesting(); 2076 GetDefaultVariationsServerURLForTesting();
2077 2077
2078 // Policy is applied and pref is already updated in local state. 2078 // Policy is applied and pref is already updated in local state.
2079 EXPECT_EQ(default_variations_url + "?restrict=restricted", 2079 EXPECT_EQ(default_variations_url + "?restrict=restricted",
2080 chrome_variations::VariationsService::GetVariationsServerURL( 2080 chrome_variations::VariationsService::GetVariationsServerURL(
2081 g_browser_process->local_state()).spec()); 2081 g_browser_process->local_state()).spec());
2082 } 2082 }
2083 #endif 2083 #endif
2084 2084
2085 } // namespace policy 2085 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698