Home | History | Annotate | Download | only in extensions
      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 "ash/shell.h"
      6 #include "base/files/file_path.h"
      7 #include "chrome/browser/chromeos/extensions/virtual_keyboard_browsertest.h"
      8 #include "chrome/browser/extensions/crx_installer.h"
      9 #include "chrome/browser/extensions/extension_service.h"
     10 #include "chrome/browser/extensions/extension_test_notification_observer.h"
     11 #include "chrome/browser/profiles/profile.h"
     12 #include "chrome/browser/ui/browser.h"
     13 #include "chrome/test/base/ui_test_utils.h"
     14 #include "chromeos/ime/extension_ime_util.h"
     15 #include "chromeos/ime/input_method_manager.h"
     16 #include "content/public/browser/render_view_host.h"
     17 #include "content/public/browser/site_instance.h"
     18 #include "content/public/browser/web_contents.h"
     19 #include "content/public/common/url_constants.h"
     20 #include "content/public/test/browser_test_utils.h"
     21 #include "extensions/common/constants.h"
     22 #include "extensions/common/extension.h"
     23 #include "extensions/common/file_util.h"
     24 #include "ui/aura/client/aura_constants.h"
     25 #include "ui/base/ime/input_method.h"
     26 
     27 namespace {
     28 
     29 const base::FilePath::CharType kExtensionName[] = "GoogleKeyboardInput-xkb.crx";
     30 
     31 const base::FilePath::CharType kInputViewTestDir[] =
     32     "chromeos/virtual_keyboard/inputview/";
     33 const base::FilePath::CharType kBaseKeyboardTestFramework[] = "test_base.js";
     34 
     35 const char kDefaultLayout[] = "us";
     36 const char kCompactLayout[] = "us.compact.qwerty";
     37 
     38 struct InputViewConfig : public VirtualKeyboardBrowserTestConfig {
     39   explicit InputViewConfig(std::string id, std::string layout) {
     40     base_framework_ = kBaseKeyboardTestFramework;
     41     extension_id_ = id;
     42     test_dir_ = kInputViewTestDir;
     43     url_ = std::string(extensions::kExtensionScheme) +
     44         url::kStandardSchemeSeparator + id + "/inputview.html?id=" +
     45         layout;
     46   }
     47 };
     48 
     49 }  // namespace
     50 
     51 class InputViewBrowserTest : public VirtualKeyboardBrowserTest {
     52  public:
     53   // Installs the IME Extension keyboard |kExtensionName|.
     54   std::string InstallIMEExtension() {
     55     // Loads extension.
     56     base::FilePath path = ui_test_utils::GetTestFilePath(
     57         base::FilePath(kInputViewTestDir), base::FilePath(kExtensionName));
     58     ExtensionService* service = browser()->profile()->GetExtensionService();
     59     scoped_refptr<extensions::CrxInstaller> installer =
     60         extensions::CrxInstaller::CreateSilent(service);
     61 
     62     ExtensionTestNotificationObserver observer(browser());
     63     observer.Watch(chrome::NOTIFICATION_CRX_INSTALLER_DONE,
     64                    content::Source<extensions::CrxInstaller>(installer.get()));
     65     installer->set_allow_silent_install(true);
     66     installer->set_creation_flags(extensions::Extension::FROM_WEBSTORE);
     67     installer->InstallCrx(path);
     68     // Wait for CRX to be installed.
     69     observer.Wait();
     70     std::string extensionId = installer->extension()->id();
     71     if (!service->GetExtensionById(extensionId, false))
     72       return "";
     73     return extensionId;
     74   }
     75 };
     76 
     77 // Disabled for leaking memory: http://crbug.com/380537
     78 IN_PROC_BROWSER_TEST_F(InputViewBrowserTest, DISABLED_TypingTest) {
     79   std::string id = InstallIMEExtension();
     80   ASSERT_FALSE(id.empty());
     81   RunTest(base::FilePath("typing_test.js"),
     82           InputViewConfig(id, kDefaultLayout));
     83 }
     84 
     85 // Disabled for leaking memory: http://crbug.com/380537
     86 IN_PROC_BROWSER_TEST_F(InputViewBrowserTest, DISABLED_CompactTypingTest) {
     87   std::string id = InstallIMEExtension();
     88   ASSERT_FALSE(id.empty());
     89   RunTest(base::FilePath("typing_test.js"),
     90           InputViewConfig(id, kCompactLayout));
     91 }
     92 
     93 // Disabled for leaking memory: http://crbug.com/380537
     94 IN_PROC_BROWSER_TEST_F(InputViewBrowserTest, DISABLED_KeysetTransitionTest) {
     95   std::string id = InstallIMEExtension();
     96   ASSERT_FALSE(id.empty());
     97   RunTest(base::FilePath("keyset_transition_test.js"),
     98           InputViewConfig(id, kDefaultLayout));
     99 }
    100 
    101 // Disabled for leaking memory: http://crbug.com/380537
    102 IN_PROC_BROWSER_TEST_F(InputViewBrowserTest,
    103                        DISABLED_CompactKeysetTransitionTest) {
    104   std::string id = InstallIMEExtension();
    105   ASSERT_FALSE(id.empty());
    106   RunTest(base::FilePath("keyset_transition_test.js"),
    107           InputViewConfig(id, kCompactLayout));
    108 }
    109