auto_fetch_unittest.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2018 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. #include "components/offline_pages/core/auto_fetch.h"
  5. #include "components/offline_pages/core/client_namespace_constants.h"
  6. #include "testing/gtest/include/gtest/gtest.h"
  7. namespace offline_pages {
  8. namespace auto_fetch {
  9. namespace {
  10. TEST(AutoFetch, MakeClientId) {
  11. EXPECT_EQ(ClientId(kAutoAsyncNamespace, "A123"),
  12. auto_fetch::MakeClientId(auto_fetch::ClientIdMetadata(123)));
  13. }
  14. TEST(AutoFetch, ExtractMetadataSuccess) {
  15. absl::optional<auto_fetch::ClientIdMetadata> metadata =
  16. auto_fetch::ExtractMetadata(
  17. auto_fetch::MakeClientId(auto_fetch::ClientIdMetadata(123)));
  18. ASSERT_TRUE(metadata);
  19. EXPECT_EQ(123, metadata.value().android_tab_id);
  20. }
  21. TEST(AutoFetch, ExtractMetadataFail) {
  22. EXPECT_FALSE(
  23. auto_fetch::ExtractMetadata(ClientId(kAutoAsyncNamespace, "123")));
  24. EXPECT_FALSE(auto_fetch::ExtractMetadata(ClientId(kAutoAsyncNamespace, "")));
  25. EXPECT_FALSE(auto_fetch::ExtractMetadata(ClientId("other", "A123")));
  26. }
  27. } // namespace
  28. } // namespace auto_fetch
  29. } // namespace offline_pages