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 34ec260b2f15ead4bedba87eec004603e3b4dbfa..40318e2fe5e8280d675acbddce78c4c1171d008a 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> |
@@ -41,82 +42,92 @@ const base::FilePath kBaseKeyboardTestFramework = |
} // namespace |
-class VirtualKeyboardBrowserTest : public InProcessBrowserTest { |
- public: |
+void VirtualKeyboardBrowserTest::SetUpCommandLine(CommandLine* command_line) { |
+ command_line->AppendSwitch(keyboard::switches::kEnableVirtualKeyboard); |
+} |
- // Ensure that the virtual keyboard is enabled. |
- virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
- command_line->AppendSwitch( |
- keyboard::switches::kEnableVirtualKeyboard); |
- } |
+GURL VirtualKeyboardBrowserTest::GetURL() { |
+ return GURL("chrome://keyboard"); |
+} |
+ |
+content::WebContents* VirtualKeyboardBrowserTest::NavigateToWebContents() { |
+ ui_test_utils::NavigateToURL(browser(), GetURL()); |
+ content::WebContents* wc = |
+ browser()->tab_strip_model()->GetActiveWebContents(); |
+ content::WaitForLoadStop(wc); |
+ return wc; |
+} |
- // 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")); |
+base::FilePath VirtualKeyboardBrowserTest::GetTestDir() { |
+ return kVirtualKeyboardTestDir; |
+} |
- content::WebContents* web_contents = |
- browser()->tab_strip_model()->GetActiveWebContents(); |
- ASSERT_TRUE(web_contents); |
+void VirtualKeyboardBrowserTest::RunTest(const base::FilePath& file) { |
+ content::WebContents* web_contents = NavigateToWebContents(); |
+ ASSERT_TRUE(web_contents); |
- // Inject testing scripts. |
- InjectJavascript(kWebuiTestDir, kMockController); |
- InjectJavascript(kWebuiTestDir, kMockTimer); |
- InjectJavascript(kVirtualKeyboardTestDir, kBaseKeyboardTestFramework); |
- InjectJavascript(kVirtualKeyboardTestDir, file); |
+ // Inject testing scripts. |
+ InjectJavascript(kWebuiTestDir, kMockController); |
+ InjectJavascript(kWebuiTestDir, kMockTimer); |
+ InjectJavascript(GetTestDir(), GetBaseFrameWork()); |
+ InjectJavascript(GetTestDir(), file); |
- ASSERT_TRUE(content::ExecuteScript(web_contents, utf8_content_)); |
+ 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)); |
- } |
+ // 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; |
- } |
+std::string VirtualKeyboardBrowserTest::GetKeyboardExtensionId() { |
+ return "mppnpdlheglhdfmldimlhpnegondlapf"; |
+} |
+ |
+base::FilePath VirtualKeyboardBrowserTest::GetBaseFrameWork() { |
+ return kBaseKeyboardTestFramework; |
+}; |
+ |
+content::RenderViewHost* |
+VirtualKeyboardBrowserTest::GetKeyboardRenderViewHost() { |
+ ShowVirtualKeyboard(); |
+ std::string kVirtualKeyboardURL = |
+ "chrome-extension://" + GetKeyboardExtensionId() + "/"; |
+ |
+ 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; |
} |
} |
- 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:" << kVirtualKeyboardURL; |
+ 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"); |
+} |
IN_PROC_BROWSER_TEST_F(VirtualKeyboardBrowserTest, AttributesTest) { |
RunTest(base::FilePath(FILE_PATH_LITERAL("attributes_test.js"))); |