Unregister from GCM when the only GCM app is removed
[chromium-blink-merge.git] / chrome / test / base / in_process_browser_test_browsertest.cc
blob61a3ed4c292d42194e177e446bb445432465009a
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 "base/files/file_util.h"
8 #include "base/path_service.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/test/base/in_process_browser_test.h"
12 #include "chrome/test/base/ui_test_utils.h"
13 #include "content/public/browser/render_view_host.h"
14 #include "content/public/browser/web_contents.h"
15 #include "content/public/browser/web_contents_observer.h"
16 #include "net/base/filename_util.h"
17 #include "net/base/net_errors.h"
18 #include "testing/gtest/include/gtest/gtest.h"
20 namespace {
22 class InProcessBrowserTestP
23 : public InProcessBrowserTest,
24 public ::testing::WithParamInterface<const char*> {
27 IN_PROC_BROWSER_TEST_P(InProcessBrowserTestP, TestP) {
28 EXPECT_EQ(0, strcmp("foo", GetParam()));
31 INSTANTIATE_TEST_CASE_P(IPBTP,
32 InProcessBrowserTestP,
33 ::testing::Values("foo"));
35 // WebContents observer that can detect provisional load failures.
36 class LoadFailObserver : public content::WebContentsObserver {
37 public:
38 explicit LoadFailObserver(content::WebContents* contents)
39 : content::WebContentsObserver(contents),
40 failed_load_(false),
41 error_code_(net::OK) { }
43 void DidFailProvisionalLoad(
44 content::RenderFrameHost* render_frame_host,
45 const GURL& validated_url,
46 int error_code,
47 const base::string16& error_description) override {
48 failed_load_ = true;
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_; }
57 private:
58 bool failed_load_;
59 net::Error error_code_;
60 GURL validated_url_;
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/",
74 "http://www.cnn.com/"
76 for (size_t i = 0; i < arraysize(kURLs); ++i) {
77 GURL url(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());
86 // Paths are to very simple HTML files. One is accessible, the other is not.
87 const base::FilePath::CharType kPassHTML[] =
88 FILE_PATH_LITERAL("chrome/test/data/accessibility_pass.html");
89 const base::FilePath::CharType kFailHTML[] =
90 FILE_PATH_LITERAL("chrome/test/data/accessibility_fail.html");
93 * This class is meant as a test for the accessibility audit in the
94 * InProcessBrowserTest. These tests do NOT validate the accessibility audit,
95 * just the ability to run it.
97 class InProcessAccessibilityBrowserTest : public InProcessBrowserTest {
98 protected:
99 // Construct a URL from a file path that can be used to get to a web page.
100 base::FilePath BuildURLToFile(const base::FilePath::CharType* file_path) {
101 base::FilePath source_root;
102 if (!PathService::Get(base::DIR_SOURCE_ROOT, &source_root))
103 return base::FilePath();
104 return source_root.Append(file_path);
107 bool NavigateToURL(const base::FilePath::CharType* address) {
108 GURL url = net::FilePathToFileURL(BuildURLToFile(address));
110 if (!url.is_valid() || url.is_empty() || !browser())
111 return false;
113 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
114 browser(), url, 1);
115 return true;
119 // Test that an accessible page doesn't fail the accessibility audit.
120 IN_PROC_BROWSER_TEST_F(
121 InProcessAccessibilityBrowserTest, VerifyAccessibilityPass) {
122 ASSERT_TRUE(NavigateToURL(kPassHTML));
124 std::string test_result;
125 EXPECT_TRUE(RunAccessibilityChecks(&test_result));
127 // No error message on success.
128 EXPECT_EQ("", test_result);
131 // Test that a page that is not accessible will fail the accessibility audit.
132 IN_PROC_BROWSER_TEST_F(
133 InProcessAccessibilityBrowserTest, VerifyAccessibilityFail) {
134 ASSERT_TRUE(NavigateToURL(kFailHTML));
136 std::string test_result;
137 EXPECT_FALSE(RunAccessibilityChecks(&test_result));
139 // Error should NOT be empty on failure.
140 EXPECT_NE("", test_result);
143 } // namespace