BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / chromeos / attestation / attestation_ca_client_unittest.cc
blobb5de15266d0b1d3417cfa686cc9d08de1444f2ee
1 // Copyright (c) 2013 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 "base/bind.h"
6 #include "base/message_loop/message_loop.h"
7 #include "chrome/browser/chromeos/attestation/attestation_ca_client.h"
8 #include "content/public/test/test_browser_thread.h"
9 #include "net/base/net_errors.h"
10 #include "net/http/http_status_code.h"
11 #include "net/url_request/test_url_fetcher_factory.h"
12 #include "net/url_request/url_fetcher.h"
13 #include "net/url_request/url_request_status.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 namespace chromeos {
17 namespace attestation {
19 class AttestationCAClientTest : public ::testing::Test {
20 public:
21 AttestationCAClientTest()
22 : io_thread_(content::BrowserThread::IO, &message_loop_),
23 num_invocations_(0),
24 result_(false) {
27 ~AttestationCAClientTest() override {}
29 void DataCallback (bool result, const std::string& data) {
30 ++num_invocations_;
31 result_ = result;
32 data_ = data;
35 void DeleteClientDataCallback (AttestationCAClient* client,
36 bool result,
37 const std::string& data) {
38 delete client;
39 DataCallback(result, data);
42 protected:
43 void SendResponse(net::Error error, int response_code) {
44 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
45 CHECK(fetcher);
46 fetcher->set_status(net::URLRequestStatus::FromError(error));
47 fetcher->set_response_code(response_code);
48 fetcher->SetResponseString(fetcher->upload_data() + "_response");
49 fetcher->delegate()->OnURLFetchComplete(fetcher);
52 base::MessageLoop message_loop_;
53 content::TestBrowserThread io_thread_;
54 net::TestURLFetcherFactory url_fetcher_factory_;
56 // For use with DataCallback.
57 int num_invocations_;
58 bool result_;
59 std::string data_;
62 TEST_F(AttestationCAClientTest, EnrollRequest) {
63 AttestationCAClient client;
64 client.SendEnrollRequest(
65 "enroll",
66 base::Bind(&AttestationCAClientTest::DataCallback,
67 base::Unretained(this)));
68 SendResponse(net::OK, net::HTTP_OK);
70 EXPECT_EQ(1, num_invocations_);
71 EXPECT_TRUE(result_);
72 EXPECT_EQ("enroll_response", data_);
75 TEST_F(AttestationCAClientTest, CertificateRequest) {
76 AttestationCAClient client;
77 client.SendCertificateRequest(
78 "certificate",
79 base::Bind(&AttestationCAClientTest::DataCallback,
80 base::Unretained(this)));
81 SendResponse(net::OK, net::HTTP_OK);
83 EXPECT_EQ(1, num_invocations_);
84 EXPECT_TRUE(result_);
85 EXPECT_EQ("certificate_response", data_);
88 TEST_F(AttestationCAClientTest, CertificateRequestNetworkFailure) {
89 AttestationCAClient client;
90 client.SendCertificateRequest(
91 "certificate",
92 base::Bind(&AttestationCAClientTest::DataCallback,
93 base::Unretained(this)));
94 SendResponse(net::ERR_FAILED, net::HTTP_OK);
96 EXPECT_EQ(1, num_invocations_);
97 EXPECT_FALSE(result_);
98 EXPECT_EQ("", data_);
101 TEST_F(AttestationCAClientTest, CertificateRequestHttpError) {
102 AttestationCAClient client;
103 client.SendCertificateRequest(
104 "certificate",
105 base::Bind(&AttestationCAClientTest::DataCallback,
106 base::Unretained(this)));
107 SendResponse(net::OK, net::HTTP_NOT_FOUND);
109 EXPECT_EQ(1, num_invocations_);
110 EXPECT_FALSE(result_);
111 EXPECT_EQ("", data_);
114 TEST_F(AttestationCAClientTest, DeleteOnCallback) {
115 AttestationCAClient* client = new AttestationCAClient();
116 client->SendCertificateRequest(
117 "certificate",
118 base::Bind(&AttestationCAClientTest::DeleteClientDataCallback,
119 base::Unretained(this),
120 client));
121 SendResponse(net::OK, net::HTTP_OK);
123 EXPECT_EQ(1, num_invocations_);
124 EXPECT_TRUE(result_);
125 EXPECT_EQ("certificate_response", data_);
128 } // namespace attestation
129 } // namespace chromeos