Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1136)

Side by Side Diff: chrome/browser/printing/cloud_print/gcd_api_flow_unittest.cc

Issue 1553333002: Move cloud print specific files out of local_discovery (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@moveprn
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/local_discovery/gcd_api_flow.h" 5 #include "chrome/browser/printing/cloud_print/gcd_api_flow.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/local_discovery/gcd_api_flow_impl.h" 13 #include "chrome/browser/printing/cloud_print/gcd_api_flow_impl.h"
14 #include "content/public/test/test_browser_thread.h" 14 #include "content/public/test/test_browser_thread.h"
15 #include "google_apis/gaia/fake_oauth2_token_service.h" 15 #include "google_apis/gaia/fake_oauth2_token_service.h"
16 #include "google_apis/gaia/google_service_auth_error.h" 16 #include "google_apis/gaia/google_service_auth_error.h"
17 #include "net/base/host_port_pair.h" 17 #include "net/base/host_port_pair.h"
18 #include "net/base/net_errors.h" 18 #include "net/base/net_errors.h"
19 #include "net/http/http_request_headers.h" 19 #include "net/http/http_request_headers.h"
20 #include "net/url_request/test_url_fetcher_factory.h" 20 #include "net/url_request/test_url_fetcher_factory.h"
21 #include "net/url_request/url_request_test_util.h" 21 #include "net/url_request/url_request_test_util.h"
22 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
24 24
25 using testing::_; 25 using testing::_;
26 using testing::Return; 26 using testing::Return;
27 27
28 namespace local_discovery { 28 namespace cloud_print {
29 29
30 namespace { 30 namespace {
31 31
32 const char kSampleConfirmResponse[] = "{}"; 32 const char kSampleConfirmResponse[] = "{}";
33 33
34 const char kFailedConfirmResponseBadJson[] = "[]"; 34 const char kFailedConfirmResponseBadJson[] = "[]";
35 35
36 const char kAccountId[] = "account_id"; 36 const char kAccountId[] = "account_id";
37 37
38 class MockDelegate : public CloudPrintApiFlowRequest { 38 class MockDelegate : public CloudPrintApiFlowRequest {
39 public: 39 public:
40 MOCK_METHOD1(OnGCDAPIFlowError, void(GCDApiFlow::Status)); 40 MOCK_METHOD1(OnGCDApiFlowError, void(GCDApiFlow::Status));
41 MOCK_METHOD1(OnGCDAPIFlowComplete, void(const base::DictionaryValue&)); 41 MOCK_METHOD1(OnGCDApiFlowComplete, void(const base::DictionaryValue&));
42 42
43 MOCK_METHOD0(GetURL, GURL()); 43 MOCK_METHOD0(GetURL, GURL());
44 }; 44 };
45 45
46 class GCDApiFlowTest : public testing::Test { 46 class GCDApiFlowTest : public testing::Test {
47 public: 47 public:
48 GCDApiFlowTest() 48 GCDApiFlowTest()
49 : ui_thread_(content::BrowserThread::UI, &loop_), 49 : ui_thread_(content::BrowserThread::UI, &loop_),
50 request_context_(new net::TestURLRequestContextGetter( 50 request_context_(new net::TestURLRequestContextGetter(
51 base::ThreadTaskRunnerHandle::Get())), 51 base::ThreadTaskRunnerHandle::Get())),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 EXPECT_TRUE(headers.GetHeader("Authorization", &oauth_header)); 93 EXPECT_TRUE(headers.GetHeader("Authorization", &oauth_header));
94 EXPECT_EQ("Bearer SomeToken", oauth_header); 94 EXPECT_EQ("Bearer SomeToken", oauth_header);
95 EXPECT_TRUE(headers.GetHeader("X-Cloudprint-Proxy", &proxy)); 95 EXPECT_TRUE(headers.GetHeader("X-Cloudprint-Proxy", &proxy));
96 EXPECT_EQ("Chrome", proxy); 96 EXPECT_EQ("Chrome", proxy);
97 97
98 fetcher->SetResponseString(kSampleConfirmResponse); 98 fetcher->SetResponseString(kSampleConfirmResponse);
99 fetcher->set_status( 99 fetcher->set_status(
100 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK)); 100 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK));
101 fetcher->set_response_code(200); 101 fetcher->set_response_code(200);
102 102
103 EXPECT_CALL(*mock_delegate_, OnGCDAPIFlowComplete(_)); 103 EXPECT_CALL(*mock_delegate_, OnGCDApiFlowComplete(_));
104 104
105 fetcher->delegate()->OnURLFetchComplete(fetcher); 105 fetcher->delegate()->OnURLFetchComplete(fetcher);
106 } 106 }
107 107
108 TEST_F(GCDApiFlowTest, BadToken) { 108 TEST_F(GCDApiFlowTest, BadToken) {
109 EXPECT_CALL(*mock_delegate_, OnGCDAPIFlowError(GCDApiFlow::ERROR_TOKEN)); 109 EXPECT_CALL(*mock_delegate_, OnGCDApiFlowError(GCDApiFlow::ERROR_TOKEN));
110 gcd_flow_->OnGetTokenFailure( 110 gcd_flow_->OnGetTokenFailure(
111 NULL, GoogleServiceAuthError(GoogleServiceAuthError::USER_NOT_SIGNED_UP)); 111 NULL, GoogleServiceAuthError(GoogleServiceAuthError::USER_NOT_SIGNED_UP));
112 } 112 }
113 113
114 TEST_F(GCDApiFlowTest, BadJson) { 114 TEST_F(GCDApiFlowTest, BadJson) {
115 gcd_flow_->OnGetTokenSuccess(NULL, "SomeToken", base::Time()); 115 gcd_flow_->OnGetTokenSuccess(NULL, "SomeToken", base::Time());
116 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); 116 net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0);
117 117
118 EXPECT_EQ(GURL("https://www.google.com/cloudprint/confirm?token=SomeToken"), 118 EXPECT_EQ(GURL("https://www.google.com/cloudprint/confirm?token=SomeToken"),
119 fetcher->GetOriginalURL()); 119 fetcher->GetOriginalURL());
120 120
121 fetcher->SetResponseString(kFailedConfirmResponseBadJson); 121 fetcher->SetResponseString(kFailedConfirmResponseBadJson);
122 fetcher->set_status( 122 fetcher->set_status(
123 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK)); 123 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK));
124 fetcher->set_response_code(200); 124 fetcher->set_response_code(200);
125 125
126 EXPECT_CALL(*mock_delegate_, 126 EXPECT_CALL(*mock_delegate_,
127 OnGCDAPIFlowError(GCDApiFlow::ERROR_MALFORMED_RESPONSE)); 127 OnGCDApiFlowError(GCDApiFlow::ERROR_MALFORMED_RESPONSE));
128 128
129 fetcher->delegate()->OnURLFetchComplete(fetcher); 129 fetcher->delegate()->OnURLFetchComplete(fetcher);
130 } 130 }
131 131
132 } // namespace 132 } // namespace
133 133
134 } // namespace local_discovery 134 } // namespace cloud_print
OLDNEW
« no previous file with comments | « chrome/browser/printing/cloud_print/gcd_api_flow_impl.cc ('k') | chrome/browser/printing/cloud_print/gcd_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698