summaryrefslogtreecommitdiffstats
path: root/chrome/browser/errorpage_uitest.cc
blob: 78939498d57a6373f597f777c87cecd044455ad2 (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
// Copyright (c) 2006-2008 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/test/ui/ui_test.h"
#include "chrome/browser/automation/url_request_failed_dns_job.h"
#include "net/url_request/url_request_unittest.h"

class ErrorPageTest : public UITest {
};

TEST_F(ErrorPageTest, DNSError) {
  GURL test_url(URLRequestFailedDnsJob::kTestUrl);
  std::wstring test_host = UTF8ToWide(test_url.host());
  NavigateToURL(test_url);

  // Verify that the url is in the title.  Since it's set via Javascript, we
  // need to give it a chance to run.
  int i;
  std::wstring title;
  for (i = 0; i < 10; ++i) {
    Sleep(sleep_timeout_ms());
    title = GetActiveTabTitle();
    if (title.find(test_host) != std::wstring::npos) {
      // Success, bail out.
      break;
    }
  }

  if (i == 10) {
    FAIL() << "failed to get error page title; got " << title;
  }
};

TEST_F(ErrorPageTest, IFrame404) {
  // iframes that have 404 pages should not trigger an alternate error page.
  // In this test, the iframe sets the title of the parent page to "SUCCESS"
  // when the iframe loads.  If the iframe fails to load (because an alternate
  // error page loads instead), then the title will remain as "FAIL".
  scoped_refptr<HTTPTestServer> server =
      HTTPTestServer::CreateServer(L"chrome/test/data");
  ASSERT_TRUE(NULL != server.get());
  GURL test_url = server->TestServerPage("files/iframe404.html");
  NavigateToURL(test_url);

  // Verify that the url is in the title.  Since it's set via Javascript, we
  // need to give it a chance to run.
  int i;
  std::wstring title;
  for (i = 0; i < 10; ++i) {
    Sleep(sleep_timeout_ms());
    title = GetActiveTabTitle();
    if (title == L"SUCCESS") {
      // Success, bail out.
      break;
    }
  }

  if (i == 10) {
    FAIL() << "iframe 404 didn't load properly";
  }
};