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

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

Issue 1983073002: Query the existence other forms of browsing history. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit. Created 4 years, 7 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
« no previous file with comments | « components/history/core/test/fake_web_history_service.h ('k') | sync/protocol/history_status.proto » ('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.cc
diff --git a/components/history/core/test/fake_web_history_service.cc b/components/history/core/test/fake_web_history_service.cc
index 2739974eec5669576689b8058928fea75d90805e..44e5be420c94f145c4a22f189116c7a80a61c13d 100644
--- a/components/history/core/test/fake_web_history_service.cc
+++ b/components/history/core/test/fake_web_history_service.cc
@@ -9,9 +9,11 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "net/base/url_util.h"
#include "net/url_request/url_request_context_getter.h"
+#include "sync/protocol/history_status.pb.h"
namespace history {
@@ -19,9 +21,22 @@ namespace history {
namespace {
+// TODO(msramek): Find a way to keep these URLs in sync with what is used
+// in WebHistoryService.
+
+const char kLookupUrl[] =
+ "https://history.google.com/history/api/lookup";
+
+const char kChromeClient[] = "chrome";
+
+const char kWebAndAppClient[] = "web_app";
+
+const char kSyncServerHost[] = "clients4.google.com";
+
class FakeRequest : public WebHistoryService::Request {
public:
FakeRequest(FakeWebHistoryService* service,
+ const GURL& url,
bool emulate_success,
int emulate_response_code,
const WebHistoryService::CompletionCallback& callback,
@@ -34,10 +49,14 @@ class FakeRequest : public WebHistoryService::Request {
int GetResponseCode() override;
const std::string& GetResponseBody() override;
void SetPostData(const std::string& post_data) override;
+ void SetPostDataAndType(const std::string& post_data,
+ const std::string& mime_type) override;
+ void SetUserAgent(const std::string& user_agent) override;
void Start() override;
private:
FakeWebHistoryService* service_;
+ GURL url_;
bool emulate_success_;
int emulate_response_code_;
const WebHistoryService::CompletionCallback& callback_;
@@ -52,6 +71,7 @@ class FakeRequest : public WebHistoryService::Request {
FakeRequest::FakeRequest(
FakeWebHistoryService* service,
+ const GURL& url,
bool emulate_success,
int emulate_response_code,
const WebHistoryService::CompletionCallback& callback,
@@ -59,13 +79,14 @@ FakeRequest::FakeRequest(
base::Time end,
int max_count)
: service_(service),
- emulate_success_(emulate_success),
- emulate_response_code_(emulate_response_code),
- callback_(callback),
- begin_(begin),
- end_(end),
- max_count_(max_count),
- is_pending_(false) {
+ url_(url),
+ emulate_success_(emulate_success),
+ emulate_response_code_(emulate_response_code),
+ callback_(callback),
+ begin_(begin),
+ end_(end),
+ max_count_(max_count),
+ is_pending_(false) {
}
bool FakeRequest::IsPending() {
@@ -77,14 +98,41 @@ int FakeRequest::GetResponseCode() {
}
const std::string& FakeRequest::GetResponseBody() {
- int count = service_->GetNumberOfVisitsBetween(begin_, end_);
- if (max_count_ && max_count_ < count)
- count = max_count_;
-
- response_body_ = "{ \"event\": [";
- for (int i = 0; i < count; ++i)
- response_body_ += i ? ", {}" : "{}";
- response_body_ += "] }";
+ std::string client;
+ net::GetValueForKeyInQuery(url_, "client", &client);
+
+ GURL::Replacements remove_query;
+ remove_query.ClearQuery();
+ GURL base_url = url_.ReplaceComponents(remove_query);
+
+ // History query.
+ if (base_url == GURL(kLookupUrl) && client == kChromeClient) {
+ int count = service_->GetNumberOfVisitsBetween(begin_, end_);
+ if (max_count_ && max_count_ < count)
+ count = max_count_;
+
+ response_body_ = "{ \"event\": [";
+ for (int i = 0; i < count; ++i)
+ response_body_ += i ? ", {}" : "{}";
+ response_body_ += "] }";
+ }
+
+ // Web and app activity query.
+ if (base_url == GURL(kLookupUrl) && client == kWebAndAppClient) {
+ response_body_ = base::StringPrintf(
+ "{ \"history_recording_enabled\": %s }",
+ service_->IsWebAndAppActivityEnabled() ? "true" : "false");
+ }
+
+ // Other forms of browsing history query.
+ if (url_.host() == kSyncServerHost) {
+ std::unique_ptr<sync_pb::HistoryStatusResponse> history_status(
+ new sync_pb::HistoryStatusResponse());
+ history_status->set_has_derived_data(
+ service_->AreOtherFormsOfBrowsingHistoryPresent());
+ history_status->SerializeToString(&response_body_);
+ }
+
return response_body_;
}
@@ -92,6 +140,15 @@ void FakeRequest::SetPostData(const std::string& post_data) {
// Unused.
};
+void FakeRequest::SetPostDataAndType(const std::string& post_data,
+ const std::string& mime_type) {
+ // Unused.
+};
+
+void FakeRequest::SetUserAgent(const std::string& user_agent) {
+ // Unused.
+};
+
void FakeRequest::Start() {
is_pending_ = true;
callback_.Run(this, emulate_success_);
@@ -165,8 +222,25 @@ FakeWebHistoryService::Request* FakeWebHistoryService::CreateRequest(
if (net::GetValueForKeyInQuery(url, "num", &max_count_str))
base::StringToInt(max_count_str, &max_count);
- return new FakeRequest(this, emulate_success_, emulate_response_code_,
+ return new FakeRequest(this, url, emulate_success_, emulate_response_code_,
callback, begin, end, max_count);
}
+bool FakeWebHistoryService::IsWebAndAppActivityEnabled() {
+ return web_and_app_activity_enabled_;
+}
+
+void FakeWebHistoryService::SetWebAndAppActivityEnabled(bool enabled) {
+ web_and_app_activity_enabled_ = enabled;
+}
+
+bool FakeWebHistoryService::AreOtherFormsOfBrowsingHistoryPresent() {
+ return other_forms_of_browsing_history_present_;
+}
+
+void FakeWebHistoryService::SetOtherFormsOfBrowsingHistoryPresent(
+ bool present) {
+ other_forms_of_browsing_history_present_ = present;
+}
+
} // namespace history
« no previous file with comments | « components/history/core/test/fake_web_history_service.h ('k') | sync/protocol/history_status.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698