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 // http://crbug.com/521409
50 #define MAYBE_DirectoryListingNavigation DISABLED_DirectoryListingNavigation
52 #define MAYBE_DirectoryListingNavigation DirectoryListingNavigation
54 IN_PROC_BROWSER_TEST_F(FtpBrowserTest
, MAYBE_DirectoryListingNavigation
) {
55 ftp_server_
.set_no_anonymous_ftp_user(true);
56 ASSERT_TRUE(ftp_server_
.Start());
58 ui_test_utils::NavigateToURL(
60 ftp_server_
.GetURLWithUserAndPassword("", "chrome", "chrome"));
62 // Navigate to directory dir1/ without needing to re-authenticate
63 EXPECT_TRUE(content::ExecuteScript(
64 browser()->tab_strip_model()->GetActiveWebContents(),
65 "var elements = document.getElementsByTagName('a');"
66 "for (var i = 0; i < elements.length; i++) {"
67 " if (elements[i].innerHTML == 'dir1/') {"
68 " elements[i].click();"
72 WaitForTitle(browser()->tab_strip_model()->GetActiveWebContents(),
75 EXPECT_TRUE(content::ExecuteScript(
76 browser()->tab_strip_model()->GetActiveWebContents(),
77 "var elements = document.getElementsByTagName('a');"
78 "for (var i = 0; i < elements.length; i++) {"
79 " if (elements[i].innerHTML == 'test.html') {"
80 " elements[i].click();"
84 WaitForTitle(browser()->tab_strip_model()->GetActiveWebContents(),