summaryrefslogtreecommitdiffstats
path: root/chrome/browser/errorpage_browsertest.cc
blob: 2a5a1951482de5e1207230f4f1aa2d80776e9edc (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 {
};

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);
  string16 title;

  NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2);
  EXPECT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title));
  EXPECT_EQ(ASCIIToUTF16("Mock Link Doctor"), 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_GoBack1) {
  GURL test_url(URLRequestFailedDnsJob::kTestUrl);
  string16 title;

  NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
  NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2);
  EXPECT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title));
  EXPECT_EQ(ASCIIToUTF16("Mock Link Doctor"), title);

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

  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);
  string16 title;

  NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
  NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2);
  EXPECT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title));
  EXPECT_EQ(ASCIIToUTF16("Mock Link Doctor"), title);
  NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title3.html"));

  browser()->GoBack(CURRENT_TAB);
  ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 2));
  EXPECT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title));
  EXPECT_EQ(ASCIIToUTF16("Mock Link Doctor"), title);

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

  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);
  string16 title;

  NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
  NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2);
  EXPECT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title));
  EXPECT_EQ(ASCIIToUTF16("Mock Link Doctor"), title);
  NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title3.html"));

  browser()->GoBack(CURRENT_TAB);
  ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 2));
  EXPECT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title));
  EXPECT_EQ(ASCIIToUTF16("Mock Link Doctor"), title);

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

  browser()->GoForward(CURRENT_TAB);
  ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 2));
}

// 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);
  string16 title;

  NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title3.html"));
  NavigateToURLBlockUntilNavigationsComplete(browser(), test_url, 2);
  EXPECT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title));
  EXPECT_EQ(ASCIIToUTF16("Mock Link Doctor"), title);
  NavigateToURL(browser(), URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));

  browser()->GoBack(CURRENT_TAB);
  ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 2));
  EXPECT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title));
  EXPECT_EQ(ASCIIToUTF16("Mock Link Doctor"), title);

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

  browser()->GoForward(CURRENT_TAB);
  ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 2));
  EXPECT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &title));
  EXPECT_EQ(ASCIIToUTF16("Mock Link Doctor"), title);

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

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

}  // namespace