Commit c66038fc authored by Clemens Arbesser's avatar Clemens Arbesser Committed by Commit Bot

[Autofill Assistant] Added missing unit tests for new service deps.

Bug: b/158998456
Change-Id: Ib580385e201a1b68967dcace71af8cd8f2ed58e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2450309
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Reviewed-by: default avatarSandro Maggi <sandromaggi@google.com>
Cr-Commit-Position: refs/heads/master@{#814184}
parent 085179d0
......@@ -302,8 +302,10 @@ source_set("unit_tests") {
"script_precondition_unittest.cc",
"script_tracker_unittest.cc",
"selector_unittest.cc",
"service/api_key_fetcher_unittest.cc",
"service/lite_service_unittest.cc",
"service/lite_service_util_unittest.cc",
"service/server_url_fetcher_unittest.cc",
"string_conversions_util_unittest.cc",
"test_util.cc",
"test_util.h",
......
// 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 "components/autofill_assistant/browser/service/api_key_fetcher.h"
#include "base/command_line.h"
#include "components/autofill_assistant/browser/switches.h"
#include "components/version_info/version_info.h"
#include "google_apis/google_api_keys.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace autofill_assistant {
namespace {
using ::testing::Eq;
TEST(ApiKeyFetcherTest, GetAPIKeyCommandLineOverride) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kAutofillAssistantServerKey, "fake_key");
EXPECT_THAT(ApiKeyFetcher().GetAPIKey(version_info::Channel::STABLE),
Eq("fake_key"));
EXPECT_THAT(ApiKeyFetcher().GetAPIKey(version_info::Channel::UNKNOWN),
Eq("fake_key"));
EXPECT_THAT(ApiKeyFetcher().GetAPIKey(version_info::Channel::CANARY),
Eq("fake_key"));
EXPECT_THAT(ApiKeyFetcher().GetAPIKey(version_info::Channel::DEV),
Eq("fake_key"));
EXPECT_THAT(ApiKeyFetcher().GetAPIKey(version_info::Channel::BETA),
Eq("fake_key"));
}
TEST(ApiKeyFetcherTest, GetAPIKeyReturnsStableAndNonstableKeys) {
base::CommandLine::ForCurrentProcess()->RemoveSwitch(
switches::kAutofillAssistantServerKey);
// Only run tests on Google Chrome builds. This intentionally does not gate
// the test with a precompiler definition, because a change to
// |IsGoogleChromeAPIKeyUsed| would go unnoticed by us.
if (!google_apis::IsGoogleChromeAPIKeyUsed()) {
return;
}
std::string api_key_stable = google_apis::GetAPIKey();
std::string api_key_nonstable = google_apis::GetNonStableAPIKey();
EXPECT_THAT(ApiKeyFetcher().GetAPIKey(version_info::Channel::STABLE),
Eq(api_key_stable));
EXPECT_THAT(ApiKeyFetcher().GetAPIKey(version_info::Channel::UNKNOWN),
Eq(api_key_nonstable));
EXPECT_THAT(ApiKeyFetcher().GetAPIKey(version_info::Channel::CANARY),
Eq(api_key_nonstable));
EXPECT_THAT(ApiKeyFetcher().GetAPIKey(version_info::Channel::DEV),
Eq(api_key_nonstable));
EXPECT_THAT(ApiKeyFetcher().GetAPIKey(version_info::Channel::BETA),
Eq(api_key_nonstable));
}
} // namespace
} // namespace autofill_assistant
// 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 "components/autofill_assistant/browser/service/server_url_fetcher.h"
#include "base/command_line.h"
#include "components/autofill_assistant/browser/switches.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace autofill_assistant {
namespace {
using ::testing::Eq;
TEST(ServerUrlFetcherTest, GetDefaultServerUrl) {
base::CommandLine::ForCurrentProcess()->RemoveSwitch(
switches::kAutofillAssistantUrl);
EXPECT_THAT(ServerUrlFetcher::GetDefaultServerUrl(),
Eq(GURL("https://automate-pa.googleapis.com")));
}
TEST(ServerUrlFetcherTest, GetDefaultServerUrlCommandLineOverride) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kAutofillAssistantUrl, "https://www.example.com");
EXPECT_THAT(ServerUrlFetcher::GetDefaultServerUrl(),
Eq(GURL("https://www.example.com")));
}
TEST(ServerUrlFetcherTest, GetScriptsEndpoint) {
EXPECT_THAT(
ServerUrlFetcher(GURL("https://www.example.com")).GetScriptsEndpoint(),
Eq(GURL("https://www.example.com/v1/supportsSite2")));
}
TEST(ServerUrlFetcherTest, GetActionsEndpoint) {
EXPECT_THAT(
ServerUrlFetcher(GURL("https://www.example.com")).GetActionsEndpoint(),
Eq(GURL("https://www.example.com/v1/actions2")));
}
} // namespace
} // namespace autofill_assistant
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment