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

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: rebase again Created 7 years, 7 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 195 }
196 196
197 // While |MakeRequestFail| is in scope URLRequests to |host| will fail. 197 // While |MakeRequestFail| is in scope URLRequests to |host| will fail.
198 class MakeRequestFail { 198 class MakeRequestFail {
199 public: 199 public:
200 // Sets up the filter on IO thread such that requests to |host| fail. 200 // Sets up the filter on IO thread such that requests to |host| fail.
201 explicit MakeRequestFail(const std::string& host) : host_(host) { 201 explicit MakeRequestFail(const std::string& host) : host_(host) {
202 BrowserThread::PostTaskAndReply( 202 BrowserThread::PostTaskAndReply(
203 BrowserThread::IO, FROM_HERE, 203 BrowserThread::IO, FROM_HERE,
204 base::Bind(MakeRequestFailOnIO, host_), 204 base::Bind(MakeRequestFailOnIO, host_),
205 MessageLoop::QuitClosure()); 205 base::MessageLoop::QuitClosure());
206 content::RunMessageLoop(); 206 content::RunMessageLoop();
207 } 207 }
208 ~MakeRequestFail() { 208 ~MakeRequestFail() {
209 BrowserThread::PostTaskAndReply( 209 BrowserThread::PostTaskAndReply(
210 BrowserThread::IO, FROM_HERE, 210 BrowserThread::IO, FROM_HERE,
211 base::Bind(UndoMakeRequestFailOnIO, host_), 211 base::Bind(UndoMakeRequestFailOnIO, host_),
212 MessageLoop::QuitClosure()); 212 base::MessageLoop::QuitClosure());
213 content::RunMessageLoop(); 213 content::RunMessageLoop();
214 } 214 }
215 215
216 private: 216 private:
217 // Filters requests to the |host| such that they fail. Run on IO thread. 217 // Filters requests to the |host| such that they fail. Run on IO thread.
218 static void MakeRequestFailOnIO(const std::string& host) { 218 static void MakeRequestFailOnIO(const std::string& host) {
219 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); 219 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance();
220 filter->AddHostnameHandler("http", host, &FailedJobFactory); 220 filter->AddHostnameHandler("http", host, &FailedJobFactory);
221 filter->AddHostnameHandler("https", host, &FailedJobFactory); 221 filter->AddHostnameHandler("https", host, &FailedJobFactory);
222 } 222 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 contents->GetRenderViewHost(), "123"); 319 contents->GetRenderViewHost(), "123");
320 int result = 0; 320 int result = 0;
321 if (!value->GetAsInteger(&result)) 321 if (!value->GetAsInteger(&result))
322 EXPECT_EQ(base::Value::TYPE_NULL, value->GetType()); 322 EXPECT_EQ(base::Value::TYPE_NULL, value->GetType());
323 return result == 123; 323 return result == 123;
324 } 324 }
325 325
326 void CopyPluginListAndQuit(std::vector<webkit::WebPluginInfo>* out, 326 void CopyPluginListAndQuit(std::vector<webkit::WebPluginInfo>* out,
327 const std::vector<webkit::WebPluginInfo>& in) { 327 const std::vector<webkit::WebPluginInfo>& in) {
328 *out = in; 328 *out = in;
329 MessageLoop::current()->QuitWhenIdle(); 329 base::MessageLoop::current()->QuitWhenIdle();
330 } 330 }
331 331
332 template<typename T> 332 template<typename T>
333 void CopyValueAndQuit(T* out, T in) { 333 void CopyValueAndQuit(T* out, T in) {
334 *out = in; 334 *out = in;
335 MessageLoop::current()->QuitWhenIdle(); 335 base::MessageLoop::current()->QuitWhenIdle();
336 } 336 }
337 337
338 void GetPluginList(std::vector<webkit::WebPluginInfo>* plugins) { 338 void GetPluginList(std::vector<webkit::WebPluginInfo>* plugins) {
339 content::PluginService* service = content::PluginService::GetInstance(); 339 content::PluginService* service = content::PluginService::GetInstance();
340 service->GetPlugins(base::Bind(CopyPluginListAndQuit, plugins)); 340 service->GetPlugins(base::Bind(CopyPluginListAndQuit, plugins));
341 content::RunMessageLoop(); 341 content::RunMessageLoop();
342 } 342 }
343 343
344 const webkit::WebPluginInfo* GetFlashPlugin( 344 const webkit::WebPluginInfo* GetFlashPlugin(
345 const std::vector<webkit::WebPluginInfo>& plugins) { 345 const std::vector<webkit::WebPluginInfo>& plugins) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 } 448 }
449 449
450 // Makes URLRequestMockHTTPJobs serve data from content::DIR_TEST_DATA 450 // Makes URLRequestMockHTTPJobs serve data from content::DIR_TEST_DATA
451 // instead of chrome::DIR_TEST_DATA. 451 // instead of chrome::DIR_TEST_DATA.
452 void ServeContentTestData() { 452 void ServeContentTestData() {
453 base::FilePath root_http; 453 base::FilePath root_http;
454 PathService::Get(content::DIR_TEST_DATA, &root_http); 454 PathService::Get(content::DIR_TEST_DATA, &root_http);
455 BrowserThread::PostTaskAndReply( 455 BrowserThread::PostTaskAndReply(
456 BrowserThread::IO, FROM_HERE, 456 BrowserThread::IO, FROM_HERE,
457 base::Bind(URLRequestMockHTTPJob::AddUrlHandler, root_http), 457 base::Bind(URLRequestMockHTTPJob::AddUrlHandler, root_http),
458 MessageLoop::current()->QuitWhenIdleClosure()); 458 base::MessageLoop::current()->QuitWhenIdleClosure());
459 content::RunMessageLoop(); 459 content::RunMessageLoop();
460 } 460 }
461 461
462 void SetScreenshotPolicy(bool enabled) { 462 void SetScreenshotPolicy(bool enabled) {
463 PolicyMap policies; 463 PolicyMap policies;
464 policies.Set(key::kDisableScreenshots, POLICY_LEVEL_MANDATORY, 464 policies.Set(key::kDisableScreenshots, POLICY_LEVEL_MANDATORY,
465 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(!enabled)); 465 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(!enabled));
466 UpdateProviderPolicy(policies); 466 UpdateProviderPolicy(policies);
467 } 467 }
468 468
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 void TestScreenshotFile(bool enabled) { 517 void TestScreenshotFile(bool enabled) {
518 SetScreenshotPolicy(enabled); 518 SetScreenshotPolicy(enabled);
519 ash::Shell::GetInstance()->accelerator_controller()->PerformAction( 519 ash::Shell::GetInstance()->accelerator_controller()->PerformAction(
520 ash::TAKE_SCREENSHOT, ui::Accelerator()); 520 ash::TAKE_SCREENSHOT, ui::Accelerator());
521 521
522 // TAKE_SCREENSHOT handler posts write file task on success, wait for it. 522 // TAKE_SCREENSHOT handler posts write file task on success, wait for it.
523 BrowserThread::PostTaskAndReply( 523 BrowserThread::PostTaskAndReply(
524 BrowserThread::IO, 524 BrowserThread::IO,
525 FROM_HERE, 525 FROM_HERE,
526 base::Bind(base::DoNothing), 526 base::Bind(base::DoNothing),
527 MessageLoop::QuitClosure()); 527 base::MessageLoop::QuitClosure());
528 content::RunMessageLoop(); 528 content::RunMessageLoop();
529 } 529 }
530 #endif 530 #endif
531 531
532 ExtensionService* extension_service() { 532 ExtensionService* extension_service() {
533 extensions::ExtensionSystem* system = 533 extensions::ExtensionSystem* system =
534 extensions::ExtensionSystem::Get(browser()->profile()); 534 extensions::ExtensionSystem::Get(browser()->profile());
535 return system->extension_service(); 535 return system->extension_service();
536 } 536 }
537 537
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 content::WindowedNotificationObserver observer( 572 content::WindowedNotificationObserver observer(
573 expect_success ? chrome::NOTIFICATION_EXTENSION_UNINSTALLED 573 expect_success ? chrome::NOTIFICATION_EXTENSION_UNINSTALLED
574 : chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, 574 : chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED,
575 content::NotificationService::AllSources()); 575 content::NotificationService::AllSources());
576 extension_service()->UninstallExtension(id, false, NULL); 576 extension_service()->UninstallExtension(id, false, NULL);
577 observer.Wait(); 577 observer.Wait();
578 } 578 }
579 579
580 void UpdateProviderPolicy(const PolicyMap& policy) { 580 void UpdateProviderPolicy(const PolicyMap& policy) {
581 provider_.UpdateChromePolicy(policy); 581 provider_.UpdateChromePolicy(policy);
582 DCHECK(MessageLoop::current()); 582 DCHECK(base::MessageLoop::current());
583 base::RunLoop loop; 583 base::RunLoop loop;
584 loop.RunUntilIdle(); 584 loop.RunUntilIdle();
585 } 585 }
586 586
587 // Sends a mouse click at the given coordinates to the current renderer. 587 // Sends a mouse click at the given coordinates to the current renderer.
588 void PerformClick(int x, int y) { 588 void PerformClick(int x, int y) {
589 content::WebContents* contents = 589 content::WebContents* contents =
590 browser()->tab_strip_model()->GetActiveWebContents(); 590 browser()->tab_strip_model()->GetActiveWebContents();
591 WebKit::WebMouseEvent click_event; 591 WebKit::WebMouseEvent click_event;
592 click_event.type = WebKit::WebInputEvent::MouseDown; 592 click_event.type = WebKit::WebInputEvent::MouseDown;
(...skipping 1417 matching lines...) Expand 10 before | Expand all | Expand 10 after
2010 void FinishAudioTest() { 2010 void FinishAudioTest() {
2011 content::MediaStreamRequest request(0, 0, GURL(), 2011 content::MediaStreamRequest request(0, 0, GURL(),
2012 content::MEDIA_OPEN_DEVICE, "fake_dev", 2012 content::MEDIA_OPEN_DEVICE, "fake_dev",
2013 content::MEDIA_DEVICE_AUDIO_CAPTURE, 2013 content::MEDIA_DEVICE_AUDIO_CAPTURE,
2014 content::MEDIA_NO_SERVICE); 2014 content::MEDIA_NO_SERVICE);
2015 MediaStreamDevicesController controller( 2015 MediaStreamDevicesController controller(
2016 browser()->tab_strip_model()->GetActiveWebContents(), request, 2016 browser()->tab_strip_model()->GetActiveWebContents(), request,
2017 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this)); 2017 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this));
2018 controller.DismissInfoBarAndTakeActionOnSettings(); 2018 controller.DismissInfoBarAndTakeActionOnSettings();
2019 2019
2020 MessageLoop::current()->QuitWhenIdle(); 2020 base::MessageLoop::current()->QuitWhenIdle();
2021 } 2021 }
2022 2022
2023 void FinishVideoTest() { 2023 void FinishVideoTest() {
2024 content::MediaStreamRequest request(0, 0, GURL(), 2024 content::MediaStreamRequest request(0, 0, GURL(),
2025 content::MEDIA_OPEN_DEVICE, "fake_dev", 2025 content::MEDIA_OPEN_DEVICE, "fake_dev",
2026 content::MEDIA_NO_SERVICE, 2026 content::MEDIA_NO_SERVICE,
2027 content::MEDIA_DEVICE_VIDEO_CAPTURE); 2027 content::MEDIA_DEVICE_VIDEO_CAPTURE);
2028 MediaStreamDevicesController controller( 2028 MediaStreamDevicesController controller(
2029 browser()->tab_strip_model()->GetActiveWebContents(), request, 2029 browser()->tab_strip_model()->GetActiveWebContents(), request,
2030 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this)); 2030 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this));
2031 controller.DismissInfoBarAndTakeActionOnSettings(); 2031 controller.DismissInfoBarAndTakeActionOnSettings();
2032 2032
2033 MessageLoop::current()->QuitWhenIdle(); 2033 base::MessageLoop::current()->QuitWhenIdle();
2034 } 2034 }
2035 2035
2036 bool policy_value_; 2036 bool policy_value_;
2037 }; 2037 };
2038 2038
2039 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, 2039 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest,
2040 AudioCaptureAllowed) { 2040 AudioCaptureAllowed) {
2041 content::MediaStreamDevices audio_devices; 2041 content::MediaStreamDevices audio_devices;
2042 content::MediaStreamDevice fake_audio_device( 2042 content::MediaStreamDevice fake_audio_device(
2043 content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev", "Fake Audio Device"); 2043 content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev", "Fake Audio Device");
2044 audio_devices.push_back(fake_audio_device); 2044 audio_devices.push_back(fake_audio_device);
2045 2045
2046 PolicyMap policies; 2046 PolicyMap policies;
2047 policies.Set(key::kAudioCaptureAllowed, POLICY_LEVEL_MANDATORY, 2047 policies.Set(key::kAudioCaptureAllowed, POLICY_LEVEL_MANDATORY,
2048 POLICY_SCOPE_USER, 2048 POLICY_SCOPE_USER,
2049 base::Value::CreateBooleanValue(policy_value_)); 2049 base::Value::CreateBooleanValue(policy_value_));
2050 UpdateProviderPolicy(policies); 2050 UpdateProviderPolicy(policies);
2051 2051
2052 content::BrowserThread::PostTaskAndReply( 2052 content::BrowserThread::PostTaskAndReply(
2053 content::BrowserThread::IO, FROM_HERE, 2053 content::BrowserThread::IO, FROM_HERE,
2054 base::Bind(&MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged, 2054 base::Bind(&MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged,
2055 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), 2055 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()),
2056 audio_devices), 2056 audio_devices),
2057 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishAudioTest, 2057 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishAudioTest,
2058 this)); 2058 this));
2059 2059
2060 MessageLoop::current()->Run(); 2060 base::MessageLoop::current()->Run();
2061 } 2061 }
2062 2062
2063 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, 2063 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest,
2064 VideoCaptureAllowed) { 2064 VideoCaptureAllowed) {
2065 content::MediaStreamDevices video_devices; 2065 content::MediaStreamDevices video_devices;
2066 content::MediaStreamDevice fake_video_device( 2066 content::MediaStreamDevice fake_video_device(
2067 content::MEDIA_DEVICE_VIDEO_CAPTURE, "fake_dev", "Fake Video Device"); 2067 content::MEDIA_DEVICE_VIDEO_CAPTURE, "fake_dev", "Fake Video Device");
2068 video_devices.push_back(fake_video_device); 2068 video_devices.push_back(fake_video_device);
2069 2069
2070 PolicyMap policies; 2070 PolicyMap policies;
2071 policies.Set(key::kVideoCaptureAllowed, POLICY_LEVEL_MANDATORY, 2071 policies.Set(key::kVideoCaptureAllowed, POLICY_LEVEL_MANDATORY,
2072 POLICY_SCOPE_USER, 2072 POLICY_SCOPE_USER,
2073 base::Value::CreateBooleanValue(policy_value_)); 2073 base::Value::CreateBooleanValue(policy_value_));
2074 UpdateProviderPolicy(policies); 2074 UpdateProviderPolicy(policies);
2075 2075
2076 content::BrowserThread::PostTaskAndReply( 2076 content::BrowserThread::PostTaskAndReply(
2077 content::BrowserThread::IO, FROM_HERE, 2077 content::BrowserThread::IO, FROM_HERE,
2078 base::Bind(&MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged, 2078 base::Bind(&MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged,
2079 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), 2079 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()),
2080 video_devices), 2080 video_devices),
2081 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishVideoTest, 2081 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishVideoTest,
2082 this)); 2082 this));
2083 2083
2084 MessageLoop::current()->Run(); 2084 base::MessageLoop::current()->Run();
2085 } 2085 }
2086 2086
2087 INSTANTIATE_TEST_CASE_P(MediaStreamDevicesControllerBrowserTestInstance, 2087 INSTANTIATE_TEST_CASE_P(MediaStreamDevicesControllerBrowserTestInstance,
2088 MediaStreamDevicesControllerBrowserTest, 2088 MediaStreamDevicesControllerBrowserTest,
2089 testing::Bool()); 2089 testing::Bool());
2090 2090
2091 #if !defined(OS_CHROMEOS) 2091 #if !defined(OS_CHROMEOS)
2092 // Similar to PolicyTest but sets the proper policy before the browser is 2092 // Similar to PolicyTest but sets the proper policy before the browser is
2093 // started. 2093 // started.
2094 class PolicyVariationsServiceTest : public PolicyTest { 2094 class PolicyVariationsServiceTest : public PolicyTest {
(...skipping 19 matching lines...) Expand all
2114 chrome_variations::VariationsService::GetVariationsServerURL( 2114 chrome_variations::VariationsService::GetVariationsServerURL(
2115 g_browser_process->local_state()); 2115 g_browser_process->local_state());
2116 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); 2116 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true));
2117 std::string value; 2117 std::string value;
2118 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); 2118 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value));
2119 EXPECT_EQ("restricted", value); 2119 EXPECT_EQ("restricted", value);
2120 } 2120 }
2121 #endif 2121 #endif
2122 2122
2123 } // namespace policy 2123 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698