diff options
author | mvanouwerkerk <mvanouwerkerk@chromium.org> | 2014-12-06 04:17:32 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-06 12:17:49 +0000 |
commit | de895c9cf83def15368652a0c2ed6afce794acd8 (patch) | |
tree | 1086fbf970309d0584f6786fd29b8550be27fe86 | |
parent | b2c19b3850943eafb0015f3b3046c7ebea670be5 (diff) | |
download | chromium_src-de895c9cf83def15368652a0c2ed6afce794acd8.zip chromium_src-de895c9cf83def15368652a0c2ed6afce794acd8.tar.gz chromium_src-de895c9cf83def15368652a0c2ed6afce794acd8.tar.bz2 |
Push API: permission methods through TestRunner for layout tests.
BUG=389194
Review URL: https://codereview.chromium.org/775933003
Cr-Commit-Position: refs/heads/master@{#307173}
16 files changed, 245 insertions, 2 deletions
diff --git a/content/content_shell.gypi b/content/content_shell.gypi index f850ba7..06d49da 100644 --- a/content/content_shell.gypi +++ b/content/content_shell.gypi @@ -112,6 +112,8 @@ 'shell/browser/layout_test/layout_test_message_filter.h', 'shell/browser/layout_test/layout_test_notification_manager.cc', 'shell/browser/layout_test/layout_test_notification_manager.h', + 'shell/browser/layout_test/layout_test_push_messaging_service.cc', + 'shell/browser/layout_test/layout_test_push_messaging_service.h', 'shell/browser/layout_test/layout_test_resource_dispatcher_host_delegate.cc', 'shell/browser/layout_test/layout_test_resource_dispatcher_host_delegate.h', 'shell/browser/layout_test/layout_test_url_request_context_getter.cc', diff --git a/content/shell/BUILD.gn b/content/shell/BUILD.gn index d9d0b26..6b8f228 100644 --- a/content/shell/BUILD.gn +++ b/content/shell/BUILD.gn @@ -61,6 +61,8 @@ static_library("content_shell_lib") { "browser/layout_test/layout_test_message_filter.h", "browser/layout_test/layout_test_notification_manager.cc", "browser/layout_test/layout_test_notification_manager.h", + "browser/layout_test/layout_test_push_messaging_service.cc", + "browser/layout_test/layout_test_push_messaging_service.h", "browser/layout_test/layout_test_resource_dispatcher_host_delegate.cc", "browser/layout_test/layout_test_resource_dispatcher_host_delegate.h", "browser/layout_test/layout_test_url_request_context_getter.cc", diff --git a/content/shell/browser/layout_test/layout_test_browser_context.cc b/content/shell/browser/layout_test/layout_test_browser_context.cc index f2477c2..efde5e4 100644 --- a/content/shell/browser/layout_test/layout_test_browser_context.cc +++ b/content/shell/browser/layout_test/layout_test_browser_context.cc @@ -9,8 +9,10 @@ #include "base/files/file_util.h" #include "base/logging.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/push_messaging_service.h" #include "content/public/browser/resource_context.h" #include "content/shell/browser/layout_test/layout_test_download_manager_delegate.h" +#include "content/shell/browser/layout_test/layout_test_push_messaging_service.h" #include "content/shell/browser/layout_test/layout_test_url_request_context_getter.h" #include "content/shell/browser/shell_url_request_context_getter.h" @@ -49,7 +51,7 @@ LayoutTestBrowserContext::CreateURLRequestContextGetter( DownloadManagerDelegate* LayoutTestBrowserContext::GetDownloadManagerDelegate() { - if (!download_manager_delegate_.get()) { + if (!download_manager_delegate_) { download_manager_delegate_.reset(new LayoutTestDownloadManagerDelegate()); download_manager_delegate_->SetDownloadManager( BrowserContext::GetDownloadManager(this)); @@ -60,4 +62,16 @@ LayoutTestBrowserContext::GetDownloadManagerDelegate() { return download_manager_delegate_.get(); } +PushMessagingService* LayoutTestBrowserContext::GetPushMessagingService() { + if (!push_messaging_service_) + push_messaging_service_.reset(new LayoutTestPushMessagingService()); + return push_messaging_service_.get(); +} + +LayoutTestPushMessagingService* +LayoutTestBrowserContext::GetLayoutTestPushMessagingService() { + return static_cast<LayoutTestPushMessagingService*>( + GetPushMessagingService()); +} + } // namespace content diff --git a/content/shell/browser/layout_test/layout_test_browser_context.h b/content/shell/browser/layout_test/layout_test_browser_context.h index fae095a..4074f4a 100644 --- a/content/shell/browser/layout_test/layout_test_browser_context.h +++ b/content/shell/browser/layout_test/layout_test_browser_context.h @@ -15,6 +15,8 @@ class NetLog; namespace content { class DownloadManagerDelegate; +class LayoutTestPushMessagingService; +class PushMessagingService; class LayoutTestBrowserContext : public ShellBrowserContext { public: @@ -23,6 +25,9 @@ class LayoutTestBrowserContext : public ShellBrowserContext { // BrowserContext implementation. DownloadManagerDelegate* GetDownloadManagerDelegate() override; + PushMessagingService* GetPushMessagingService() override; + + LayoutTestPushMessagingService* GetLayoutTestPushMessagingService(); protected: ShellURLRequestContextGetter* CreateURLRequestContextGetter( @@ -30,6 +35,8 @@ class LayoutTestBrowserContext : public ShellBrowserContext { URLRequestInterceptorScopedVector request_interceptors) override; private: + scoped_ptr<LayoutTestPushMessagingService> push_messaging_service_; + DISALLOW_COPY_AND_ASSIGN(LayoutTestBrowserContext); }; diff --git a/content/shell/browser/layout_test/layout_test_content_browser_client.cc b/content/shell/browser/layout_test/layout_test_content_browser_client.cc index b4b2b08..b4d25f6 100644 --- a/content/shell/browser/layout_test/layout_test_content_browser_client.cc +++ b/content/shell/browser/layout_test/layout_test_content_browser_client.cc @@ -8,6 +8,7 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/storage_partition.h" +#include "content/shell/browser/layout_test/layout_test_browser_context.h" #include "content/shell/browser/layout_test/layout_test_message_filter.h" #include "content/shell/browser/layout_test/layout_test_notification_manager.h" #include "content/shell/browser/shell_browser_context.h" @@ -53,6 +54,11 @@ LayoutTestContentBrowserClient* LayoutTestContentBrowserClient::Get() { return g_layout_test_browser_client; } +LayoutTestBrowserContext* +LayoutTestContentBrowserClient::GetLayoutTestBrowserContext() { + return static_cast<LayoutTestBrowserContext*>(browser_context()); +} + LayoutTestNotificationManager* LayoutTestContentBrowserClient::GetLayoutTestNotificationManager() { return layout_test_notification_manager_.get(); diff --git a/content/shell/browser/layout_test/layout_test_content_browser_client.h b/content/shell/browser/layout_test/layout_test_content_browser_client.h index e21b521..b764801 100644 --- a/content/shell/browser/layout_test/layout_test_content_browser_client.h +++ b/content/shell/browser/layout_test/layout_test_content_browser_client.h @@ -10,6 +10,7 @@ namespace content { +class LayoutTestBrowserContext; class LayoutTestNotificationManager; class LayoutTestContentBrowserClient : public ShellContentBrowserClient { @@ -20,6 +21,8 @@ class LayoutTestContentBrowserClient : public ShellContentBrowserClient { LayoutTestContentBrowserClient(); ~LayoutTestContentBrowserClient() override; + LayoutTestBrowserContext* GetLayoutTestBrowserContext(); + // Will be lazily created when running layout tests. LayoutTestNotificationManager* GetLayoutTestNotificationManager(); diff --git a/content/shell/browser/layout_test/layout_test_message_filter.cc b/content/shell/browser/layout_test/layout_test_message_filter.cc index 256b8e6..35dc096 100644 --- a/content/shell/browser/layout_test/layout_test_message_filter.cc +++ b/content/shell/browser/layout_test/layout_test_message_filter.cc @@ -7,8 +7,10 @@ #include "base/files/file_util.h" #include "base/threading/thread_restrictions.h" #include "content/public/browser/child_process_security_policy.h" +#include "content/shell/browser/layout_test/layout_test_browser_context.h" #include "content/shell/browser/layout_test/layout_test_content_browser_client.h" #include "content/shell/browser/layout_test/layout_test_notification_manager.h" +#include "content/shell/browser/layout_test/layout_test_push_messaging_service.h" #include "content/shell/browser/shell_browser_context.h" #include "content/shell/browser/shell_content_browser_client.h" #include "content/shell/browser/shell_network_delegate.h" @@ -42,7 +44,9 @@ void LayoutTestMessageFilter::OverrideThreadForMessage( const IPC::Message& message, BrowserThread::ID* thread) { if (message.type() == LayoutTestHostMsg_ClearAllDatabases::ID) *thread = BrowserThread::FILE; - if (message.type() == LayoutTestHostMsg_SimulateWebNotificationClick::ID) + if (message.type() == LayoutTestHostMsg_SimulateWebNotificationClick::ID || + message.type() == LayoutTestHostMsg_SetPushMessagingPermission::ID || + message.type() == LayoutTestHostMsg_ClearPushMessagingPermissions::ID) *thread = BrowserThread::UI; } @@ -61,6 +65,10 @@ bool LayoutTestMessageFilter::OnMessageReceived(const IPC::Message& message) { OnClearWebNotificationPermissions) IPC_MESSAGE_HANDLER(LayoutTestHostMsg_SimulateWebNotificationClick, OnSimulateWebNotificationClick) + IPC_MESSAGE_HANDLER(LayoutTestHostMsg_SetPushMessagingPermission, + OnSetPushMessagingPermission) + IPC_MESSAGE_HANDLER(LayoutTestHostMsg_ClearPushMessagingPermissions, + OnClearPushMessagingPermissions) IPC_MESSAGE_HANDLER(LayoutTestHostMsg_AcceptAllCookies, OnAcceptAllCookies) IPC_MESSAGE_HANDLER(LayoutTestHostMsg_DeleteAllCookies, OnDeleteAllCookies) IPC_MESSAGE_UNHANDLED(handled = false) @@ -129,6 +137,23 @@ void LayoutTestMessageFilter::OnSimulateWebNotificationClick( manager->SimulateClick(title); } +void LayoutTestMessageFilter::OnSetPushMessagingPermission(const GURL& origin, + bool allowed) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + LayoutTestContentBrowserClient::Get() + ->GetLayoutTestBrowserContext() + ->GetLayoutTestPushMessagingService() + ->SetPermission(origin, allowed); +} + +void LayoutTestMessageFilter::OnClearPushMessagingPermissions() { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + LayoutTestContentBrowserClient::Get() + ->GetLayoutTestBrowserContext() + ->GetLayoutTestPushMessagingService() + ->ClearPermissions(); +} + void LayoutTestMessageFilter::OnAcceptAllCookies(bool accept) { ShellNetworkDelegate::SetAcceptAllCookies(accept); } diff --git a/content/shell/browser/layout_test/layout_test_message_filter.h b/content/shell/browser/layout_test/layout_test_message_filter.h index fbeb01c..e7fa567 100644 --- a/content/shell/browser/layout_test/layout_test_message_filter.h +++ b/content/shell/browser/layout_test/layout_test_message_filter.h @@ -54,6 +54,8 @@ class LayoutTestMessageFilter : public BrowserMessageFilter { bool permission_granted); void OnClearWebNotificationPermissions(); void OnSimulateWebNotificationClick(const std::string& title); + void OnSetPushMessagingPermission(const GURL& origin, bool allowed); + void OnClearPushMessagingPermissions(); void OnAcceptAllCookies(bool accept); void OnDeleteAllCookies(); diff --git a/content/shell/browser/layout_test/layout_test_push_messaging_service.cc b/content/shell/browser/layout_test/layout_test_push_messaging_service.cc new file mode 100644 index 0000000..de39f2c --- /dev/null +++ b/content/shell/browser/layout_test/layout_test_push_messaging_service.cc @@ -0,0 +1,69 @@ +// 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/browser/layout_test/layout_test_push_messaging_service.h" + +#include "base/logging.h" + +namespace content { + +LayoutTestPushMessagingService::LayoutTestPushMessagingService() { +} + +LayoutTestPushMessagingService::~LayoutTestPushMessagingService() { +} + +void LayoutTestPushMessagingService::SetPermission(const GURL& origin, + bool allowed) { + permission_map_[origin] = allowed ? blink::WebPushPermissionStatusGranted + : blink::WebPushPermissionStatusDenied; +} + +void LayoutTestPushMessagingService::ClearPermissions() { + permission_map_.clear(); +} + +GURL LayoutTestPushMessagingService::PushEndpoint() { + return GURL("https://example.com/LayoutTestEndpoint"); +} + +void LayoutTestPushMessagingService::RegisterFromDocument( + const GURL& requesting_origin, + int64 service_worker_registration_id, + const std::string& sender_id, + int renderer_id, + int render_frame_id, + bool user_gesture, + const PushMessagingService::RegisterCallback& callback) { +} + +void LayoutTestPushMessagingService::RegisterFromWorker( + const GURL& requesting_origin, + int64 service_worker_registration_id, + const std::string& sender_id, + const PushMessagingService::RegisterCallback& callback) { +} + +blink::WebPushPermissionStatus +LayoutTestPushMessagingService::GetPermissionStatus( + const GURL& requesting_origin, + int renderer_id, + int render_frame_id) { + auto it = permission_map_.find(requesting_origin); + if (it == permission_map_.end()) + return blink::WebPushPermissionStatusDefault; + return it->second; +} + +blink::WebPushPermissionStatus +LayoutTestPushMessagingService::GetPermissionStatus( + const GURL& requesting_origin, + const GURL& embedding_origin) { + auto it = permission_map_.find(requesting_origin); + if (it == permission_map_.end()) + return blink::WebPushPermissionStatusDefault; + return it->second; +} + +} // namespace content diff --git a/content/shell/browser/layout_test/layout_test_push_messaging_service.h b/content/shell/browser/layout_test/layout_test_push_messaging_service.h new file mode 100644 index 0000000..b4c9a53 --- /dev/null +++ b/content/shell/browser/layout_test/layout_test_push_messaging_service.h @@ -0,0 +1,57 @@ +// 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_BROWSER_LAYOUT_TEST_LAYOUT_TEST_PUSH_MESSAGING_SERVICE_H_ +#define CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_PUSH_MESSAGING_SERVICE_H_ + +#include <map> + +#include "content/public/browser/push_messaging_service.h" +#include "content/public/common/push_messaging_status.h" +#include "third_party/WebKit/public/platform/WebPushPermissionStatus.h" + +namespace content { + +class LayoutTestPushMessagingService : public PushMessagingService { + public: + LayoutTestPushMessagingService(); + ~LayoutTestPushMessagingService() override; + + void SetPermission(const GURL& origin, bool allowed); + void ClearPermissions(); + + // PushMessagingService implementation: + GURL PushEndpoint() override; + void RegisterFromDocument( + const GURL& requesting_origin, + int64 service_worker_registration_id, + const std::string& sender_id, + int renderer_id, + int render_frame_id, + bool user_gesture, + const PushMessagingService::RegisterCallback& callback) override; + void RegisterFromWorker( + const GURL& requesting_origin, + int64 service_worker_registration_id, + const std::string& sender_id, + const PushMessagingService::RegisterCallback& callback) override; + // TODO(mvanouwerkerk): Delete once the Push API flows through platform. + // https://crbug.com/389194 + blink::WebPushPermissionStatus GetPermissionStatus( + const GURL& requesting_origin, + int renderer_id, + int render_frame_id) override; + blink::WebPushPermissionStatus GetPermissionStatus( + const GURL& requesting_origin, + const GURL& embedding_origin) override; + + private: + std::map<GURL, blink::WebPushPermissionStatus> permission_map_; + + DISALLOW_COPY_AND_ASSIGN(LayoutTestPushMessagingService); +}; + +} // namespace content + +#endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_PUSH_MESSAGING_SERVICE_H_ diff --git a/content/shell/common/layout_test/layout_test_messages.h b/content/shell/common/layout_test/layout_test_messages.h index e7bfdb8..9c813e0 100644 --- a/content/shell/common/layout_test/layout_test_messages.h +++ b/content/shell/common/layout_test/layout_test_messages.h @@ -28,6 +28,10 @@ IPC_MESSAGE_ROUTED2(LayoutTestHostMsg_GrantWebNotificationPermission, IPC_MESSAGE_ROUTED0(LayoutTestHostMsg_ClearWebNotificationPermissions) IPC_MESSAGE_ROUTED1(LayoutTestHostMsg_SimulateWebNotificationClick, std::string /* title */) +IPC_MESSAGE_ROUTED2(LayoutTestHostMsg_SetPushMessagingPermission, + GURL /* origin */, + bool /* allowed */) +IPC_MESSAGE_ROUTED0(LayoutTestHostMsg_ClearPushMessagingPermissions) IPC_MESSAGE_ROUTED1(LayoutTestHostMsg_AcceptAllCookies, bool /* accept */) IPC_MESSAGE_ROUTED0(LayoutTestHostMsg_DeleteAllCookies) diff --git a/content/shell/renderer/layout_test/webkit_test_runner.cc b/content/shell/renderer/layout_test/webkit_test_runner.cc index ea817c5..b8e205f1 100644 --- a/content/shell/renderer/layout_test/webkit_test_runner.cc +++ b/content/shell/renderer/layout_test/webkit_test_runner.cc @@ -432,6 +432,16 @@ void WebKitTestRunner::SimulateWebNotificationClick(const std::string& title) { Send(new LayoutTestHostMsg_SimulateWebNotificationClick(routing_id(), title)); } +void WebKitTestRunner::SetPushMessagingPermission(const GURL& origin, + bool allowed) { + Send(new LayoutTestHostMsg_SetPushMessagingPermission(routing_id(), origin, + allowed)); +} + +void WebKitTestRunner::ClearPushMessagingPermissions() { + Send(new LayoutTestHostMsg_ClearPushMessagingPermissions(routing_id())); +} + void WebKitTestRunner::SetDeviceScaleFactor(float factor) { content::SetDeviceScaleFactor(render_view(), factor); } diff --git a/content/shell/renderer/layout_test/webkit_test_runner.h b/content/shell/renderer/layout_test/webkit_test_runner.h index ac9508b..c31ffd3 100644 --- a/content/shell/renderer/layout_test/webkit_test_runner.h +++ b/content/shell/renderer/layout_test/webkit_test_runner.h @@ -92,6 +92,8 @@ class WebKitTestRunner : public RenderViewObserver, bool permission_granted) override; void ClearWebNotificationPermissions() override; void SimulateWebNotificationClick(const std::string& title) override; + void SetPushMessagingPermission(const GURL& origin, bool allowed) override; + void ClearPushMessagingPermissions() override; void SetDeviceScaleFactor(float factor) override; void SetDeviceColorProfile(const std::string& name) override; void SetBluetoothMockDataSet(const std::string& name) override; diff --git a/content/shell/renderer/test_runner/test_runner.cc b/content/shell/renderer/test_runner/test_runner.cc index 24a953a..04fffe8 100644 --- a/content/shell/renderer/test_runner/test_runner.cc +++ b/content/shell/renderer/test_runner/test_runner.cc @@ -296,6 +296,8 @@ class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> { void SetMockPushClientSuccess(const std::string& endpoint, const std::string& registration_id); void SetMockPushClientError(const std::string& message); + void SetPushMessagingPermission(const std::string& origin, bool allowed); + void ClearPushMessagingPermissions(); void SetBluetoothMockDataSet(const std::string& dataset_name); std::string PlatformName(); @@ -543,6 +545,10 @@ gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder( &TestRunnerBindings::SetMockPushClientSuccess) .SetMethod("setMockPushClientError", &TestRunnerBindings::SetMockPushClientError) + .SetMethod("setPushMessagingPermission", + &TestRunnerBindings::SetPushMessagingPermission) + .SetMethod("clearPushMessagingPermissions", + &TestRunnerBindings::ClearPushMessagingPermissions) .SetMethod("setBluetoothMockDataSet", &TestRunnerBindings::SetBluetoothMockDataSet) .SetMethod("forceNextWebGLContextCreationToFail", @@ -1416,6 +1422,17 @@ void TestRunnerBindings::SetMockPushClientError(const std::string& message) { runner_->SetMockPushClientError(message); } +void TestRunnerBindings::SetPushMessagingPermission(const std::string& origin, + bool allowed) { + if (runner_) + runner_->SetPushMessagingPermission(GURL(origin), allowed); +} + +void TestRunnerBindings::ClearPushMessagingPermissions() { + if (runner_) + runner_->ClearPushMessagingPermissions(); +} + std::string TestRunnerBindings::PlatformName() { if (runner_) return runner_->platform_name_; @@ -2918,6 +2935,14 @@ void TestRunner::SetMockPushClientError(const std::string& message) { proxy_->GetPushClientMock()->SetMockErrorValues(message); } +void TestRunner::SetPushMessagingPermission(const GURL& origin, bool allowed) { + delegate_->SetPushMessagingPermission(origin, allowed); +} + +void TestRunner::ClearPushMessagingPermissions() { + delegate_->ClearPushMessagingPermissions(); +} + void TestRunner::LocationChangeDone() { web_history_item_count_ = delegate_->NavigationEntryCount(); diff --git a/content/shell/renderer/test_runner/test_runner.h b/content/shell/renderer/test_runner/test_runner.h index 7092bb9..f8b0b8f 100644 --- a/content/shell/renderer/test_runner/test_runner.h +++ b/content/shell/renderer/test_runner/test_runner.h @@ -561,10 +561,21 @@ class TestRunner : public WebTestRunner, void CopyImageAtAndCapturePixelsAsyncThen( int x, int y, const v8::Handle<v8::Function> callback); + // TODO(mvanouwerkerk): Delete once refactor to platform is complete. + // https://crbug.com/389194 void SetMockPushClientSuccess(const std::string& endpoint, const std::string& registration_id); + + // TODO(mvanouwerkerk): Delete once refactor to platform is complete. + // https://crbug.com/389194 void SetMockPushClientError(const std::string& message); + // Sets the origin's permission to use the Push API to granted or denied. + void SetPushMessagingPermission(const GURL& origin, bool allowed); + + // Clears all previously granted Push API permissions. + void ClearPushMessagingPermissions(); + void GetManifestThen(v8::Handle<v8::Function> callback); /////////////////////////////////////////////////////////////////////////// diff --git a/content/shell/renderer/test_runner/web_test_delegate.h b/content/shell/renderer/test_runner/web_test_delegate.h index 2fd4e4d..6e44cee 100644 --- a/content/shell/renderer/test_runner/web_test_delegate.h +++ b/content/shell/renderer/test_runner/web_test_delegate.h @@ -140,6 +140,10 @@ class WebTestDelegate { virtual void ClearWebNotificationPermissions() = 0; virtual void SimulateWebNotificationClick(const std::string& title) = 0; + // Controls the Push API. + virtual void SetPushMessagingPermission(const GURL& origin, bool allowed) = 0; + virtual void ClearPushMessagingPermissions() = 0; + // Controls the device scale factor of the main WebView for hidpi tests. virtual void SetDeviceScaleFactor(float factor) = 0; |