• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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.
4 
5 #include "base/files/file_path.h"
6 #include "base/path_service.h"
7 #include "base/strings/string_number_conversions.h"
8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/browser/extensions/extension_test_message_listener.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/common/chrome_paths.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/public/browser/render_widget_host.h"
15 #include "content/public/browser/render_widget_host_view.h"
16 #include "content/public/browser/web_contents.h"
17 #include "net/dns/mock_host_resolver.h"
18 #include "net/test/embedded_test_server/embedded_test_server.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20 
21 namespace extensions {
22 
23 namespace {
24 static const char kDomain[] = "a.com";
25 static const char kSitesDir[] = "automation/sites";
26 static const char kGotTree[] = "got_tree";
27 }  // anonymous namespace
28 
29 class AutomationApiTest : public ExtensionApiTest {
30  protected:
GetURLForPath(const std::string & host,const std::string & path)31   GURL GetURLForPath(const std::string& host, const std::string& path) {
32     std::string port = base::IntToString(embedded_test_server()->port());
33     GURL::Replacements replacements;
34     replacements.SetHostStr(host);
35     replacements.SetPortStr(port);
36     GURL url =
37         embedded_test_server()->GetURL(path).ReplaceComponents(replacements);
38     return url;
39   }
40 
StartEmbeddedTestServer()41   void StartEmbeddedTestServer() {
42     base::FilePath test_data;
43     ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data));
44     embedded_test_server()->ServeFilesFromDirectory(
45         test_data.AppendASCII("extensions/api_test")
46         .AppendASCII(kSitesDir));
47     ASSERT_TRUE(ExtensionApiTest::StartEmbeddedTestServer());
48     host_resolver()->AddRule("*", embedded_test_server()->base_url().host());
49   }
50 
LoadPage()51   void LoadPage() {
52     StartEmbeddedTestServer();
53     const GURL url = GetURLForPath(kDomain, "/index.html");
54     ui_test_utils::NavigateToURL(browser(), url);
55   }
56 
57  public:
SetUpInProcessBrowserTestFixture()58   virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
59     ExtensionApiTest::SetUpInProcessBrowserTestFixture();
60   }
61 };
62 
IN_PROC_BROWSER_TEST_F(AutomationApiTest,TestRendererAccessibilityEnabled)63 IN_PROC_BROWSER_TEST_F(AutomationApiTest, TestRendererAccessibilityEnabled) {
64   LoadPage();
65 
66   ASSERT_EQ(1, browser()->tab_strip_model()->count());
67   content::WebContents* const tab =
68       browser()->tab_strip_model()->GetWebContentsAt(0);
69   content::RenderWidgetHost* rwh =
70       tab->GetRenderWidgetHostView()->GetRenderWidgetHost();
71   ASSERT_NE((content::RenderWidgetHost*)NULL, rwh)
72       << "Couldn't get RenderWidgetHost";
73   ASSERT_FALSE(rwh->IsFullAccessibilityModeForTesting());
74   ASSERT_FALSE(rwh->IsTreeOnlyAccessibilityModeForTesting());
75 
76   base::FilePath extension_path =
77       test_data_dir_.AppendASCII("automation/tests/basic");
78   ExtensionTestMessageListener got_tree(kGotTree, false /* no reply */);
79   LoadExtension(extension_path);
80   ASSERT_TRUE(got_tree.WaitUntilSatisfied());
81 
82   rwh = tab->GetRenderWidgetHostView()->GetRenderWidgetHost();
83   ASSERT_NE((content::RenderWidgetHost*)NULL, rwh)
84       << "Couldn't get RenderWidgetHost";
85   ASSERT_FALSE(rwh->IsFullAccessibilityModeForTesting());
86   ASSERT_TRUE(rwh->IsTreeOnlyAccessibilityModeForTesting());
87 }
88 
89 #if defined(ADDRESS_SANITIZER)
90 #define Maybe_SanityCheck DISABLED_SanityCheck
91 #else
92 #define Maybe_SanityCheck SanityCheck
93 #endif
IN_PROC_BROWSER_TEST_F(AutomationApiTest,Maybe_SanityCheck)94 IN_PROC_BROWSER_TEST_F(AutomationApiTest, Maybe_SanityCheck) {
95   StartEmbeddedTestServer();
96   ASSERT_TRUE(RunExtensionSubtest("automation/tests/tabs", "sanity_check.html"))
97       << message_;
98 }
99 
100 // Test is failing on ASAN bots, crbug.com/379927
IN_PROC_BROWSER_TEST_F(AutomationApiTest,DISABLED_GetTreeByTabId)101 IN_PROC_BROWSER_TEST_F(AutomationApiTest, DISABLED_GetTreeByTabId) {
102   StartEmbeddedTestServer();
103   ASSERT_TRUE(RunExtensionSubtest("automation/tests/tabs", "tab_id.html"))
104       << message_;
105 }
106 
IN_PROC_BROWSER_TEST_F(AutomationApiTest,Events)107 IN_PROC_BROWSER_TEST_F(AutomationApiTest, Events) {
108   StartEmbeddedTestServer();
109   ASSERT_TRUE(RunExtensionSubtest("automation/tests/tabs", "events.html"))
110       << message_;
111 }
112 
113 #if defined(OS_LINUX) && defined(ADDRESS_SANITIZER)
114 // Timing out on linux ASan bot: http://crbug.com/385701
115 #define MAYBE_Actions DISABLED_Actions
116 #else
117 #define MAYBE_Actions Actions
118 #endif
119 
IN_PROC_BROWSER_TEST_F(AutomationApiTest,MAYBE_Actions)120 IN_PROC_BROWSER_TEST_F(AutomationApiTest, MAYBE_Actions) {
121   StartEmbeddedTestServer();
122   ASSERT_TRUE(RunExtensionSubtest("automation/tests/tabs", "actions.html"))
123       << message_;
124 }
125 
126 #if defined(ADDRESS_SANITIZER)
127 #define Maybe_Location DISABLED_Location
128 #else
129 #define Maybe_Location Location
130 #endif
IN_PROC_BROWSER_TEST_F(AutomationApiTest,Maybe_Location)131 IN_PROC_BROWSER_TEST_F(AutomationApiTest, Maybe_Location) {
132   StartEmbeddedTestServer();
133   ASSERT_TRUE(RunExtensionSubtest("automation/tests/tabs", "location.html"))
134       << message_;
135 }
136 
IN_PROC_BROWSER_TEST_F(AutomationApiTest,TabsAutomationBooleanPermissions)137 IN_PROC_BROWSER_TEST_F(AutomationApiTest, TabsAutomationBooleanPermissions) {
138   StartEmbeddedTestServer();
139   ASSERT_TRUE(RunExtensionSubtest(
140           "automation/tests/tabs_automation_boolean", "permissions.html"))
141       << message_;
142 }
143 
144 // See crbug.com/384673
145 #if defined(ADDRESS_SANITIZER) || defined(OS_CHROMEOS)
146 #define Maybe_TabsAutomationBooleanActions DISABLED_TabsAutomationBooleanActions
147 #else
148 #define Maybe_TabsAutomationBooleanActions TabsAutomationBooleanActions
149 #endif
IN_PROC_BROWSER_TEST_F(AutomationApiTest,Maybe_TabsAutomationBooleanActions)150 IN_PROC_BROWSER_TEST_F(AutomationApiTest, Maybe_TabsAutomationBooleanActions) {
151   StartEmbeddedTestServer();
152   ASSERT_TRUE(RunExtensionSubtest(
153           "automation/tests/tabs_automation_boolean", "actions.html"))
154       << message_;
155 }
156 
IN_PROC_BROWSER_TEST_F(AutomationApiTest,TabsAutomationHostsPermissions)157 IN_PROC_BROWSER_TEST_F(AutomationApiTest, TabsAutomationHostsPermissions) {
158   StartEmbeddedTestServer();
159   ASSERT_TRUE(RunExtensionSubtest(
160           "automation/tests/tabs_automation_hosts", "permissions.html"))
161       << message_;
162 }
163 
164 #if defined(OS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(AutomationApiTest,Desktop)165 IN_PROC_BROWSER_TEST_F(AutomationApiTest, Desktop) {
166   ASSERT_TRUE(RunExtensionSubtest("automation/tests/desktop", "desktop.html"))
167       << message_;
168 }
169 
IN_PROC_BROWSER_TEST_F(AutomationApiTest,DesktopNotRequested)170 IN_PROC_BROWSER_TEST_F(AutomationApiTest, DesktopNotRequested) {
171   ASSERT_TRUE(RunExtensionSubtest("automation/tests/tabs",
172                                   "desktop_not_requested.html")) << message_;
173 }
174 
IN_PROC_BROWSER_TEST_F(AutomationApiTest,DesktopActions)175 IN_PROC_BROWSER_TEST_F(AutomationApiTest, DesktopActions) {
176   ASSERT_TRUE(RunExtensionSubtest("automation/tests/desktop", "actions.html"))
177       << message_;
178 }
179 #else
IN_PROC_BROWSER_TEST_F(AutomationApiTest,DesktopNotSupported)180 IN_PROC_BROWSER_TEST_F(AutomationApiTest, DesktopNotSupported) {
181   ASSERT_TRUE(RunExtensionSubtest("automation/tests/desktop",
182                                   "desktop_not_supported.html")) << message_;
183 }
184 #endif
185 
186 }  // namespace extensions
187