blob: 68c4c2719f716afe006cd95ed139d8a2d9e1d364 [file] [log] [blame]
Orin Jaworski231af1e2020-08-10 18:33:031// 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
17TEST(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[] = {
Orin Jaworskid495bef2020-08-14 22:44:3527 // clang-format off
28 {"am", "ሰርዝ ታሪክ"},
29 {"de", "leeren cache"},
30 {"en", "clear history"},
31 {"fr", "supprime historique"},
32 {"ja", "消す 履歴"},
Orin Jaworski231af1e2020-08-10 18:33:0333 {"zh-CN", "清除 数据"},
Orin Jaworskid495bef2020-08-14 22:44:3534 // clang-format on
Orin Jaworski231af1e2020-08-10 18:33:0335 };
36 for (const TestCase& test_case : test_cases) {
37 // Prepare the shared ResourceBundle with data for tested locale.
38 env->SetVar("LANG", test_case.locale);
39 ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources(
40 test_case.locale);
41
42 // Instantiating the provider loads concept data from shared ResourceBundle.
43 OmniboxPedalProvider provider(client);
44
45 EXPECT_EQ(provider.FindPedalMatch(base::UTF8ToUTF16("")), nullptr);
Orin Jaworskid495bef2020-08-14 22:44:3546#if defined(OS_CHROMEOS)
47 // TODO(orinj): Get ChromeOS to use the right dataset, but for now make this
48 // a soft failure so as to not block all other platforms. To ensure this
49 // is not going to cause failure in production, still test that English
50 // triggering functions. Data is there; it works; but warn about locale.
51 if (!provider.FindPedalMatch(base::UTF8ToUTF16(test_case.trigger))) {
52 EXPECT_NE(provider.FindPedalMatch(base::UTF8ToUTF16("clear history")),
53 nullptr);
54 LOG(WARNING) << "ChromeOS using English for locale " << test_case.locale;
55 continue;
56 }
57#endif
Orin Jaworski231af1e2020-08-10 18:33:0358 EXPECT_NE(provider.FindPedalMatch(base::UTF8ToUTF16(test_case.trigger)),
59 nullptr)
60 << "locale: " << test_case.locale;
61 }
62}