Commit 49a225f6 authored by avayvod's avatar avayvod Committed by Commit bot

Added MockPresentationClient to use in layout tests.

Blink change with the test follows: https://codereview.chromium.org/906673002/

BUG=412331

Review URL: https://codereview.chromium.org/905823004

Cr-Commit-Position: refs/heads/master@{#315204}
parent b22a69d1
......@@ -229,6 +229,8 @@
'shell/renderer/test_runner/mock_credential_manager_client.h',
'shell/renderer/test_runner/mock_grammar_check.cc',
'shell/renderer/test_runner/mock_grammar_check.h',
'shell/renderer/test_runner/mock_presentation_client.cc',
'shell/renderer/test_runner/mock_presentation_client.h',
'shell/renderer/test_runner/mock_screen_orientation_client.cc',
'shell/renderer/test_runner/mock_screen_orientation_client.h',
'shell/renderer/test_runner/mock_spell_check.cc',
......
......@@ -172,6 +172,8 @@ static_library("content_shell_lib") {
"renderer/test_runner/mock_credential_manager_client.h",
"renderer/test_runner/mock_grammar_check.cc",
"renderer/test_runner/mock_grammar_check.h",
"renderer/test_runner/mock_presentation_client.cc",
"renderer/test_runner/mock_presentation_client.h",
"renderer/test_runner/mock_screen_orientation_client.cc",
"renderer/test_runner/mock_screen_orientation_client.h",
"renderer/test_runner/mock_spell_check.cc",
......
......@@ -35,6 +35,7 @@
#include "content/shell/renderer/layout_test/gc_controller.h"
#include "content/shell/renderer/layout_test/layout_test_render_process_observer.h"
#include "content/shell/renderer/layout_test/leak_detector.h"
#include "content/shell/renderer/test_runner/mock_presentation_client.h"
#include "content/shell/renderer/test_runner/mock_screen_orientation_client.h"
#include "content/shell/renderer/test_runner/web_task.h"
#include "content/shell/renderer/test_runner/web_test_interfaces.h"
......@@ -248,6 +249,11 @@ void WebKitTestRunner::DidChangeBatteryStatus(
MockBatteryStatusChanged(status);
}
void WebKitTestRunner::SetScreenAvailability(bool available) {
MockPresentationClient* mock_client = proxy()->GetPresentationClientMock();
mock_client->SetScreenAvailability(available);
}
void WebKitTestRunner::PrintMessage(const std::string& message) {
Send(new ShellViewHostMsg_PrintMessage(routing_id(), message));
}
......
......@@ -64,6 +64,7 @@ class WebKitTestRunner : public RenderViewObserver,
const blink::WebScreenOrientationType& orientation) override;
void ResetScreenOrientation() override;
void DidChangeBatteryStatus(const blink::WebBatteryStatus& status) override;
void SetScreenAvailability(bool available) override;
void PrintMessage(const std::string& message) override;
void PostTask(WebTask* task) override;
void PostDelayedTask(WebTask* task, long long ms) override;
......
// Copyright 2015 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.
#include "content/shell/renderer/test_runner/mock_presentation_client.h"
#include "base/logging.h"
#include "third_party/WebKit/public/platform/modules/presentation/WebPresentationController.h"
namespace content {
MockPresentationClient::MockPresentationClient()
: controller_(nullptr),
screen_availability_(false) {
}
MockPresentationClient::~MockPresentationClient() {
}
void MockPresentationClient::SetScreenAvailability(bool available) {
if (screen_availability_ == available)
return;
screen_availability_ = available;
if (!controller_)
return;
if (!controller_->isAvailableChangeWatched())
return;
controller_->didChangeAvailability(screen_availability_);
}
void MockPresentationClient::setController(
blink::WebPresentationController* controller) {
DCHECK(controller_ != controller && (!controller || !controller_));
controller_ = controller;
if (controller_)
updateAvailableChangeWatched(controller_->isAvailableChangeWatched());
}
void MockPresentationClient::updateAvailableChangeWatched(bool watched) {
if (!watched)
return;
DCHECK(controller_);
if (screen_availability_)
controller_->didChangeAvailability(screen_availability_);
}
} // namespace content
// Copyright 2015 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.
#ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCK_PRESENTATION_CLIENT_H_
#define CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCK_PRESENTATION_CLIENT_H_
#include "base/macros.h"
#include "third_party/WebKit/public/platform/modules/presentation/WebPresentationClient.h"
namespace content {
// A mock implementation of WebPresentationClient to be used in tests with
// content shell.
class MockPresentationClient : public blink::WebPresentationClient {
public:
explicit MockPresentationClient();
virtual ~MockPresentationClient();
void SetScreenAvailability(bool available);
private:
// From blink::WebPresentationClient.
// Passes the Blink-side delegate to the embedder.
virtual void setController(blink::WebPresentationController*);
// Called when the frame attaches the first event listener to or removes the
// last event listener from the |availablechange| event.
virtual void updateAvailableChangeWatched(bool watched);
blink::WebPresentationController* controller_;
bool screen_availability_;
DISALLOW_COPY_AND_ASSIGN(MockPresentationClient);
};
} // namespace content
#endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCK_PRESENTATION_CLIENT_H_
......@@ -204,6 +204,7 @@ class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> {
double dischargingTime,
double level);
void ResetBatteryStatus();
void SetMockScreenAvailability(bool available);
void DidAcquirePointerLock();
void DidNotAcquirePointerLock();
void DidLosePointerLock();
......@@ -410,6 +411,8 @@ gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder(
.SetMethod("didChangeBatteryStatus",
&TestRunnerBindings::DidChangeBatteryStatus)
.SetMethod("resetBatteryStatus", &TestRunnerBindings::ResetBatteryStatus)
.SetMethod("setMockScreenAvailability",
&TestRunnerBindings::SetMockScreenAvailability)
.SetMethod("didAcquirePointerLock",
&TestRunnerBindings::DidAcquirePointerLock)
.SetMethod("didNotAcquirePointerLock",
......@@ -964,6 +967,11 @@ void TestRunnerBindings::ResetBatteryStatus() {
runner_->ResetBatteryStatus();
}
void TestRunnerBindings::SetMockScreenAvailability(bool available) {
if (runner_)
runner_->SetMockScreenAvailability(available);
}
void TestRunnerBindings::DidAcquirePointerLock() {
if (runner_)
runner_->DidAcquirePointerLock();
......@@ -2447,6 +2455,10 @@ void TestRunner::ResetBatteryStatus() {
delegate_->DidChangeBatteryStatus(status);
}
void TestRunner::SetMockScreenAvailability(bool available) {
delegate_->SetScreenAvailability(available);
}
void TestRunner::DidAcquirePointerLock() {
DidAcquirePointerLockInternal();
}
......
......@@ -309,6 +309,9 @@ class TestRunner : public WebTestRunner,
double level);
void ResetBatteryStatus();
// Presentation API related functions.
void SetMockScreenAvailability(bool available);
void DidAcquirePointerLock();
void DidNotAcquirePointerLock();
void DidLosePointerLock();
......
......@@ -6,6 +6,7 @@
#define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_FRAME_TEST_PROXY_H_
#include "base/basictypes.h"
#include "content/shell/renderer/test_runner/mock_presentation_client.h"
#include "content/shell/renderer/test_runner/mock_screen_orientation_client.h"
#include "content/shell/renderer/test_runner/test_interfaces.h"
#include "content/shell/renderer/test_runner/test_runner.h"
......@@ -40,6 +41,10 @@ class WebFrameTestProxy : public Base {
return base_proxy_->GetScreenOrientationClientMock();
}
virtual blink::WebPresentationClient* presentationClient() {
return base_proxy_->GetPresentationClientMock();
}
virtual void didAddMessageToConsole(const blink::WebConsoleMessage& message,
const blink::WebString& source_name,
unsigned source_line,
......
......@@ -70,6 +70,9 @@ class WebTestDelegate {
virtual void DidChangeBatteryStatus(
const blink::WebBatteryStatus& status) = 0;
// Sets second screen availability for the Presentation API.
virtual void SetScreenAvailability(bool available) = 0;
// Add a message to the text dump for the layout test.
virtual void PrintMessage(const std::string& message) = 0;
......
......@@ -18,6 +18,7 @@
#include "content/shell/renderer/test_runner/event_sender.h"
#include "content/shell/renderer/test_runner/mock_color_chooser.h"
#include "content/shell/renderer/test_runner/mock_credential_manager_client.h"
#include "content/shell/renderer/test_runner/mock_presentation_client.h"
#include "content/shell/renderer/test_runner/mock_screen_orientation_client.h"
#include "content/shell/renderer/test_runner/mock_web_speech_recognizer.h"
#include "content/shell/renderer/test_runner/mock_web_user_media_client.h"
......@@ -652,6 +653,12 @@ WebTestProxyBase::GetCredentialManagerClientMock() {
return credential_manager_client_.get();
}
MockPresentationClient* WebTestProxyBase::GetPresentationClientMock() {
if (!presentation_client_.get())
presentation_client_.reset(new MockPresentationClient());
return presentation_client_.get();
}
void WebTestProxyBase::ScheduleAnimation() {
if (!test_interfaces_->GetTestRunner()->TestIsRunning())
return;
......
......@@ -76,6 +76,7 @@ typedef unsigned WebColor;
namespace content {
class MockCredentialManagerClient;
class MockPresentationClient;
class MockScreenOrientationClient;
class MockWebSpeechRecognizer;
class MockWebUserMediaClient;
......@@ -131,6 +132,7 @@ class WebTestProxyBase {
blink::WebMIDIClientMock* GetMIDIClientMock();
MockWebSpeechRecognizer* GetSpeechRecognizerMock();
MockCredentialManagerClient* GetCredentialManagerClientMock();
MockPresentationClient* GetPresentationClientMock();
WebTaskList* mutable_task_list() { return &task_list_; }
......@@ -267,6 +269,7 @@ class WebTestProxyBase {
scoped_ptr<blink::WebMIDIClientMock> midi_client_;
scoped_ptr<MockWebSpeechRecognizer> speech_recognizer_;
scoped_ptr<MockScreenOrientationClient> screen_orientation_client_;
scoped_ptr<MockPresentationClient> presentation_client_;
std::string accept_languages_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment