OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 "chrome/browser/remoting/directory_add_request.h" |
| 6 #include "net/url_request/url_request_status.h" |
| 7 #include "testing/gmock/include/gmock/gmock.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace remoting { |
| 11 |
| 12 namespace { |
| 13 class MockDoneCallback { |
| 14 public: |
| 15 MOCK_METHOD2(OnDone, |
| 16 void(DirectoryAddRequest::Result, |
| 17 const std::string& message)); |
| 18 }; |
| 19 } // namespace |
| 20 |
| 21 class DirectoryAddRequestTest : public testing::Test { |
| 22 protected: |
| 23 void TestResult(int response_code, const std::string& data, |
| 24 DirectoryAddRequest::Result expected_result, |
| 25 const std::string& expected_message) { |
| 26 MockDoneCallback callback; |
| 27 EXPECT_CALL(callback, OnDone(expected_result, expected_message)) |
| 28 .Times(1); |
| 29 |
| 30 target_.done_callback_.reset( |
| 31 NewCallback(&callback, &MockDoneCallback::OnDone)); |
| 32 |
| 33 GURL url; |
| 34 URLRequestStatus status_ok; |
| 35 ResponseCookies cookies; |
| 36 target_.OnURLFetchComplete(NULL, url, status_ok, response_code, |
| 37 cookies, data); |
| 38 } |
| 39 |
| 40 DirectoryAddRequest target_; |
| 41 }; |
| 42 |
| 43 TEST_F(DirectoryAddRequestTest, Success) { |
| 44 TestResult(200, "{\"data\":{\"kind\":\"chromoting#host\"," |
| 45 "\"hostId\":\"e64906c9-fdc9-4921-80cb-563cf7f564f3\"," |
| 46 "\"hostName\":\"host_name\",\"publicKey\":\"PUBLIC+KEY\"}}", |
| 47 DirectoryAddRequest::SUCCESS, ""); |
| 48 } |
| 49 |
| 50 TEST_F(DirectoryAddRequestTest, Duplicate) { |
| 51 TestResult(400, "{\"error\":{\"errors\":[{\"domain\":\"global\"," |
| 52 "\"reason\":\"invalid\",\"message\":\"Attempt to register " |
| 53 "a duplicate host.\"}],\"code\":400,\"message\":\"Attempt to " |
| 54 "register a duplicate host.\"}}", |
| 55 DirectoryAddRequest::ERROR_EXISTS, |
| 56 "Attempt to register a duplicate host."); |
| 57 } |
| 58 |
| 59 TEST_F(DirectoryAddRequestTest, InvalidRequest) { |
| 60 TestResult(400, "{\"error\":{\"errors\":[{\"domain\":\"global\"," |
| 61 "\"reason\":\"invalid\",\"message\":\"Invalid Value\"}]," |
| 62 "\"code\":400,\"message\":\"Invalid Value\"}}", |
| 63 DirectoryAddRequest::ERROR_INVALID_REQUEST, |
| 64 "Invalid Value"); |
| 65 } |
| 66 |
| 67 TEST_F(DirectoryAddRequestTest, InvalidToken) { |
| 68 TestResult(401, "{\"error\":{\"errors\":[{\"domain\":\"global\"," |
| 69 "\"reason\":\"invalid\",\"message\":\"Token invalid\"," |
| 70 "\"locationType\":\"header\",\"location\":\"Authorization\"}]," |
| 71 "\"code\":401,\"message\":\"Token invalid\"}}", |
| 72 DirectoryAddRequest::ERROR_AUTH, |
| 73 "Token invalid"); |
| 74 } |
| 75 |
| 76 } // namespace remoting |
OLD | NEW |