| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/shell/renderer/test_runner/mock_web_push_client.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "third_party/WebKit/public/platform/WebPushError.h" | |
| 10 #include "third_party/WebKit/public/platform/WebPushPermissionStatus.h" | |
| 11 #include "third_party/WebKit/public/platform/WebPushRegistration.h" | |
| 12 #include "third_party/WebKit/public/platform/WebString.h" | |
| 13 | |
| 14 using blink::WebString; | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 MockWebPushClient::MockWebPushClient() | |
| 19 : error_message_( | |
| 20 "Registration failed (default mock client error message)") { | |
| 21 } | |
| 22 | |
| 23 MockWebPushClient::~MockWebPushClient() {} | |
| 24 | |
| 25 void MockWebPushClient::SetMockSuccessValues( | |
| 26 const std::string& end_point, const std::string& registration_id) { | |
| 27 end_point_ = end_point; | |
| 28 registration_id_ = registration_id; | |
| 29 error_message_ = ""; | |
| 30 } | |
| 31 | |
| 32 void MockWebPushClient::SetMockErrorValues(const std::string& message) { | |
| 33 end_point_ = ""; | |
| 34 registration_id_ = ""; | |
| 35 error_message_ = message; | |
| 36 } | |
| 37 | |
| 38 void MockWebPushClient::registerPushMessaging( | |
| 39 blink::WebPushRegistrationCallbacks* callbacks, | |
| 40 blink::WebServiceWorkerProvider* service_worker_provider) { | |
| 41 DCHECK(callbacks); | |
| 42 | |
| 43 if (!error_message_.empty()) { | |
| 44 scoped_ptr<blink::WebPushError> error( | |
| 45 new blink::WebPushError(blink::WebPushError::ErrorTypeAbort, | |
| 46 WebString::fromUTF8(error_message_))); | |
| 47 callbacks->onError(error.release()); | |
| 48 } else { | |
| 49 DCHECK(!end_point_.empty() && !registration_id_.empty()); | |
| 50 | |
| 51 scoped_ptr<blink::WebPushRegistration> registration( | |
| 52 new blink::WebPushRegistration(WebString::fromUTF8(end_point_), | |
| 53 WebString::fromUTF8(registration_id_))); | |
| 54 callbacks->onSuccess(registration.release()); | |
| 55 } | |
| 56 | |
| 57 delete callbacks; | |
| 58 } | |
| 59 | |
| 60 void MockWebPushClient::getPermissionStatus( | |
| 61 blink::WebPushPermissionStatusCallback* callback, | |
| 62 blink::WebServiceWorkerProvider* provider) { | |
| 63 blink::WebPushPermissionStatus status; | |
| 64 if (error_message_.empty()) | |
| 65 status = blink::WebPushPermissionStatusGranted; | |
| 66 else if (error_message_ == "deny_permission") | |
| 67 status = blink::WebPushPermissionStatusDenied; | |
| 68 else | |
| 69 status = blink::WebPushPermissionStatusDefault; | |
| 70 | |
| 71 callback->onSuccess(&status); | |
| 72 delete callback; | |
| 73 } | |
| 74 | |
| 75 } // Namespace content | |
| OLD | NEW |