Home | History | Annotate | Download | only in browser
      1 // Copyright (c) 2011 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.
      4 
      5 #include "base/string_util.h"
      6 #include "base/test/test_timeouts.h"
      7 #include "base/threading/platform_thread.h"
      8 #include "chrome/test/automation/tab_proxy.h"
      9 #include "chrome/test/ui/ui_test.h"
     10 #include "chrome/browser/net/url_request_failed_dns_job.h"
     11 #include "chrome/browser/net/url_request_mock_http_job.h"
     12 #include "net/test/test_server.h"
     13 
     14 class ErrorPageTest : public UITest {
     15  protected:
     16   bool WaitForTitleMatching(const std::wstring& title) {
     17     for (int i = 0; i < 10; ++i) {
     18       if (GetActiveTabTitle() == title)
     19         return true;
     20       base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms());
     21     }
     22     EXPECT_EQ(title, GetActiveTabTitle());
     23     return false;
     24   }
     25 };
     26 
     27 TEST_F(ErrorPageTest, DNSError_Basic) {
     28   GURL test_url(URLRequestFailedDnsJob::kTestUrl);
     29 
     30   // The first navigation should fail, and the second one should be the error
     31   // page.
     32   NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
     33 
     34   EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
     35 }
     36 
     37 TEST_F(ErrorPageTest, DNSError_GoBack1) {
     38   // Test that a DNS error occuring in the main frame does not result in an
     39   // additional session history entry.
     40   GURL test_url(URLRequestFailedDnsJob::kTestUrl);
     41 
     42   NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
     43                     FilePath(FILE_PATH_LITERAL("title2.html"))));
     44   // The first navigation should fail, and the second one should be the error
     45   // page.
     46   NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
     47   EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
     48 
     49   EXPECT_TRUE(GetActiveTab()->GoBack());
     50 
     51   EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness"));
     52 }
     53 
     54 // Flaky on Linux, see http://crbug.com/19361
     55 #if defined(OS_LINUX)
     56 #define MAYBE_DNSError_GoBack2 FLAKY_DNSError_GoBack2
     57 #else
     58 #define MAYBE_DNSError_GoBack2 DNSError_GoBack2
     59 #endif
     60 TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack2) {
     61   // Test that a DNS error occuring in the main frame does not result in an
     62   // additional session history entry.
     63   GURL test_url(URLRequestFailedDnsJob::kTestUrl);
     64 
     65   NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
     66                     FilePath(FILE_PATH_LITERAL("title2.html"))));
     67   // The first navigation should fail, and the second one should be the error
     68   // page.
     69   NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
     70   EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
     71   NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
     72                     FilePath(FILE_PATH_LITERAL("title3.html"))));
     73 
     74   // The first navigation should fail, and the second one should be the error
     75   // page.
     76   EXPECT_TRUE(GetActiveTab()->GoBackBlockUntilNavigationsComplete(2));
     77   EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
     78   EXPECT_TRUE(GetActiveTab()->GoBack());
     79 
     80   EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness"));
     81 }
     82 
     83 // Flaky on Linux, see http://crbug.com/19361
     84 #if defined(OS_LINUX)
     85 #define MAYBE_DNSError_GoBack2AndForward FLAKY_DNSError_GoBack2AndForward
     86 #else
     87 #define MAYBE_DNSError_GoBack2AndForward DNSError_GoBack2AndForward
     88 #endif
     89 TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack2AndForward) {
     90   // Test that a DNS error occuring in the main frame does not result in an
     91   // additional session history entry.
     92 
     93   GURL test_url(URLRequestFailedDnsJob::kTestUrl);
     94 
     95   NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
     96                     FilePath(FILE_PATH_LITERAL("title2.html"))));
     97   // The first navigation should fail, and the second one should be the error
     98   // page.
     99   NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
    100   EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
    101   NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
    102                     FilePath(FILE_PATH_LITERAL("title3.html"))));
    103 
    104   // The first navigation should fail, and the second one should be the error
    105   // page.
    106   EXPECT_TRUE(GetActiveTab()->GoBackBlockUntilNavigationsComplete(2));
    107   EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
    108   EXPECT_TRUE(GetActiveTab()->GoBack());
    109   // The first navigation should fail, and the second one should be the error
    110   // page.
    111   EXPECT_TRUE(GetActiveTab()->GoForwardBlockUntilNavigationsComplete(2));
    112 
    113   EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
    114 }
    115 
    116 // Flaky on Linux, see http://crbug.com/19361
    117 #if defined(OS_LINUX)
    118 #define MAYBE_DNSError_GoBack2Forward2 FLAKY_DNSError_GoBack2Forward2
    119 #else
    120 #define MAYBE_DNSError_GoBack2Forward2 DNSError_GoBack2Forward2
    121 #endif
    122 TEST_F(ErrorPageTest, MAYBE_DNSError_GoBack2Forward2) {
    123   // Test that a DNS error occuring in the main frame does not result in an
    124   // additional session history entry.
    125 
    126   GURL test_url(URLRequestFailedDnsJob::kTestUrl);
    127 
    128   NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
    129                     FilePath(FILE_PATH_LITERAL("title3.html"))));
    130   // The first navigation should fail, and the second one should be the error
    131   // page.
    132   NavigateToURLBlockUntilNavigationsComplete(test_url, 2);
    133   EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
    134   NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
    135                     FilePath(FILE_PATH_LITERAL("title2.html"))));
    136 
    137   // The first navigation should fail, and the second one should be the error
    138   // page.
    139   EXPECT_TRUE(GetActiveTab()->GoBackBlockUntilNavigationsComplete(2));
    140   EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
    141   EXPECT_TRUE(GetActiveTab()->GoBack());
    142   // The first navigation should fail, and the second one should be the error
    143   // page.
    144   EXPECT_TRUE(GetActiveTab()->GoForwardBlockUntilNavigationsComplete(2));
    145   EXPECT_TRUE(WaitForTitleMatching(L"Mock Link Doctor"));
    146   EXPECT_TRUE(GetActiveTab()->GoForward());
    147 
    148   EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness"));
    149 }
    150 
    151 TEST_F(ErrorPageTest, IFrameDNSError_Basic) {
    152   NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
    153                     FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))));
    154   EXPECT_TRUE(WaitForTitleMatching(L"Blah"));
    155 }
    156 
    157 TEST_F(ErrorPageTest, IFrameDNSError_GoBack) {
    158   // Test that a DNS error occuring in an iframe does not result in an
    159   // additional session history entry.
    160 
    161   NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
    162                     FilePath(FILE_PATH_LITERAL("title2.html"))));
    163   NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
    164                     FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))));
    165 
    166   EXPECT_TRUE(GetActiveTab()->GoBack());
    167 
    168   EXPECT_TRUE(WaitForTitleMatching(L"Title Of Awesomeness"));
    169 }
    170 
    171 TEST_F(ErrorPageTest, IFrameDNSError_GoBackAndForward) {
    172   // Test that a DNS error occuring in an iframe does not result in an
    173   // additional session history entry.
    174 
    175   NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
    176                     FilePath(FILE_PATH_LITERAL("title2.html"))));
    177   NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
    178                     FilePath(FILE_PATH_LITERAL("iframe_dns_error.html"))));
    179 
    180   EXPECT_TRUE(GetActiveTab()->GoBack());
    181   EXPECT_TRUE(GetActiveTab()->GoForward());
    182 
    183   EXPECT_TRUE(WaitForTitleMatching(L"Blah"));
    184 }
    185 
    186 // Checks that the Link Doctor is not loaded when we receive an actual 404 page.
    187 TEST_F(ErrorPageTest, Page404) {
    188   NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
    189                     FilePath(FILE_PATH_LITERAL("page404.html"))));
    190 
    191   EXPECT_TRUE(WaitForTitleMatching(L"SUCCESS"));
    192 }
    193