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.
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 #include "chrome/test/base/in_process_browser_test.h"
10 #include "chrome/test/base/ui_test_utils.h"
11 #include "content/public/browser/render_view_host.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_contents_observer.h"
14 #include "net/base/net_errors.h"
15 #include "testing/gtest/include/gtest/gtest.h"
19 class InProcessBrowserTestP
20 : public InProcessBrowserTest
,
21 public ::testing::WithParamInterface
<const char*> {
24 IN_PROC_BROWSER_TEST_P(InProcessBrowserTestP
, TestP
) {
25 EXPECT_EQ(0, strcmp("foo", GetParam()));
28 INSTANTIATE_TEST_CASE_P(IPBTP
,
29 InProcessBrowserTestP
,
30 ::testing::Values("foo"));
32 // WebContents observer that can detect provisional load failures.
33 class LoadFailObserver
: public content::WebContentsObserver
{
35 explicit LoadFailObserver(content::WebContents
* contents
)
36 : content::WebContentsObserver(contents
),
38 error_code_(net::OK
) { }
40 virtual void DidFailProvisionalLoad(
42 const base::string16
& frame_unique_name
,
44 const GURL
& validated_url
,
46 const base::string16
& error_description
,
47 content::RenderViewHost
* render_view_host
) OVERRIDE
{
49 error_code_
= static_cast<net::Error
>(error_code
);
50 validated_url_
= validated_url
;
53 bool failed_load() const { return failed_load_
; }
54 net::Error
error_code() const { return error_code_
; }
55 const GURL
& validated_url() const { return validated_url_
; }
59 net::Error error_code_
;
62 DISALLOW_COPY_AND_ASSIGN(LoadFailObserver
);
65 // Tests that InProcessBrowserTest cannot resolve external host, in this case
66 // "google.com" and "cnn.com". Using external resources is disabled by default
67 // in InProcessBrowserTest because it causes flakiness.
68 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest
, ExternalConnectionFail
) {
69 content::WebContents
* contents
=
70 browser()->tab_strip_model()->GetActiveWebContents();
72 const char* const kURLs
[] = {
73 "http://www.google.com/",
76 for (size_t i
= 0; i
< arraysize(kURLs
); ++i
) {
78 LoadFailObserver
observer(contents
);
79 ui_test_utils::NavigateToURL(browser(), url
);
80 EXPECT_TRUE(observer
.failed_load());
81 EXPECT_EQ(net::ERR_NOT_IMPLEMENTED
, observer
.error_code());
82 EXPECT_EQ(url
, observer
.validated_url());