Chromium Code Reviews| Index: ios/net/cookies/cookie_store_ios_unittest.mm |
| diff --git a/ios/net/cookies/cookie_store_ios_unittest.mm b/ios/net/cookies/cookie_store_ios_unittest.mm |
| index fb4554e09ef443188af8f352f9b5e5b9e14bb774..e507ea444aaf55014f257115676bf1556b062b34 100644 |
| --- a/ios/net/cookies/cookie_store_ios_unittest.mm |
| +++ b/ios/net/cookies/cookie_store_ios_unittest.mm |
| @@ -14,23 +14,11 @@ |
| #include "base/message_loop/message_loop.h" |
| #include "base/run_loop.h" |
| #include "base/strings/sys_string_conversions.h" |
| -#import "ios/net/cookies/cookie_store_ios_persistent.h" |
| +#import "ios/net/cookies/cookie_store_ios_unittest_helper.h" |
| #import "net/base/mac/url_conversions.h" |
| #include "net/cookies/cookie_store_unittest.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| -namespace { |
| -// Clears the underlying NSHTTPCookieStorage. |
| -void ClearCookies() { |
| - NSHTTPCookieStorage* store = [NSHTTPCookieStorage sharedHTTPCookieStorage]; |
| - [store setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways]; |
| - NSArray* cookies = [store cookies]; |
| - for (NSHTTPCookie* cookie in cookies) |
| - [store deleteCookie:cookie]; |
| - EXPECT_EQ(0u, [[store cookies] count]); |
| -} |
| -} // namespace |
| - |
| namespace net { |
| struct CookieStoreIOSTestTraits { |
| @@ -50,123 +38,13 @@ struct CookieStoreIOSTestTraits { |
| base::MessageLoop loop_; |
| }; |
| -struct InactiveCookieStoreIOSTestTraits { |
| - static std::unique_ptr<net::CookieStore> Create() { |
| - return base::MakeUnique<CookieStoreIOSPersistent>(nullptr); |
| - } |
| - |
| - static const bool is_cookie_monster = false; |
| - static const bool supports_http_only = false; |
| - static const bool supports_non_dotted_domains = true; |
| - static const bool preserves_trailing_dots = true; |
| - static const bool filters_schemes = false; |
| - static const bool has_path_prefix_bug = false; |
| - static const int creation_time_granularity_in_ms = 0; |
| - static const int enforces_prefixes = true; |
| - static const bool enforce_strict_secure = false; |
| - |
| - base::MessageLoop loop_; |
| -}; |
| - |
| -} // namespace net |
| - |
| -namespace net { |
| - |
| INSTANTIATE_TYPED_TEST_CASE_P(CookieStoreIOS, |
| CookieStoreTest, |
| CookieStoreIOSTestTraits); |
| -INSTANTIATE_TYPED_TEST_CASE_P(InactiveCookieStoreIOS, |
| - CookieStoreTest, |
| - InactiveCookieStoreIOSTestTraits); |
| - |
| -} // namespace net |
| namespace { |
| -// Test net::CookieMonster::PersistentCookieStore allowing to control when the |
| -// initialization completes. |
| -class TestPersistentCookieStore |
| - : public net::CookieMonster::PersistentCookieStore { |
| - public: |
| - TestPersistentCookieStore() |
| - : kTestCookieURL("http://foo.google.com/bar"), flushed_(false) {} |
| - |
| - // Runs the completion callback with a "a=b" cookie. |
| - void RunLoadedCallback() { |
| - std::vector<std::unique_ptr<net::CanonicalCookie>> cookies; |
| - net::CookieOptions options; |
| - options.set_include_httponly(); |
| - |
| - std::unique_ptr<net::CanonicalCookie> cookie(net::CanonicalCookie::Create( |
| - kTestCookieURL, "a=b", base::Time::Now(), options)); |
| - cookies.push_back(std::move(cookie)); |
| - |
| - // Some canonical cookies cannot be converted into System cookies, for |
| - // example if value is not valid utf8. Such cookies are ignored. |
| - std::unique_ptr<net::CanonicalCookie> bad_canonical_cookie( |
| - net::CanonicalCookie::Create(GURL("http://domain/"), "name", |
| - "\x81r\xe4\xbd\xa0\xe5\xa5\xbd", |
| - std::string(), "/path/", |
| - base::Time(), // creation |
| - base::Time(), // expires |
| - false, // secure |
| - false, // httponly |
| - net::CookieSameSite::DEFAULT_MODE, |
| - net::COOKIE_PRIORITY_DEFAULT)); |
| - cookies.push_back(std::move(bad_canonical_cookie)); |
| - loaded_callback_.Run(std::move(cookies)); |
| - } |
| - |
| - bool flushed() { return flushed_; } |
| - |
| - private: |
| - // net::CookieMonster::PersistentCookieStore implementation: |
| - void Load(const LoadedCallback& loaded_callback) override { |
| - loaded_callback_ = loaded_callback; |
| - } |
| - |
| - void LoadCookiesForKey(const std::string& key, |
| - const LoadedCallback& loaded_callback) override { |
| - loaded_callback_ = loaded_callback; |
| - } |
| - |
| - void AddCookie(const net::CanonicalCookie& cc) override {} |
| - void UpdateCookieAccessTime(const net::CanonicalCookie& cc) override {} |
| - void DeleteCookie(const net::CanonicalCookie& cc) override {} |
| - void SetForceKeepSessionState() override {} |
| - void Flush(const base::Closure& callback) override { flushed_ = true; } |
| - |
| - private: |
| - ~TestPersistentCookieStore() override {} |
| - |
| - const GURL kTestCookieURL; |
| - LoadedCallback loaded_callback_; |
| - bool flushed_; |
| -}; |
| - |
| -// Helper callback to be passed to CookieStore::GetCookiesWithOptionsAsync(). |
| -class GetCookieCallback { |
| - public: |
| - GetCookieCallback() : did_run_(false) {} |
| - |
| - // Returns true if the callback has been run. |
| - bool did_run() { return did_run_; } |
| - |
| - // Returns the parameter of the callback. |
| - const std::string& cookie_line() { return cookie_line_; } |
| - |
| - void Run(const std::string& cookie_line) { |
| - ASSERT_FALSE(did_run_); |
| - did_run_ = true; |
| - cookie_line_ = cookie_line; |
| - } |
| - |
| - private: |
| - bool did_run_; |
| - std::string cookie_line_; |
| -}; |
| - |
| // Helper callback to be passed to CookieStore::GetAllCookiesForURLAsync(). |
| class GetAllCookiesCallback { |
| public: |
| @@ -189,18 +67,6 @@ class GetAllCookiesCallback { |
| net::CookieList cookie_list_; |
| }; |
| -namespace { |
| - |
| -void RecordCookieChanges(std::vector<net::CanonicalCookie>* out_cookies, |
| - std::vector<bool>* out_removes, |
| - const net::CanonicalCookie& cookie, |
| - net::CookieStore::ChangeCause cause) { |
| - DCHECK(out_cookies); |
| - out_cookies->push_back(cookie); |
| - if (out_removes) |
| - out_removes->push_back(net::CookieStore::ChangeCauseIsDeletion(cause)); |
| -} |
| - |
| void IgnoreBoolean(bool ignored) { |
| } |
| @@ -209,61 +75,6 @@ void IgnoreString(const std::string& ignored) { |
| } // namespace |
| -// Sets a cookie. |
| -void SetCookie(const std::string& cookie_line, |
| - const GURL& url, |
| - net::CookieStore* store) { |
| - net::CookieOptions options; |
| - options.set_include_httponly(); |
| - store->SetCookieWithOptionsAsync(url, cookie_line, options, |
| - base::Bind(&IgnoreBoolean)); |
| - net::CookieStoreIOS::NotifySystemCookiesChanged(); |
| - // Wait until the flush is posted. |
| - base::RunLoop().RunUntilIdle(); |
| -} |
| - |
| -// Test fixture to exersize net::CookieStoreIOS created with |
| -// TestPersistentCookieStore backend and not synchronized with |
| -// NSHTTPCookieStorage. |
| -class NotSynchronizedCookieStoreIOSWithBackend : public testing::Test { |
| - public: |
| - NotSynchronizedCookieStoreIOSWithBackend() |
| - : kTestCookieURL("http://foo.google.com/bar"), |
| - backend_(new TestPersistentCookieStore), |
| - store_(base::MakeUnique<net::CookieStoreIOSPersistent>(backend_.get())) |
| - { |
| - cookie_changed_callback_ = store_->AddCallbackForCookie( |
| - kTestCookieURL, "abc", |
| - base::Bind(&RecordCookieChanges, &cookies_changed_, &cookies_removed_)); |
| - } |
| - |
| - ~NotSynchronizedCookieStoreIOSWithBackend() override {} |
| - |
| - // Gets the cookies. |callback| will be called on completion. |
| - void GetCookies(const net::CookieStore::GetCookiesCallback& callback) { |
| - net::CookieOptions options; |
| - options.set_include_httponly(); |
| - store_->GetCookiesWithOptionsAsync(kTestCookieURL, options, callback); |
| - } |
| - |
| - // Sets a cookie. |
| - void SetCookie(const std::string& cookie_line) { |
| - ::SetCookie(cookie_line, kTestCookieURL, store_.get()); |
| - } |
| - |
| - private: |
| - const GURL kTestCookieURL; |
| - |
| - protected: |
| - base::MessageLoop loop_; |
| - scoped_refptr<TestPersistentCookieStore> backend_; |
| - std::unique_ptr<net::CookieStoreIOS> store_; |
| - std::unique_ptr<net::CookieStore::CookieChangedSubscription> |
| - cookie_changed_callback_; |
| - std::vector<net::CanonicalCookie> cookies_changed_; |
| - std::vector<bool> cookies_removed_; |
| -}; |
| - |
| // Test fixture to exersize net::CookieStoreIOS created without backend and |
| // synchronized with |[NSHTTPCookieStorage sharedHTTPCookieStorage]|. |
| class SynchronizedCookieStoreIOS : public testing::Test { |
|
Eugene But (OOO till 7-30)
2017/02/01 17:35:54
How about s/SynchronizedCookieStoreIOS/CookieStore
maksims (do not use this acc)
2017/02/02 06:47:04
Done.
|
| @@ -292,7 +103,7 @@ class SynchronizedCookieStoreIOS : public testing::Test { |
| // Sets a cookie. |
| void SetCookie(const std::string& cookie_line) { |
| - ::SetCookie(cookie_line, kTestCookieURL, store_.get()); |
| + net::SetCookie(cookie_line, kTestCookieURL, store_.get()); |
| } |
| void SetSystemCookie(const GURL& url, |
| @@ -340,36 +151,6 @@ class SynchronizedCookieStoreIOS : public testing::Test { |
| std::vector<bool> cookies_removed_; |
| }; |
| -} // namespace |
| - |
| -namespace net { |
| - |
| -TEST_F(NotSynchronizedCookieStoreIOSWithBackend, SetCookieCallsHook) { |
| - ClearCookies(); |
| - SetCookie("abc=def"); |
| - EXPECT_EQ(0U, cookies_changed_.size()); |
| - EXPECT_EQ(0U, cookies_removed_.size()); |
| - backend_->RunLoadedCallback(); |
| - base::RunLoop().RunUntilIdle(); |
| - EXPECT_EQ(1U, cookies_changed_.size()); |
| - EXPECT_EQ(1U, cookies_removed_.size()); |
| - EXPECT_EQ("abc", cookies_changed_[0].Name()); |
| - EXPECT_EQ("def", cookies_changed_[0].Value()); |
| - EXPECT_FALSE(cookies_removed_[0]); |
| - |
| - // Replacing an existing cookie is actually a two-phase delete + set |
| - // operation, so we get an extra notification. |
| - SetCookie("abc=ghi"); |
| - EXPECT_EQ(3U, cookies_changed_.size()); |
| - EXPECT_EQ(3U, cookies_removed_.size()); |
| - EXPECT_EQ("abc", cookies_changed_[1].Name()); |
| - EXPECT_EQ("def", cookies_changed_[1].Value()); |
| - EXPECT_TRUE(cookies_removed_[1]); |
| - EXPECT_EQ("abc", cookies_changed_[2].Name()); |
| - EXPECT_EQ("ghi", cookies_changed_[2].Value()); |
| - EXPECT_FALSE(cookies_removed_[2]); |
| -} |
| - |
| TEST_F(SynchronizedCookieStoreIOS, SetCookieCallsHookWhenSynchronized) { |
| GetCookies(base::Bind(&IgnoreString)); |
| ClearCookies(); |
| @@ -438,17 +219,6 @@ TEST(CookieStoreIOS, GetAllCookiesForURLAsync) { |
| EXPECT_EQ("b", cookie.Value()); |
| } |
| -// Tests that cookies can be read before the backend is loaded. |
| -TEST_F(NotSynchronizedCookieStoreIOSWithBackend, NotSynchronized) { |
| - // Start fetching the cookie. |
| - GetCookieCallback callback; |
| - GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback))); |
| - // Backend loading completes. |
| - backend_->RunLoadedCallback(); |
| - EXPECT_TRUE(callback.did_run()); |
| - EXPECT_EQ("a=b", callback.cookie_line()); |
| -} |
| - |
| TEST_F(SynchronizedCookieStoreIOS, NoInitialNotifyWithNoCookie) { |
| std::vector<net::CanonicalCookie> cookies; |
| store_->AddCallbackForCookie( |