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

Unified Diff: components/history/core/test/fake_web_history_service.h

Issue 1454413002: Move FakeWebHistoryService to components/history (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed forward declaration. Created 5 years 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
« no previous file with comments | « components/history/core/test/BUILD.gn ('k') | components/history/core/test/fake_web_history_service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/history/core/test/fake_web_history_service.h
diff --git a/components/history/core/test/fake_web_history_service.h b/components/history/core/test/fake_web_history_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..79a5b37bc5fde0c57bbbd7840268e6497374bf2c
--- /dev/null
+++ b/components/history/core/test/fake_web_history_service.h
@@ -0,0 +1,76 @@
+// 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.
+
+#ifndef COMPONENTS_HISTORY_CORE_BROWSER_FAKE_WEB_HISTORY_SERVICE_H_
+#define COMPONENTS_HISTORY_CORE_BROWSER_FAKE_WEB_HISTORY_SERVICE_H_
+
+#include <string>
+#include <vector>
+
+#include "base/macros.h"
+#include "base/time/time.h"
+#include "components/history/core/browser/web_history_service.h"
+#include "url/gurl.h"
+
+class OAuth2TokenService;
+class SigninManagerBase;
+
+namespace history {
+
+// A fake WebHistoryService for testing.
+//
+// Use |AddSyncedVisit| to fill the fake server-side database of synced visits.
+// Use |SetupFakeResponse| to influence whether the requests should succeed
+// or fail, and with which error code.
+//
+// Note: Currently, the only test that uses this class only counts the number
+// of visits and does not inspect their contents. Therefore, the behavior
+// of this class is only defined for |WebHistoryService::QueryHistory| queries
+// and even for them, we only return the correct number of items, without
+// contents.
+//
+// TODO(msramek): This class might need its own set of tests.
+class FakeWebHistoryService : public history::WebHistoryService {
+ public:
+ FakeWebHistoryService(
+ OAuth2TokenService* token_service,
+ SigninManagerBase* signin_manager,
+ const scoped_refptr<net::URLRequestContextGetter>& request_context);
+ ~FakeWebHistoryService() override;
+
+ // Sets up the behavior of the fake response returned when calling
+ // |WebHistoryService::QueryHistory|; whether it will succeed, and with
+ // which response code.
+ void SetupFakeResponse(bool emulate_success, int emulate_response_code);
+
+ // Adds a fake visit.
+ void AddSyncedVisit(std::string url, base::Time timestamp);
+
+ // Clears all fake visits.
+ void ClearSyncedVisits();
+
+ // Counts the number of visits within a certain time range.
+ int GetNumberOfVisitsBetween(const base::Time& begin, const base::Time& end);
+
+ private:
+ base::Time GetTimeForKeyInQuery(const GURL& url, const std::string& key);
+
+ // WebHistoryService:
+ Request* CreateRequest(const GURL& url,
+ const CompletionCallback& callback) override;
+
+ // Parameters for the fake request.
+ bool emulate_success_;
+ int emulate_response_code_;
+
+ // Fake visits storage.
+ typedef std::pair<std::string, base::Time> Visit;
+ std::vector<Visit> visits_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeWebHistoryService);
+};
+
+} // namespace history
+
+#endif // COMPONENTS_HISTORY_CORE_BROWSER_FAKE_WEB_HISTORY_SERVICE_H_
« no previous file with comments | « components/history/core/test/BUILD.gn ('k') | components/history/core/test/fake_web_history_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698