| Index: chrome/browser/chromeos/extensions/virtual_keyboard_browsertest.cc
|
| diff --git a/chrome/browser/chromeos/extensions/virtual_keyboard_browsertest.cc b/chrome/browser/chromeos/extensions/virtual_keyboard_browsertest.cc
|
| index 222fcfdc31958883ccb02a352b85138b29249cc6..530bfd18f75995c9c474d5aa58752de3f0323584 100644
|
| --- a/chrome/browser/chromeos/extensions/virtual_keyboard_browsertest.cc
|
| +++ b/chrome/browser/chromeos/extensions/virtual_keyboard_browsertest.cc
|
| @@ -3,6 +3,7 @@
|
| * Use of this source code is governed by a BSD-style license that can be
|
| * found in the LICENSE file.
|
| */
|
| +#include "chrome/browser/chromeos/extensions/virtual_keyboard_browsertest.h"
|
|
|
| #include <vector>
|
|
|
| @@ -17,127 +18,132 @@
|
| #include "content/public/browser/site_instance.h"
|
| #include "content/public/browser/web_contents.h"
|
| #include "content/public/test/browser_test_utils.h"
|
| +#include "extensions/common/extension.h"
|
| #include "ui/aura/client/aura_constants.h"
|
| #include "ui/base/ime/input_method.h"
|
| #include "ui/keyboard/keyboard_controller.h"
|
| #include "ui/keyboard/keyboard_switches.h"
|
|
|
| namespace {
|
| +const base::FilePath::CharType kWebuiTestDir[] = FILE_PATH_LITERAL("webui");
|
|
|
| -const base::FilePath kWebuiTestDir =
|
| - base::FilePath(FILE_PATH_LITERAL("webui"));
|
| +const base::FilePath::CharType kMockController[] =
|
| + FILE_PATH_LITERAL("mock_controller.js");
|
|
|
| -const base::FilePath kVirtualKeyboardTestDir =
|
| - base::FilePath(FILE_PATH_LITERAL("chromeos/virtual_keyboard"));
|
| +const base::FilePath::CharType kMockTimer[] =
|
| + FILE_PATH_LITERAL("mock_timer.js");
|
|
|
| -const base::FilePath kMockController =
|
| - base::FilePath(FILE_PATH_LITERAL("mock_controller.js"));
|
| +const char kVirtualKeyboardTestDir[] = "chromeos/virtual_keyboard";
|
|
|
| -const base::FilePath kMockTimer =
|
| - base::FilePath(FILE_PATH_LITERAL("mock_timer.js"));
|
| +const char kBaseKeyboardTestFramework[] = "virtual_keyboard_test_base.js";
|
|
|
| -const base::FilePath kBaseKeyboardTestFramework =
|
| - base::FilePath(FILE_PATH_LITERAL("virtual_keyboard_test_base.js"));
|
| +const char kExtensionId[] = "mppnpdlheglhdfmldimlhpnegondlapf";
|
|
|
| -} // namespace
|
| -
|
| -class VirtualKeyboardBrowserTest : public InProcessBrowserTest {
|
| - public:
|
| -
|
| - // Ensure that the virtual keyboard is enabled.
|
| - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
|
| - command_line->AppendSwitch(
|
| - keyboard::switches::kEnableVirtualKeyboard);
|
| - }
|
| +const char kVirtualKeyboardURL[] = "chrome://keyboard";
|
|
|
| - // Injects javascript in |file| into the keyboard page and runs test methods.
|
| - void RunTest(const base::FilePath& file) {
|
| - ui_test_utils::NavigateToURL(browser(), GURL("chrome://keyboard"));
|
| +} // namespace
|
|
|
| - content::WebContents* web_contents =
|
| - browser()->tab_strip_model()->GetActiveWebContents();
|
| - ASSERT_TRUE(web_contents);
|
| +VirtualKeyboardBrowserTestConfig::VirtualKeyboardBrowserTestConfig()
|
| + : base_framework_(kBaseKeyboardTestFramework),
|
| + extension_id_(kExtensionId),
|
| + test_dir_(kVirtualKeyboardTestDir),
|
| + url_(kVirtualKeyboardURL) {
|
| +}
|
|
|
| - // Inject testing scripts.
|
| - InjectJavascript(kWebuiTestDir, kMockController);
|
| - InjectJavascript(kWebuiTestDir, kMockTimer);
|
| - InjectJavascript(kVirtualKeyboardTestDir, kBaseKeyboardTestFramework);
|
| - InjectJavascript(kVirtualKeyboardTestDir, file);
|
| +VirtualKeyboardBrowserTestConfig::~VirtualKeyboardBrowserTestConfig() {};
|
|
|
| - ASSERT_TRUE(content::ExecuteScript(web_contents, utf8_content_));
|
| +void VirtualKeyboardBrowserTest::SetUpCommandLine(CommandLine* command_line) {
|
| + command_line->AppendSwitch(keyboard::switches::kEnableVirtualKeyboard);
|
| +}
|
|
|
| - // Inject DOM-automation test harness and run tests.
|
| - std::vector<int> resource_ids;
|
| - EXPECT_TRUE(ExecuteWebUIResourceTest(web_contents, resource_ids));
|
| - }
|
| +void VirtualKeyboardBrowserTest::RunTest(
|
| + const base::FilePath& file,
|
| + const VirtualKeyboardBrowserTestConfig& config) {
|
| + ui_test_utils::NavigateToURL(browser(), GURL(config.url_));
|
| + content::WebContents* web_contents =
|
| + browser()->tab_strip_model()->GetActiveWebContents();
|
| + content::WaitForLoadStop(web_contents);
|
| + ASSERT_TRUE(web_contents);
|
| +
|
| + // Inject testing scripts.
|
| + InjectJavascript(base::FilePath(kWebuiTestDir),
|
| + base::FilePath(kMockController));
|
| + InjectJavascript(base::FilePath(kWebuiTestDir), base::FilePath(kMockTimer));
|
| + InjectJavascript(base::FilePath(FILE_PATH_LITERAL(config.test_dir_)),
|
| + base::FilePath(FILE_PATH_LITERAL(config.base_framework_)));
|
| + InjectJavascript(base::FilePath(FILE_PATH_LITERAL(config.test_dir_)), file);
|
| +
|
| + ASSERT_TRUE(content::ExecuteScript(web_contents, utf8_content_));
|
| +
|
| + // Inject DOM-automation test harness and run tests.
|
| + std::vector<int> resource_ids;
|
| + EXPECT_TRUE(ExecuteWebUIResourceTest(web_contents, resource_ids));
|
| +}
|
|
|
| - void showVirtualKeyboard() {
|
| - aura::Window *window = ash::Shell::GetPrimaryRootWindow();
|
| - ui::InputMethod* input_method = window->GetProperty(
|
| - aura::client::kRootWindowInputMethodKey);
|
| - ASSERT_TRUE(input_method);
|
| - input_method->ShowImeIfNeeded();
|
| - }
|
| +void VirtualKeyboardBrowserTest::ShowVirtualKeyboard() {
|
| + aura::Window* window = ash::Shell::GetPrimaryRootWindow();
|
| + ui::InputMethod* input_method =
|
| + window->GetProperty(aura::client::kRootWindowInputMethodKey);
|
| + ASSERT_TRUE(input_method);
|
| + input_method->ShowImeIfNeeded();
|
| +}
|
|
|
| - content::RenderViewHost* GetKeyboardRenderViewHost() {
|
| - showVirtualKeyboard();
|
| - std::string kVirtualKeyboardURL =
|
| - "chrome-extension://mppnpdlheglhdfmldimlhpnegondlapf/";
|
| - scoped_ptr<content::RenderWidgetHostIterator> widgets(
|
| - content::RenderWidgetHost::GetRenderWidgetHosts());
|
| - while (content::RenderWidgetHost* widget = widgets->GetNextHost()) {
|
| - if (widget->IsRenderView()) {
|
| - content::RenderViewHost* view = content::RenderViewHost::From(widget);
|
| - std::string url = view->GetSiteInstance()->GetSiteURL().spec();
|
| - if (url == kVirtualKeyboardURL) {
|
| - content::WebContents* wc =
|
| - content::WebContents::FromRenderViewHost(view);
|
| - // Waits for Polymer to load.
|
| - content::WaitForLoadStop(wc);
|
| - return view;
|
| - }
|
| +content::RenderViewHost* VirtualKeyboardBrowserTest::GetKeyboardRenderViewHost(
|
| + const std::string& id) {
|
| + ShowVirtualKeyboard();
|
| + GURL url = extensions::Extension::GetBaseURLFromExtensionId(id);
|
| + scoped_ptr<content::RenderWidgetHostIterator> widgets(
|
| + content::RenderWidgetHost::GetRenderWidgetHosts());
|
| + while (content::RenderWidgetHost* widget = widgets->GetNextHost()) {
|
| + if (widget->IsRenderView()) {
|
| + content::RenderViewHost* view = content::RenderViewHost::From(widget);
|
| + if (url == view->GetSiteInstance()->GetSiteURL()) {
|
| + content::WebContents* wc =
|
| + content::WebContents::FromRenderViewHost(view);
|
| + // Waits for Polymer to load.
|
| + content::WaitForLoadStop(wc);
|
| + return view;
|
| }
|
| }
|
| - return NULL;
|
| - }
|
| -
|
| - private:
|
| -
|
| - // Injects javascript into the keyboard page. The test |file| is in
|
| - // directory |dir| relative to the root testing directory.
|
| - void InjectJavascript(const base::FilePath& dir,
|
| - const base::FilePath& file) {
|
| - base::FilePath path = ui_test_utils::GetTestFilePath(dir, file);
|
| - std::string library_content;
|
| - ASSERT_TRUE(base::ReadFileToString(path, &library_content))
|
| - << path.value();
|
| - utf8_content_.append(library_content);
|
| - utf8_content_.append(";\n");
|
| }
|
| + LOG(ERROR) << "Extension not found:" << url;
|
| + return NULL;
|
| +}
|
|
|
| - std::string utf8_content_;
|
| -};
|
| +void VirtualKeyboardBrowserTest::InjectJavascript(const base::FilePath& dir,
|
| + const base::FilePath& file) {
|
| + base::FilePath path = ui_test_utils::GetTestFilePath(dir, file);
|
| + std::string library_content;
|
| + ASSERT_TRUE(base::ReadFileToString(path, &library_content)) << path.value();
|
| + utf8_content_.append(library_content);
|
| + utf8_content_.append(";\n");
|
| +}
|
|
|
| // crbug.com/367817. Either this feature or just the test are depending
|
| // on the presense of Object.observe which is presently disabled by default.
|
| IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, DISABLED_AttributesTest) {
|
| - RunTest(base::FilePath(FILE_PATH_LITERAL("attributes_test.js")));
|
| + RunTest(base::FilePath(FILE_PATH_LITERAL("attributes_test.js")),
|
| + VirtualKeyboardBrowserTestConfig());
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, TypingTest) {
|
| - RunTest(base::FilePath(FILE_PATH_LITERAL("typing_test.js")));
|
| + RunTest(base::FilePath(FILE_PATH_LITERAL("typing_test.js")),
|
| + VirtualKeyboardBrowserTestConfig());
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, ControlKeysTest) {
|
| - RunTest(base::FilePath(FILE_PATH_LITERAL("control_keys_test.js")));
|
| + RunTest(base::FilePath(FILE_PATH_LITERAL("control_keys_test.js")),
|
| + VirtualKeyboardBrowserTestConfig());
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, HideKeyboardKeyTest) {
|
| - RunTest(base::FilePath(FILE_PATH_LITERAL("hide_keyboard_key_test.js")));
|
| + RunTest(base::FilePath(FILE_PATH_LITERAL("hide_keyboard_key_test.js")),
|
| + VirtualKeyboardBrowserTestConfig());
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, KeysetTransitionTest) {
|
| - RunTest(base::FilePath(FILE_PATH_LITERAL("keyset_transition_test.js")));
|
| + RunTest(base::FilePath(FILE_PATH_LITERAL("keyset_transition_test.js")),
|
| + VirtualKeyboardBrowserTestConfig());
|
| }
|
|
|
| // Fails when enabling Object.observe. See http://crbug.com/370004
|
| @@ -147,7 +153,8 @@ IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, KeysetTransitionTest) {
|
| #define MAYBE_IsKeyboardLoaded IsKeyboardLoaded
|
| #endif
|
| IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, MAYBE_IsKeyboardLoaded) {
|
| - content::RenderViewHost* keyboard_rvh = GetKeyboardRenderViewHost();
|
| + content::RenderViewHost* keyboard_rvh =
|
| + GetKeyboardRenderViewHost(kExtensionId);
|
| ASSERT_TRUE(keyboard_rvh);
|
| bool loaded = false;
|
| std::string script = "!!chrome.virtualKeyboardPrivate";
|
| @@ -161,7 +168,8 @@ IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, MAYBE_IsKeyboardLoaded) {
|
|
|
| IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, DISABLED_EndToEndTest) {
|
| // Get the virtual keyboard's render view host.
|
| - content::RenderViewHost* keyboard_rvh = GetKeyboardRenderViewHost();
|
| + content::RenderViewHost* keyboard_rvh =
|
| + GetKeyboardRenderViewHost(kExtensionId);
|
| ASSERT_TRUE(keyboard_rvh);
|
|
|
| // Get the test page's render view host.
|
| @@ -178,7 +186,7 @@ IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, DISABLED_EndToEndTest) {
|
|
|
| // Press 'a' on keyboard.
|
| base::FilePath path = ui_test_utils::GetTestFilePath(
|
| - kVirtualKeyboardTestDir,
|
| + base::FilePath(FILE_PATH_LITERAL(kVirtualKeyboardTestDir)),
|
| base::FilePath(FILE_PATH_LITERAL("end_to_end_test.js")));
|
| std::string script;
|
| ASSERT_TRUE(base::ReadFileToString(path, &script));
|
|
|