Merge html-office-public repo into src
[chromium-blink-merge.git] / chrome / test / base / in_process_browser_test_browsertest.cc
blob33502a4fd9fd8b89665443553660785cd8844df1
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.
5 #include <string.h>
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"
17 namespace {
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 {
34 public:
35 explicit LoadFailObserver(content::WebContents* contents)
36 : content::WebContentsObserver(contents),
37 failed_load_(false),
38 error_code_(net::OK) { }
40 void DidFailProvisionalLoad(
41 content::RenderFrameHost* render_frame_host,
42 const GURL& validated_url,
43 int error_code,
44 const base::string16& error_description) override {
45 failed_load_ = true;
46 error_code_ = static_cast<net::Error>(error_code);
47 validated_url_ = validated_url;
50 bool failed_load() const { return failed_load_; }
51 net::Error error_code() const { return error_code_; }
52 const GURL& validated_url() const { return validated_url_; }
54 private:
55 bool failed_load_;
56 net::Error error_code_;
57 GURL validated_url_;
59 DISALLOW_COPY_AND_ASSIGN(LoadFailObserver);
62 // Tests that InProcessBrowserTest cannot resolve external host, in this case
63 // "google.com" and "cnn.com". Using external resources is disabled by default
64 // in InProcessBrowserTest because it causes flakiness.
65 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, ExternalConnectionFail) {
66 content::WebContents* contents =
67 browser()->tab_strip_model()->GetActiveWebContents();
69 const char* const kURLs[] = {
70 "http://www.google.com/",
71 "http://www.cnn.com/"
73 for (size_t i = 0; i < arraysize(kURLs); ++i) {
74 GURL url(kURLs[i]);
75 LoadFailObserver observer(contents);
76 ui_test_utils::NavigateToURL(browser(), url);
77 EXPECT_TRUE(observer.failed_load());
78 EXPECT_EQ(net::ERR_NOT_IMPLEMENTED, observer.error_code());
79 EXPECT_EQ(url, observer.validated_url());
83 } // namespace