OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/command_line.h" |
| 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "content/browser/web_contents/web_contents_impl.h" |
| 8 #include "content/public/common/content_switches.h" |
| 9 #include "content/public/test/browser_test_utils.h" |
| 10 #include "content/public/test/content_browser_test.h" |
| 11 #include "content/public/test/content_browser_test_utils.h" |
| 12 #include "content/public/test/test_utils.h" |
| 13 #include "content/shell/browser/shell.h" |
| 14 #include "media/base/media_switches.h" |
| 15 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 16 |
| 17 namespace { |
| 18 |
| 19 const base::CommandLine::StringType FAKE_DEVICE_FLAG = |
| 20 #if defined(OS_WIN) |
| 21 base::ASCIIToUTF16(switches::kUseFakeDeviceForMediaStream); |
| 22 #else |
| 23 switches::kUseFakeDeviceForMediaStream; |
| 24 #endif |
| 25 |
| 26 bool IsUseFakeDeviceForMediaStream(const base::CommandLine::StringType& arg) { |
| 27 return arg.find(FAKE_DEVICE_FLAG) != std::string::npos; |
| 28 } |
| 29 |
| 30 void RemoveFakeDeviceFromCommandLine(base::CommandLine* command_line) { |
| 31 CommandLine::StringVector argv = command_line->argv(); |
| 32 argv.erase(std::remove_if(argv.begin(), argv.end(), |
| 33 IsUseFakeDeviceForMediaStream), |
| 34 argv.end()); |
| 35 command_line->InitFromArgv(argv); |
| 36 } |
| 37 |
| 38 } // namespace |
| 39 |
| 40 namespace content { |
| 41 |
| 42 // This class doesn't inherit from WebRtcContentBrowserTestBase like the others |
| 43 // since we want it to actually acquire the real webcam on the system (if there |
| 44 // is one). |
| 45 class WebRtcWebcamBrowserTest: public ContentBrowserTest { |
| 46 public: |
| 47 ~WebRtcWebcamBrowserTest() override {} |
| 48 |
| 49 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 50 ASSERT_TRUE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream)); |
| 51 |
| 52 // The content_browsertests run with this flag by default, and this test is |
| 53 // the only current exception to that rule, so just remove the flag |
| 54 // --use-fake-device-for-media-stream here. We could also have all tests |
| 55 // involving media streams add this flag explicitly, but it will be really |
| 56 // unintuitive for developers to write tests involving media stream and have |
| 57 // them fail on what looks like random bots, so running with fake devices |
| 58 // is really a reasonable default. |
| 59 RemoveFakeDeviceFromCommandLine(command_line); |
| 60 } |
| 61 |
| 62 void SetUp() override { |
| 63 EnablePixelOutput(); |
| 64 ContentBrowserTest::SetUp(); |
| 65 } |
| 66 }; |
| 67 |
| 68 // The test is tagged as MANUAL since the webcam is a system-level resource; we |
| 69 // only want it to run on bots where we can ensure sequential execution. The |
| 70 // Android bots will run the test since they ignore MANUAL, but that's what we |
| 71 // want here since the bot runs tests sequentially on the device. |
| 72 IN_PROC_BROWSER_TEST_F(WebRtcWebcamBrowserTest, |
| 73 MANUAL_CanAcquireVgaOnRealWebcam) { |
| 74 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 75 GURL url(embedded_test_server()->GetURL( |
| 76 "/media/getusermedia-real-webcam.html")); |
| 77 NavigateToURL(shell(), url); |
| 78 |
| 79 std::string result; |
| 80 ASSERT_TRUE(ExecuteScriptAndExtractString(shell()->web_contents(), |
| 81 "hasVideoInputDeviceOnSystem()", |
| 82 &result)); |
| 83 if (result != "has-video-input-device") { |
| 84 VLOG(0) << "No video device; skipping test..."; |
| 85 return; |
| 86 } |
| 87 |
| 88 // GetUserMedia should acquire VGA by default. |
| 89 ASSERT_TRUE(ExecuteScriptAndExtractString( |
| 90 shell()->web_contents(), |
| 91 "getUserMediaAndReturnVideoDimensions({video: true})", |
| 92 &result)); |
| 93 |
| 94 if (result == "640x480" || result == "480x640") { |
| 95 // Don't care if the device happens to be in landscape or portrait mode |
| 96 // since we don't know how it is oriented in the lab :) |
| 97 return; |
| 98 } |
| 99 FAIL() << "Expected resolution to be 640x480 or 480x640, got" << result; |
| 100 } |
| 101 |
| 102 } // namespace content |
OLD | NEW |