File: local_surface_id_unittest.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (84 lines) | stat: -rw-r--r-- 3,907 bytes parent folder | download | duplicates (5)
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
// 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 "components/viz/common/surfaces/local_surface_id.h"

#include "base/logging.h"
#include "testing/gtest/include/gtest/gtest.h"

// Verifying that Local_Surface_Id::ToString() prints its corresponding
// UnguessableToken as ABCD... if logging is not verbose and prints full
// 16-character token otherwise.
TEST(LocalSurfaceIdTest, VerifyToString) {
  const base::UnguessableToken token =
      base::UnguessableToken::CreateForTesting(0x111111, 0);
  const base::UnguessableToken big_token =
      base::UnguessableToken::CreateForTesting(0x123456789, 0xABCABCABC);
  const base::UnguessableToken small_token =
      base::UnguessableToken::CreateForTesting(0, 0x1);
  const viz::LocalSurfaceId local_surface_id(11, 22, token);
  const viz::LocalSurfaceId big_local_surface_id(11, 22, big_token);
  const viz::LocalSurfaceId small_local_surface_id(11, 22, small_token);

  const std::string verbose_expected =
      "LocalSurfaceId(11, 22, " + token.ToString() + ")";
  const std::string brief_expected =
      "LocalSurfaceId(11, 22, " + token.ToString().substr(0, 4) + "...)";

  const std::string big_verbose_expected =
      "LocalSurfaceId(11, 22, " + big_token.ToString() + ")";
  const std::string big_brief_expected =
      "LocalSurfaceId(11, 22, " + big_token.ToString().substr(0, 4) + "...)";

  const std::string small_verbose_expected =
      "LocalSurfaceId(11, 22, " + small_token.ToString() + ")";
  const std::string small_brief_expected =
      "LocalSurfaceId(11, 22, " + small_token.ToString().substr(0, 4) + "...)";

  int previous_log_lvl = logging::GetMinLogLevel();

  // TODO(crbug.com/405151792): Switching the logging level to verbose in the
  // test isn't working correctly on Chrome OS or Fuchsia. Fix logging and
  // enable again.
  if constexpr (!BUILDFLAG(IS_CHROMEOS) && !BUILDFLAG(IS_FUCHSIA)) {
    // When |g_min_log_level| is set to LOGGING_VERBOSE we expect verbose
    // versions of local_surface_id::ToString().
    logging::SetMinLogLevel(logging::LOGGING_VERBOSE);
    ASSERT_TRUE(VLOG_IS_ON(1));
    EXPECT_EQ(verbose_expected, local_surface_id.ToString());
    EXPECT_EQ(big_verbose_expected, big_local_surface_id.ToString());
    EXPECT_EQ(small_verbose_expected, small_local_surface_id.ToString());
  }

  // When |g_min_log_level| is set to LOGGING_INFO we expect less verbose
  // versions of local_surface_id::ToString().
  logging::SetMinLogLevel(logging::LOGGING_INFO);
  ASSERT_FALSE(VLOG_IS_ON(1));
  EXPECT_EQ(brief_expected, local_surface_id.ToString());
  EXPECT_EQ(big_brief_expected, big_local_surface_id.ToString());
  EXPECT_EQ(small_brief_expected, small_local_surface_id.ToString());

  logging::SetMinLogLevel(previous_log_lvl);
}

// Test that when two allocators have advanced different sequence numbers, that
// IsNewerThan gives prcedence to neither sequence. Instead reporting that
// neither is newer than the other.
TEST(LocalSurfaceIdTest, NewerThan) {
  const base::UnguessableToken token = base::UnguessableToken::Create();
  // Consider a base case of (6, 2). Here `id1` has only the child advancing.
  // While `id2` only the parent advanced.
  const viz::LocalSurfaceId id1(6, 3, token);
  const viz::LocalSurfaceId id2(8, 2, token);
  const viz::LocalSurfaceId id3(8, 3, token);
  // This represents both the parent and child sequence having been advanced in
  // parallel. We do not give precedence to either sequence, and such treat
  // neither as newer than the other.
  EXPECT_FALSE(id1.IsNewerThan(id2));
  EXPECT_FALSE(id2.IsNewerThan(id1));
  // This represents the merged LocalSurfaceId that would be submitted to Viz.
  // It would be newer than both of the separately advanced sequences.
  EXPECT_TRUE(id3.IsNewerThan(id1));
  EXPECT_TRUE(id3.IsNewerThan(id2));
}