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

Side by Side Diff: chrome/browser/login_prompt_uitest.cc

Issue 113722: Make automation proxy objects to ref_counted. That allows to process async no... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "chrome/browser/net/url_fixer_upper.h" 7 #include "chrome/browser/net/url_fixer_upper.h"
8 #include "chrome/common/chrome_switches.h" 8 #include "chrome/common/chrome_switches.h"
9 #include "chrome/test/automation/tab_proxy.h" 9 #include "chrome/test/automation/tab_proxy.h"
10 #include "chrome/test/automation/browser_proxy.h" 10 #include "chrome/test/automation/browser_proxy.h"
11 #include "chrome/test/ui/ui_test.h" 11 #include "chrome/test/ui/ui_test.h"
12 #include "net/url_request/url_request_unittest.h" 12 #include "net/url_request/url_request_unittest.h"
13 13
14 using std::wstring; 14 using std::wstring;
15 15
16 namespace { 16 namespace {
17 17
18 const wchar_t kDocRoot[] = L"chrome/test/data"; 18 const wchar_t kDocRoot[] = L"chrome/test/data";
19 19
20 class LoginPromptTest : public UITest { 20 class LoginPromptTest : public UITest {
21 protected: 21 protected:
22 LoginPromptTest() 22 LoginPromptTest()
23 : UITest(), 23 : UITest(),
24 username_basic_(L"basicuser"), 24 username_basic_(L"basicuser"),
25 username_digest_(L"digestuser"), 25 username_digest_(L"digestuser"),
26 password_(L"secret"), 26 password_(L"secret"),
27 password_bad_(L"denyme") { 27 password_bad_(L"denyme") {
28 } 28 }
29 29
30 TabProxy* GetActiveTabProxy() { 30 scoped_refptr<TabProxy> GetActiveTabProxy() {
31 scoped_ptr<BrowserProxy> window_proxy(automation()->GetBrowserWindow(0)); 31 scoped_refptr<BrowserProxy> window_proxy(automation()->GetBrowserWindow(0));
32 EXPECT_TRUE(window_proxy.get()); 32 EXPECT_TRUE(window_proxy.get());
33 33
34 int active_tab_index = 0; 34 int active_tab_index = 0;
35 EXPECT_TRUE(window_proxy->GetActiveTabIndex(&active_tab_index)); 35 EXPECT_TRUE(window_proxy->GetActiveTabIndex(&active_tab_index));
36 return window_proxy->GetTab(active_tab_index); 36 return window_proxy->GetTab(active_tab_index);
37 } 37 }
38 38
39 void NavigateTab(TabProxy* tab_proxy, const GURL& url) { 39 void NavigateTab(TabProxy* tab_proxy, const GURL& url) {
40 ASSERT_TRUE(tab_proxy->NavigateToURL(url)); 40 ASSERT_TRUE(tab_proxy->NavigateToURL(url));
41 } 41 }
42 42
43 void AppendTab(const GURL& url) { 43 void AppendTab(const GURL& url) {
44 scoped_ptr<BrowserProxy> window_proxy(automation()->GetBrowserWindow(0)); 44 scoped_refptr<BrowserProxy> window_proxy(automation()->GetBrowserWindow(0));
45 EXPECT_TRUE(window_proxy.get()); 45 EXPECT_TRUE(window_proxy.get());
46 EXPECT_TRUE(window_proxy->AppendTab(url)); 46 EXPECT_TRUE(window_proxy->AppendTab(url));
47 } 47 }
48 48
49 protected: 49 protected:
50 wstring username_basic_; 50 wstring username_basic_;
51 wstring username_digest_; 51 wstring username_digest_;
52 wstring password_; 52 wstring password_;
53 wstring password_bad_; 53 wstring password_bad_;
54 }; 54 };
55 55
56 wstring ExpectedTitleFromAuth(wstring username, wstring password) { 56 wstring ExpectedTitleFromAuth(wstring username, wstring password) {
57 // The TestServer sets the title to username/password on successful login. 57 // The TestServer sets the title to username/password on successful login.
58 return username + L"/" + password; 58 return username + L"/" + password;
59 } 59 }
60 60
61 } // namespace 61 } // namespace
62 62
63 // Test that "Basic" HTTP authentication works. 63 // Test that "Basic" HTTP authentication works.
64 TEST_F(LoginPromptTest, TestBasicAuth) { 64 TEST_F(LoginPromptTest, TestBasicAuth) {
65 scoped_refptr<HTTPTestServer> server = 65 scoped_refptr<HTTPTestServer> server =
66 HTTPTestServer::CreateServer(kDocRoot, NULL); 66 HTTPTestServer::CreateServer(kDocRoot, NULL);
67 ASSERT_TRUE(NULL != server.get()); 67 ASSERT_TRUE(NULL != server.get());
68 ::scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 68 scoped_refptr<TabProxy> tab(GetActiveTabProxy());
69 NavigateTab(tab.get(), server->TestServerPageW(L"auth-basic")); 69 NavigateTab(tab.get(), server->TestServerPageW(L"auth-basic"));
70 70
71 EXPECT_TRUE(tab->NeedsAuth()); 71 EXPECT_TRUE(tab->NeedsAuth());
72 EXPECT_FALSE(tab->SetAuth(username_basic_, password_bad_)); 72 EXPECT_FALSE(tab->SetAuth(username_basic_, password_bad_));
73 EXPECT_TRUE(tab->NeedsAuth()); 73 EXPECT_TRUE(tab->NeedsAuth());
74 EXPECT_TRUE(tab->CancelAuth()); 74 EXPECT_TRUE(tab->CancelAuth());
75 EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle()); 75 EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle());
76 76
77 NavigateTab(tab.get(), server->TestServerPageW(L"auth-basic")); 77 NavigateTab(tab.get(), server->TestServerPageW(L"auth-basic"));
78 78
79 EXPECT_TRUE(tab->NeedsAuth()); 79 EXPECT_TRUE(tab->NeedsAuth());
80 EXPECT_TRUE(tab->SetAuth(username_basic_, password_)); 80 EXPECT_TRUE(tab->SetAuth(username_basic_, password_));
81 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), 81 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_),
82 GetActiveTabTitle()); 82 GetActiveTabTitle());
83 } 83 }
84 84
85 // Test that "Digest" HTTP authentication works. 85 // Test that "Digest" HTTP authentication works.
86 TEST_F(LoginPromptTest, TestDigestAuth) { 86 TEST_F(LoginPromptTest, TestDigestAuth) {
87 scoped_refptr<HTTPTestServer> server = 87 scoped_refptr<HTTPTestServer> server =
88 HTTPTestServer::CreateServer(kDocRoot, NULL); 88 HTTPTestServer::CreateServer(kDocRoot, NULL);
89 ASSERT_TRUE(NULL != server.get()); 89 ASSERT_TRUE(NULL != server.get());
90 ::scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 90 scoped_refptr<TabProxy> tab(GetActiveTabProxy());
91 NavigateTab(tab.get(), server->TestServerPageW(L"auth-digest")); 91 NavigateTab(tab.get(), server->TestServerPageW(L"auth-digest"));
92 92
93 EXPECT_TRUE(tab->NeedsAuth()); 93 EXPECT_TRUE(tab->NeedsAuth());
94 EXPECT_FALSE(tab->SetAuth(username_digest_, password_bad_)); 94 EXPECT_FALSE(tab->SetAuth(username_digest_, password_bad_));
95 EXPECT_TRUE(tab->CancelAuth()); 95 EXPECT_TRUE(tab->CancelAuth());
96 EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle()); 96 EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle());
97 97
98 NavigateTab(tab.get(), server->TestServerPageW(L"auth-digest")); 98 NavigateTab(tab.get(), server->TestServerPageW(L"auth-digest"));
99 99
100 EXPECT_TRUE(tab->NeedsAuth()); 100 EXPECT_TRUE(tab->NeedsAuth());
101 EXPECT_TRUE(tab->SetAuth(username_digest_, password_)); 101 EXPECT_TRUE(tab->SetAuth(username_digest_, password_));
102 EXPECT_EQ(ExpectedTitleFromAuth(username_digest_, password_), 102 EXPECT_EQ(ExpectedTitleFromAuth(username_digest_, password_),
103 GetActiveTabTitle()); 103 GetActiveTabTitle());
104 } 104 }
105 105
106 // Test that logging in on 2 tabs at once works. 106 // Test that logging in on 2 tabs at once works.
107 TEST_F(LoginPromptTest, TestTwoAuths) { 107 TEST_F(LoginPromptTest, TestTwoAuths) {
108 scoped_refptr<HTTPTestServer> server = 108 scoped_refptr<HTTPTestServer> server =
109 HTTPTestServer::CreateServer(kDocRoot, NULL); 109 HTTPTestServer::CreateServer(kDocRoot, NULL);
110 ASSERT_TRUE(NULL != server.get()); 110 ASSERT_TRUE(NULL != server.get());
111 111
112 ::scoped_ptr<TabProxy> basic_tab(GetActiveTabProxy()); 112 scoped_refptr<TabProxy> basic_tab(GetActiveTabProxy());
113 NavigateTab(basic_tab.get(), server->TestServerPageW(L"auth-basic")); 113 NavigateTab(basic_tab.get(), server->TestServerPageW(L"auth-basic"));
114 114
115 AppendTab(GURL("about:blank")); 115 AppendTab(GURL("about:blank"));
116 ::scoped_ptr<TabProxy> digest_tab(GetActiveTabProxy()); 116 scoped_refptr<TabProxy> digest_tab(GetActiveTabProxy());
117 NavigateTab(digest_tab.get(), server->TestServerPageW(L"auth-digest")); 117 NavigateTab(digest_tab.get(), server->TestServerPageW(L"auth-digest"));
118 118
119 // TODO(devint): http://b/1158262 basic_tab is not active, so this logs in to 119 // TODO(devint): http://b/1158262 basic_tab is not active, so this logs in to
120 // a page whose tab isn't active, which isn't actually possible for the user 120 // a page whose tab isn't active, which isn't actually possible for the user
121 // to do. I had a fix for this, but I'm reverting it to see if it makes the 121 // to do. I had a fix for this, but I'm reverting it to see if it makes the
122 // test less flaky. 122 // test less flaky.
123 EXPECT_TRUE(basic_tab->NeedsAuth()); 123 EXPECT_TRUE(basic_tab->NeedsAuth());
124 EXPECT_TRUE(basic_tab->SetAuth(username_basic_, password_)); 124 EXPECT_TRUE(basic_tab->SetAuth(username_basic_, password_));
125 EXPECT_TRUE(digest_tab->NeedsAuth()); 125 EXPECT_TRUE(digest_tab->NeedsAuth());
126 EXPECT_TRUE(digest_tab->SetAuth(username_digest_, password_)); 126 EXPECT_TRUE(digest_tab->SetAuth(username_digest_, password_));
127 127
128 wstring title; 128 wstring title;
129 EXPECT_TRUE(basic_tab->GetTabTitle(&title)); 129 EXPECT_TRUE(basic_tab->GetTabTitle(&title));
130 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title); 130 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title);
131 131
132 EXPECT_TRUE(digest_tab->GetTabTitle(&title)); 132 EXPECT_TRUE(digest_tab->GetTabTitle(&title));
133 EXPECT_EQ(ExpectedTitleFromAuth(username_digest_, password_), title); 133 EXPECT_EQ(ExpectedTitleFromAuth(username_digest_, password_), title);
134 } 134 }
135 135
136 // Test that cancelling authentication works. 136 // Test that cancelling authentication works.
137 TEST_F(LoginPromptTest, TestCancelAuth) { 137 TEST_F(LoginPromptTest, TestCancelAuth) {
138 scoped_refptr<HTTPTestServer> server = 138 scoped_refptr<HTTPTestServer> server =
139 HTTPTestServer::CreateServer(kDocRoot, NULL); 139 HTTPTestServer::CreateServer(kDocRoot, NULL);
140 ASSERT_TRUE(NULL != server.get()); 140 ASSERT_TRUE(NULL != server.get());
141 ::scoped_ptr<TabProxy> tab(GetActiveTabProxy()); 141 scoped_refptr<TabProxy> tab(GetActiveTabProxy());
142 142
143 // First navigate to a test server page so we have something to go back to. 143 // First navigate to a test server page so we have something to go back to.
144 EXPECT_TRUE(tab->NavigateToURL(server->TestServerPageW(L"a"))); 144 EXPECT_TRUE(tab->NavigateToURL(server->TestServerPageW(L"a")));
145 145
146 // Navigating while auth is requested is the same as cancelling. 146 // Navigating while auth is requested is the same as cancelling.
147 NavigateTab(tab.get(), server->TestServerPageW(L"auth-basic")); 147 NavigateTab(tab.get(), server->TestServerPageW(L"auth-basic"));
148 EXPECT_TRUE(tab->NeedsAuth()); 148 EXPECT_TRUE(tab->NeedsAuth());
149 EXPECT_TRUE(tab->NavigateToURL(server->TestServerPageW(L"b"))); 149 EXPECT_TRUE(tab->NavigateToURL(server->TestServerPageW(L"b")));
150 EXPECT_FALSE(tab->NeedsAuth()); 150 EXPECT_FALSE(tab->NeedsAuth());
151 151
(...skipping 11 matching lines...) Expand all
163 EXPECT_TRUE(tab->GoForward()); // should bring us to 'c' 163 EXPECT_TRUE(tab->GoForward()); // should bring us to 'c'
164 EXPECT_FALSE(tab->NeedsAuth()); 164 EXPECT_FALSE(tab->NeedsAuth());
165 165
166 // Now test that cancelling works as expected. 166 // Now test that cancelling works as expected.
167 NavigateTab(tab.get(), server->TestServerPageW(L"auth-basic")); 167 NavigateTab(tab.get(), server->TestServerPageW(L"auth-basic"));
168 EXPECT_TRUE(tab->NeedsAuth()); 168 EXPECT_TRUE(tab->NeedsAuth());
169 EXPECT_TRUE(tab->CancelAuth()); 169 EXPECT_TRUE(tab->CancelAuth());
170 EXPECT_FALSE(tab->NeedsAuth()); 170 EXPECT_FALSE(tab->NeedsAuth());
171 EXPECT_EQ(L"Denied: no auth", GetActiveTabTitle()); 171 EXPECT_EQ(L"Denied: no auth", GetActiveTabTitle());
172 } 172 }
OLDNEW
« no previous file with comments | « chrome/browser/history/redirect_uitest.cc ('k') | chrome/browser/metrics/metrics_service_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698