1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "base/files/file_path.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "chrome/test/base/ui_test_utils.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/test/browser_test_utils.h"
14 #include "net/test/spawned_test_server/spawned_test_server.h"
15 #include "testing/gtest/include/gtest/gtest.h"
18 class FtpBrowserTest
: public InProcessBrowserTest
{
21 : ftp_server_(net::SpawnedTestServer::TYPE_FTP
,
22 net::SpawnedTestServer::kLocalhost
,
23 base::FilePath(FILE_PATH_LITERAL("chrome/test/data/ftp"))) {
27 net::SpawnedTestServer ftp_server_
;
30 void WaitForTitle(content::WebContents
* contents
, const char* expected_title
) {
31 content::TitleWatcher
title_watcher(contents
,
32 base::ASCIIToUTF16(expected_title
));
34 EXPECT_EQ(base::ASCIIToUTF16(expected_title
),
35 title_watcher
.WaitAndGetTitle());
38 IN_PROC_BROWSER_TEST_F(FtpBrowserTest
, BasicFtpUrlAuthentication
) {
39 ASSERT_TRUE(ftp_server_
.Start());
40 ui_test_utils::NavigateToURL(
42 ftp_server_
.GetURLWithUserAndPassword("", "chrome", "chrome"));
44 WaitForTitle(browser()->tab_strip_model()->GetActiveWebContents(),
48 IN_PROC_BROWSER_TEST_F(FtpBrowserTest
, DirectoryListingNavigation
) {
49 ftp_server_
.set_no_anonymous_ftp_user(true);
50 ASSERT_TRUE(ftp_server_
.Start());
52 ui_test_utils::NavigateToURL(
54 ftp_server_
.GetURLWithUserAndPassword("", "chrome", "chrome"));
56 // Navigate to directory dir1/ without needing to re-authenticate
57 EXPECT_TRUE(content::ExecuteScript(
58 browser()->tab_strip_model()->GetActiveWebContents(),
59 "var elements = document.getElementsByTagName('a');"
60 "for (var i = 0; i < elements.length; i++) {"
61 " if (elements[i].innerHTML == 'dir1/') {"
62 " elements[i].click();"
66 WaitForTitle(browser()->tab_strip_model()->GetActiveWebContents(),
69 EXPECT_TRUE(content::ExecuteScript(
70 browser()->tab_strip_model()->GetActiveWebContents(),
71 "var elements = document.getElementsByTagName('a');"
72 "for (var i = 0; i < elements.length; i++) {"
73 " if (elements[i].innerHTML == 'test.html') {"
74 " elements[i].click();"
78 WaitForTitle(browser()->tab_strip_model()->GetActiveWebContents(),