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 <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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 } | 196 } |
197 | 197 |
198 // While |MakeRequestFail| is in scope URLRequests to |host| will fail. | 198 // While |MakeRequestFail| is in scope URLRequests to |host| will fail. |
199 class MakeRequestFail { | 199 class MakeRequestFail { |
200 public: | 200 public: |
201 // Sets up the filter on IO thread such that requests to |host| fail. | 201 // Sets up the filter on IO thread such that requests to |host| fail. |
202 explicit MakeRequestFail(const std::string& host) : host_(host) { | 202 explicit MakeRequestFail(const std::string& host) : host_(host) { |
203 BrowserThread::PostTaskAndReply( | 203 BrowserThread::PostTaskAndReply( |
204 BrowserThread::IO, FROM_HERE, | 204 BrowserThread::IO, FROM_HERE, |
205 base::Bind(MakeRequestFailOnIO, host_), | 205 base::Bind(MakeRequestFailOnIO, host_), |
206 MessageLoop::QuitClosure()); | 206 base::MessageLoop::QuitClosure()); |
207 content::RunMessageLoop(); | 207 content::RunMessageLoop(); |
208 } | 208 } |
209 ~MakeRequestFail() { | 209 ~MakeRequestFail() { |
210 BrowserThread::PostTaskAndReply( | 210 BrowserThread::PostTaskAndReply( |
211 BrowserThread::IO, FROM_HERE, | 211 BrowserThread::IO, FROM_HERE, |
212 base::Bind(UndoMakeRequestFailOnIO, host_), | 212 base::Bind(UndoMakeRequestFailOnIO, host_), |
213 MessageLoop::QuitClosure()); | 213 base::MessageLoop::QuitClosure()); |
214 content::RunMessageLoop(); | 214 content::RunMessageLoop(); |
215 } | 215 } |
216 | 216 |
217 private: | 217 private: |
218 // Filters requests to the |host| such that they fail. Run on IO thread. | 218 // Filters requests to the |host| such that they fail. Run on IO thread. |
219 static void MakeRequestFailOnIO(const std::string& host) { | 219 static void MakeRequestFailOnIO(const std::string& host) { |
220 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); | 220 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); |
221 filter->AddHostnameHandler("http", host, &FailedJobFactory); | 221 filter->AddHostnameHandler("http", host, &FailedJobFactory); |
222 filter->AddHostnameHandler("https", host, &FailedJobFactory); | 222 filter->AddHostnameHandler("https", host, &FailedJobFactory); |
223 } | 223 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 contents->GetRenderViewHost(), "123"); | 320 contents->GetRenderViewHost(), "123"); |
321 int result = 0; | 321 int result = 0; |
322 if (!value->GetAsInteger(&result)) | 322 if (!value->GetAsInteger(&result)) |
323 EXPECT_EQ(base::Value::TYPE_NULL, value->GetType()); | 323 EXPECT_EQ(base::Value::TYPE_NULL, value->GetType()); |
324 return result == 123; | 324 return result == 123; |
325 } | 325 } |
326 | 326 |
327 void CopyPluginListAndQuit(std::vector<webkit::WebPluginInfo>* out, | 327 void CopyPluginListAndQuit(std::vector<webkit::WebPluginInfo>* out, |
328 const std::vector<webkit::WebPluginInfo>& in) { | 328 const std::vector<webkit::WebPluginInfo>& in) { |
329 *out = in; | 329 *out = in; |
330 MessageLoop::current()->QuitWhenIdle(); | 330 base::MessageLoop::current()->QuitWhenIdle(); |
331 } | 331 } |
332 | 332 |
333 template<typename T> | 333 template<typename T> |
334 void CopyValueAndQuit(T* out, T in) { | 334 void CopyValueAndQuit(T* out, T in) { |
335 *out = in; | 335 *out = in; |
336 MessageLoop::current()->QuitWhenIdle(); | 336 base::MessageLoop::current()->QuitWhenIdle(); |
337 } | 337 } |
338 | 338 |
339 void GetPluginList(std::vector<webkit::WebPluginInfo>* plugins) { | 339 void GetPluginList(std::vector<webkit::WebPluginInfo>* plugins) { |
340 content::PluginService* service = content::PluginService::GetInstance(); | 340 content::PluginService* service = content::PluginService::GetInstance(); |
341 service->GetPlugins(base::Bind(CopyPluginListAndQuit, plugins)); | 341 service->GetPlugins(base::Bind(CopyPluginListAndQuit, plugins)); |
342 content::RunMessageLoop(); | 342 content::RunMessageLoop(); |
343 } | 343 } |
344 | 344 |
345 const webkit::WebPluginInfo* GetFlashPlugin( | 345 const webkit::WebPluginInfo* GetFlashPlugin( |
346 const std::vector<webkit::WebPluginInfo>& plugins) { | 346 const std::vector<webkit::WebPluginInfo>& plugins) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 } | 449 } |
450 | 450 |
451 // Makes URLRequestMockHTTPJobs serve data from content::DIR_TEST_DATA | 451 // Makes URLRequestMockHTTPJobs serve data from content::DIR_TEST_DATA |
452 // instead of chrome::DIR_TEST_DATA. | 452 // instead of chrome::DIR_TEST_DATA. |
453 void ServeContentTestData() { | 453 void ServeContentTestData() { |
454 base::FilePath root_http; | 454 base::FilePath root_http; |
455 PathService::Get(content::DIR_TEST_DATA, &root_http); | 455 PathService::Get(content::DIR_TEST_DATA, &root_http); |
456 BrowserThread::PostTaskAndReply( | 456 BrowserThread::PostTaskAndReply( |
457 BrowserThread::IO, FROM_HERE, | 457 BrowserThread::IO, FROM_HERE, |
458 base::Bind(URLRequestMockHTTPJob::AddUrlHandler, root_http), | 458 base::Bind(URLRequestMockHTTPJob::AddUrlHandler, root_http), |
459 MessageLoop::current()->QuitWhenIdleClosure()); | 459 base::MessageLoop::current()->QuitWhenIdleClosure()); |
460 content::RunMessageLoop(); | 460 content::RunMessageLoop(); |
461 } | 461 } |
462 | 462 |
463 void SetScreenshotPolicy(bool enabled) { | 463 void SetScreenshotPolicy(bool enabled) { |
464 PolicyMap policies; | 464 PolicyMap policies; |
465 policies.Set(key::kDisableScreenshots, POLICY_LEVEL_MANDATORY, | 465 policies.Set(key::kDisableScreenshots, POLICY_LEVEL_MANDATORY, |
466 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(!enabled)); | 466 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(!enabled)); |
467 UpdateProviderPolicy(policies); | 467 UpdateProviderPolicy(policies); |
468 } | 468 } |
469 | 469 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 void TestScreenshotFile(bool enabled) { | 518 void TestScreenshotFile(bool enabled) { |
519 SetScreenshotPolicy(enabled); | 519 SetScreenshotPolicy(enabled); |
520 ash::Shell::GetInstance()->accelerator_controller()->PerformAction( | 520 ash::Shell::GetInstance()->accelerator_controller()->PerformAction( |
521 ash::TAKE_SCREENSHOT, ui::Accelerator()); | 521 ash::TAKE_SCREENSHOT, ui::Accelerator()); |
522 | 522 |
523 // TAKE_SCREENSHOT handler posts write file task on success, wait for it. | 523 // TAKE_SCREENSHOT handler posts write file task on success, wait for it. |
524 BrowserThread::PostTaskAndReply( | 524 BrowserThread::PostTaskAndReply( |
525 BrowserThread::IO, | 525 BrowserThread::IO, |
526 FROM_HERE, | 526 FROM_HERE, |
527 base::Bind(base::DoNothing), | 527 base::Bind(base::DoNothing), |
528 MessageLoop::QuitClosure()); | 528 base::MessageLoop::QuitClosure()); |
529 content::RunMessageLoop(); | 529 content::RunMessageLoop(); |
530 } | 530 } |
531 #endif | 531 #endif |
532 | 532 |
533 ExtensionService* extension_service() { | 533 ExtensionService* extension_service() { |
534 extensions::ExtensionSystem* system = | 534 extensions::ExtensionSystem* system = |
535 extensions::ExtensionSystem::Get(browser()->profile()); | 535 extensions::ExtensionSystem::Get(browser()->profile()); |
536 return system->extension_service(); | 536 return system->extension_service(); |
537 } | 537 } |
538 | 538 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 content::WindowedNotificationObserver observer( | 573 content::WindowedNotificationObserver observer( |
574 expect_success ? chrome::NOTIFICATION_EXTENSION_UNINSTALLED | 574 expect_success ? chrome::NOTIFICATION_EXTENSION_UNINSTALLED |
575 : chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, | 575 : chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, |
576 content::NotificationService::AllSources()); | 576 content::NotificationService::AllSources()); |
577 extension_service()->UninstallExtension(id, false, NULL); | 577 extension_service()->UninstallExtension(id, false, NULL); |
578 observer.Wait(); | 578 observer.Wait(); |
579 } | 579 } |
580 | 580 |
581 void UpdateProviderPolicy(const PolicyMap& policy) { | 581 void UpdateProviderPolicy(const PolicyMap& policy) { |
582 provider_.UpdateChromePolicy(policy); | 582 provider_.UpdateChromePolicy(policy); |
583 DCHECK(MessageLoop::current()); | 583 DCHECK(base::MessageLoop::current()); |
584 base::RunLoop loop; | 584 base::RunLoop loop; |
585 loop.RunUntilIdle(); | 585 loop.RunUntilIdle(); |
586 } | 586 } |
587 | 587 |
588 // Sends a mouse click at the given coordinates to the current renderer. | 588 // Sends a mouse click at the given coordinates to the current renderer. |
589 void PerformClick(int x, int y) { | 589 void PerformClick(int x, int y) { |
590 content::WebContents* contents = | 590 content::WebContents* contents = |
591 browser()->tab_strip_model()->GetActiveWebContents(); | 591 browser()->tab_strip_model()->GetActiveWebContents(); |
592 WebKit::WebMouseEvent click_event; | 592 WebKit::WebMouseEvent click_event; |
593 click_event.type = WebKit::WebInputEvent::MouseDown; | 593 click_event.type = WebKit::WebInputEvent::MouseDown; |
(...skipping 1456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2050 void FinishAudioTest() { | 2050 void FinishAudioTest() { |
2051 content::MediaStreamRequest request(0, 0, request_url_.GetOrigin(), | 2051 content::MediaStreamRequest request(0, 0, request_url_.GetOrigin(), |
2052 content::MEDIA_OPEN_DEVICE, "fake_dev", | 2052 content::MEDIA_OPEN_DEVICE, "fake_dev", |
2053 content::MEDIA_DEVICE_AUDIO_CAPTURE, | 2053 content::MEDIA_DEVICE_AUDIO_CAPTURE, |
2054 content::MEDIA_NO_SERVICE); | 2054 content::MEDIA_NO_SERVICE); |
2055 MediaStreamDevicesController controller( | 2055 MediaStreamDevicesController controller( |
2056 browser()->tab_strip_model()->GetActiveWebContents(), request, | 2056 browser()->tab_strip_model()->GetActiveWebContents(), request, |
2057 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this)); | 2057 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this)); |
2058 controller.DismissInfoBarAndTakeActionOnSettings(); | 2058 controller.DismissInfoBarAndTakeActionOnSettings(); |
2059 | 2059 |
2060 MessageLoop::current()->QuitWhenIdle(); | 2060 base::MessageLoop::current()->QuitWhenIdle(); |
2061 } | 2061 } |
2062 | 2062 |
2063 void FinishVideoTest() { | 2063 void FinishVideoTest() { |
2064 content::MediaStreamRequest request(0, 0, request_url_.GetOrigin(), | 2064 content::MediaStreamRequest request(0, 0, request_url_.GetOrigin(), |
2065 content::MEDIA_OPEN_DEVICE, "fake_dev", | 2065 content::MEDIA_OPEN_DEVICE, "fake_dev", |
2066 content::MEDIA_NO_SERVICE, | 2066 content::MEDIA_NO_SERVICE, |
2067 content::MEDIA_DEVICE_VIDEO_CAPTURE); | 2067 content::MEDIA_DEVICE_VIDEO_CAPTURE); |
2068 MediaStreamDevicesController controller( | 2068 MediaStreamDevicesController controller( |
2069 browser()->tab_strip_model()->GetActiveWebContents(), request, | 2069 browser()->tab_strip_model()->GetActiveWebContents(), request, |
2070 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this)); | 2070 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this)); |
2071 controller.DismissInfoBarAndTakeActionOnSettings(); | 2071 controller.DismissInfoBarAndTakeActionOnSettings(); |
2072 | 2072 |
2073 MessageLoop::current()->QuitWhenIdle(); | 2073 base::MessageLoop::current()->QuitWhenIdle(); |
2074 } | 2074 } |
2075 | 2075 |
2076 bool policy_value_; | 2076 bool policy_value_; |
2077 bool request_url_allowed_via_whitelist_; | 2077 bool request_url_allowed_via_whitelist_; |
2078 GURL request_url_; | 2078 GURL request_url_; |
2079 static const char kExampleRequestPattern[]; | 2079 static const char kExampleRequestPattern[]; |
2080 }; | 2080 }; |
2081 | 2081 |
2082 // static | 2082 // static |
2083 const char MediaStreamDevicesControllerBrowserTest::kExampleRequestPattern[] = | 2083 const char MediaStreamDevicesControllerBrowserTest::kExampleRequestPattern[] = |
(...skipping 11 matching lines...) Expand all Loading... |
2095 UpdateProviderPolicy(policies); | 2095 UpdateProviderPolicy(policies); |
2096 | 2096 |
2097 content::BrowserThread::PostTaskAndReply( | 2097 content::BrowserThread::PostTaskAndReply( |
2098 content::BrowserThread::IO, FROM_HERE, | 2098 content::BrowserThread::IO, FROM_HERE, |
2099 base::Bind(&MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged, | 2099 base::Bind(&MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged, |
2100 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), | 2100 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), |
2101 audio_devices), | 2101 audio_devices), |
2102 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishAudioTest, | 2102 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishAudioTest, |
2103 this)); | 2103 this)); |
2104 | 2104 |
2105 MessageLoop::current()->Run(); | 2105 base::MessageLoop::current()->Run(); |
2106 } | 2106 } |
2107 | 2107 |
2108 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, | 2108 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, |
2109 AudioCaptureAllowedUrls) { | 2109 AudioCaptureAllowedUrls) { |
2110 content::MediaStreamDevices audio_devices; | 2110 content::MediaStreamDevices audio_devices; |
2111 content::MediaStreamDevice fake_audio_device( | 2111 content::MediaStreamDevice fake_audio_device( |
2112 content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev", "Fake Audio Device"); | 2112 content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev", "Fake Audio Device"); |
2113 audio_devices.push_back(fake_audio_device); | 2113 audio_devices.push_back(fake_audio_device); |
2114 | 2114 |
2115 const char* allow_pattern[] = { | 2115 const char* allow_pattern[] = { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2152 UpdateProviderPolicy(policies); | 2152 UpdateProviderPolicy(policies); |
2153 | 2153 |
2154 content::BrowserThread::PostTaskAndReply( | 2154 content::BrowserThread::PostTaskAndReply( |
2155 content::BrowserThread::IO, FROM_HERE, | 2155 content::BrowserThread::IO, FROM_HERE, |
2156 base::Bind(&MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged, | 2156 base::Bind(&MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged, |
2157 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), | 2157 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), |
2158 video_devices), | 2158 video_devices), |
2159 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishVideoTest, | 2159 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishVideoTest, |
2160 this)); | 2160 this)); |
2161 | 2161 |
2162 MessageLoop::current()->Run(); | 2162 base::MessageLoop::current()->Run(); |
2163 } | 2163 } |
2164 | 2164 |
2165 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, | 2165 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, |
2166 VideoCaptureAllowedUrls) { | 2166 VideoCaptureAllowedUrls) { |
2167 content::MediaStreamDevices video_devices; | 2167 content::MediaStreamDevices video_devices; |
2168 content::MediaStreamDevice fake_video_device( | 2168 content::MediaStreamDevice fake_video_device( |
2169 content::MEDIA_DEVICE_VIDEO_CAPTURE, "fake_dev", "Fake Video Device"); | 2169 content::MEDIA_DEVICE_VIDEO_CAPTURE, "fake_dev", "Fake Video Device"); |
2170 video_devices.push_back(fake_video_device); | 2170 video_devices.push_back(fake_video_device); |
2171 | 2171 |
2172 const char* allow_pattern[] = { | 2172 const char* allow_pattern[] = { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2227 chrome_variations::VariationsService::GetVariationsServerURL( | 2227 chrome_variations::VariationsService::GetVariationsServerURL( |
2228 g_browser_process->local_state()); | 2228 g_browser_process->local_state()); |
2229 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); | 2229 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); |
2230 std::string value; | 2230 std::string value; |
2231 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); | 2231 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); |
2232 EXPECT_EQ("restricted", value); | 2232 EXPECT_EQ("restricted", value); |
2233 } | 2233 } |
2234 #endif | 2234 #endif |
2235 | 2235 |
2236 } // namespace policy | 2236 } // namespace policy |
OLD | NEW |