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

Unified Diff: chrome/browser/net/proxy_browsertest.cc

Issue 10854139: Use HttpAuthController in SocketStream (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add browser test. Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | chrome/test/data/http/tests/ws.html » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/net/proxy_browsertest.cc
diff --git a/chrome/browser/net/proxy_browsertest.cc b/chrome/browser/net/proxy_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4147dc10e0f4348a2ad612d82fd4a89d1ec517ef
--- /dev/null
+++ b/chrome/browser/net/proxy_browsertest.cc
@@ -0,0 +1,107 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/command_line.h"
+#include "base/path_service.h"
+#include "base/string_util.h"
+#include "base/stringprintf.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_tabstrip.h"
+#include "chrome/browser/ui/login/login_prompt.h"
+#include "chrome/browser/ui/tab_contents/tab_contents.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/common/chrome_switches.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/browser/notification_details.h"
+#include "content/public/browser/notification_source.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "content/public/test/browser_test_utils.h"
+#include "net/test/test_server.h"
+
+namespace {
+
+class LoginPromptObserver : public content::NotificationObserver {
wtc 2012/08/22 19:42:27 Nit: it may be a good idea to add a comment to des
bashi 2012/08/23 09:54:15 Done.
+ public:
+ LoginPromptObserver()
+ : auth_handled_(false) {}
wtc 2012/08/22 19:42:27 Nit: you can define this constructor on a single l
bashi 2012/08/23 09:54:15 Done.
+
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE {
+ if (type == chrome::NOTIFICATION_AUTH_NEEDED) {
+ LoginNotificationDetails* login_details =
+ content::Details<LoginNotificationDetails>(details).ptr();
+ login_details->handler()->SetAuth(ASCIIToUTF16("foo"),
+ ASCIIToUTF16("bar"));
wtc 2012/08/22 19:42:27 The fact that "foo:bar" is the required username:p
bashi 2012/08/23 09:54:15 Done.
+ auth_handled_ = true;
+ }
+ }
+
+ bool AuthHandled() const { return auth_handled_; }
wtc 2012/08/22 19:42:27 Nit: our Style Guide recommends naming this getter
bashi 2012/08/23 09:54:15 Done.
+
+ private:
+ bool auth_handled_;
+};
+
+class ProxyBrowserTest : public InProcessBrowserTest {
+ public:
+ ProxyBrowserTest()
+ : proxy_server_(net::TestServer::TYPE_BASIC_AUTH_PROXY,
+ net::TestServer::kLocalhost,
+ FilePath()) {
+ }
+
+ virtual void SetUp() OVERRIDE {
+ ASSERT_TRUE(proxy_server_.Start());
+ InProcessBrowserTest::SetUp();
+ }
+
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+ command_line->AppendSwitchASCII(switches::kProxyServer,
+ proxy_server_.host_port_pair().ToString());
+ }
+
+ protected:
+ net::TestServer proxy_server_;
+};
+
+// Test that the browser can establish a WebSocket connection via a proxy
+// that requires basic authentication.
+IN_PROC_BROWSER_TEST_F(ProxyBrowserTest, BasicAuthWSConnect) {
+ // Launch WebSocket server.
+ content::TestWebSocketServer ws_server;
+ int port = ws_server.UseRandomPort();
+ FilePath ws_root_dir;
+ ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &ws_root_dir));
+ ASSERT_TRUE(ws_server.Start(ws_root_dir));
+
+ content::WebContents* tab = chrome::GetActiveWebContents(browser());
+ content::NavigationController* controller = &tab->GetController();
+ content::NotificationRegistrar registrar;
+ // The proxy server will request basic authentication.
+ // |observer| supplies the credential.
+ LoginPromptObserver observer;
+ registrar.Add(&observer, chrome::NOTIFICATION_AUTH_NEEDED,
+ content::Source<content::NavigationController>(controller));
+
+ content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS"));
+ watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
+
+ // Visit a page that tries to establish WebSocket connection. The title
+ // of the page will be 'PASS' on success.
+ std::string url_path =
+ StringPrintf("%s%d%s", "http://localhost:", port, "/ws.html");
cbentzel 2012/08/22 20:19:43 Perhaps not in this CL - but it seems like it woul
bashi 2012/08/23 09:54:15 I agree. I'll make another CL for it after this CL
+ ui_test_utils::NavigateToURL(browser(), GURL(url_path));
+
+ const string16 result = watcher.WaitAndGetTitle();
+ EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass"));
wtc 2012/08/22 19:42:27 Nit: it seems that we already know the page title
bashi 2012/08/23 09:54:15 Done.
+ EXPECT_TRUE(observer.AuthHandled());
+}
+
+} // namespace
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | chrome/test/data/http/tests/ws.html » ('J')

Powered by Google App Engine
This is Rietveld 408576698