Commit 111f14f6 authored by tfarina@chromium.org's avatar tfarina@chromium.org

test_runner: Migrate WebPermissions to our Chromium C++ style.

Changes:
1) Run clang-format through source and header files.
2) Rename data member variables to use unix_hacker_ style.
2) Rename methods to use CamelCase style.
3) Rename file name to web_permissions.

BUG=331299
TEST=content_unittests, content_shell. No functional changes
TBR=dpranke@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277981 0039d316-1c4b-4281-b951-d872f2087c98
parent 651aa66f
...@@ -191,8 +191,6 @@ ...@@ -191,8 +191,6 @@
'shell/renderer/test_runner/TestInterfaces.h', 'shell/renderer/test_runner/TestInterfaces.h',
'shell/renderer/test_runner/TestPlugin.cpp', 'shell/renderer/test_runner/TestPlugin.cpp',
'shell/renderer/test_runner/TestPlugin.h', 'shell/renderer/test_runner/TestPlugin.h',
'shell/renderer/test_runner/WebPermissions.cpp',
'shell/renderer/test_runner/WebPermissions.h',
'shell/renderer/test_runner/WebTask.cpp', 'shell/renderer/test_runner/WebTask.cpp',
'shell/renderer/test_runner/WebTask.h', 'shell/renderer/test_runner/WebTask.h',
'shell/renderer/test_runner/WebTestDelegate.h', 'shell/renderer/test_runner/WebTestDelegate.h',
...@@ -233,6 +231,8 @@ ...@@ -233,6 +231,8 @@
'shell/renderer/test_runner/web_ax_object_proxy.cc', 'shell/renderer/test_runner/web_ax_object_proxy.cc',
'shell/renderer/test_runner/web_ax_object_proxy.h', 'shell/renderer/test_runner/web_ax_object_proxy.h',
'shell/renderer/test_runner/web_frame_test_proxy.h', 'shell/renderer/test_runner/web_frame_test_proxy.h',
'shell/renderer/test_runner/web_permissions.cc',
'shell/renderer/test_runner/web_permissions.h',
'shell/renderer/test_runner/web_test_proxy.cc', 'shell/renderer/test_runner/web_test_proxy.cc',
'shell/renderer/test_runner/web_test_proxy.h', 'shell/renderer/test_runner/web_test_proxy.h',
'shell/renderer/test_runner/web_test_runner.h', 'shell/renderer/test_runner/web_test_runner.h',
......
// 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.
#include "content/shell/renderer/test_runner/WebPermissions.h"
#include "content/shell/renderer/test_runner/TestCommon.h"
#include "content/shell/renderer/test_runner/WebTestDelegate.h"
#include "third_party/WebKit/public/platform/WebCString.h"
#include "third_party/WebKit/public/platform/WebURL.h"
using namespace std;
namespace content {
WebPermissions::WebPermissions()
: m_delegate(0)
{
reset();
}
WebPermissions::~WebPermissions()
{
}
bool WebPermissions::allowImage(bool enabledPerSettings, const blink::WebURL& imageURL)
{
bool allowed = enabledPerSettings && m_imagesAllowed;
if (m_dumpCallbacks && m_delegate)
m_delegate->printMessage(std::string("PERMISSION CLIENT: allowImage(") + normalizeLayoutTestURL(imageURL.spec()) + "): " + (allowed ? "true" : "false") + "\n");
return allowed;
}
bool WebPermissions::allowMedia(const blink::WebURL& imageURL)
{
bool allowed = m_mediaAllowed;
if (m_dumpCallbacks && m_delegate)
m_delegate->printMessage(std::string("PERMISSION CLIENT: allowMedia(") + normalizeLayoutTestURL(imageURL.spec()) + "): " + (allowed ? "true" : "false") + "\n");
return allowed;
}
bool WebPermissions::allowScriptFromSource(bool enabledPerSettings, const blink::WebURL& scriptURL)
{
bool allowed = enabledPerSettings && m_scriptsAllowed;
if (m_dumpCallbacks && m_delegate)
m_delegate->printMessage(std::string("PERMISSION CLIENT: allowScriptFromSource(") + normalizeLayoutTestURL(scriptURL.spec()) + "): " + (allowed ? "true" : "false") + "\n");
return allowed;
}
bool WebPermissions::allowStorage(bool)
{
return m_storageAllowed;
}
bool WebPermissions::allowPlugins(bool enabledPerSettings)
{
return enabledPerSettings && m_pluginsAllowed;
}
bool WebPermissions::allowDisplayingInsecureContent(bool enabledPerSettings, const blink::WebSecurityOrigin&, const blink::WebURL&)
{
return enabledPerSettings || m_displayingInsecureContentAllowed;
}
bool WebPermissions::allowRunningInsecureContent(bool enabledPerSettings, const blink::WebSecurityOrigin&, const blink::WebURL&)
{
return enabledPerSettings || m_runningInsecureContentAllowed;
}
void WebPermissions::setImagesAllowed(bool imagesAllowed)
{
m_imagesAllowed = imagesAllowed;
}
void WebPermissions::setMediaAllowed(bool mediaAllowed)
{
m_mediaAllowed = mediaAllowed;
}
void WebPermissions::setScriptsAllowed(bool scriptsAllowed)
{
m_scriptsAllowed = scriptsAllowed;
}
void WebPermissions::setStorageAllowed(bool storageAllowed)
{
m_storageAllowed = storageAllowed;
}
void WebPermissions::setPluginsAllowed(bool pluginsAllowed)
{
m_pluginsAllowed = pluginsAllowed;
}
void WebPermissions::setDisplayingInsecureContentAllowed(bool allowed)
{
m_displayingInsecureContentAllowed = allowed;
}
void WebPermissions::setRunningInsecureContentAllowed(bool allowed)
{
m_runningInsecureContentAllowed = allowed;
}
void WebPermissions::setDelegate(WebTestDelegate* delegate)
{
m_delegate = delegate;
}
void WebPermissions::setDumpCallbacks(bool dumpCallbacks)
{
m_dumpCallbacks = dumpCallbacks;
}
void WebPermissions::reset()
{
m_dumpCallbacks = false;
m_imagesAllowed = true;
m_mediaAllowed = true;
m_scriptsAllowed = true;
m_storageAllowed = true;
m_pluginsAllowed = true;
m_displayingInsecureContentAllowed = false;
m_runningInsecureContentAllowed = false;
}
} // namespace content
// 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.
#ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBPERMISSIONS_H_
#define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBPERMISSIONS_H_
#include "base/macros.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebPermissionClient.h"
namespace content {
class WebTestDelegate;
class WebPermissions : public blink::WebPermissionClient {
public:
WebPermissions();
virtual ~WebPermissions();
// Override WebPermissionClient methods.
virtual bool allowImage(bool enabledPerSettings, const blink::WebURL& imageURL);
virtual bool allowMedia(const blink::WebURL& mediaURL);
virtual bool allowScriptFromSource(bool enabledPerSettings, const blink::WebURL& scriptURL);
virtual bool allowStorage(bool local);
virtual bool allowPlugins(bool enabledPerSettings);
virtual bool allowDisplayingInsecureContent(bool enabledPerSettings, const blink::WebSecurityOrigin&, const blink::WebURL&);
virtual bool allowRunningInsecureContent(bool enabledPerSettings, const blink::WebSecurityOrigin&, const blink::WebURL&);
// Hooks to set the different policies.
void setImagesAllowed(bool);
void setMediaAllowed(bool);
void setScriptsAllowed(bool);
void setStorageAllowed(bool);
void setPluginsAllowed(bool);
void setDisplayingInsecureContentAllowed(bool);
void setRunningInsecureContentAllowed(bool);
// Resets the policy to allow everything, except for running insecure content.
void reset();
void setDelegate(WebTestDelegate*);
void setDumpCallbacks(bool);
private:
WebTestDelegate* m_delegate;
bool m_dumpCallbacks;
bool m_imagesAllowed;
bool m_mediaAllowed;
bool m_scriptsAllowed;
bool m_storageAllowed;
bool m_pluginsAllowed;
bool m_displayingInsecureContentAllowed;
bool m_runningInsecureContentAllowed;
DISALLOW_COPY_AND_ASSIGN(WebPermissions);
};
} // namespace content
#endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEBPERMISSIONS_H_
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
#include "content/shell/common/test_runner/test_preferences.h" #include "content/shell/common/test_runner/test_preferences.h"
#include "content/shell/renderer/test_runner/MockWebSpeechRecognizer.h" #include "content/shell/renderer/test_runner/MockWebSpeechRecognizer.h"
#include "content/shell/renderer/test_runner/TestInterfaces.h" #include "content/shell/renderer/test_runner/TestInterfaces.h"
#include "content/shell/renderer/test_runner/WebPermissions.h"
#include "content/shell/renderer/test_runner/WebTestDelegate.h" #include "content/shell/renderer/test_runner/WebTestDelegate.h"
#include "content/shell/renderer/test_runner/mock_web_push_client.h" #include "content/shell/renderer/test_runner/mock_web_push_client.h"
#include "content/shell/renderer/test_runner/notification_presenter.h" #include "content/shell/renderer/test_runner/notification_presenter.h"
#include "content/shell/renderer/test_runner/web_permissions.h"
#include "content/shell/renderer/test_runner/web_test_proxy.h" #include "content/shell/renderer/test_runner/web_test_proxy.h"
#include "gin/arguments.h" #include "gin/arguments.h"
#include "gin/array_buffer.h" #include "gin/array_buffer.h"
...@@ -1503,7 +1503,7 @@ void TestRunner::Install(WebFrame* frame) { ...@@ -1503,7 +1503,7 @@ void TestRunner::Install(WebFrame* frame) {
void TestRunner::SetDelegate(WebTestDelegate* delegate) { void TestRunner::SetDelegate(WebTestDelegate* delegate) {
delegate_ = delegate; delegate_ = delegate;
web_permissions_->setDelegate(delegate); web_permissions_->SetDelegate(delegate);
notification_presenter_->set_delegate(delegate); notification_presenter_->set_delegate(delegate);
} }
...@@ -1601,7 +1601,7 @@ void TestRunner::Reset() { ...@@ -1601,7 +1601,7 @@ void TestRunner::Reset() {
web_history_item_count_ = 0; web_history_item_count_ = 0;
intercept_post_message_ = false; intercept_post_message_ = false;
web_permissions_->reset(); web_permissions_->Reset();
notification_presenter_->Reset(); notification_presenter_->Reset();
use_mock_theme_ = true; use_mock_theme_ = true;
...@@ -2553,35 +2553,35 @@ void TestRunner::DumpResourceResponseMIMETypes() { ...@@ -2553,35 +2553,35 @@ void TestRunner::DumpResourceResponseMIMETypes() {
} }
void TestRunner::SetImagesAllowed(bool allowed) { void TestRunner::SetImagesAllowed(bool allowed) {
web_permissions_->setImagesAllowed(allowed); web_permissions_->SetImagesAllowed(allowed);
} }
void TestRunner::SetMediaAllowed(bool allowed) { void TestRunner::SetMediaAllowed(bool allowed) {
web_permissions_->setMediaAllowed(allowed); web_permissions_->SetMediaAllowed(allowed);
} }
void TestRunner::SetScriptsAllowed(bool allowed) { void TestRunner::SetScriptsAllowed(bool allowed) {
web_permissions_->setScriptsAllowed(allowed); web_permissions_->SetScriptsAllowed(allowed);
} }
void TestRunner::SetStorageAllowed(bool allowed) { void TestRunner::SetStorageAllowed(bool allowed) {
web_permissions_->setStorageAllowed(allowed); web_permissions_->SetStorageAllowed(allowed);
} }
void TestRunner::SetPluginsAllowed(bool allowed) { void TestRunner::SetPluginsAllowed(bool allowed) {
web_permissions_->setPluginsAllowed(allowed); web_permissions_->SetPluginsAllowed(allowed);
} }
void TestRunner::SetAllowDisplayOfInsecureContent(bool allowed) { void TestRunner::SetAllowDisplayOfInsecureContent(bool allowed) {
web_permissions_->setDisplayingInsecureContentAllowed(allowed); web_permissions_->SetDisplayingInsecureContentAllowed(allowed);
} }
void TestRunner::SetAllowRunningOfInsecureContent(bool allowed) { void TestRunner::SetAllowRunningOfInsecureContent(bool allowed) {
web_permissions_->setRunningInsecureContentAllowed(allowed); web_permissions_->SetRunningInsecureContentAllowed(allowed);
} }
void TestRunner::DumpPermissionClientCallbacks() { void TestRunner::DumpPermissionClientCallbacks() {
web_permissions_->setDumpCallbacks(true); web_permissions_->SetDumpCallbacks(true);
} }
void TestRunner::DumpWindowStatusChanges() { void TestRunner::DumpWindowStatusChanges() {
......
// Copyright 2014 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/web_permissions.h"
#include "content/shell/renderer/test_runner/TestCommon.h"
#include "content/shell/renderer/test_runner/WebTestDelegate.h"
#include "third_party/WebKit/public/platform/WebCString.h"
#include "third_party/WebKit/public/platform/WebURL.h"
namespace content {
WebPermissions::WebPermissions() : delegate_(0) {
Reset();
}
WebPermissions::~WebPermissions() {}
bool WebPermissions::allowImage(bool enabled_per_settings,
const blink::WebURL& image_url) {
bool allowed = enabled_per_settings && images_allowed_;
if (dump_callbacks_ && delegate_) {
delegate_->printMessage(std::string("PERMISSION CLIENT: allowImage(") +
normalizeLayoutTestURL(image_url.spec()) + "): " +
(allowed ? "true" : "false") + "\n");
}
return allowed;
}
bool WebPermissions::allowMedia(const blink::WebURL& image_url) {
bool allowed = media_allowed_;
if (dump_callbacks_ && delegate_)
delegate_->printMessage(std::string("PERMISSION CLIENT: allowMedia(") +
normalizeLayoutTestURL(image_url.spec()) + "): " +
(allowed ? "true" : "false") + "\n");
return allowed;
}
bool WebPermissions::allowScriptFromSource(bool enabled_per_settings,
const blink::WebURL& scriptURL) {
bool allowed = enabled_per_settings && scripts_allowed_;
if (dump_callbacks_ && delegate_) {
delegate_->printMessage(
std::string("PERMISSION CLIENT: allowScriptFromSource(") +
normalizeLayoutTestURL(scriptURL.spec()) + "): " +
(allowed ? "true" : "false") + "\n");
}
return allowed;
}
bool WebPermissions::allowStorage(bool) {
return storage_allowed_;
}
bool WebPermissions::allowPlugins(bool enabled_per_settings) {
return enabled_per_settings && plugins_allowed_;
}
bool WebPermissions::allowDisplayingInsecureContent(
bool enabled_per_settings,
const blink::WebSecurityOrigin&,
const blink::WebURL&) {
return enabled_per_settings || displaying_insecure_content_allowed_;
}
bool WebPermissions::allowRunningInsecureContent(
bool enabled_per_settings,
const blink::WebSecurityOrigin&,
const blink::WebURL&) {
return enabled_per_settings || running_insecure_content_allowed_;
}
void WebPermissions::SetImagesAllowed(bool images_allowed) {
images_allowed_ = images_allowed;
}
void WebPermissions::SetMediaAllowed(bool media_allowed) {
media_allowed_ = media_allowed;
}
void WebPermissions::SetScriptsAllowed(bool scripts_allowed) {
scripts_allowed_ = scripts_allowed;
}
void WebPermissions::SetStorageAllowed(bool storage_allowed) {
storage_allowed_ = storage_allowed;
}
void WebPermissions::SetPluginsAllowed(bool plugins_allowed) {
plugins_allowed_ = plugins_allowed;
}
void WebPermissions::SetDisplayingInsecureContentAllowed(bool allowed) {
displaying_insecure_content_allowed_ = allowed;
}
void WebPermissions::SetRunningInsecureContentAllowed(bool allowed) {
running_insecure_content_allowed_ = allowed;
}
void WebPermissions::SetDelegate(WebTestDelegate* delegate) {
delegate_ = delegate;
}
void WebPermissions::SetDumpCallbacks(bool dump_callbacks) {
dump_callbacks_ = dump_callbacks;
}
void WebPermissions::Reset() {
dump_callbacks_ = false;
images_allowed_ = true;
media_allowed_ = true;
scripts_allowed_ = true;
storage_allowed_ = true;
plugins_allowed_ = true;
displaying_insecure_content_allowed_ = false;
running_insecure_content_allowed_ = false;
}
} // namespace content
// Copyright 2014 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_WEB_PERMISSIONS_H_
#define CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_PERMISSIONS_H_
#include "base/macros.h"
#include "third_party/WebKit/public/web/WebPermissionClient.h"
namespace content {
class WebTestDelegate;
class WebPermissions : public blink::WebPermissionClient {
public:
WebPermissions();
virtual ~WebPermissions();
// blink::WebPermissionClient:
virtual bool allowImage(bool enabledPerSettings,
const blink::WebURL& imageURL);
virtual bool allowMedia(const blink::WebURL& mediaURL);
virtual bool allowScriptFromSource(bool enabledPerSettings,
const blink::WebURL& scriptURL);
virtual bool allowStorage(bool local);
virtual bool allowPlugins(bool enabledPerSettings);
virtual bool allowDisplayingInsecureContent(bool enabledPerSettings,
const blink::WebSecurityOrigin&,
const blink::WebURL&);
virtual bool allowRunningInsecureContent(bool enabledPerSettings,
const blink::WebSecurityOrigin&,
const blink::WebURL&);
// Hooks to set the different policies.
void SetImagesAllowed(bool);
void SetMediaAllowed(bool);
void SetScriptsAllowed(bool);
void SetStorageAllowed(bool);
void SetPluginsAllowed(bool);
void SetDisplayingInsecureContentAllowed(bool);
void SetRunningInsecureContentAllowed(bool);
void SetDelegate(WebTestDelegate*);
void SetDumpCallbacks(bool);
// Resets the policy to allow everything, except for running insecure content.
void Reset();
private:
WebTestDelegate* delegate_;
bool dump_callbacks_;
bool images_allowed_;
bool media_allowed_;
bool scripts_allowed_;
bool storage_allowed_;
bool plugins_allowed_;
bool displaying_insecure_content_allowed_;
bool running_insecure_content_allowed_;
DISALLOW_COPY_AND_ASSIGN(WebPermissions);
};
} // namespace content
#endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_WEB_PERMISSIONS_H_
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