File: multidevice_mojom_traits_unittest.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (120 lines) | stat: -rw-r--r-- 5,327 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chromeos/ash/components/multidevice/mojom/multidevice_mojom_traits.h"

#include "base/time/time.h"
#include "chromeos/ash/components/multidevice/beacon_seed.h"
#include "chromeos/ash/components/multidevice/mojom/multidevice_types.mojom.h"
#include "chromeos/ash/components/multidevice/remote_device.h"
#include "mojo/public/cpp/base/time_mojom_traits.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace {

const char kTestBeaconSeedData[] = "data";
const int64_t kTestBeaconSeedStartTimeMillis = 1L;
const int64_t kTestBeaconSeedEndTimeMillis = 2L;

ash::multidevice::BeaconSeed CreateTestBeaconSeed() {
  return ash::multidevice::BeaconSeed(
      kTestBeaconSeedData,
      base::Time::FromMillisecondsSinceUnixEpoch(
          kTestBeaconSeedStartTimeMillis),
      base::Time::FromMillisecondsSinceUnixEpoch(kTestBeaconSeedEndTimeMillis));
}

}  // namespace

TEST(MultiDeviceMojomStructTraitsTest, BeaconSeed) {
  ash::multidevice::BeaconSeed input = CreateTestBeaconSeed();

  ash::multidevice::BeaconSeed output;
  EXPECT_TRUE(
      mojo::test::SerializeAndDeserialize<ash::multidevice::mojom::BeaconSeed>(
          input, output));

  EXPECT_EQ(kTestBeaconSeedData, output.data());
  EXPECT_EQ(kTestBeaconSeedStartTimeMillis,
            output.start_time().InMillisecondsSinceUnixEpoch());
  EXPECT_EQ(kTestBeaconSeedEndTimeMillis,
            output.end_time().InMillisecondsSinceUnixEpoch());
}

TEST(MultiDeviceMojomStructTraitsTest, RemoteDevice) {
  std::map<ash::multidevice::SoftwareFeature,
           ash::multidevice::SoftwareFeatureState>
      software_features = std::map<ash::multidevice::SoftwareFeature,
                                   ash::multidevice::SoftwareFeatureState>();
  software_features[ash::multidevice::SoftwareFeature::kBetterTogetherClient] =
      ash::multidevice::SoftwareFeatureState::kSupported;
  software_features[ash::multidevice::SoftwareFeature::kBetterTogetherHost] =
      ash::multidevice::SoftwareFeatureState::kEnabled;

  ash::multidevice::RemoteDevice input;
  input.user_email = "userEmail";
  input.instance_id = "instanceId";
  input.name = "name";
  input.pii_free_name = "piiFreeName";
  input.public_key = "publicKey";
  input.persistent_symmetric_key = "persistentSymmetricKey";
  input.last_update_time_millis = 3L;
  input.software_features = software_features;
  input.beacon_seeds = {CreateTestBeaconSeed()};
  input.bluetooth_public_address = "01:23:45:67:89:AB";

  ash::multidevice::RemoteDevice output;
  EXPECT_TRUE(mojo::test::SerializeAndDeserialize<
              ash::multidevice::mojom::RemoteDevice>(input, output));

  EXPECT_EQ("userEmail", output.user_email);
  EXPECT_EQ("instanceId", output.instance_id);
  EXPECT_EQ("name", output.name);
  EXPECT_EQ("piiFreeName", output.pii_free_name);
  EXPECT_EQ("publicKey", output.public_key);
  EXPECT_EQ("persistentSymmetricKey", output.persistent_symmetric_key);
  EXPECT_EQ(3L, output.last_update_time_millis);
  EXPECT_EQ(software_features, output.software_features);
  ASSERT_EQ(1u, output.beacon_seeds.size());
  EXPECT_EQ(kTestBeaconSeedData, output.beacon_seeds[0].data());
  EXPECT_EQ(kTestBeaconSeedStartTimeMillis,
            output.beacon_seeds[0].start_time().InMillisecondsSinceUnixEpoch());
  EXPECT_EQ(kTestBeaconSeedEndTimeMillis,
            output.beacon_seeds[0].end_time().InMillisecondsSinceUnixEpoch());
  EXPECT_EQ("01:23:45:67:89:AB", output.bluetooth_public_address);
}

TEST(DeviceSyncMojomEnumTraitsTest, SoftwareFeature) {
  static constexpr ash::multidevice::SoftwareFeature kTestSoftwareFeatures[] = {
      ash::multidevice::SoftwareFeature::kBetterTogetherHost,
      ash::multidevice::SoftwareFeature::kBetterTogetherClient,
      ash::multidevice::SoftwareFeature::kSmartLockHost,
      ash::multidevice::SoftwareFeature::kSmartLockClient,
      ash::multidevice::SoftwareFeature::kInstantTetheringHost,
      ash::multidevice::SoftwareFeature::kInstantTetheringClient,
      ash::multidevice::SoftwareFeature::kMessagesForWebHost,
      ash::multidevice::SoftwareFeature::kMessagesForWebClient,
      ash::multidevice::SoftwareFeature::kPhoneHubHost,
      ash::multidevice::SoftwareFeature::kPhoneHubClient,
      ash::multidevice::SoftwareFeature::kWifiSyncHost,
      ash::multidevice::SoftwareFeature::kWifiSyncClient,
      ash::multidevice::SoftwareFeature::kEcheHost,
      ash::multidevice::SoftwareFeature::kEcheClient,
      ash::multidevice::SoftwareFeature::kPhoneHubCameraRollHost,
      ash::multidevice::SoftwareFeature::kPhoneHubCameraRollClient};

  for (auto feature_in : kTestSoftwareFeatures) {
    ash::multidevice::SoftwareFeature feature_out;

    ash::multidevice::mojom::SoftwareFeature serialized_feature =
        mojo::EnumTraits<
            ash::multidevice::mojom::SoftwareFeature,
            ash::multidevice::SoftwareFeature>::ToMojom(feature_in);
    ASSERT_TRUE((mojo::EnumTraits<ash::multidevice::mojom::SoftwareFeature,
                                  ash::multidevice::SoftwareFeature>::
                     FromMojom(serialized_feature, &feature_out)));
    EXPECT_EQ(feature_in, feature_out);
  }
}