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

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

Issue 2799883003: Switch from TestBrowserThread to TestBrowserThreadBundle in chrome. (Closed)
Patch Set: fix-string Created 3 years, 7 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/printing/cloud_print/gcd_api_flow.h" 5 #include "chrome/browser/printing/cloud_print/gcd_api_flow.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
13 #include "base/values.h" 12 #include "base/values.h"
14 #include "chrome/browser/printing/cloud_print/gcd_api_flow_impl.h" 13 #include "chrome/browser/printing/cloud_print/gcd_api_flow_impl.h"
15 #include "content/public/test/test_browser_thread.h" 14 #include "content/public/test/test_browser_thread_bundle.h"
16 #include "google_apis/gaia/fake_oauth2_token_service.h" 15 #include "google_apis/gaia/fake_oauth2_token_service.h"
17 #include "google_apis/gaia/google_service_auth_error.h" 16 #include "google_apis/gaia/google_service_auth_error.h"
18 #include "net/base/host_port_pair.h" 17 #include "net/base/host_port_pair.h"
19 #include "net/base/net_errors.h" 18 #include "net/base/net_errors.h"
20 #include "net/http/http_request_headers.h" 19 #include "net/http/http_request_headers.h"
21 #include "net/url_request/test_url_fetcher_factory.h" 20 #include "net/url_request/test_url_fetcher_factory.h"
22 #include "net/url_request/url_request_test_util.h" 21 #include "net/url_request/url_request_test_util.h"
23 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
25 24
(...skipping 15 matching lines...) Expand all
41 MOCK_METHOD1(OnGCDApiFlowError, void(GCDApiFlow::Status)); 40 MOCK_METHOD1(OnGCDApiFlowError, void(GCDApiFlow::Status));
42 MOCK_METHOD1(OnGCDApiFlowComplete, void(const base::DictionaryValue&)); 41 MOCK_METHOD1(OnGCDApiFlowComplete, void(const base::DictionaryValue&));
43 MOCK_METHOD0(GetURL, GURL()); 42 MOCK_METHOD0(GetURL, GURL());
44 MOCK_METHOD0(GetNetworkTrafficAnnotationType, 43 MOCK_METHOD0(GetNetworkTrafficAnnotationType,
45 GCDApiFlow::Request::NetworkTrafficAnnotation()); 44 GCDApiFlow::Request::NetworkTrafficAnnotation());
46 }; 45 };
47 46
48 class GCDApiFlowTest : public testing::Test { 47 class GCDApiFlowTest : public testing::Test {
49 public: 48 public:
50 GCDApiFlowTest() 49 GCDApiFlowTest()
51 : ui_thread_(content::BrowserThread::UI, &loop_), 50 : request_context_(new net::TestURLRequestContextGetter(
52 request_context_(new net::TestURLRequestContextGetter(
53 base::ThreadTaskRunnerHandle::Get())), 51 base::ThreadTaskRunnerHandle::Get())),
54 account_id_(kAccountId) {} 52 account_id_(kAccountId) {}
55 53
56 ~GCDApiFlowTest() override {} 54 ~GCDApiFlowTest() override {}
57 55
58 protected: 56 protected:
59 void SetUp() override { 57 void SetUp() override {
60 token_service_.GetFakeOAuth2TokenServiceDelegate()->set_request_context( 58 token_service_.GetFakeOAuth2TokenServiceDelegate()->set_request_context(
61 request_context_.get()); 59 request_context_.get());
62 token_service_.AddAccount(account_id_); 60 token_service_.AddAccount(account_id_);
63 ui_thread_.Stop(); // HACK: Fake being on the UI thread
64 61
65 std::unique_ptr<MockDelegate> delegate = base::MakeUnique<MockDelegate>(); 62 std::unique_ptr<MockDelegate> delegate = base::MakeUnique<MockDelegate>();
66 mock_delegate_ = delegate.get(); 63 mock_delegate_ = delegate.get();
67 EXPECT_CALL(*mock_delegate_, GetURL()) 64 EXPECT_CALL(*mock_delegate_, GetURL())
68 .WillRepeatedly(Return( 65 .WillRepeatedly(Return(
69 GURL("https://www.google.com/cloudprint/confirm?token=SomeToken"))); 66 GURL("https://www.google.com/cloudprint/confirm?token=SomeToken")));
70 gcd_flow_ = base::MakeUnique<GCDApiFlowImpl>(request_context_.get(), 67 gcd_flow_ = base::MakeUnique<GCDApiFlowImpl>(request_context_.get(),
71 &token_service_, account_id_); 68 &token_service_, account_id_);
72 gcd_flow_->Start(std::move(delegate)); 69 gcd_flow_->Start(std::move(delegate));
73 } 70 }
74 71
75 base::MessageLoopForUI loop_; 72 content::TestBrowserThreadBundle test_browser_thread_bundle_;
76 content::TestBrowserThread ui_thread_;
77 scoped_refptr<net::TestURLRequestContextGetter> request_context_; 73 scoped_refptr<net::TestURLRequestContextGetter> request_context_;
78 net::TestURLFetcherFactory fetcher_factory_; 74 net::TestURLFetcherFactory fetcher_factory_;
79 FakeOAuth2TokenService token_service_; 75 FakeOAuth2TokenService token_service_;
80 std::string account_id_; 76 std::string account_id_;
81 std::unique_ptr<GCDApiFlowImpl> gcd_flow_; 77 std::unique_ptr<GCDApiFlowImpl> gcd_flow_;
82 MockDelegate* mock_delegate_; 78 MockDelegate* mock_delegate_;
83 }; 79 };
84 80
85 TEST_F(GCDApiFlowTest, SuccessOAuth2) { 81 TEST_F(GCDApiFlowTest, SuccessOAuth2) {
86 gcd_flow_->OnGetTokenSuccess(NULL, "SomeToken", base::Time()); 82 gcd_flow_->OnGetTokenSuccess(NULL, "SomeToken", base::Time());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 124
129 EXPECT_CALL(*mock_delegate_, 125 EXPECT_CALL(*mock_delegate_,
130 OnGCDApiFlowError(GCDApiFlow::ERROR_MALFORMED_RESPONSE)); 126 OnGCDApiFlowError(GCDApiFlow::ERROR_MALFORMED_RESPONSE));
131 127
132 fetcher->delegate()->OnURLFetchComplete(fetcher); 128 fetcher->delegate()->OnURLFetchComplete(fetcher);
133 } 129 }
134 130
135 } // namespace 131 } // namespace
136 132
137 } // namespace cloud_print 133 } // namespace cloud_print
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698