Commit 36ebc4c2 authored by Maks Orlovich's avatar Maks Orlovich Committed by Commit Bot

Refactor the DeferredCookieTaskTest to not use NewMockPersistentCookieStore, and remove it.

The gMock use got in the way of making something that ought to be a
OnceCallback such since it has some limitations with respect to move-only
types.

Also, the tests weren't usefully distinguishing on whether the code was
waiting for Load or LoadForKey to complete first; they do now.

Plus, this group of test had its own ways of doing things totally different from everything
else; now things standardize on the simpler MockPersistentCookieStore.

Change-Id: I933386d311b6cce3fc230944e206b94cd1c0fff2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1529074Reviewed-by: default avatarEric Orth <ericorth@chromium.org>
Commit-Queue: Maks Orlovich <morlovich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#642316}
parent 4cb979b9
......@@ -89,6 +89,7 @@ class MockPersistentCookieStore : public CookieMonster::PersistentCookieStore {
std::vector<std::unique_ptr<CanonicalCookie>> result);
const CommandList& commands() const { return commands_; }
CommandList TakeCommands() { return std::move(commands_); }
void Load(const LoadedCallback& loaded_callback,
const NetLogWithSource& net_log) override;
......
This diff is collapsed.
......@@ -14,15 +14,16 @@
namespace net {
CookieCallback::CookieCallback(base::Thread* run_in_thread)
: run_in_thread_(run_in_thread) {}
: run_in_thread_(run_in_thread), was_run_(false) {}
CookieCallback::CookieCallback()
: run_in_thread_(nullptr),
run_in_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
run_in_task_runner_(base::ThreadTaskRunnerHandle::Get()),
was_run_(false) {}
CookieCallback::~CookieCallback() = default;
void CookieCallback::CallbackEpilogue() {
void CookieCallback::ValidateThread() const {
scoped_refptr<base::SingleThreadTaskRunner> expected_task_runner;
if (run_in_thread_) {
DCHECK(!run_in_task_runner_);
......@@ -31,8 +32,12 @@ void CookieCallback::CallbackEpilogue() {
expected_task_runner = run_in_task_runner_;
}
ASSERT_TRUE(expected_task_runner);
EXPECT_TRUE(expected_task_runner->BelongsToCurrentThread());
}
void CookieCallback::CallbackEpilogue() {
ValidateThread();
was_run_ = true;
loop_to_quit_.Quit();
}
......@@ -40,6 +45,11 @@ void CookieCallback::WaitUntilDone() {
loop_to_quit_.Run();
}
bool CookieCallback::was_run() const {
ValidateThread();
return was_run_;
}
NoResultCookieCallback::NoResultCookieCallback() = default;
NoResultCookieCallback::NoResultCookieCallback(base::Thread* run_in_thread)
: CookieCallback(run_in_thread) {}
......
......@@ -8,6 +8,7 @@
#include <string>
#include <vector>
#include "base/bind.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
......@@ -28,6 +29,10 @@ class CookieCallback {
// Waits until the callback is invoked.
void WaitUntilDone();
// Returns whether the callback was invoked. Should only be used on the thread
// the callback runs on.
bool was_run() const;
protected:
// Constructs a callback that expects to be called in the given thread.
explicit CookieCallback(base::Thread* run_in_thread);
......@@ -43,9 +48,12 @@ class CookieCallback {
void CallbackEpilogue();
private:
void ValidateThread() const;
base::Thread* run_in_thread_;
scoped_refptr<base::SingleThreadTaskRunner> run_in_task_runner_;
base::RunLoop loop_to_quit_;
bool was_run_;
};
// Callback implementations for the asynchronous CookieStore methods.
......@@ -64,6 +72,13 @@ class ResultSavingCookieCallback : public CookieCallback {
CallbackEpilogue();
}
// Makes a callback that will invoke Run. Assumes that |this| will be kept
// alive till the time the callback is used.
base::OnceCallback<void(T)> MakeCallback() {
return base::BindOnce(&ResultSavingCookieCallback<T>::Run,
base::Unretained(this));
}
const T& result() { return result_; }
private:
......@@ -89,6 +104,13 @@ class GetCookieListCallback : public CookieCallback {
void Run(const CookieList& cookies, const CookieStatusList& excluded_cookies);
// Makes a callback that will invoke Run. Assumes that |this| will be kept
// alive till the time the callback is used.
base::OnceCallback<void(const CookieList&, const CookieStatusList&)>
MakeCallback() {
return base::BindOnce(&GetCookieListCallback::Run, base::Unretained(this));
}
const CookieList& cookies() { return cookies_; }
const CookieStatusList& excluded_cookies() { return excluded_cookies_; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment