Popular sites on the NTP: re-download popular suggestions once per Chrome run
[chromium-blink-merge.git] / chrome / browser / net / ftp_browsertest.cc
blob2e86a378e867a498cd4a1400ec9791177736a046
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"
16 #include "url/gurl.h"
18 class FtpBrowserTest : public InProcessBrowserTest {
19 public:
20 FtpBrowserTest()
21 : ftp_server_(net::SpawnedTestServer::TYPE_FTP,
22 net::SpawnedTestServer::kLocalhost,
23 base::FilePath(FILE_PATH_LITERAL("chrome/test/data/ftp"))) {
26 protected:
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(
41 browser(),
42 ftp_server_.GetURLWithUserAndPassword("", "chrome", "chrome"));
44 WaitForTitle(browser()->tab_strip_model()->GetActiveWebContents(),
45 "Index of /");
48 // http://crbug.com/521409
49 #if defined(OS_WIN)
50 #define MAYBE_DirectoryListingNavigation DISABLED_DirectoryListingNavigation
51 #else
52 #define MAYBE_DirectoryListingNavigation DirectoryListingNavigation
53 #endif
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(
59 browser(),
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();"
69 " }"
70 "}"));
72 WaitForTitle(browser()->tab_strip_model()->GetActiveWebContents(),
73 "Index of /dir1/");
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();"
81 " }"
82 "}"));
84 WaitForTitle(browser()->tab_strip_model()->GetActiveWebContents(),
85 "PASS");