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

Unified Diff: chrome/browser/local_discovery/cloud_print_printer_list_unittest.cc

Issue 284223004: List cloud devices in chrome://devices page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
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..0ac28f39dc71690873a1b9ec9d421d7b40dcd780 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;
@@ -40,10 +33,10 @@ const char kSampleSuccessResponseOAuth[] = "{"
" ]"
"}";
-class MockDelegate : public CloudPrintPrinterList::Delegate {
+class MockDelegate : public CloudDeviceListDelegate {
public:
- MOCK_METHOD0(OnCloudPrintPrinterListUnavailable, void());
- MOCK_METHOD0(OnCloudPrintPrinterListReady, void());
+ MOCK_METHOD0(OnDeviceListUnavailable, void());
+ MOCK_METHOD0(OnDeviceListReady, void());
};
class CloudPrintPrinterListTest : public testing::Test {
@@ -51,80 +44,62 @@ 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_, OnDeviceListReady());
- 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_.printer_list().begin();
+ i != printer_list_.printer_list().end(); i++) {
ids_found.insert(i->id);
}
- EXPECT_EQ(ids_expected, ids_found);
- EXPECT_EQ(1, length);
+ ASSERT_EQ(ids_expected, ids_found);
- const CloudPrintPrinterList::PrinterDetails* found =
- printer_list_->GetDetailsFor("someID");
- ASSERT_TRUE(found != NULL);
- EXPECT_EQ("someID", found->id);
- EXPECT_EQ("someDisplayName", found->display_name);
- EXPECT_EQ("someDescription", found->description);
+ EXPECT_EQ("someID", printer_list_.printer_list()[0].id);
+ EXPECT_EQ("someDisplayName", printer_list_.printer_list()[0].display_name);
+ EXPECT_EQ("someDescription", printer_list_.printer_list()[0].description);
+ EXPECT_EQ("printer", printer_list_.printer_list()[0].type);
}
} // namespace
« no previous file with comments | « chrome/browser/local_discovery/cloud_print_printer_list.cc ('k') | chrome/browser/local_discovery/gcd_base_api_flow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698