diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-27 15:04:14 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-27 15:04:14 +0000 |
commit | 88509ab43312fbecef5cfc6257b3784be5c87264 (patch) | |
tree | 7d3ac8ed292b07ec400b61cdc294ee477f37629f /chrome/browser/net | |
parent | 7be2fc658bb6c7aba6d1e20bc25e19dedb7c1124 (diff) | |
download | chromium_src-88509ab43312fbecef5cfc6257b3784be5c87264.zip chromium_src-88509ab43312fbecef5cfc6257b3784be5c87264.tar.gz chromium_src-88509ab43312fbecef5cfc6257b3784be5c87264.tar.bz2 |
Rewrite the cookies pyauto test as browser tests.
I didn't port testCookiesFile since cookies aren't supposed to work on file urls by default (see crbug.com/535).
I removed all the duplicate code for getting cookies in browser tests and moved them to browser_test_utils.h.
BUG=143637
Review URL: https://chromiumcodereview.appspot.com/10875045
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153484 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net')
-rw-r--r-- | chrome/browser/net/cookie_policy_browsertest.cc | 51 |
1 files changed, 9 insertions, 42 deletions
diff --git a/chrome/browser/net/cookie_policy_browsertest.cc b/chrome/browser/net/cookie_policy_browsertest.cc index 19641df..45cce27 100644 --- a/chrome/browser/net/cookie_policy_browsertest.cc +++ b/chrome/browser/net/cookie_policy_browsertest.cc @@ -4,62 +4,27 @@ #include "base/bind.h" #include "base/bind_helpers.h" -#include "base/synchronization/waitable_event.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_tabstrip.h" +#include "chrome/browser/ui/tab_contents/tab_contents.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" +#include "content/public/test/browser_test_utils.h" #include "net/base/mock_host_resolver.h" -#include "net/cookies/cookie_store.h" #include "net/test/test_server.h" -#include "net/url_request/url_request_context.h" -#include "net/url_request/url_request_context_getter.h" using content::BrowserThread; namespace { -void GetCookiesCallback(std::string* cookies_out, - base::WaitableEvent* event, - const std::string& cookies) { - *cookies_out = cookies; - event->Signal(); -} - -void GetCookiesOnIOThread(const GURL& url, - net::URLRequestContextGetter* context_getter, - base::WaitableEvent* event, - std::string* cookies) { - net::CookieStore* cookie_store = - context_getter->GetURLRequestContext()->cookie_store(); - cookie_store->GetCookiesWithOptionsAsync( - url, net::CookieOptions(), - base::Bind(&GetCookiesCallback, - base::Unretained(cookies), base::Unretained(event))); -} - class CookiePolicyBrowserTest : public InProcessBrowserTest { protected: CookiePolicyBrowserTest() {} - std::string GetCookies(const GURL& url) { - std::string cookies; - base::WaitableEvent event(true /* manual reset */, - false /* not initially signaled */); - net::URLRequestContextGetter* context_getter = - browser()->profile()->GetRequestContext(); - EXPECT_TRUE( - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&GetCookiesOnIOThread, url, - make_scoped_refptr(context_getter), &event, &cookies))); - event.Wait(); - return cookies; - } - private: DISALLOW_COPY_AND_ASSIGN(CookiePolicyBrowserTest); }; @@ -73,12 +38,13 @@ IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, AllowFirstPartyCookies) { GURL url(test_server()->GetURL("set-cookie?cookie1")); - std::string cookie = GetCookies(url); + TabContents* tab = chrome::GetActiveTabContents(browser()); + std::string cookie = content::GetCookies(tab->profile(), url); ASSERT_EQ("", cookie); ui_test_utils::NavigateToURL(browser(), url); - cookie = GetCookies(url); + cookie = content::GetCookies(tab->profile(), url); EXPECT_EQ("cookie1", cookie); } @@ -103,7 +69,8 @@ IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, replacements.SetHostStr(new_host); redirected_url = redirected_url.ReplaceComponents(replacements); - std::string cookie = GetCookies(redirected_url); + TabContents* tab = chrome::GetActiveTabContents(browser()); + std::string cookie = content::GetCookies(tab->profile(), redirected_url); ASSERT_EQ("", cookie); host_resolver()->AddRule("www.example.com", "127.0.0.1"); @@ -111,7 +78,7 @@ IN_PROC_BROWSER_TEST_F(CookiePolicyBrowserTest, ui_test_utils::NavigateToURL(browser(), GURL(url.spec() + redirected_url.spec())); - cookie = GetCookies(redirected_url); + cookie = content::GetCookies(tab->profile(), redirected_url); EXPECT_EQ("cookie2", cookie); } |