| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <set> | 5 #include <set> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "chrome/browser/local_discovery/cloud_print_printer_list.h" | 9 #include "chrome/browser/local_discovery/cloud_print_printer_list.h" |
| 10 #include "content/public/test/test_browser_thread.h" | 10 #include "content/public/test/test_browser_thread.h" |
| 11 #include "google_apis/gaia/google_service_auth_error.h" | 11 #include "google_apis/gaia/google_service_auth_error.h" |
| 12 #include "net/base/host_port_pair.h" | 12 #include "net/base/host_port_pair.h" |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 #include "net/http/http_request_headers.h" | 14 #include "net/http/http_request_headers.h" |
| 15 #include "net/url_request/test_url_fetcher_factory.h" | 15 #include "net/url_request/test_url_fetcher_factory.h" |
| 16 #include "net/url_request/url_fetcher_impl.h" | 16 #include "net/url_request/url_fetcher_impl.h" |
| 17 #include "net/url_request/url_request_test_util.h" | 17 #include "net/url_request/url_request_test_util.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "url/gurl.h" |
| 20 | 21 |
| 22 using testing::Mock; |
| 21 using testing::NiceMock; | 23 using testing::NiceMock; |
| 22 using testing::StrictMock; | 24 using testing::StrictMock; |
| 23 using testing::Mock; | |
| 24 | 25 |
| 25 namespace local_discovery { | 26 namespace local_discovery { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 const char kSampleSuccessResponseOAuth[] = "{" | 30 const char kSampleSuccessResponseOAuth[] = "{" |
| 30 " \"success\": true," | 31 " \"success\": true," |
| 31 " \"printers\": [" | 32 " \"printers\": [" |
| 32 " {\"id\" : \"someID\"," | 33 " {\"id\" : \"someID\"," |
| 33 " \"displayName\": \"someDisplayName\"," | 34 " \"displayName\": \"someDisplayName\"," |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 // Use a test factory as a fallback so we don't have to deal with OAuth2 | 96 // Use a test factory as a fallback so we don't have to deal with OAuth2 |
| 96 // requests. | 97 // requests. |
| 97 scoped_ptr<net::TestURLFetcherFactory> fallback_fetcher_factory_; | 98 scoped_ptr<net::TestURLFetcherFactory> fallback_fetcher_factory_; |
| 98 scoped_ptr<net::FakeURLFetcherFactory> fetcher_factory_; | 99 scoped_ptr<net::FakeURLFetcherFactory> fetcher_factory_; |
| 99 TestOAuth2TokenService token_service_; | 100 TestOAuth2TokenService token_service_; |
| 100 StrictMock<MockDelegate> delegate_; | 101 StrictMock<MockDelegate> delegate_; |
| 101 scoped_ptr<CloudPrintPrinterList> printer_list_; | 102 scoped_ptr<CloudPrintPrinterList> printer_list_; |
| 102 }; | 103 }; |
| 103 | 104 |
| 104 TEST_F(CloudPrintPrinterListTest, SuccessOAuth2) { | 105 TEST_F(CloudPrintPrinterListTest, SuccessOAuth2) { |
| 105 fetcher_factory_->SetFakeResponse("http://SoMeUrL.com/cloudprint/search", | 106 fetcher_factory_->SetFakeResponse( |
| 106 kSampleSuccessResponseOAuth, | 107 GURL("http://SoMeUrL.com/cloudprint/search"), |
| 107 true); | 108 kSampleSuccessResponseOAuth, |
| 108 | 109 true); |
| 109 | 110 |
| 110 CloudPrintBaseApiFlow* cloudprint_flow = | 111 CloudPrintBaseApiFlow* cloudprint_flow = |
| 111 printer_list_->GetOAuth2ApiFlowForTests(); | 112 printer_list_->GetOAuth2ApiFlowForTests(); |
| 112 | 113 |
| 113 printer_list_->Start(); | 114 printer_list_->Start(); |
| 114 | 115 |
| 115 cloudprint_flow->OnGetTokenSuccess(NULL, "SomeToken", base::Time()); | 116 cloudprint_flow->OnGetTokenSuccess(NULL, "SomeToken", base::Time()); |
| 116 | 117 |
| 117 EXPECT_CALL(delegate_, OnCloudPrintPrinterListReady()); | 118 EXPECT_CALL(delegate_, OnCloudPrintPrinterListReady()); |
| 118 | 119 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 138 printer_list_->GetDetailsFor("someID"); | 139 printer_list_->GetDetailsFor("someID"); |
| 139 ASSERT_TRUE(found != NULL); | 140 ASSERT_TRUE(found != NULL); |
| 140 EXPECT_EQ("someID", found->id); | 141 EXPECT_EQ("someID", found->id); |
| 141 EXPECT_EQ("someDisplayName", found->display_name); | 142 EXPECT_EQ("someDisplayName", found->display_name); |
| 142 EXPECT_EQ("someDescription", found->description); | 143 EXPECT_EQ("someDescription", found->description); |
| 143 } | 144 } |
| 144 | 145 |
| 145 } // namespace | 146 } // namespace |
| 146 | 147 |
| 147 } // namespace local_discovery | 148 } // namespace local_discovery |
| OLD | NEW |