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

Unified Diff: components/password_manager/core/browser/fake_affiliation_api.cc

Issue 868253005: AffiliationBackend: Implement the better part of on-demand fetching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tidy up NULL time related issues. Created 5 years, 11 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: components/password_manager/core/browser/fake_affiliation_api.cc
diff --git a/components/password_manager/core/browser/fake_affiliation_api.cc b/components/password_manager/core/browser/fake_affiliation_api.cc
new file mode 100644
index 0000000000000000000000000000000000000000..38e15ad3078828050d6f4f24b771461e7ed18c21
--- /dev/null
+++ b/components/password_manager/core/browser/fake_affiliation_api.cc
@@ -0,0 +1,69 @@
+// Copyright 2015 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 "components/password_manager/core/browser/fake_affiliation_api.h"
+
+#include <algorithm>
+
+#include "base/memory/scoped_ptr.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace password_manager {
+
+ScopedFakeAffiliationAPI::ScopedFakeAffiliationAPI() {
+}
+
+ScopedFakeAffiliationAPI::~ScopedFakeAffiliationAPI() {
+ // Note that trying to provide details of dangling fetchers would be unwise,
+ // as it is quite possible that they have been destroyed already.
+ EXPECT_FALSE(HasPendingRequest())
+ << "Pending AffilitionFetcher on shutdown.\n"
+ << "Call IgnoreNextRequest() if this is intended.";
+}
+
+void ScopedFakeAffiliationAPI::AddTestEquivalenceClass(
+ const AffiliatedFacets& affiliated_facets) {
+ preset_equivalence_relation_.push_back(affiliated_facets);
+}
+
+bool ScopedFakeAffiliationAPI::HasPendingRequest() {
+ return fake_fetcher_factory_.has_pending_fetchers();
+}
+
+std::vector<FacetURI> ScopedFakeAffiliationAPI::GetNextRequestedFacets() {
+ if (fake_fetcher_factory_.has_pending_fetchers())
+ return fake_fetcher_factory_.PeekNextFetcher()->requested_facet_uris();
+ return std::vector<FacetURI>();
+}
+
+void ScopedFakeAffiliationAPI::ServeNextRequest() {
+ if (!fake_fetcher_factory_.has_pending_fetchers())
+ return;
+
+ FakeAffiliationFetcher* fetcher = fake_fetcher_factory_.PopNextFetcher();
+ scoped_ptr<AffiliationFetcherDelegate::Result> fake_response(
+ new AffiliationFetcherDelegate::Result);
+ for (const auto& preset_equivalence_class : preset_equivalence_relation_) {
+ bool had_intersection_with_request = false;
+ for (const auto& requested_facet_uri : fetcher->requested_facet_uris()) {
+ if (std::find(preset_equivalence_class.begin(),
+ preset_equivalence_class.end(),
+ requested_facet_uri) != preset_equivalence_class.end()) {
+ had_intersection_with_request = true;
+ break;
+ }
+ }
+ if (had_intersection_with_request)
+ fake_response->push_back(preset_equivalence_class);
+ }
+ fetcher->SimulateSuccess(fake_response.Pass());
+}
+
+void ScopedFakeAffiliationAPI::IgnoreNextRequest() {
+ if (!fake_fetcher_factory_.has_pending_fetchers())
+ return;
+ ignore_result(fake_fetcher_factory_.PopNextFetcher());
+}
+
+} // namespace password_manager

Powered by Google App Engine
This is Rietveld 408576698