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

Unified Diff: components/history/core/browser/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: Created 5 years, 1 month 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/history/core/browser/fake_web_history_service.h
diff --git a/components/history/core/browser/fake_web_history_service.h b/components/history/core/browser/fake_web_history_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..c0f8b3e815996e1fe249d6649620fc5fd9f92bbd
--- /dev/null
+++ b/components/history/core/browser/fake_web_history_service.h
@@ -0,0 +1,114 @@
+// 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 <vector>
+
+#include "base/macros.h"
+#include "components/history/core/browser/web_history_service.h"
+
+namespace base {
+class CompletionCallback;
engedy 2015/11/19 16:02:16 nit: I think this is a different type, the one you
msramek 2015/11/30 15:17:10 Done. I even managed two include two different wro
+class Time;
+}
+
+namespace net {
+class URLRequestContextGetter;
+}
+
+class OAuth2TokenService;
+class SigninManagerBase;
+
engedy 2015/11/19 16:02:16 nit: -newline
msramek 2015/11/30 15:17:10 Done.
+
+namespace history {
+
+// A fake WebHistoryService for testing.
+//
+// Use |AddSyncedVisit| to fill the fake server-side database of synced visits.
+// Use |SetRequestOptions| to influence whether the requests should succeed
+// or fail, and with which error code.
+//
+// Call |WebHistoryService::QueryHistory| to retrieve the fake server-side
engedy 2015/11/19 16:02:16 I would argue that no one would really want to cal
msramek 2015/11/30 15:17:10 Done.
+// visits.
+// TODO(msramek): Currently, the only test that uses this only counts the number
engedy 2015/11/19 16:02:16 nit: Do you actually intend to work on these? If
msramek 2015/11/30 15:17:10 No, as this is not needed anywhere yet. But that i
+// of visits and does not inspect their contents, so we represent each visit
+// with an empty dictionary. Implement actual contents if needed.
+// TODO(msramek): Other requests, such as |WebHistoryService::ExpireHistory|
+// will currently not work. Implement them if needed.
+// TODO(msramek): This class might need its own set of tests.
+class FakeWebHistoryService : public history::WebHistoryService {
+ public:
+
engedy 2015/11/19 16:02:16 nit: -newline
msramek 2015/11/30 15:17:10 Done.
+ class Request : public history::WebHistoryService::Request {
engedy 2015/11/19 16:02:16 nit: I think this can be moved to the implementati
msramek 2015/11/30 15:17:10 Forward declaration is not enough here. We must sp
engedy 2015/11/30 15:47:08 You could just return the base class (i.e. WebHist
msramek 2015/12/01 12:27:12 Oh, right. It's still not possible to have the ent
+ public:
+ Request(FakeWebHistoryService* service,
+ bool emulate_success,
+ int emulate_response_code,
+ const CompletionCallback& callback,
+ base::Time begin,
+ base::Time end,
+ int max_count);
+
+ // WebHistoryService::Request:
+ bool IsPending() override;
+ int GetResponseCode() override;
+ const std::string& GetResponseBody() override;
+ void SetPostData(const std::string& post_data) override;
+ void Start() override;
+
+ private:
+ FakeWebHistoryService* service_;
+ bool emulate_success_;
+ int emulate_response_code_;
+ const CompletionCallback& callback_;
+ base::Time begin_;
+ base::Time end_;
+ int max_count_;
+ bool is_pending_;
+ std::string response_body_;
+
+ DISALLOW_COPY_AND_ASSIGN(Request);
+ };
+
+ FakeWebHistoryService(
+ OAuth2TokenService* token_service,
+ SigninManagerBase* signin_manager,
+ const scoped_refptr<net::URLRequestContextGetter>& request_context);
engedy 2015/11/19 16:02:16 nit: Same here. Does this really work with just t
msramek 2015/11/30 15:17:10 Hm, weird. I was also surprised that this would wo
+ ~FakeWebHistoryService() override;
+
+ // Sets the parameters according to which requests will be created.
+ void SetRequestOptions(bool emulate_success, int emulate_response_code);
engedy 2015/11/19 16:02:16 nit: I think this name is rather confusing. How a
msramek 2015/11/30 15:17:10 Agreed. IIRC this is a remnant from an earlier des
+
+ // 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);
engedy 2015/11/19 16:02:16 nit: Need to include <string>, and I'd include gur
msramek 2015/11/30 15:17:10 Done. Both are popular, inclusion is a bit more.
+
+ // 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;
engedy 2015/11/19 16:02:16 I find it hard to believe that this works with jus
msramek 2015/11/30 15:17:10 Done. Yes, it's already included.
engedy 2015/11/30 15:47:08 In this case, I'd explicitly include the header he
msramek 2015/12/01 12:27:12 Done. I actually do find it somewhat obvious that
+ std::vector<Visit> visits_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeWebHistoryService);
+};
+
+} // namespace history
+
+#endif // COMPONENTS_HISTORY_CORE_BROWSER_FAKE_WEB_HISTORY_SERVICE_H_

Powered by Google App Engine
This is Rietveld 408576698