Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/attestation/attestation_ca_client.h" | |
|
gab
2017/04/25 14:53:15
include fixer should have added a newline below :(
fdoray
2017/04/27 13:12:26
Done.
| |
| 5 #include "base/bind.h" | 6 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 7 #include "base/message_loop/message_loop.h" | |
| 8 #include "chrome/browser/chromeos/attestation/attestation_ca_client.h" | |
| 9 #include "chromeos/chromeos_switches.h" | 8 #include "chromeos/chromeos_switches.h" |
| 10 #include "content/public/test/test_browser_thread.h" | 9 #include "content/public/test/test_browser_thread_bundle.h" |
| 11 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 12 #include "net/http/http_status_code.h" | 11 #include "net/http/http_status_code.h" |
| 13 #include "net/url_request/test_url_fetcher_factory.h" | 12 #include "net/url_request/test_url_fetcher_factory.h" |
| 14 #include "net/url_request/url_fetcher.h" | 13 #include "net/url_request/url_fetcher.h" |
| 15 #include "net/url_request/url_request_status.h" | 14 #include "net/url_request/url_request_status.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 16 |
| 18 namespace chromeos { | 17 namespace chromeos { |
| 19 namespace attestation { | 18 namespace attestation { |
| 20 | 19 |
| 21 class AttestationCAClientTest : public ::testing::Test { | 20 class AttestationCAClientTest : public ::testing::Test { |
| 22 public: | 21 public: |
| 23 AttestationCAClientTest() | 22 AttestationCAClientTest() : num_invocations_(0), result_(false) {} |
| 24 : io_thread_(content::BrowserThread::IO, &message_loop_), | |
| 25 num_invocations_(0), | |
| 26 result_(false) { | |
| 27 } | |
| 28 | 23 |
| 29 ~AttestationCAClientTest() override {} | 24 ~AttestationCAClientTest() override {} |
| 30 | 25 |
| 31 void DataCallback(bool result, const std::string& data) { | 26 void DataCallback(bool result, const std::string& data) { |
| 32 ++num_invocations_; | 27 ++num_invocations_; |
| 33 result_ = result; | 28 result_ = result; |
| 34 data_ = data; | 29 data_ = data; |
| 35 } | 30 } |
| 36 | 31 |
| 37 void DeleteClientDataCallback(AttestationCAClient* client, | 32 void DeleteClientDataCallback(AttestationCAClient* client, |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 59 | 54 |
| 60 void SendFetcherResponse(net::TestURLFetcher* fetcher, | 55 void SendFetcherResponse(net::TestURLFetcher* fetcher, |
| 61 net::Error error, | 56 net::Error error, |
| 62 int response_code) { | 57 int response_code) { |
| 63 fetcher->set_status(net::URLRequestStatus::FromError(error)); | 58 fetcher->set_status(net::URLRequestStatus::FromError(error)); |
| 64 fetcher->set_response_code(response_code); | 59 fetcher->set_response_code(response_code); |
| 65 fetcher->SetResponseString(fetcher->upload_data() + "_response"); | 60 fetcher->SetResponseString(fetcher->upload_data() + "_response"); |
| 66 fetcher->delegate()->OnURLFetchComplete(fetcher); | 61 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 67 } | 62 } |
| 68 | 63 |
| 69 base::MessageLoop message_loop_; | 64 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
| 70 content::TestBrowserThread io_thread_; | |
| 71 net::TestURLFetcherFactory url_fetcher_factory_; | 65 net::TestURLFetcherFactory url_fetcher_factory_; |
| 72 | 66 |
| 73 // For use with DataCallback. | 67 // For use with DataCallback. |
| 74 int num_invocations_; | 68 int num_invocations_; |
| 75 bool result_; | 69 bool result_; |
| 76 std::string data_; | 70 std::string data_; |
| 77 }; | 71 }; |
| 78 | 72 |
| 79 TEST_F(AttestationCAClientTest, EnrollRequest) { | 73 TEST_F(AttestationCAClientTest, EnrollRequest) { |
| 80 AttestationCAClient client; | 74 AttestationCAClient client; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 CheckURLAndSendResponse(GURL("https://asbestos-qa.corp.google.com/sign"), | 196 CheckURLAndSendResponse(GURL("https://asbestos-qa.corp.google.com/sign"), |
| 203 net::OK, net::HTTP_OK); | 197 net::OK, net::HTTP_OK); |
| 204 | 198 |
| 205 EXPECT_EQ(1, num_invocations_); | 199 EXPECT_EQ(1, num_invocations_); |
| 206 EXPECT_TRUE(result_); | 200 EXPECT_TRUE(result_); |
| 207 EXPECT_EQ("certificate_response", data_); | 201 EXPECT_EQ("certificate_response", data_); |
| 208 } | 202 } |
| 209 | 203 |
| 210 } // namespace attestation | 204 } // namespace attestation |
| 211 } // namespace chromeos | 205 } // namespace chromeos |
| OLD | NEW |