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.
5 #include "content/shell/renderer/test_runner/mock_web_push_client.h"
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/WebPushRegistration.h"
11 #include "third_party/WebKit/public/platform/WebString.h"
13 using blink::WebString;
17 MockWebPushClient::MockWebPushClient()
19 "Registration failed (default mock client error message)") {
22 MockWebPushClient::~MockWebPushClient() {}
24 void MockWebPushClient::SetMockSuccessValues(
25 const std::string& end_point, const std::string& registration_id) {
26 end_point_ = end_point;
27 registration_id_ = registration_id;
31 void MockWebPushClient::SetMockErrorValues(const std::string& message) {
33 registration_id_ = "";
34 error_message_ = message;
37 void MockWebPushClient::registerPushMessaging(
38 const WebString& sender_id,
39 blink::WebPushRegistrationCallbacks* callbacks) {
40 registerPushMessaging(sender_id, callbacks, NULL);
43 void MockWebPushClient::registerPushMessaging(
44 const WebString& sender_id,
45 blink::WebPushRegistrationCallbacks* callbacks,
46 blink::WebServiceWorkerProvider* service_worker_provider) {
49 if (!error_message_.empty()) {
50 scoped_ptr<blink::WebPushError> error(
51 new blink::WebPushError(blink::WebPushError::ErrorTypeAbort,
52 WebString::fromUTF8(error_message_)));
53 callbacks->onError(error.release());
55 DCHECK(!end_point_.empty() && !registration_id_.empty());
57 scoped_ptr<blink::WebPushRegistration> registration(
58 new blink::WebPushRegistration(WebString::fromUTF8(end_point_),
59 WebString::fromUTF8(registration_id_)));
60 callbacks->onSuccess(registration.release());
66 } // namespace content