Index: chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_snapshots_polling_fetcher_unittest.cc |
diff --git a/chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_snapshots_polling_fetcher_unittest.cc b/chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_snapshots_polling_fetcher_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e0d60013c8b5fa9d10cb114a653a6d54696e3cfd |
--- /dev/null |
+++ b/chrome/browser/chrome_to_mobile/receive/chrome_to_mobile_snapshots_polling_fetcher_unittest.cc |
@@ -0,0 +1,1127 @@ |
+// 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 <set> |
+#include <string> |
+ |
+#include "base/stringprintf.h" |
+#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/receive/chrome_to_mobile_snapshots_polling_fetcher.h" |
+#include "chrome/browser/chrome_to_mobile/receive/testing_chrome_to_mobile_receive.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+using namespace chrome_to_mobile_receive; |
+using namespace cloud_print; |
+ |
+namespace { |
+ |
+const char* kFetchResponseURLJobFormat = |
+ " {" |
+ " \"id\": \"job id %s\"," |
+ " \"tags\": [" |
+ " \"__snapshot_type=%s\"," |
+ " \"__apns__original_url=http://original.url\"," |
+ " \"__snapshot_id=%s\"" |
+ " ]" |
+ " }"; |
+ |
+const char* kFetchResponseOfflineDataJobFormat = |
+ " {" |
+ " \"id\": \"offline job id %s\"," |
+ " \"fileUrl\": \"https://oogl/download?id\"," |
+ " \"tags\": [" |
+ " \"__apns__suppress_notification\"," |
+ " \"__snapshot_type=snapshot\"," |
+ " \"__snapshot_id=%s\"" |
+ " ]" |
+ " }"; |
+ |
+std::string GenerateURLOnlyJobStringInFetchResponse(const char* snapshot_id) { |
+ return base::StringPrintf( |
+ kFetchResponseURLJobFormat, snapshot_id, "url", snapshot_id); |
+} |
+ |
+std::string GenerateURLWithDelayedSnapshotJobStringInFetchResponse( |
+ const char* snapshot_id) { |
+ return base::StringPrintf(kFetchResponseURLJobFormat, |
+ snapshot_id, "url_with_delayed_snapshot", snapshot_id); |
+} |
+ |
+std::string GenerateFetchResponseWithSingleURLOnlyJob(const char* snapshot_id) { |
+ return GenerateFetchSuccessResponseWithJobStrings( |
+ 1, GenerateURLOnlyJobStringInFetchResponse(snapshot_id).c_str()); |
+} |
+ |
+std::string GenerateFetchResponseWithURLOnlyJobs( |
+ const char* snapshot_id, const char* snapshot_id2) { |
+ return GenerateFetchSuccessResponseWithJobStrings( |
+ 2, |
+ GenerateURLOnlyJobStringInFetchResponse(snapshot_id).c_str(), |
+ GenerateURLOnlyJobStringInFetchResponse(snapshot_id2).c_str()); |
+} |
+ |
+std::string GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot( |
+ const char* snapshot_id) { |
+ return GenerateFetchSuccessResponseWithJobStrings( |
+ 1, |
+ GenerateURLWithDelayedSnapshotJobStringInFetchResponse( |
+ snapshot_id).c_str()); |
+} |
+ |
+std::string GenerateFetchResponseWithSingleOfflineDataJob( |
+ const char* snapshot_id) { |
+ return GenerateFetchSuccessResponseWithJobStrings(1, base::StringPrintf( |
+ kFetchResponseOfflineDataJobFormat, snapshot_id, snapshot_id).c_str()); |
+} |
+ |
+std::string GenerateFetchResponseWithOfflineAndURLWithDelayedSnapshotJobs( |
+ std::string offline_job_snapshot_id, |
+ std::string url_job_snapshot_id) { |
+ std::string offline_job_string = base::StringPrintf( |
+ kFetchResponseOfflineDataJobFormat, |
+ offline_job_snapshot_id.c_str(), offline_job_snapshot_id.c_str()); |
+ std::string url_job_string = |
+ GenerateURLWithDelayedSnapshotJobStringInFetchResponse( |
+ url_job_snapshot_id.c_str()); |
+ return GenerateFetchSuccessResponseWithJobStrings( |
+ 2, |
+ offline_job_string.c_str(), |
+ url_job_string.c_str()); |
+} |
+ |
+class MockChromeToMobileSnapshotsFetcherConsumer |
+ : public ChromeToMobileSnapshotsFetcher::Consumer { |
+ public: |
+ MockChromeToMobileSnapshotsFetcherConsumer(); |
+ virtual ~MockChromeToMobileSnapshotsFetcherConsumer(); |
+ |
+ virtual void OnSnapshotUrlFetched(const std::string& snapshot_id, |
+ const std::string& original_url, |
+ const std::string& title, |
+ const bool& is_offline_data_expected, |
+ const std::string& create_time) OVERRIDE; |
+ virtual void OnSnapshotDataDownloadComplete(const std::string& snapshot_id, |
+ const bool& success, |
+ const std::string& data_mime_type, |
+ const std::string& data) OVERRIDE; |
+ virtual void OnSnapshotsFetchComplete(ChromeToMobileSnapshotsFetcher * source) |
+ OVERRIDE; |
+ |
+ int GetCompletionNumber() const; |
+ std::set<std::string> GetURLOnlySnapshots() const; |
+ std::set<std::string> GetOfflineDataSnapshots() const; |
+ std::map<std::string, bool> GetNotifiedOfflineDataSnapshots() const; |
+ bool HasNotifiedOfflineDataSnapshot(const std::string& snapshot_id, |
+ const bool& succeed); |
+ |
+ private: |
+ std::set<std::string> url_only_snapshots_; |
+ std::set<std::string> offline_data_snapshots_; |
+ std::map<std::string, bool> notified_offline_data_snapshots_; |
+ int completion_number_; |
+}; |
+ |
+MockChromeToMobileSnapshotsFetcherConsumer:: |
+ MockChromeToMobileSnapshotsFetcherConsumer() |
+ : completion_number_(0) { |
+} |
+ |
+MockChromeToMobileSnapshotsFetcherConsumer:: |
+ ~MockChromeToMobileSnapshotsFetcherConsumer() { |
+} |
+ |
+void MockChromeToMobileSnapshotsFetcherConsumer::OnSnapshotUrlFetched( |
+ const std::string& snapshot_id, |
+ const std::string& original_url, |
+ const std::string& title, |
+ const bool& is_offline_data_expected, |
+ const std::string& create_time) { |
+ if (is_offline_data_expected) |
+ offline_data_snapshots_.insert(snapshot_id); |
+ else |
+ url_only_snapshots_.insert(snapshot_id); |
+} |
+ |
+void MockChromeToMobileSnapshotsFetcherConsumer::OnSnapshotDataDownloadComplete( |
+ const std::string& snapshot_id, |
+ const bool& success, |
+ const std::string& data_mime_type, |
+ const std::string& data) { |
+ DCHECK(offline_data_snapshots_.find(snapshot_id) != |
+ offline_data_snapshots_.end()); |
+ notified_offline_data_snapshots_[snapshot_id] = success; |
+} |
+ |
+void MockChromeToMobileSnapshotsFetcherConsumer::OnSnapshotsFetchComplete( |
+ ChromeToMobileSnapshotsFetcher * source) { |
+ ++completion_number_; |
+} |
+ |
+std::set<std::string> MockChromeToMobileSnapshotsFetcherConsumer:: |
+ GetURLOnlySnapshots() const { |
+ return url_only_snapshots_; |
+} |
+ |
+std::set<std::string> MockChromeToMobileSnapshotsFetcherConsumer:: |
+ GetOfflineDataSnapshots() const { |
+ return offline_data_snapshots_; |
+} |
+ |
+std::map<std::string, bool> MockChromeToMobileSnapshotsFetcherConsumer:: |
+ GetNotifiedOfflineDataSnapshots() const { |
+ return notified_offline_data_snapshots_; |
+} |
+ |
+bool MockChromeToMobileSnapshotsFetcherConsumer:: |
+ HasNotifiedOfflineDataSnapshot(const std::string& snapshot_id, |
+ const bool& succeed) { |
+ if (notified_offline_data_snapshots_.find(snapshot_id) == |
+ notified_offline_data_snapshots_.end()) { |
+ return false; |
+ } |
+ return notified_offline_data_snapshots_[snapshot_id] == succeed; |
+} |
+ |
+int MockChromeToMobileSnapshotsFetcherConsumer::GetCompletionNumber() const { |
+ return completion_number_; |
+} |
+ |
+} // namespace |
+ |
+class ChromeToMobileSnapshotsFetcherTest : public ChromeToMobileReceiveTest { |
+ public: |
+ ChromeToMobileSnapshotsFetcherTest(); |
+ virtual ~ChromeToMobileSnapshotsFetcherTest(); |
+ |
+ virtual void SetUp() OVERRIDE; |
+ |
+ scoped_ptr<MockChromeToMobileSnapshotsFetcherConsumer> consumer_; |
+ scoped_ptr<ChromeToMobileSnapshotsFetcher> fetcher_; |
+}; |
+ |
+ChromeToMobileSnapshotsFetcherTest::ChromeToMobileSnapshotsFetcherTest() { |
+} |
+ |
+ChromeToMobileSnapshotsFetcherTest::~ChromeToMobileSnapshotsFetcherTest() { |
+} |
+ |
+void ChromeToMobileSnapshotsFetcherTest::SetUp() { |
+ ChromeToMobileReceiveTest::SetUp(); |
+ consumer_.reset(new MockChromeToMobileSnapshotsFetcherConsumer()); |
+ fetcher_.reset(new ChromeToMobileSnapshotsPollingFetcher( |
+ cloud_print_server_url_, std::string("p"), settings_, consumer_.get(), |
+ 0, 0, 5)); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ NoSnapshots) { |
+ fetcher_->Fetch(); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/fetch").size()); |
+ |
+ factory_.CompleteRequestAtPath("/fetch", 0, true); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().empty()); |
+ EXPECT_TRUE(consumer_->GetNotifiedOfflineDataSnapshots().empty()); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ InvalidSnapshots) { |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ "kTestFetchDataInvalid", std::string(), true, false, false); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().empty()); |
+ EXPECT_TRUE(consumer_->GetNotifiedOfflineDataSnapshots().empty()); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ SingleURLOnlySnapshot) { |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, GenerateFetchResponseWithSingleURLOnlyJob("8-7110"), |
+ std::string(), true, false, false); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().begin()->compare("8-7110") == 0); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().empty()); |
+ EXPECT_TRUE(consumer_->GetNotifiedOfflineDataSnapshots().empty()); |
+ EXPECT_TRUE(factory_.GetPendingRequests().size() == 1); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/deletejob").size()) |
+ << "The print job should be deleted."; |
+ |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().begin()->compare("8-7110") == 0); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().empty()); |
+ EXPECT_TRUE(consumer_->GetNotifiedOfflineDataSnapshots().empty()); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ SeveralURLOnlySnapshots) { |
+ fetcher_->Fetch(); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/fetch").size()); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithURLOnlyJobs("8", "88"), |
+ std::string(), true, false, false); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(2U, consumer_->GetURLOnlySnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().find("8") != |
+ consumer_->GetURLOnlySnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().find("88") != |
+ consumer_->GetURLOnlySnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().empty()); |
+ EXPECT_TRUE(consumer_->GetNotifiedOfflineDataSnapshots().empty()); |
+ EXPECT_TRUE(factory_.GetPendingRequests().size() == 2); |
+ EXPECT_EQ(2U, factory_.GetPendingRequestsAtPath("/deletejob").size()); |
+ |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(2U, consumer_->GetURLOnlySnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().find("8") != |
+ consumer_->GetURLOnlySnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().find("88") != |
+ consumer_->GetURLOnlySnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().empty()); |
+ EXPECT_TRUE(consumer_->GetNotifiedOfflineDataSnapshots().empty()); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ OneOfflineDataSnapshotFetchSucceedAndDownloadSuccess) { |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(1U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_EQ(0, consumer_->GetOfflineDataSnapshots().begin()->compare("8A5")); |
+ EXPECT_TRUE(consumer_->GetNotifiedOfflineDataSnapshots().empty()); |
+ EXPECT_TRUE(factory_.GetPendingRequests().size() == 2); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/deletejob").size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/fetch").size()); |
+ |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ |
+ // The expected offline data job comes. |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithSingleOfflineDataJob("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(1U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_EQ(0, consumer_->GetOfflineDataSnapshots().begin()->compare("8A5")); |
+ EXPECT_TRUE(consumer_->GetNotifiedOfflineDataSnapshots().empty()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/download").size()); |
+ |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(1U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_EQ(1U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", true)); |
+ EXPECT_EQ(1U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/deletejob").size()); |
+ |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(1U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_EQ(1U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", true)); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ OneOfflineDataSnapshotFetchSucceedWithRepeatedJobsAndDownloadFail) { |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ |
+ // Somehow the same job is received. |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(1U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_EQ(0, consumer_->GetOfflineDataSnapshots().begin()->compare("8A5")); |
+ EXPECT_TRUE(consumer_->GetNotifiedOfflineDataSnapshots().empty()); |
+ EXPECT_TRUE(factory_.GetPendingRequests().size() == 1); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/fetch").size()); |
+ |
+ // The expected offline data job comes. |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithSingleOfflineDataJob("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(1U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_EQ(0, consumer_->GetOfflineDataSnapshots().begin()->compare("8A5")); |
+ EXPECT_TRUE(consumer_->GetNotifiedOfflineDataSnapshots().empty()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/download").size()); |
+ |
+ factory_.CompleteRequestAtPath("/download", 0, false); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(1U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_EQ(0, consumer_->GetOfflineDataSnapshots().begin()->compare("8A5")); |
+ EXPECT_EQ(1U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", false)); |
+ EXPECT_EQ(1U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/deletejob").size()); |
+ |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(1U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_EQ(1U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", false)); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ OneOfflineDataSnapshotFetchSucceedWithRepeatedJobsDownloadSuccess) { |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ // Somehow the same job is received. |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithSingleOfflineDataJob("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(1U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_EQ(0, consumer_->GetOfflineDataSnapshots().begin()->compare("8A5")); |
+ EXPECT_EQ(1U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", true)); |
+ EXPECT_EQ(1U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/deletejob").size()); |
+ |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(1U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_EQ(0, consumer_->GetOfflineDataSnapshots().begin()->compare("8A5")); |
+ EXPECT_EQ(1U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", true)); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ UnexpectedOfflineDataJob) { |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithSingleOfflineDataJob("Not8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(1U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_EQ(0, consumer_->GetOfflineDataSnapshots().begin()->compare("8A5")); |
+ EXPECT_TRUE(consumer_->GetNotifiedOfflineDataSnapshots().empty()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/fetch").size()); |
+ |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithSingleOfflineDataJob("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ EXPECT_EQ(1U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/download").size()); |
+ |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(1U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_EQ(0, consumer_->GetOfflineDataSnapshots().begin()->compare("8A5")); |
+ EXPECT_EQ(1U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", true)); |
+ EXPECT_EQ(1U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/deletejob").size()); |
+ |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(1U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_EQ(0, consumer_->GetOfflineDataSnapshots().begin()->compare("8A5")); |
+ EXPECT_EQ(1U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", true)); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ MorePendingJobsComing) { |
+ fetcher_->Fetch(); |
+ |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ // Repeated job. |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ // A mix of url with delayed snapshot jobs and offline data jobs. |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithOfflineAndURLWithDelayedSnapshotJobs("8A5", "8"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ EXPECT_EQ(2U, factory_.GetPendingRequestsAtPath("/deletejob").size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/download").size()); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(2U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A5") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetNotifiedOfflineDataSnapshots().empty()); |
+ |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(2U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A5") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_EQ(1U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", true)); |
+ EXPECT_EQ(3U, factory_.GetPendingRequestsAtPath("/deletejob").size()); |
+ |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithSingleOfflineDataJob("8"), std::string(), true, |
+ false, false); |
+ test_loop_.RunUntilIdle(); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/download").size()); |
+ |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(2U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A5") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_EQ(2U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", true)); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8", true)); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ GiveUpPolling) { |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath("/fetch", 0, false); |
+ test_loop_.RunUntilIdle(); |
+ while (!factory_.GetPendingRequestsAtPath("/fetch").empty()) { |
+ factory_.CompleteRequestAtPath("/fetch", 0, false); |
+ test_loop_.RunUntilIdle(); |
+ } |
+ |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(1U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A5") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_EQ(1U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", false)); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ MorePendingJobsComingAndThenGiveUpPolling) { |
+ fetcher_->Fetch(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithOfflineAndURLWithDelayedSnapshotJobs("8A5", "8"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(2U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A5") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_EQ(1U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", true)); |
+ |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ while (!factory_.GetPendingRequestsAtPath("/fetch").empty()) { |
+ factory_.CompleteRequestAtPath("/fetch", 0, false); |
+ test_loop_.RunUntilIdle(); |
+ } |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(2U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A5") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_EQ(2U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", true)); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8", false)); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ GiveUpPollingWhileDownloading) { |
+ fetcher_->Fetch(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithOfflineAndURLWithDelayedSnapshotJobs("8A5", "8"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ while (!factory_.GetPendingRequestsAtPath("/fetch").empty()) { |
+ factory_.CompleteRequestAtPath("/fetch", 0, false); |
+ test_loop_.RunUntilIdle(); |
+ } |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(2U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A5") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_EQ(1U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8", false)); |
+ EXPECT_EQ(3U, factory_.GetPendingRequests().size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/download").size()); |
+ EXPECT_EQ(2U, factory_.GetPendingRequestsAtPath("/deletejob").size()); |
+ |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(2U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A5") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_EQ(2U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", true)); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8", false)); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ GiveUpPollingBeforeDeleteRequestsCompleted) { |
+ fetcher_->Fetch(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithOfflineAndURLWithDelayedSnapshotJobs("8A5", "8"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ while (!factory_.GetPendingRequestsAtPath("/fetch").empty()) { |
+ factory_.CompleteRequestAtPath("/fetch", 0, false); |
+ test_loop_.RunUntilIdle(); |
+ } |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(2U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A5") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_EQ(2U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", true)); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8", false)); |
+ EXPECT_EQ(2U, factory_.GetPendingRequests().size()); |
+ |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(2U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A5") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_EQ(2U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", true)); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8", false)); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ GiveUpPollingBeforeUrlOnlyJobsComplete) { |
+ fetcher_->Fetch(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithURLOnlyJobs("8S", "88S"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ while (!factory_.GetPendingRequestsAtPath("/fetch").empty()) { |
+ factory_.CompleteRequestAtPath("/fetch", 0, false); |
+ test_loop_.RunUntilIdle(); |
+ } |
+ |
+ EXPECT_EQ(0, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(2U, consumer_->GetURLOnlySnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().find("8S") != |
+ consumer_->GetURLOnlySnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().find("88S") != |
+ consumer_->GetURLOnlySnapshots().end()); |
+ EXPECT_EQ(1U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A5") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_EQ(1U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", false)); |
+ EXPECT_EQ(2U, factory_.GetPendingRequests().size()); |
+ |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(2U, consumer_->GetURLOnlySnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().find("8S") != |
+ consumer_->GetURLOnlySnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().find("88S") != |
+ consumer_->GetURLOnlySnapshots().end()); |
+ EXPECT_EQ(1U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A5") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_EQ(1U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", false)); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ FetcherDeletedWhilePolling) { |
+ fetcher_->Fetch(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A6"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A7"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleOfflineDataJob("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleOfflineDataJob("8A7"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ |
+ // Reset the fetcher when it is polling the offline data job for "86A". |
+ fetcher_.reset(); |
+ |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(3U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A5") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A6") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A7") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_EQ(3U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", true)); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A6", false)); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A7", true)); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ FetcherDeletedWhileDownloading) { |
+ fetcher_->Fetch(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A7"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleOfflineDataJob("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleOfflineDataJob("8A7"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ |
+ // Reset the fetcher while it is downloading offline data job "8A7". |
+ fetcher_.reset(); |
+ |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(2U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A5") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A7") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_EQ(2U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", true)); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A7", false)); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ FetcherDeletedWhileDeleting) { |
+ fetcher_->Fetch(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A7"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleOfflineDataJob("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleOfflineDataJob("8A7"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ |
+ // Reset the fetcher while it is downloading offline data job "8A7". |
+ fetcher_.reset(); |
+ |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(2U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A5") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A7") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_EQ(2U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", true)); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A7", true)); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ MultipleFetchURLOnlySnapshots) { |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithURLOnlyJobs("8", "88"), |
+ std::string(), true, false, false); |
+ |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(2U, consumer_->GetURLOnlySnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().find("8") != |
+ consumer_->GetURLOnlySnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().find("88") != |
+ consumer_->GetURLOnlySnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().empty()); |
+ EXPECT_TRUE(consumer_->GetNotifiedOfflineDataSnapshots().empty()); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+ |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithURLOnlyJobs("888", "8888"), |
+ std::string(), true, false, false); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ |
+ EXPECT_EQ(2, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(4U, consumer_->GetURLOnlySnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().find("8") != |
+ consumer_->GetURLOnlySnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().find("88") != |
+ consumer_->GetURLOnlySnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().find("888") != |
+ consumer_->GetURLOnlySnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().find("8888") != |
+ consumer_->GetURLOnlySnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().empty()); |
+ EXPECT_TRUE(consumer_->GetNotifiedOfflineDataSnapshots().empty()); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ FetchDeletedAfterMultipleFetch) { |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithURLOnlyJobs("8", "88"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ // Fetch again while polling the offline data for "8A5". |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithURLOnlyJobs("888", "8888"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ |
+ fetcher_.reset(); |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(4U, consumer_->GetURLOnlySnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().find("8") != |
+ consumer_->GetURLOnlySnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().find("88") != |
+ consumer_->GetURLOnlySnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().find("888") != |
+ consumer_->GetURLOnlySnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().find("8888") != |
+ consumer_->GetURLOnlySnapshots().end()); |
+ EXPECT_EQ(1U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A5") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_EQ(1U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", false)); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ FetchAgainWhilePolling) { |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ factory_.CompleteRequestAtPath("/fetch", 0, |
+ GenerateFetchResponseWithURLOnlyJobs("8", "88"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/fetch").size()); |
+ EXPECT_EQ(3U, factory_.GetPendingRequestsAtPath("/deletejob").size()); |
+ |
+ // Fetch again while polling the offline data for "8A5". |
+ fetcher_->Fetch(); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/fetch").size()); |
+ EXPECT_EQ(3U, factory_.GetPendingRequestsAtPath("/deletejob").size()); |
+ |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleOfflineDataJob("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ EXPECT_EQ(0U, factory_.GetPendingRequestsAtPath("/fetch").size()); |
+ EXPECT_EQ(3U, factory_.GetPendingRequestsAtPath("/deletejob").size()); |
+ EXPECT_EQ(1U, factory_.GetPendingRequestsAtPath("/download").size()); |
+ |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_EQ(2U, consumer_->GetURLOnlySnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().find("8") != |
+ consumer_->GetURLOnlySnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().find("88") != |
+ consumer_->GetURLOnlySnapshots().end()); |
+ EXPECT_EQ(1U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A5") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_EQ(1U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", true)); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |
+ |
+TEST_F(ChromeToMobileSnapshotsFetcherTest, |
+ FetchAgainWhileDeleting) { |
+ fetcher_->Fetch(); |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleOfflineDataJob("8A5"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ |
+ // Fetch again while deleting. |
+ fetcher_->Fetch(); |
+ |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleURLJobWithDelayedSnapshot("8A6"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ factory_.CompleteRequestAtPath( |
+ "/fetch", 0, |
+ GenerateFetchResponseWithSingleOfflineDataJob("8A6"), |
+ std::string(), true, false, false); |
+ test_loop_.RunUntilIdle(); |
+ factory_.CompleteRequestAtPath("/download", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ factory_.CompleteRequestAtPath("/deletejob", 0, true); |
+ |
+ EXPECT_EQ(1, consumer_->GetCompletionNumber()); |
+ EXPECT_TRUE(consumer_->GetURLOnlySnapshots().empty()); |
+ EXPECT_EQ(2U, consumer_->GetOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A5") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_TRUE(consumer_->GetOfflineDataSnapshots().find("8A6") != |
+ consumer_->GetOfflineDataSnapshots().end()); |
+ EXPECT_EQ(2U, consumer_->GetNotifiedOfflineDataSnapshots().size()); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A5", true)); |
+ EXPECT_TRUE(consumer_->HasNotifiedOfflineDataSnapshot("8A6", true)); |
+ EXPECT_EQ(0U, factory_.GetPendingRequests().size()); |
+} |