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 blink::WebPushRegistrationCallbacks* callbacks,
39 blink::WebServiceWorkerProvider* service_worker_provider) {
42 if (!error_message_.empty()) {
43 scoped_ptr<blink::WebPushError> error(
44 new blink::WebPushError(blink::WebPushError::ErrorTypeAbort,
45 WebString::fromUTF8(error_message_)));
46 callbacks->onError(error.release());
48 DCHECK(!end_point_.empty() && !registration_id_.empty());
50 scoped_ptr<blink::WebPushRegistration> registration(
51 new blink::WebPushRegistration(WebString::fromUTF8(end_point_),
52 WebString::fromUTF8(registration_id_)));
53 callbacks->onSuccess(registration.release());
59 } // namespace content