| Index: content/browser/media/capture/web_contents_video_capture_device_unittest.cc
|
| diff --git a/content/browser/media/capture/web_contents_video_capture_device_unittest.cc b/content/browser/media/capture/web_contents_video_capture_device_unittest.cc
|
| index 162df4bd06302580700812603beffa15ca74dddd..4723c79febed72fff8b054c44f7283921a3a39a1 100644
|
| --- a/content/browser/media/capture/web_contents_video_capture_device_unittest.cc
|
| +++ b/content/browser/media/capture/web_contents_video_capture_device_unittest.cc
|
| @@ -32,6 +32,8 @@
|
| #include "skia/ext/platform_canvas.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "third_party/skia/include/core/SkColor.h"
|
| +#include "ui/gfx/display.h"
|
| +#include "ui/gfx/screen.h"
|
|
|
| namespace content {
|
| namespace {
|
| @@ -39,6 +41,7 @@ namespace {
|
| const int kTestWidth = 320;
|
| const int kTestHeight = 240;
|
| const int kTestFramesPerSecond = 20;
|
| +const float kTestDeviceScaleFactor = 2.0f;
|
| const SkColor kNothingYet = 0xdeadbeef;
|
| const SkColor kNotInterested = ~kNothingYet;
|
|
|
| @@ -466,6 +469,49 @@ class StubClientObserver {
|
| DISALLOW_COPY_AND_ASSIGN(StubClientObserver);
|
| };
|
|
|
| +// A dummy implementation of gfx::Screen, since WebContentsVideoCaptureDevice
|
| +// needs access to a gfx::Display's device scale factor.
|
| +class FakeScreen : public gfx::Screen {
|
| + public:
|
| + FakeScreen() : the_one_display_(0x1337, gfx::Rect(0, 0, 2560, 1440)) {
|
| + the_one_display_.set_device_scale_factor(kTestDeviceScaleFactor);
|
| + }
|
| + virtual ~FakeScreen() {}
|
| +
|
| + // gfx::Screen implementation (only what's needed for testing).
|
| + virtual bool IsDIPEnabled() OVERRIDE { return true; }
|
| + virtual gfx::Point GetCursorScreenPoint() OVERRIDE { return gfx::Point(); }
|
| + virtual gfx::NativeWindow GetWindowUnderCursor() OVERRIDE { return NULL; }
|
| + virtual gfx::NativeWindow GetWindowAtScreenPoint(
|
| + const gfx::Point& point) OVERRIDE { return NULL; }
|
| + virtual int GetNumDisplays() const OVERRIDE { return 1; }
|
| + virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE {
|
| + return std::vector<gfx::Display>(1, the_one_display_);
|
| + }
|
| + virtual gfx::Display GetDisplayNearestWindow(
|
| + gfx::NativeView view) const OVERRIDE {
|
| + return the_one_display_;
|
| + }
|
| + virtual gfx::Display GetDisplayNearestPoint(
|
| + const gfx::Point& point) const OVERRIDE {
|
| + return the_one_display_;
|
| + }
|
| + virtual gfx::Display GetDisplayMatching(
|
| + const gfx::Rect& match_rect) const OVERRIDE {
|
| + return the_one_display_;
|
| + }
|
| + virtual gfx::Display GetPrimaryDisplay() const OVERRIDE {
|
| + return the_one_display_;
|
| + }
|
| + virtual void AddObserver(gfx::DisplayObserver* observer) OVERRIDE {}
|
| + virtual void RemoveObserver(gfx::DisplayObserver* observer) OVERRIDE {}
|
| +
|
| + private:
|
| + gfx::Display the_one_display_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(FakeScreen);
|
| +};
|
| +
|
| // Test harness that sets up a minimal environment with necessary stubs.
|
| class WebContentsVideoCaptureDeviceTest : public testing::Test {
|
| public:
|
| @@ -477,6 +523,9 @@ class WebContentsVideoCaptureDeviceTest : public testing::Test {
|
|
|
| protected:
|
| virtual void SetUp() {
|
| + gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, &fake_screen_);
|
| + ASSERT_EQ(&fake_screen_, gfx::Screen::GetNativeScreen());
|
| +
|
| // TODO(nick): Sadness and woe! Much "mock-the-world" boilerplate could be
|
| // eliminated here, if only we could use RenderViewHostTestHarness. The
|
| // catch is that we need our TestRenderViewHost to support a
|
| @@ -530,10 +579,13 @@ class WebContentsVideoCaptureDeviceTest : public testing::Test {
|
| SiteInstanceImpl::set_render_process_host_factory(NULL);
|
| render_view_host_factory_.reset();
|
| render_process_host_factory_.reset();
|
| +
|
| + gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, NULL);
|
| }
|
|
|
| // Accessors.
|
| CaptureTestSourceController* source() { return &controller_; }
|
| + WebContents* web_contents() const { return web_contents_.get(); }
|
| media::VideoCaptureDevice* device() { return device_.get(); }
|
|
|
| void SimulateDrawEvent() {
|
| @@ -558,6 +610,8 @@ class WebContentsVideoCaptureDeviceTest : public testing::Test {
|
| }
|
|
|
| private:
|
| + FakeScreen fake_screen_;
|
| +
|
| StubClientObserver client_observer_;
|
|
|
| // The controller controls which pixel patterns to produce.
|
| @@ -597,6 +651,11 @@ TEST_F(WebContentsVideoCaptureDeviceTest, InvalidInitialWebContentsError) {
|
| }
|
|
|
| TEST_F(WebContentsVideoCaptureDeviceTest, WebContentsDestroyed) {
|
| + const gfx::Size capture_preferred_size(
|
| + static_cast<int>(kTestWidth / kTestDeviceScaleFactor),
|
| + static_cast<int>(kTestHeight / kTestDeviceScaleFactor));
|
| + ASSERT_NE(capture_preferred_size, web_contents()->GetPreferredSize());
|
| +
|
| // We'll simulate the tab being closed after the capture pipeline is up and
|
| // running.
|
| media::VideoCaptureParams capture_params;
|
| @@ -612,6 +671,10 @@ TEST_F(WebContentsVideoCaptureDeviceTest, WebContentsDestroyed) {
|
|
|
| base::RunLoop().RunUntilIdle();
|
|
|
| + // Check that the preferred size of the WebContents matches the one provided
|
| + // by WebContentsVideoCaptureDevice.
|
| + EXPECT_EQ(capture_preferred_size, web_contents()->GetPreferredSize());
|
| +
|
| // Post a task to close the tab. We should see an error reported to the
|
| // consumer.
|
| BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
|
|