| Index: content/test/layout_tests/runner/WebUserMediaClientMock.cpp
|
| diff --git a/content/test/layout_tests/runner/WebUserMediaClientMock.cpp b/content/test/layout_tests/runner/WebUserMediaClientMock.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3177715ccf57a1067d86f5aa9e1d77ac42cd3925
|
| --- /dev/null
|
| +++ b/content/test/layout_tests/runner/WebUserMediaClientMock.cpp
|
| @@ -0,0 +1,171 @@
|
| +// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +/*
|
| + * Copyright (C) 2012 Google Inc. All rights reserved.
|
| + *
|
| + * Redistribution and use in source and binary forms, with or without
|
| + * modification, are permitted provided that the following conditions are
|
| + * met:
|
| + *
|
| + * * Redistributions of source code must retain the above copyright
|
| + * notice, this list of conditions and the following disclaimer.
|
| + * * Redistributions in binary form must reproduce the above
|
| + * copyright notice, this list of conditions and the following disclaimer
|
| + * in the documentation and/or other materials provided with the
|
| + * distribution.
|
| + * * Neither the name of Google Inc. nor the names of its
|
| + * contributors may be used to endorse or promote products derived from
|
| + * this software without specific prior written permission.
|
| + *
|
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| + */
|
| +
|
| +#include "content/test/layout_tests/runner/WebUserMediaClientMock.h"
|
| +
|
| +#include "content/public/test/layout_tests/WebTestDelegate.h"
|
| +#include "content/test/layout_tests/runner/MockConstraints.h"
|
| +#include "third_party/WebKit/public/platform/WebMediaConstraints.h"
|
| +#include "third_party/WebKit/public/platform/WebMediaStream.h"
|
| +#include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
|
| +#include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
|
| +#include "third_party/WebKit/public/platform/WebVector.h"
|
| +#include "third_party/WebKit/public/web/WebDocument.h"
|
| +#include "third_party/WebKit/public/web/WebMediaStreamRegistry.h"
|
| +#include "third_party/WebKit/public/web/WebUserMediaRequest.h"
|
| +
|
| +using namespace blink;
|
| +
|
| +namespace WebTestRunner {
|
| +
|
| +class UserMediaRequestTask : public WebMethodTask<WebUserMediaClientMock> {
|
| +public:
|
| + UserMediaRequestTask(WebUserMediaClientMock* object, const WebUserMediaRequest& request, const WebMediaStream result)
|
| + : WebMethodTask<WebUserMediaClientMock>(object)
|
| + , m_request(request)
|
| + , m_result(result)
|
| + {
|
| + BLINK_ASSERT(!m_result.isNull());
|
| + }
|
| +
|
| + virtual void runIfValid() OVERRIDE
|
| + {
|
| + m_request.requestSucceeded(m_result);
|
| + }
|
| +
|
| +private:
|
| + WebUserMediaRequest m_request;
|
| + WebMediaStream m_result;
|
| +};
|
| +
|
| +class UserMediaRequestConstraintFailedTask : public WebMethodTask<WebUserMediaClientMock> {
|
| +public:
|
| + UserMediaRequestConstraintFailedTask(WebUserMediaClientMock* object, const WebUserMediaRequest& request, const WebString& constraint)
|
| + : WebMethodTask<WebUserMediaClientMock>(object)
|
| + , m_request(request)
|
| + , m_constraint(constraint)
|
| + {
|
| + }
|
| +
|
| + virtual void runIfValid() OVERRIDE
|
| + {
|
| + m_request.requestFailedConstraint(m_constraint);
|
| + }
|
| +
|
| +private:
|
| + WebUserMediaRequest m_request;
|
| + WebString m_constraint;
|
| +};
|
| +
|
| +class UserMediaRequestPermissionDeniedTask : public WebMethodTask<WebUserMediaClientMock> {
|
| +public:
|
| + UserMediaRequestPermissionDeniedTask(WebUserMediaClientMock* object, const WebUserMediaRequest& request)
|
| + : WebMethodTask<WebUserMediaClientMock>(object)
|
| + , m_request(request)
|
| + {
|
| + }
|
| +
|
| + virtual void runIfValid() OVERRIDE
|
| + {
|
| + m_request.requestFailed();
|
| + }
|
| +
|
| +private:
|
| + WebUserMediaRequest m_request;
|
| +};
|
| +
|
| +////////////////////////////////
|
| +
|
| +class MockExtraData : public WebMediaStream::ExtraData {
|
| +public:
|
| + int foo;
|
| +};
|
| +
|
| +WebUserMediaClientMock::WebUserMediaClientMock(WebTestDelegate* delegate)
|
| + : m_delegate(delegate)
|
| +{
|
| +}
|
| +
|
| +void WebUserMediaClientMock::requestUserMedia(const WebUserMediaRequest& streamRequest)
|
| +{
|
| + BLINK_ASSERT(!streamRequest.isNull());
|
| + WebUserMediaRequest request = streamRequest;
|
| +
|
| + if (request.ownerDocument().isNull() || !request.ownerDocument().frame()) {
|
| + m_delegate->postTask(new UserMediaRequestPermissionDeniedTask(this, request));
|
| + return;
|
| + }
|
| +
|
| + WebMediaConstraints constraints = request.audioConstraints();
|
| + WebString failedConstraint;
|
| + if (!constraints.isNull() && !MockConstraints::verifyConstraints(constraints, &failedConstraint)) {
|
| + m_delegate->postTask(new UserMediaRequestConstraintFailedTask(this, request, failedConstraint));
|
| + return;
|
| + }
|
| + constraints = request.videoConstraints();
|
| + if (!constraints.isNull() && !MockConstraints::verifyConstraints(constraints, &failedConstraint)) {
|
| + m_delegate->postTask(new UserMediaRequestConstraintFailedTask(this, request, failedConstraint));
|
| + return;
|
| + }
|
| +
|
| + const size_t zero = 0;
|
| + const size_t one = 1;
|
| + WebVector<WebMediaStreamTrack> audioTracks(request.audio() ? one : zero);
|
| + WebVector<WebMediaStreamTrack> videoTracks(request.video() ? one : zero);
|
| +
|
| + if (request.audio()) {
|
| + WebMediaStreamSource source;
|
| + source.initialize("MockAudioDevice#1", WebMediaStreamSource::TypeAudio, "Mock audio device");
|
| + audioTracks[0].initialize(source);
|
| + }
|
| +
|
| + if (request.video()) {
|
| + WebMediaStreamSource source;
|
| + source.initialize("MockVideoDevice#1", WebMediaStreamSource::TypeVideo, "Mock video device");
|
| + videoTracks[0].initialize(source);
|
| + }
|
| +
|
| + WebMediaStream stream;
|
| + stream.initialize(audioTracks, videoTracks);
|
| +
|
| + stream.setExtraData(new MockExtraData());
|
| +
|
| + m_delegate->postTask(new UserMediaRequestTask(this, request, stream));
|
| +}
|
| +
|
| +void WebUserMediaClientMock::cancelUserMediaRequest(const WebUserMediaRequest&)
|
| +{
|
| +}
|
| +
|
| +}
|
|
|