Index: chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_print_to_phone_jobs_fetcher_unittest.cc |
diff --git a/chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_print_to_phone_jobs_fetcher_unittest.cc b/chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_print_to_phone_jobs_fetcher_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..600815b2ad26c2a2176f730a086ec26927918475 |
--- /dev/null |
+++ b/chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_print_to_phone_jobs_fetcher_unittest.cc |
@@ -0,0 +1,478 @@ |
+// Copyright 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+// |
+#include <map> |
+#include <string> |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "base/stringprintf.h" |
+#include "chrome/common/cloud_print/test_cloud_print_utils.h" |
+#include "chrome/browser/chrome_to_mobile/common/test_cloud_print_request_factory.h" |
+#include "chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_print_to_phone_jobs_fetcher.h" |
+#include "chrome/browser/chrome_to_mobile/receive/testing_chrome_to_mobile_receive.h" |
+ |
+using namespace chrome_to_mobile_receive; |
+using namespace cloud_print; |
+ |
+namespace { |
+ |
+const char* kFetchResponseErrorJob = |
+ " {" |
+ " \"id\": \"job id\"," |
+ " \"fileUrl\": \"https://oogl/download?id\"," |
+ " \"status\": \"ERROR\"," |
+ " \"tags\": [" |
+ " \"__apns__original_url=http://original.url\"" |
+ " ]" |
+ " }"; |
+ |
+const char* kFetchResponseNoPrintJob = |
+ " {" |
+ " \"id\": \"job id\"," |
+ " \"status\": \"%s\"," |
+ " \"fileUrl\": \"https://oogl/download?id\"," |
+ " \"tags\": [" |
+ " \"__snapshot_type=url\"," |
+ " \"__apns__original_url=http://original.url\"" |
+ " \"__snapshot_id=111\"" |
+ " ]" |
+ " }"; |
+ |
+const char* kFetchResponseQueuedPrintJobFormat = |
+ " {" |
+ " \"id\": \"%s\"," |
+ " \"status\": \"%s\"," |
+ " \"fileUrl\": \"https://oogl/download?id\"," |
+ " \"tags\": [" |
+ " \"__apns__original_url=http://original.url\"" |
+ " ]" |
+ " }"; |
+ |
+std::string GenerateFetchResponseWithQueuedPrintJob(const char* job_id) { |
+ return GenerateFetchSuccessResponseWithJobStrings(1, base::StringPrintf( |
+ kFetchResponseQueuedPrintJobFormat, job_id, "QUEUED").c_str()); |
+} |
+ |
+std::string GenerateFetchResponseWithQueuedPrintJobs( |
+ const char* job_id, const char* job_id2) { |
+ return GenerateFetchSuccessResponseWithJobStrings( |
+ 2, |
+ base::StringPrintf( |
+ kFetchResponseQueuedPrintJobFormat, job_id, "QUEUED").c_str(), |
+ base::StringPrintf( |
+ kFetchResponseQueuedPrintJobFormat, job_id2, "QUEUED").c_str()); |
+} |
+ |
+std::string GenerateFetchResponseWithPrintJobs( |
+ const char* job_id1, const char* status1, |
+ const char* job_id2, const char* status2) { |
+ return GenerateFetchSuccessResponseWithJobStrings( |
+ 2, |
+ base::StringPrintf( |
+ kFetchResponseQueuedPrintJobFormat, job_id1, status1).c_str(), |
+ base::StringPrintf( |
+ kFetchResponseQueuedPrintJobFormat, job_id2, status2).c_str()); |
+} |
+ |
+class MockChromeToMobilePrintToPhoneJobsFetcherConsumer |
+ : public ChromeToMobilePrintToPhoneJobsFetcher::Consumer { |
+ public: |
+ MockChromeToMobilePrintToPhoneJobsFetcherConsumer(); |
+ virtual ~MockChromeToMobilePrintToPhoneJobsFetcherConsumer(); |
+ |
+ // |ChromeToMobilePrintToPhoneJobsFetcher::Consumer| |
+ virtual void OnPrintToPhoneJobDownloadStart( |
+ const std::string& job_id, |
+ const std::string& title) OVERRIDE; |
+ virtual void OnPrintToPhoneJobDownloadComplete( |
+ const std::string& job_id, |
+ const bool& success, |
+ const std::string& data_mime_type, |
+ const std::string& data) OVERRIDE; |
+ virtual void OnPrintJobsFetchComplete( |
+ ChromeToMobilePrintToPhoneJobsFetcher* fetcher) OVERRIDE; |
+ |
+ int GetCompletionNumber() const; |
+ const std::map<std::string, bool>* GetJobs() const; |
+ bool HasJob(std::string job_id, bool downloaded) const; |
+ |
+ private: |
+ std::map<std::string /* job id */, bool /* if the job has been downloaded */> |
+ jobs_; |
+ int completion_number_; |
+}; |
+ |
+MockChromeToMobilePrintToPhoneJobsFetcherConsumer:: |
+ MockChromeToMobilePrintToPhoneJobsFetcherConsumer() |
+ : completion_number_(0) { |
+} |
+ |
+MockChromeToMobilePrintToPhoneJobsFetcherConsumer:: |
+ ~MockChromeToMobilePrintToPhoneJobsFetcherConsumer() { |
+} |
+ |
+void MockChromeToMobilePrintToPhoneJobsFetcherConsumer:: |
+ OnPrintToPhoneJobDownloadStart( |
+ const std::string& job_id, |
+ const std::string& title) { |
+ DCHECK(jobs_.find(job_id) == jobs_.end()); |
+ jobs_[job_id] = false; |
+} |
+ |
+void MockChromeToMobilePrintToPhoneJobsFetcherConsumer |
+ ::OnPrintToPhoneJobDownloadComplete( |
+ const std::string& job_id, |
+ const bool& success, |
+ const std::string& data_mime_type, |
+ const std::string& data) { |
+ DCHECK(jobs_.find(job_id) != jobs_.end()); |
+ jobs_[job_id] = true; |
+} |
+ |
+void MockChromeToMobilePrintToPhoneJobsFetcherConsumer:: |
+ OnPrintJobsFetchComplete( |
+ ChromeToMobilePrintToPhoneJobsFetcher* fetcher) { |
+ ++completion_number_; |
+} |
+ |
+const std::map<std::string, bool>* |
+ MockChromeToMobilePrintToPhoneJobsFetcherConsumer::GetJobs() const { |
+ return &jobs_; |
+} |
+ |
+bool MockChromeToMobilePrintToPhoneJobsFetcherConsumer::HasJob( |
+ std::string job_id, bool downloaded) const { |
+ std::map<std::string, bool>::const_iterator it = jobs_.find(job_id); |
+ if (it == jobs_.end()) |
+ return false; |
+ return it->second == downloaded; |
+} |
+ |
+int MockChromeToMobilePrintToPhoneJobsFetcherConsumer::GetCompletionNumber() |
+ const { |
+ return completion_number_; |
+} |
+ |
+} // namespace |
+ |
+class ChromeToMobilePrintToPhoneJobsFetcherTest |
+ : public ChromeToMobileReceiveTest { |
+ public: |
+ ChromeToMobilePrintToPhoneJobsFetcherTest(); |
+ virtual ~ChromeToMobilePrintToPhoneJobsFetcherTest(); |
+ |
+ virtual void SetUp() OVERRIDE; |
+ |
+ scoped_ptr<MockChromeToMobilePrintToPhoneJobsFetcherConsumer> consumer_; |
+ scoped_ptr<ChromeToMobilePrintToPhoneJobsFetcher> fetcher_; |
+}; |
+ |
+ChromeToMobilePrintToPhoneJobsFetcherTest |
+ ::ChromeToMobilePrintToPhoneJobsFetcherTest() { |
+} |
+ |
+ChromeToMobilePrintToPhoneJobsFetcherTest |
+ ::~ChromeToMobilePrintToPhoneJobsFetcherTest() { |
+} |
+ |
+void ChromeToMobilePrintToPhoneJobsFetcherTest::SetUp() { |
+ ChromeToMobileReceiveTest::SetUp(); |
+ consumer_.reset(new MockChromeToMobilePrintToPhoneJobsFetcherConsumer()); |
+ fetcher_.reset(new ChromeToMobilePrintToPhoneJobsFetcher( |
+ cloud_print_server_url_, std::string("pid"), settings_, consumer_.get())); |
+} |
+ |
+TEST_F(ChromeToMobilePrintToPhoneJobsFetcherTest, |
+ NoJobs) { |
+ fetcher_->Fetch(); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/fetch").size()); |
+ |
+ factory_.CompleteRequestAtPath("/fetch", 0, true); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetJobs()->empty()); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobilePrintToPhoneJobsFetcherTest, |
+ InvalidFetchResponse) { |
+ fetcher_->Fetch(); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/fetch").size()); |
+ |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ "kTestFetchDataInvalid", std::string(), true, false, false); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetJobs()->empty()); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobilePrintToPhoneJobsFetcherTest, |
+ NoQueuedJob) { |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ kFetchResponseErrorJob, std::string(), true, false, false); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetJobs()->empty()); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobilePrintToPhoneJobsFetcherTest, |
+ NoPrintJob) { |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ kFetchResponseNoPrintJob, std::string(), true, false, false); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetJobs()->empty()); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobilePrintToPhoneJobsFetcherTest, |
+ OnePrintJob) { |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithQueuedPrintJob("job1"), std::string(), true, |
+ false, false); |
+ EXPECT_EQ(1U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/download").size()) |
+ << "fetcher should start downloading the fetched job (job1)."; |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(1U, consumer_->GetJobs()->size()); |
+ EXPECT_TRUE(consumer_->HasJob("job1", false)) |
+ << "Consumer should be notified that a job download has started."; |
+ |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ EXPECT_EQ(1U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/control").size()) |
+ << "Job status should be updated after downloaded."; |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(1U, consumer_->GetJobs()->size()); |
+ EXPECT_TRUE(consumer_->HasJob("job1", true)) |
+ << "Consumer should be notified that a job download has completed."; |
+ |
+ factory_.CompleteRequestAtPath("/control", 0, true); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(1U, consumer_->GetJobs()->size()); |
+ EXPECT_TRUE(consumer_->HasJob("job1", true)); |
+} |
+ |
+TEST_F(ChromeToMobilePrintToPhoneJobsFetcherTest, |
+ DuplicationInTheSameResponse) { |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithQueuedPrintJobs("job1", "job1"), |
+ std::string(), true, false, false); |
+ EXPECT_EQ(1U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/download").size()); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(1U, consumer_->GetJobs()->size()); |
+ EXPECT_TRUE(consumer_->HasJob("job1", false)); |
+ |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ EXPECT_EQ(1U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/control").size()); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(1U, consumer_->GetJobs()->size()); |
+ EXPECT_TRUE(consumer_->HasJob("job1", true)); |
+ |
+ factory_.CompleteRequestAtPath("/control", 0, true); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(1U, consumer_->GetJobs()->size()); |
+ EXPECT_TRUE(consumer_->HasJob("job1", true)); |
+} |
+ |
+TEST_F(ChromeToMobilePrintToPhoneJobsFetcherTest, |
+ MultipleFetchesNoOverlap) { |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithQueuedPrintJobs("job1", "job2"), |
+ std::string(), true, false, false); |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/control", 0, true); |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/control", 0, true); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->HasJob("job1", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job2", true)); |
+ |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithQueuedPrintJobs("job3", "job4"), |
+ std::string(), true, false, false); |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/control", 0, true); |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/control", 0, true); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(2, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->HasJob("job1", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job2", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job3", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job4", true)); |
+} |
+ |
+TEST_F(ChromeToMobilePrintToPhoneJobsFetcherTest, |
+ MultipleFetchesOverlapped) { |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithQueuedPrintJobs("job1", "job2"), |
+ std::string(), true, false, false); |
+ EXPECT_EQ(2U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(2U, factory_.GetPendingRequestsAtPath("/download").size()); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(2U, consumer_->GetJobs()->size()); |
+ EXPECT_TRUE(consumer_->HasJob("job1", false)); |
+ EXPECT_TRUE(consumer_->HasJob("job2", false)); |
+ |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/control", 0, true); |
+ EXPECT_EQ(2U, consumer_->GetJobs()->size()); |
+ EXPECT_TRUE(consumer_->HasJob("job1", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job2", false)); |
+ |
+ fetcher_->Fetch(); |
+ EXPECT_EQ(2U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/download").size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/fetch").size()); |
+ |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithQueuedPrintJobs("job3", "job4"), |
+ std::string(), true, false, false); |
+ EXPECT_EQ(3U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(3U, factory_.GetPendingRequestsAtPath("/download").size()); |
+ EXPECT_EQ(4U, consumer_->GetJobs()->size()); |
+ EXPECT_TRUE(consumer_->HasJob("job1", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job2", false)); |
+ EXPECT_TRUE(consumer_->HasJob("job3", false)); |
+ EXPECT_TRUE(consumer_->HasJob("job4", false)); |
+ |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/control", 0, true); |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/control", 0, true); |
+ factory_.CompleteRequestAtPath("/control", 0, true); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->HasJob("job1", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job2", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job3", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job4", true)); |
+} |
+ |
+TEST_F(ChromeToMobilePrintToPhoneJobsFetcherTest, |
+ MultipleFetchesRepeatedJobs) { |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithQueuedPrintJobs("job1", "job2"), |
+ std::string(), true, false, false); |
+ |
+ fetcher_->Fetch(); |
+ EXPECT_EQ(3U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(2U, factory_.GetPendingRequestsAtPath("/download").size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/fetch").size()); |
+ |
+ // "job1" is a duplicate, |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithQueuedPrintJobs("job1", "job3"), |
+ std::string(), true, false, false); |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ EXPECT_EQ(3U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/control").size()); |
+ EXPECT_EQ(2U, factory_.GetPendingRequestsAtPath("/download").size()); |
+ EXPECT_EQ(3U, consumer_->GetJobs()->size()); |
+ EXPECT_TRUE(consumer_->HasJob("job1", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job2", false)); |
+ EXPECT_TRUE(consumer_->HasJob("job3", false)); |
+ |
+ factory_.CompleteRequestAtPath("/control", 0, true); |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/control", 0, true); |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/control", 0, true); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(3U, consumer_->GetJobs()->size()); |
+ EXPECT_TRUE(consumer_->HasJob("job1", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job2", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job3", true)); |
+} |
+ |
+TEST_F(ChromeToMobilePrintToPhoneJobsFetcherTest, |
+ MultipleFetchesUpdatedJobs) { |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithQueuedPrintJobs("job1", "job2"), |
+ std::string(), true, false, false); |
+ |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/control", 0, true); |
+ EXPECT_EQ(2U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/download").size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/fetch").size()); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(2U, consumer_->GetJobs()->size()); |
+ EXPECT_TRUE(consumer_->HasJob("job1", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job2", false)); |
+ |
+ // Fetch response include a job fetched before with status updated. |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithPrintJobs("job1", "DONE", "job3", "QUEUED"), |
+ std::string(), true, false, false); |
+ EXPECT_EQ(2U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(2U, factory_.GetPendingRequestsAtPath("/download").size()); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(3U, consumer_->GetJobs()->size()); |
+ EXPECT_TRUE(consumer_->HasJob("job1", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job3", false)); |
+ EXPECT_TRUE(consumer_->HasJob("job3", false)); |
+ |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/control", 0, true); |
+ factory_.CompleteRequestAtPath("/control", 0, true); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(3U, consumer_->GetJobs()->size()); |
+ EXPECT_TRUE(consumer_->HasJob("job1", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job2", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job3", true)); |
+} |
+ |
+TEST_F(ChromeToMobilePrintToPhoneJobsFetcherTest, |
+ DeletedWhileFetching) { |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithQueuedPrintJobs("job1", "job2"), |
+ std::string(), true, false, false); |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithQueuedPrintJobs("job3", "job4"), |
+ std::string(), true, false, false); |
+ |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/control", 0, true); |
+ factory_.CompleteRequestAtPath("/control", 0, true); |
+ factory_.CompleteRequestAtPath("/control", 0, true); |
+ EXPECT_EQ(1U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/download").size()); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(4U, consumer_->GetJobs()->size()); |
+ EXPECT_TRUE(consumer_->HasJob("job1", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job2", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job3", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job4", false)); |
+ |
+ fetcher_.reset(); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(4U, consumer_->GetJobs()->size()); |
+ EXPECT_TRUE(consumer_->HasJob("job1", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job2", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job3", true)); |
+ EXPECT_TRUE(consumer_->HasJob("job4", true)); |
+} |