Orin Jaworski | 231af1e | 2020-08-10 18:33:03 | [diff] [blame] | 1 | // Copyright 2020 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 "base/environment.h" |
| 6 | #include "base/strings/utf_string_conversions.h" |
| 7 | #include "components/omnibox/browser/mock_autocomplete_provider_client.h" |
| 8 | #include "components/omnibox/browser/omnibox_pedal_provider.h" |
| 9 | #include "testing/gtest/include/gtest/gtest.h" |
| 10 | #include "ui/base/resource/resource_bundle.h" |
| 11 | |
| 12 | // Note: Pedals have their own components unit tests, which should be |
| 13 | // the preferred place for testing the classes. The tests here are for |
| 14 | // testing things that depend on Chrome resources, for example the localization |
| 15 | // pak files generated by chrome:packed_resources. |
| 16 | |
| 17 | TEST(OmniboxPedals, DataLoadsForAllLocales) { |
| 18 | // Locale selection is platform sensitive. On Linux, environment is used. |
| 19 | std::unique_ptr<base::Environment> env = base::Environment::Create(); |
| 20 | MockAutocompleteProviderClient client; |
| 21 | |
| 22 | struct TestCase { |
| 23 | std::string locale; |
| 24 | std::string trigger; |
| 25 | }; |
| 26 | const TestCase test_cases[] = { |
| 27 | {"de", "leeren cache"}, {"en", "clear history"}, |
| 28 | {"fr", "supprime historique"}, {"ja", "消す 履歴"}, |
| 29 | {"zh-CN", "清除 数据"}, |
| 30 | }; |
| 31 | for (const TestCase& test_case : test_cases) { |
| 32 | // Prepare the shared ResourceBundle with data for tested locale. |
| 33 | env->SetVar("LANG", test_case.locale); |
| 34 | ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources( |
| 35 | test_case.locale); |
| 36 | |
| 37 | // Instantiating the provider loads concept data from shared ResourceBundle. |
| 38 | OmniboxPedalProvider provider(client); |
| 39 | |
| 40 | EXPECT_EQ(provider.FindPedalMatch(base::UTF8ToUTF16("")), nullptr); |
| 41 | EXPECT_NE(provider.FindPedalMatch(base::UTF8ToUTF16(test_case.trigger)), |
| 42 | nullptr) |
| 43 | << "locale: " << test_case.locale; |
| 44 | } |
| 45 | } |