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.
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"
21 namespace extensions
{
24 static const char kDomain
[] = "a.com";
25 static const char kSitesDir
[] = "automation/sites";
26 static const char kGotTree
[] = "got_tree";
27 } // anonymous namespace
29 class AutomationApiTest
: public ExtensionApiTest
{
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
);
37 embedded_test_server()->GetURL(path
).ReplaceComponents(replacements
);
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());
52 StartEmbeddedTestServer();
53 const GURL url
= GetURLForPath(kDomain
, "/index.html");
54 ui_test_utils::NavigateToURL(browser(), url
);
58 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
59 ExtensionApiTest::SetUpCommandLine(command_line
);
60 command_line
->AppendSwitch(::switches::kEnableAutomationAPI
);
63 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE
{
64 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
68 IN_PROC_BROWSER_TEST_F(AutomationApiTest
, TestRendererAccessibilityEnabled
) {
71 ASSERT_EQ(1, browser()->tab_strip_model()->count());
72 content::WebContents
* const tab
=
73 browser()->tab_strip_model()->GetWebContentsAt(0);
74 content::RenderWidgetHost
* rwh
=
75 tab
->GetRenderWidgetHostView()->GetRenderWidgetHost();
76 ASSERT_NE((content::RenderWidgetHost
*)NULL
, rwh
)
77 << "Couldn't get RenderWidgetHost";
78 ASSERT_FALSE(rwh
->IsFullAccessibilityModeForTesting());
79 ASSERT_FALSE(rwh
->IsTreeOnlyAccessibilityModeForTesting());
81 base::FilePath extension_path
=
82 test_data_dir_
.AppendASCII("automation/basic");
83 ExtensionTestMessageListener
got_tree(kGotTree
, false /* no reply */);
84 LoadExtension(extension_path
);
85 ASSERT_TRUE(got_tree
.WaitUntilSatisfied());
87 rwh
= tab
->GetRenderWidgetHostView()->GetRenderWidgetHost();
88 ASSERT_NE((content::RenderWidgetHost
*)NULL
, rwh
)
89 << "Couldn't get RenderWidgetHost";
90 ASSERT_FALSE(rwh
->IsFullAccessibilityModeForTesting());
91 ASSERT_TRUE(rwh
->IsTreeOnlyAccessibilityModeForTesting());
94 // TODO(dtseng): See crbug.com/360297.
95 #if defined(OS_MACOSX)
96 #define MAYBE_SanityCheck DISABLED_SanityCheck
98 #define MAYBE_SanityCheck SanityCheck
99 #endif // defined(OS_MACOSX)
100 IN_PROC_BROWSER_TEST_F(AutomationApiTest
, MAYBE_SanityCheck
) {
101 StartEmbeddedTestServer();
102 ASSERT_TRUE(RunExtensionSubtest("automation/tests", "sanity_check.html"))
106 IN_PROC_BROWSER_TEST_F(AutomationApiTest
, Events
) {
108 ASSERT_TRUE(RunExtensionSubtest("automation/tests", "events.html"))
112 IN_PROC_BROWSER_TEST_F(AutomationApiTest
, Actions
) {
114 ASSERT_TRUE(RunExtensionSubtest("automation/tests", "actions.html"))
118 IN_PROC_BROWSER_TEST_F(AutomationApiTest
, Location
) {
120 ASSERT_TRUE(RunExtensionSubtest("automation/tests", "location.html"))
124 } // namespace extensions