[omnibox] Add Pedal provider unit test to load and trigger every locale

To aid in smoke testing Pedal concept matching data for all the new
languages, a unit test is added that ensures each locale's data set
can be loaded and used.

Bug: 893183
Change-Id: Ic4686e5cf85dd0f1734fa1a2129f9b4ac3c72da7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2337107
Commit-Queue: Orin Jaworski <[email protected]>
Reviewed-by: Tommy Li <[email protected]>
Cr-Commit-Position: refs/heads/master@{#796475}
diff --git a/chrome/browser/ui/omnibox/omnibox_pedals_unittest.cc b/chrome/browser/ui/omnibox/omnibox_pedals_unittest.cc
new file mode 100644
index 0000000..9924b96
--- /dev/null
+++ b/chrome/browser/ui/omnibox/omnibox_pedals_unittest.cc
@@ -0,0 +1,45 @@
+// Copyright 2020 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/environment.h"
+#include "base/strings/utf_string_conversions.h"
+#include "components/omnibox/browser/mock_autocomplete_provider_client.h"
+#include "components/omnibox/browser/omnibox_pedal_provider.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/base/resource/resource_bundle.h"
+
+// Note: Pedals have their own components unit tests, which should be
+// the preferred place for testing the classes. The tests here are for
+// testing things that depend on Chrome resources, for example the localization
+// pak files generated by chrome:packed_resources.
+
+TEST(OmniboxPedals, DataLoadsForAllLocales) {
+  // Locale selection is platform sensitive. On Linux, environment is used.
+  std::unique_ptr<base::Environment> env = base::Environment::Create();
+  MockAutocompleteProviderClient client;
+
+  struct TestCase {
+    std::string locale;
+    std::string trigger;
+  };
+  const TestCase test_cases[] = {
+      {"de", "leeren cache"},        {"en", "clear history"},
+      {"fr", "supprime historique"}, {"ja", "消す 履歴"},
+      {"zh-CN", "清除 数据"},
+  };
+  for (const TestCase& test_case : test_cases) {
+    // Prepare the shared ResourceBundle with data for tested locale.
+    env->SetVar("LANG", test_case.locale);
+    ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources(
+        test_case.locale);
+
+    // Instantiating the provider loads concept data from shared ResourceBundle.
+    OmniboxPedalProvider provider(client);
+
+    EXPECT_EQ(provider.FindPedalMatch(base::UTF8ToUTF16("")), nullptr);
+    EXPECT_NE(provider.FindPedalMatch(base::UTF8ToUTF16(test_case.trigger)),
+              nullptr)
+        << "locale: " << test_case.locale;
+  }
+}