| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/virtual_keyboard_selector.h" | 5 #include "chrome/browser/chromeos/input_method/virtual_keyboard_selector.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 // For EXPECT_TRUE calls below. The operator has to be in the global namespace. | 10 // For EXPECT_TRUE calls below. The operator has to be in the global namespace. |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 EXPECT_FALSE(selector.SetUserPreference("a", GURL("http://bad_url"))); | 393 EXPECT_FALSE(selector.SetUserPreference("a", GURL("http://bad_url"))); |
| 394 EXPECT_EQ(0U, selector.user_preference().size()); | 394 EXPECT_EQ(0U, selector.user_preference().size()); |
| 395 EXPECT_TRUE(selector.SetUserPreference("a", GURL("http://system"))); | 395 EXPECT_TRUE(selector.SetUserPreference("a", GURL("http://system"))); |
| 396 EXPECT_EQ(1U, selector.user_preference().size()); | 396 EXPECT_EQ(1U, selector.user_preference().size()); |
| 397 EXPECT_TRUE(selector.SetUserPreference("b", GURL("http://system"))); | 397 EXPECT_TRUE(selector.SetUserPreference("b", GURL("http://system"))); |
| 398 EXPECT_EQ(2U, selector.user_preference().size()); | 398 EXPECT_EQ(2U, selector.user_preference().size()); |
| 399 EXPECT_TRUE(selector.SetUserPreference("c", GURL("http://system"))); | 399 EXPECT_TRUE(selector.SetUserPreference("c", GURL("http://system"))); |
| 400 EXPECT_EQ(3U, selector.user_preference().size()); | 400 EXPECT_EQ(3U, selector.user_preference().size()); |
| 401 } | 401 } |
| 402 | 402 |
| 403 TEST(VirtualKeyboardSelectorTest, TestRemoveUserPreference) { |
| 404 static const char* layouts[] = { "a", "b", "c" }; |
| 405 |
| 406 VirtualKeyboard user_virtual_keyboard_1( |
| 407 GURL("http://user1"), CreateLayoutSet(layouts), false /* is_system */); |
| 408 VirtualKeyboard user_virtual_keyboard_2( |
| 409 GURL("http://user2"), CreateLayoutSet(layouts), false /* is_system */); |
| 410 |
| 411 TestableVirtualKeyboardSelector selector; |
| 412 EXPECT_TRUE(selector.AddVirtualKeyboard( |
| 413 user_virtual_keyboard_1.url(), |
| 414 user_virtual_keyboard_1.supported_layouts(), |
| 415 user_virtual_keyboard_1.is_system())); |
| 416 EXPECT_TRUE(selector.AddVirtualKeyboard( |
| 417 user_virtual_keyboard_2.url(), |
| 418 user_virtual_keyboard_2.supported_layouts(), |
| 419 user_virtual_keyboard_2.is_system())); |
| 420 |
| 421 EXPECT_TRUE(selector.SetUserPreference("a", GURL("http://user1"))); |
| 422 EXPECT_TRUE(selector.SetUserPreference("b", GURL("http://user1"))); |
| 423 EXPECT_TRUE(selector.SetUserPreference("c", GURL("http://user1"))); |
| 424 EXPECT_EQ(3U, selector.user_preference().size()); |
| 425 |
| 426 selector.RemoveUserPreference("b"); |
| 427 EXPECT_EQ(2U, selector.user_preference().size()); |
| 428 ASSERT_TRUE(selector.SelectVirtualKeyboardWithoutPreferences("b")); |
| 429 // user_virtual_keyboard_2 should be selected here since the keyboard is |
| 430 // added most recently and the user preference on "b" is already removed. |
| 431 EXPECT_TRUE(user_virtual_keyboard_2 == *selector.SelectVirtualKeyboard("b")); |
| 432 |
| 433 selector.ClearAllUserPreferences(); |
| 434 EXPECT_EQ(0U, selector.user_preference().size()); |
| 435 } |
| 436 |
| 403 TEST(VirtualKeyboardSelectorTest, TestSetUserPreferenceUserSystemMixed) { | 437 TEST(VirtualKeyboardSelectorTest, TestSetUserPreferenceUserSystemMixed) { |
| 404 static const char* ulayouts_1[] = { "a", "b", "c" }; | 438 static const char* ulayouts_1[] = { "a", "b", "c" }; |
| 405 static const char* ulayouts_2[] = { "a", "c", "d" }; | 439 static const char* ulayouts_2[] = { "a", "c", "d" }; |
| 406 static const char* layouts_1[] = { "a", "x", "y" }; | 440 static const char* layouts_1[] = { "a", "x", "y" }; |
| 407 static const char* layouts_2[] = { "a", "y", "z" }; | 441 static const char* layouts_2[] = { "a", "y", "z" }; |
| 408 | 442 |
| 409 VirtualKeyboard user_virtual_keyboard_1( | 443 VirtualKeyboard user_virtual_keyboard_1( |
| 410 GURL("http://user1"), CreateLayoutSet(ulayouts_1), false /* is_system */); | 444 GURL("http://user1"), CreateLayoutSet(ulayouts_1), false /* is_system */); |
| 411 VirtualKeyboard user_virtual_keyboard_2( | 445 VirtualKeyboard user_virtual_keyboard_2( |
| 412 GURL("http://user2"), CreateLayoutSet(ulayouts_2), false /* is_system */); | 446 GURL("http://user2"), CreateLayoutSet(ulayouts_2), false /* is_system */); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 426 user_virtual_keyboard_2.is_system())); | 460 user_virtual_keyboard_2.is_system())); |
| 427 EXPECT_TRUE(selector.AddVirtualKeyboard( | 461 EXPECT_TRUE(selector.AddVirtualKeyboard( |
| 428 system_virtual_keyboard_1.url(), | 462 system_virtual_keyboard_1.url(), |
| 429 system_virtual_keyboard_1.supported_layouts(), | 463 system_virtual_keyboard_1.supported_layouts(), |
| 430 system_virtual_keyboard_1.is_system())); | 464 system_virtual_keyboard_1.is_system())); |
| 431 EXPECT_TRUE(selector.AddVirtualKeyboard( | 465 EXPECT_TRUE(selector.AddVirtualKeyboard( |
| 432 system_virtual_keyboard_2.url(), | 466 system_virtual_keyboard_2.url(), |
| 433 system_virtual_keyboard_2.supported_layouts(), | 467 system_virtual_keyboard_2.supported_layouts(), |
| 434 system_virtual_keyboard_2.is_system())); | 468 system_virtual_keyboard_2.is_system())); |
| 435 | 469 |
| 436 // Set and then remove user pref (=NOP). | 470 // Set and then remove user prefs (=NOP). |
| 437 EXPECT_TRUE(selector.SetUserPreference("a", GURL("http://system1"))); | 471 EXPECT_TRUE(selector.SetUserPreference("a", GURL("http://system1"))); |
| 438 selector.RemoveUserPreference("a"); | 472 EXPECT_TRUE(selector.SetUserPreference("z", GURL("http://system2"))); |
| 473 selector.ClearAllUserPreferences(); |
| 439 | 474 |
| 440 // At this point, user_virtual_keyboard_2 has the highest priority. | 475 // At this point, user_virtual_keyboard_2 has the highest priority. |
| 441 ASSERT_TRUE(selector.SelectVirtualKeyboardWithoutPreferences("a")); | 476 ASSERT_TRUE(selector.SelectVirtualKeyboardWithoutPreferences("a")); |
| 442 EXPECT_TRUE(user_virtual_keyboard_2 == | 477 EXPECT_TRUE(user_virtual_keyboard_2 == |
| 443 *selector.SelectVirtualKeyboard("a")); | 478 *selector.SelectVirtualKeyboard("a")); |
| 444 ASSERT_TRUE(selector.SelectVirtualKeyboardWithoutPreferences("c")); | 479 ASSERT_TRUE(selector.SelectVirtualKeyboardWithoutPreferences("c")); |
| 445 EXPECT_TRUE(user_virtual_keyboard_2 == | 480 EXPECT_TRUE(user_virtual_keyboard_2 == |
| 446 *selector.SelectVirtualKeyboard("c")); | 481 *selector.SelectVirtualKeyboard("c")); |
| 447 ASSERT_TRUE(selector.SelectVirtualKeyboardWithoutPreferences("d")); | 482 ASSERT_TRUE(selector.SelectVirtualKeyboardWithoutPreferences("d")); |
| 448 EXPECT_TRUE(user_virtual_keyboard_2 == | 483 EXPECT_TRUE(user_virtual_keyboard_2 == |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 *selector.SelectVirtualKeyboard("a")); | 537 *selector.SelectVirtualKeyboard("a")); |
| 503 | 538 |
| 504 // Switch back to user_virtual_keyboard_1. | 539 // Switch back to user_virtual_keyboard_1. |
| 505 ASSERT_TRUE(selector.SelectVirtualKeyboardWithoutPreferences("c")); | 540 ASSERT_TRUE(selector.SelectVirtualKeyboardWithoutPreferences("c")); |
| 506 EXPECT_TRUE(user_virtual_keyboard_2 == | 541 EXPECT_TRUE(user_virtual_keyboard_2 == |
| 507 *selector.SelectVirtualKeyboard("c")); | 542 *selector.SelectVirtualKeyboard("c")); |
| 508 } | 543 } |
| 509 | 544 |
| 510 } // namespace input_method | 545 } // namespace input_method |
| 511 } // namespace chromeos | 546 } // namespace chromeos |
| OLD | NEW |