Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: chrome/browser/chromeos/input_method/input_method_manager_impl_unittest.cc

Issue 2652793003: Add login screen locale and input method device policies (Closed)
Patch Set: Rebase. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h" 5 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
19 #include "base/run_loop.h" 19 #include "base/run_loop.h"
20 #include "chrome/browser/chromeos/input_method/mock_candidate_window_controller. h" 20 #include "chrome/browser/chromeos/input_method/mock_candidate_window_controller. h"
21 #include "chrome/browser/chromeos/input_method/mock_input_method_engine.h" 21 #include "chrome/browser/chromeos/input_method/mock_input_method_engine.h"
22 #include "chrome/browser/profiles/profile_manager.h" 22 #include "chrome/browser/profiles/profile_manager.h"
23 #include "chrome/test/base/browser_with_test_window_test.h" 23 #include "chrome/test/base/browser_with_test_window_test.h"
24 #include "chrome/test/base/testing_browser_process.h" 24 #include "chrome/test/base/testing_browser_process.h"
25 #include "chrome/test/base/testing_profile.h" 25 #include "chrome/test/base/testing_profile.h"
26 #include "chrome/test/base/testing_profile_manager.h" 26 #include "chrome/test/base/testing_profile_manager.h"
27 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/base/accelerators/accelerator.h" 29 #include "ui/base/accelerators/accelerator.h"
29 #include "ui/base/ime/chromeos/extension_ime_util.h" 30 #include "ui/base/ime/chromeos/extension_ime_util.h"
30 #include "ui/base/ime/chromeos/fake_ime_keyboard.h" 31 #include "ui/base/ime/chromeos/fake_ime_keyboard.h"
31 #include "ui/base/ime/chromeos/fake_input_method_delegate.h" 32 #include "ui/base/ime/chromeos/fake_input_method_delegate.h"
32 #include "ui/base/ime/chromeos/mock_component_extension_ime_manager_delegate.h" 33 #include "ui/base/ime/chromeos/mock_component_extension_ime_manager_delegate.h"
33 #include "ui/base/ime/chromeos/mock_ime_engine_handler.h" 34 #include "ui/base/ime/chromeos/mock_ime_engine_handler.h"
34 #include "ui/base/ime/ime_bridge.h" 35 #include "ui/base/ime/ime_bridge.h"
35 #include "ui/base/ime/input_method_initializer.h" 36 #include "ui/base/ime/input_method_initializer.h"
36 #include "ui/chromeos/ime/input_method_menu_item.h" 37 #include "ui/chromeos/ime/input_method_menu_item.h"
(...skipping 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 TEST_F(InputMethodManagerImplTest, OverrideDefaultKeyboardUrlRef) { 1449 TEST_F(InputMethodManagerImplTest, OverrideDefaultKeyboardUrlRef) {
1449 const GURL default_url("chrome://inputview.html"); 1450 const GURL default_url("chrome://inputview.html");
1450 keyboard::SetOverrideContentUrl(default_url); 1451 keyboard::SetOverrideContentUrl(default_url);
1451 1452
1452 EXPECT_EQ(default_url, keyboard::GetOverrideContentUrl()); 1453 EXPECT_EQ(default_url, keyboard::GetOverrideContentUrl());
1453 1454
1454 manager_->OverrideKeyboardUrlRef("emoji"); 1455 manager_->OverrideKeyboardUrlRef("emoji");
1455 EXPECT_EQ(default_url, keyboard::GetOverrideContentUrl()); 1456 EXPECT_EQ(default_url, keyboard::GetOverrideContentUrl());
1456 } 1457 }
1457 1458
1459 TEST_F(InputMethodManagerImplTest, AllowedKeyboardLayoutsValid) {
1460 InitComponentExtension();
1461
1462 // First, setup xkb:fr::fra input method
1463 std::string original_input_method(ImeIdFromEngineId("xkb:fr::fra"));
1464 ASSERT_TRUE(
1465 manager_->GetActiveIMEState()->EnableInputMethod(original_input_method));
1466 manager_->GetActiveIMEState()->ChangeInputMethod(original_input_method,
1467 false);
1468 EXPECT_THAT(manager_->GetActiveIMEState()->GetCurrentInputMethod().id(),
1469 original_input_method);
1470
1471 // Only allow xkb:us::eng
1472 std::vector<std::string> allowed = {"xkb:us::eng"};
1473 EXPECT_TRUE(manager_->GetActiveIMEState()->SetAllowedInputMethods(allowed));
1474 EXPECT_THAT(manager_->GetActiveIMEState()->GetActiveInputMethodIds(),
1475 testing::ElementsAre(ImeIdFromEngineId("xkb:us::eng")));
1476 EXPECT_THAT(manager_->GetActiveIMEState()->GetCurrentInputMethod().id(),
1477 ImeIdFromEngineId("xkb:us::eng"));
1478 EXPECT_THAT(manager_->GetActiveIMEState()->GetAllowedInputMethods(),
1479 testing::ElementsAre(ImeIdFromEngineId("xkb:us::eng")));
1480 }
1481
1482 TEST_F(InputMethodManagerImplTest, AllowedKeyboardLayoutsInvalid) {
1483 InitComponentExtension();
1484
1485 // First, setup xkb:fr::fra input method
1486 std::string original_input_method(ImeIdFromEngineId("xkb:fr::fra"));
1487 ASSERT_TRUE(
1488 manager_->GetActiveIMEState()->EnableInputMethod(original_input_method));
1489 manager_->GetActiveIMEState()->ChangeInputMethod(original_input_method,
1490 false);
1491 EXPECT_THAT(manager_->GetActiveIMEState()->GetCurrentInputMethod().id(),
1492 original_input_method);
1493
1494 // Only allow xkb:us::eng
1495 std::vector<std::string> allowed = {"invalid_input_method"};
1496 EXPECT_FALSE(manager_->GetActiveIMEState()->SetAllowedInputMethods(allowed));
1497 EXPECT_THAT(manager_->GetActiveIMEState()->GetCurrentInputMethod().id(),
1498 original_input_method);
1499 EXPECT_THAT(manager_->GetActiveIMEState()->GetAllowedInputMethods(),
1500 testing::IsEmpty());
1501 }
1502
1503 TEST_F(InputMethodManagerImplTest, AllowedKeyboardLayoutsValidAndInvalid) {
1504 InitComponentExtension();
1505
1506 // First, enable xkb:fr::fra and xkb:de::ger
1507 std::string original_input_method_1(ImeIdFromEngineId("xkb:fr::fra"));
1508 std::string original_input_method_2(ImeIdFromEngineId("xkb:de::ger"));
1509 ASSERT_TRUE(manager_->GetActiveIMEState()->EnableInputMethod(
1510 original_input_method_1));
1511 ASSERT_TRUE(manager_->GetActiveIMEState()->EnableInputMethod(
1512 original_input_method_2));
1513 manager_->GetActiveIMEState()->ChangeInputMethod(original_input_method_1,
1514 false);
1515
1516 // Allow xkb:fr::fra and an invalid input method id. The invalid id should be
1517 // ignored.
1518 std::vector<std::string> allowed = {original_input_method_1,
1519 "invalid_input_method"};
1520 EXPECT_TRUE(manager_->GetActiveIMEState()->SetAllowedInputMethods(allowed));
1521 EXPECT_THAT(manager_->GetActiveIMEState()->GetCurrentInputMethod().id(),
1522 original_input_method_1);
1523 EXPECT_THAT(manager_->GetActiveIMEState()->GetAllowedInputMethods(),
1524 testing::ElementsAre(original_input_method_1));
1525
1526 // Try to re-enable xkb:de::ger
1527 EXPECT_FALSE(manager_->GetActiveIMEState()->EnableInputMethod(
1528 original_input_method_2));
1529 }
1530
1531 TEST_F(InputMethodManagerImplTest, AllowedKeyboardLayoutsAndExtensions) {
1532 InitComponentExtension();
1533
1534 EXPECT_TRUE(manager_->GetActiveIMEState()->EnableInputMethod(
1535 ImeIdFromEngineId(kNaclMozcJpId)));
1536 EXPECT_TRUE(manager_->GetActiveIMEState()->EnableInputMethod(
1537 ImeIdFromEngineId("xkb:fr::fra")));
1538
1539 std::vector<std::string> allowed = {"xkb:us::eng"};
1540 EXPECT_TRUE(manager_->GetActiveIMEState()->SetAllowedInputMethods(allowed));
1541
1542 EXPECT_TRUE(manager_->GetActiveIMEState()->EnableInputMethod(
1543 ImeIdFromEngineId(kNaclMozcUsId)));
1544 EXPECT_THAT(manager_->GetActiveIMEState()->GetActiveInputMethodIds(),
1545 testing::ElementsAre(ImeIdFromEngineId("xkb:us::eng"),
1546 ImeIdFromEngineId(kNaclMozcJpId),
1547 ImeIdFromEngineId(kNaclMozcUsId)));
1548 }
1549
1458 } // namespace input_method 1550 } // namespace input_method
1459 } // namespace chromeos 1551 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698