| Index: chrome/browser/local_discovery/cloud_print_printer_list_unittest.cc
|
| diff --git a/chrome/browser/local_discovery/cloud_print_printer_list_unittest.cc b/chrome/browser/local_discovery/cloud_print_printer_list_unittest.cc
|
| index f312898f1573ec648800934192a52c313d86e06d..c69e442737dd5716cf698eff74c9ec036b0f9ec4 100644
|
| --- a/chrome/browser/local_discovery/cloud_print_printer_list_unittest.cc
|
| +++ b/chrome/browser/local_discovery/cloud_print_printer_list_unittest.cc
|
| @@ -2,26 +2,19 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include "chrome/browser/local_discovery/cloud_print_printer_list.h"
|
| +
|
| #include <set>
|
|
|
| -#include "base/bind.h"
|
| #include "base/message_loop/message_loop.h"
|
| -#include "chrome/browser/local_discovery/cloud_print_printer_list.h"
|
| +#include "base/run_loop.h"
|
| #include "components/cloud_devices/common/cloud_devices_urls.h"
|
| #include "content/public/test/test_browser_thread.h"
|
| #include "google_apis/gaia/fake_oauth2_token_service.h"
|
| -#include "google_apis/gaia/google_service_auth_error.h"
|
| -#include "net/base/host_port_pair.h"
|
| -#include "net/base/net_errors.h"
|
| -#include "net/http/http_request_headers.h"
|
| -#include "net/http/http_status_code.h"
|
| #include "net/url_request/test_url_fetcher_factory.h"
|
| -#include "net/url_request/url_fetcher_impl.h"
|
| -#include "net/url_request/url_request_status.h"
|
| #include "net/url_request/url_request_test_util.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| -#include "url/gurl.h"
|
|
|
| using testing::Mock;
|
| using testing::NiceMock;
|
| @@ -51,76 +44,61 @@ class CloudPrintPrinterListTest : public testing::Test {
|
| CloudPrintPrinterListTest()
|
| : ui_thread_(content::BrowserThread::UI, &loop_),
|
| request_context_(new net::TestURLRequestContextGetter(
|
| - base::MessageLoopProxy::current())) {
|
| + base::MessageLoopProxy::current())),
|
| + fetcher_factory_(NULL),
|
| + printer_list_(request_context_.get(), &token_service_, "account_id",
|
| + &delegate_) {
|
| + }
|
| +
|
| + virtual void SetUp() OVERRIDE {
|
| ui_thread_.Stop(); // HACK: Fake being on the UI thread
|
| token_service_.set_request_context(request_context_.get());
|
| token_service_.AddAccount("account_id");
|
| - printer_list_.reset(
|
| - new CloudPrintPrinterList(request_context_.get(),
|
| - &token_service_,
|
| - "account_id",
|
| - &delegate_));
|
| -
|
| - fallback_fetcher_factory_.reset(new net::TestURLFetcherFactory());
|
| - net::URLFetcherImpl::set_factory(NULL);
|
| - fetcher_factory_.reset(new net::FakeURLFetcherFactory(
|
| - fallback_fetcher_factory_.get()));
|
| - }
|
| -
|
| - virtual ~CloudPrintPrinterListTest() {
|
| - fetcher_factory_.reset();
|
| - net::URLFetcherImpl::set_factory(fallback_fetcher_factory_.get());
|
| - fallback_fetcher_factory_.reset();
|
| }
|
|
|
| protected:
|
| base::MessageLoopForUI loop_;
|
| content::TestBrowserThread ui_thread_;
|
| scoped_refptr<net::TestURLRequestContextGetter> request_context_;
|
| - // Use a test factory as a fallback so we don't have to deal with OAuth2
|
| - // requests.
|
| - scoped_ptr<net::TestURLFetcherFactory> fallback_fetcher_factory_;
|
| - scoped_ptr<net::FakeURLFetcherFactory> fetcher_factory_;
|
| + net::FakeURLFetcherFactory fetcher_factory_;
|
| FakeOAuth2TokenService token_service_;
|
| StrictMock<MockDelegate> delegate_;
|
| - scoped_ptr<CloudPrintPrinterList> printer_list_;
|
| + CloudPrintPrinterList printer_list_;
|
| };
|
|
|
| -TEST_F(CloudPrintPrinterListTest, SuccessOAuth2) {
|
| - fetcher_factory_->SetFakeResponse(
|
| +TEST_F(CloudPrintPrinterListTest, List) {
|
| + fetcher_factory_.SetFakeResponse(
|
| cloud_devices::GetCloudPrintRelativeURL("search"),
|
| kSampleSuccessResponseOAuth,
|
| net::HTTP_OK,
|
| net::URLRequestStatus::SUCCESS);
|
|
|
| - GCDBaseApiFlow* cloudprint_flow = printer_list_->GetOAuth2ApiFlowForTests();
|
| + GCDBaseApiFlow* cloudprint_flow = printer_list_.GetOAuth2ApiFlowForTests();
|
|
|
| - printer_list_->Start();
|
| + printer_list_.Start();
|
|
|
| cloudprint_flow->OnGetTokenSuccess(NULL, "SomeToken", base::Time());
|
|
|
| EXPECT_CALL(delegate_, OnCloudPrintPrinterListReady());
|
| + EXPECT_CALL(delegate_, OnCloudPrintPrinterListUnavailable()).Times(0);
|
|
|
| - base::MessageLoop::current()->RunUntilIdle();
|
| + base::RunLoop().RunUntilIdle();
|
|
|
| Mock::VerifyAndClear(&delegate_);
|
|
|
| std::set<std::string> ids_found;
|
| std::set<std::string> ids_expected;
|
| -
|
| ids_expected.insert("someID");
|
|
|
| - int length = 0;
|
| - for (CloudPrintPrinterList::iterator i = printer_list_->begin();
|
| - i != printer_list_->end(); i++, length++) {
|
| + for (CloudPrintPrinterList::iterator i = printer_list_.begin();
|
| + i != printer_list_.end(); i++) {
|
| ids_found.insert(i->id);
|
| }
|
|
|
| EXPECT_EQ(ids_expected, ids_found);
|
| - EXPECT_EQ(1, length);
|
|
|
| const CloudPrintPrinterList::PrinterDetails* found =
|
| - printer_list_->GetDetailsFor("someID");
|
| + printer_list_.GetDetailsFor("someID");
|
| ASSERT_TRUE(found != NULL);
|
| EXPECT_EQ("someID", found->id);
|
| EXPECT_EQ("someDisplayName", found->display_name);
|
|
|