diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-17 20:07:11 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-17 20:07:11 +0000 |
commit | 95409e1020037b0bbfbce17f861d3de090d10186 (patch) | |
tree | 90a893af1247b1d4a3767c5ab14aae797f467946 /chrome/browser/login_prompt_uitest.cc | |
parent | 701e869b30deffda579c5c413cf1d73defee34fa (diff) | |
download | chromium_src-95409e1020037b0bbfbce17f861d3de090d10186.zip chromium_src-95409e1020037b0bbfbce17f861d3de090d10186.tar.gz chromium_src-95409e1020037b0bbfbce17f861d3de090d10186.tar.bz2 |
Test server cleanup patch of death:
- reduce the number of different classes
- clean up the internal code
- modify the interface to expose less internal details
(this will allow more flexibility with port numbers)
TEST=many
BUG=49680
Review URL: http://codereview.chromium.org/3080029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56405 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/login_prompt_uitest.cc')
-rw-r--r-- | chrome/browser/login_prompt_uitest.cc | 71 |
1 files changed, 32 insertions, 39 deletions
diff --git a/chrome/browser/login_prompt_uitest.cc b/chrome/browser/login_prompt_uitest.cc index 91ee08f..11315ef 100644 --- a/chrome/browser/login_prompt_uitest.cc +++ b/chrome/browser/login_prompt_uitest.cc @@ -16,18 +16,18 @@ using std::wstring; namespace { -const wchar_t kDocRoot[] = L"chrome/test/data"; +const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); } // namespace class LoginPromptTest : public UITest { protected: LoginPromptTest() - : UITest(), - username_basic_(L"basicuser"), + : username_basic_(L"basicuser"), username_digest_(L"digestuser"), password_(L"secret"), - password_bad_(L"denyme") { + password_bad_(L"denyme"), + test_server_(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)) { } void AppendTab(const GURL& url) { @@ -41,6 +41,8 @@ class LoginPromptTest : public UITest { wstring username_digest_; wstring password_; wstring password_bad_; + + net::TestServer test_server_; }; wstring ExpectedTitleFromAuth(const wstring& username, @@ -51,12 +53,11 @@ wstring ExpectedTitleFromAuth(const wstring& username, // Test that "Basic" HTTP authentication works. TEST_F(LoginPromptTest, TestBasicAuth) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); + scoped_refptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab.get()); - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("auth-basic"))); EXPECT_TRUE(tab->NeedsAuth()); EXPECT_FALSE(tab->SetAuth(username_basic_, password_bad_)); @@ -64,7 +65,7 @@ TEST_F(LoginPromptTest, TestBasicAuth) { EXPECT_TRUE(tab->CancelAuth()); EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle()); - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("auth-basic"))); EXPECT_TRUE(tab->NeedsAuth()); EXPECT_TRUE(tab->SetAuth(username_basic_, password_)); @@ -74,19 +75,18 @@ TEST_F(LoginPromptTest, TestBasicAuth) { // Test that "Digest" HTTP authentication works. TEST_F(LoginPromptTest, TestDigestAuth) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); + scoped_refptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab.get()); - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-digest"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("auth-digest"))); EXPECT_TRUE(tab->NeedsAuth()); EXPECT_FALSE(tab->SetAuth(username_digest_, password_bad_)); EXPECT_TRUE(tab->CancelAuth()); EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle()); - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-digest"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("auth-digest"))); EXPECT_TRUE(tab->NeedsAuth()); EXPECT_TRUE(tab->SetAuth(username_digest_, password_)); @@ -96,19 +96,17 @@ TEST_F(LoginPromptTest, TestDigestAuth) { // Test that logging in on 2 tabs at once works. TEST_F(LoginPromptTest, TestTwoAuths) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); scoped_refptr<TabProxy> basic_tab(GetActiveTab()); ASSERT_TRUE(basic_tab.get()); - ASSERT_TRUE(basic_tab->NavigateToURL(server->TestServerPage("auth-basic"))); + ASSERT_TRUE(basic_tab->NavigateToURL(test_server_.GetURL("auth-basic"))); AppendTab(GURL(chrome::kAboutBlankURL)); scoped_refptr<TabProxy> digest_tab(GetActiveTab()); ASSERT_TRUE(digest_tab.get()); ASSERT_TRUE( - digest_tab->NavigateToURL(server->TestServerPage("auth-digest"))); + digest_tab->NavigateToURL(test_server_.GetURL("auth-digest"))); EXPECT_TRUE(basic_tab->NeedsAuth()); EXPECT_TRUE(basic_tab->SetAuth(username_basic_, password_)); @@ -125,37 +123,36 @@ TEST_F(LoginPromptTest, TestTwoAuths) { // Test that cancelling authentication works. TEST_F(LoginPromptTest, TestCancelAuth) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); + scoped_refptr<TabProxy> tab(GetActiveTab()); ASSERT_TRUE(tab.get()); // First navigate to a test server page so we have something to go back to. - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("a"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("a"))); // Navigating while auth is requested is the same as cancelling. - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("auth-basic"))); EXPECT_TRUE(tab->NeedsAuth()); - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("b"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("b"))); EXPECT_FALSE(tab->NeedsAuth()); - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("auth-basic"))); EXPECT_TRUE(tab->NeedsAuth()); EXPECT_TRUE(tab->GoBack()); // should bring us back to 'a' EXPECT_FALSE(tab->NeedsAuth()); // Now add a page and go back, so we have something to go forward to. - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("c"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("c"))); EXPECT_TRUE(tab->GoBack()); // should bring us back to 'a' - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("auth-basic"))); EXPECT_TRUE(tab->NeedsAuth()); EXPECT_TRUE(tab->GoForward()); // should bring us to 'c' EXPECT_FALSE(tab->NeedsAuth()); // Now test that cancelling works as expected. - ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); + ASSERT_TRUE(tab->NavigateToURL(test_server_.GetURL("auth-basic"))); EXPECT_TRUE(tab->NeedsAuth()); EXPECT_TRUE(tab->CancelAuth()); EXPECT_FALSE(tab->NeedsAuth()); @@ -165,21 +162,19 @@ TEST_F(LoginPromptTest, TestCancelAuth) { // If multiple tabs are looking for the same auth, the user should only have to // enter it once (http://crbug.com/8914). TEST_F(LoginPromptTest, SupplyRedundantAuths) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); scoped_refptr<TabProxy> basic_tab1(GetActiveTab()); ASSERT_TRUE(basic_tab1.get()); ASSERT_TRUE( - basic_tab1->NavigateToURL(server->TestServerPage("auth-basic/1"))); + basic_tab1->NavigateToURL(test_server_.GetURL("auth-basic/1"))); EXPECT_TRUE(basic_tab1->NeedsAuth()); AppendTab(GURL(chrome::kAboutBlankURL)); scoped_refptr<TabProxy> basic_tab2(GetActiveTab()); ASSERT_TRUE(basic_tab2.get()); ASSERT_TRUE( - basic_tab2->NavigateToURL(server->TestServerPage("auth-basic/2"))); + basic_tab2->NavigateToURL(test_server_.GetURL("auth-basic/2"))); EXPECT_TRUE(basic_tab2->NeedsAuth()); // Set the auth in only one of the tabs (but wait for the other to load). @@ -200,21 +195,19 @@ TEST_F(LoginPromptTest, SupplyRedundantAuths) { // If multiple tabs are looking for the same auth, and one is cancelled, the // other should be cancelled as well. TEST_F(LoginPromptTest, CancelRedundantAuths) { - scoped_refptr<net::HTTPTestServer> server( - net::HTTPTestServer::CreateServer(kDocRoot)); - ASSERT_TRUE(NULL != server.get()); + ASSERT_TRUE(test_server_.Start()); scoped_refptr<TabProxy> basic_tab1(GetActiveTab()); ASSERT_TRUE(basic_tab1.get()); ASSERT_TRUE( - basic_tab1->NavigateToURL(server->TestServerPage("auth-basic/1"))); + basic_tab1->NavigateToURL(test_server_.GetURL("auth-basic/1"))); EXPECT_TRUE(basic_tab1->NeedsAuth()); AppendTab(GURL(chrome::kAboutBlankURL)); scoped_refptr<TabProxy> basic_tab2(GetActiveTab()); ASSERT_TRUE(basic_tab2.get()); ASSERT_TRUE( - basic_tab2->NavigateToURL(server->TestServerPage("auth-basic/2"))); + basic_tab2->NavigateToURL(test_server_.GetURL("auth-basic/2"))); EXPECT_TRUE(basic_tab2->NeedsAuth()); // Cancel the auth in only one of the tabs (but wait for the other to load). |