Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / shell / renderer / test_runner / mock_web_push_client.cc
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/WebPushRegistration.h"
11 #include "third_party/WebKit/public/platform/WebString.h"
12
13 using blink::WebString;
14
15 namespace content {
16
17 MockWebPushClient::MockWebPushClient()
18     : error_message_(
19           "Registration failed (default mock client error message)") {
20 }
21
22 MockWebPushClient::~MockWebPushClient() {}
23
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;
28   error_message_ = "";
29 }
30
31 void MockWebPushClient::SetMockErrorValues(const std::string& message) {
32   end_point_ = "";
33   registration_id_ = "";
34   error_message_ = message;
35 }
36
37 void MockWebPushClient::registerPushMessaging(
38     blink::WebPushRegistrationCallbacks* callbacks,
39     blink::WebServiceWorkerProvider* service_worker_provider) {
40   DCHECK(callbacks);
41
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());
47   } else {
48     DCHECK(!end_point_.empty() && !registration_id_.empty());
49
50     scoped_ptr<blink::WebPushRegistration> registration(
51         new blink::WebPushRegistration(WebString::fromUTF8(end_point_),
52                                        WebString::fromUTF8(registration_id_)));
53     callbacks->onSuccess(registration.release());
54   }
55
56   delete callbacks;
57 }
58
59 }  // namespace content