summaryrefslogtreecommitdiffstats
path: root/chrome/browser/errorpage_browsertest.cc
blob: 338c521230d4e4d0a59325be8d970422e43b2a8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright (c) 2009 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/string_util.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/net/url_request_failed_dns_job.h"
#include "chrome/browser/net/url_request_mock_http_job.h"
#include "chrome/test/in_process_browser_test.h"
#include "chrome/test/ui_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/glue/window_open_disposition.h"

namespace {

class ErrorPageBrowserTest : public InProcessBrowserTest {
 protected:
  // We're generally not sure what the title will be exactly (it comes from
  // external source, and may be localized etc), but it will alway contain the
  // hostname, so we check for that.
  // For a proper way to do that http://crbug.com/18365 has been filed.
  void AssertCurrentTabTitleContains(const std::string& text) {
    string16 title;
    EXPECT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title));
    EXPECT_NE(string16::npos, title.find(ASCIIToUTF16(text))) <<
        "could not find \"" << text << "\" in \"" << title << "\"";
  }
};

using ui_test_utils::NavigateToURL;

// We want to wait for two navigations: first will be the failing one,
// and the second will be the error page.
using ui_test_utils::NavigateToURLBlockUntilNavigationsComplete;

IN_PROC_BROWSER_TEST_F(ErrorPageBrowserTest, DNSError_Basic) {
  GURL test_url(URLRequestFailedDnsJob::kTestUrl);
  NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2);
  AssertCurrentTabTitleContains(test_url.host());
}

// Test that a DNS error occuring in the main frame does not result in an
// additional session history entry.
IN_PROC_BROWSER_TEST_F(ErrorPageBrowserTest, DNSError_GoBack1) {
  GURL test_url(URLRequestFailedDnsJob::kTestUrl);

  NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
  NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2);
  AssertCurrentTabTitleContains(test_url.host());

  browser()->GoBack(CURRENT_TAB);
  ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));

  string16 title;
  ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title));
  EXPECT_EQ(ASCIIToUTF16("Title Of Awesomeness"), title);
}

// Test that a DNS error occuring in the main frame does not result in an
// additional session history entry.
IN_PROC_BROWSER_TEST_F(ErrorPageBrowserTest, DNSError_GoBack2) {
  GURL test_url(URLRequestFailedDnsJob::kTestUrl);

  NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
  NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2);
  AssertCurrentTabTitleContains(test_url.host());
  NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title3.html"));

  browser()->GoBack(CURRENT_TAB);
  ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 2));
  AssertCurrentTabTitleContains(test_url.host());

  browser()->GoBack(CURRENT_TAB);
  ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));

  string16 title;
  ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title));
  EXPECT_EQ(ASCIIToUTF16("Title Of Awesomeness"), title);
}

// Test that a DNS error occuring in the main frame does not result in an
// additional session history entry.
IN_PROC_BROWSER_TEST_F(ErrorPageBrowserTest, DNSError_GoBackAndForward1) {
  GURL test_url(URLRequestFailedDnsJob::kTestUrl);

  NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
  NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2);
  AssertCurrentTabTitleContains(test_url.host());
  NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title3.html"));

  browser()->GoBack(CURRENT_TAB);
  ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 2));
  AssertCurrentTabTitleContains(test_url.host());

  browser()->GoBack(CURRENT_TAB);
  ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));

  browser()->GoForward(CURRENT_TAB);
  ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 2));
  AssertCurrentTabTitleContains(test_url.host());
}

// Test that a DNS error occuring in the main frame does not result in an
// additional session history entry.
IN_PROC_BROWSER_TEST_F(ErrorPageBrowserTest, DNSError_GoBackAndForward2) {
  GURL test_url(URLRequestFailedDnsJob::kTestUrl);

  NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title3.html"));
  NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2);
  AssertCurrentTabTitleContains(test_url.host());
  NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));

  browser()->GoBack(CURRENT_TAB);
  ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 2));
  AssertCurrentTabTitleContains(test_url.host());

  browser()->GoBack(CURRENT_TAB);
  ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));

  browser()->GoForward(CURRENT_TAB);
  ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 2));
  AssertCurrentTabTitleContains(test_url.host());

  browser()->GoForward(CURRENT_TAB);
  ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));

  string16 title;
  ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title));
  EXPECT_EQ(ASCIIToUTF16("Title Of Awesomeness"), title);
}

}  // namespace