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 // The default state should be be an error with "Registration failed." message 19 // because LayoutTests are currently depending on that. 20 : error_message_("Registration failed.") { 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 const WebString& sender_id, 40 blink::WebPushRegistrationCallbacks* callbacks) { 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 } // namespace content 61