File: model_execution_live_test.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; 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,811; 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 (144 lines) | stat: -rw-r--r-- 5,534 bytes parent folder | download | duplicates (4)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service_factory.h"
#include "chrome/browser/signin/e2e_tests/account_capabilities_observer.h"
#include "chrome/browser/signin/e2e_tests/live_test.h"
#include "chrome/browser/signin/e2e_tests/signin_util.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/optimization_guide/core/model_execution/model_execution_features.h"
#include "components/optimization_guide/core/optimization_guide_features.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"

namespace optimization_guide {

// Manual live tests that sign-in and check model execution state.
//
// Developers can run the tests as follows:
// 1. Enable the tests by changing the "#if 0" below to "#if 1"
// 2. browser_tests --gtest_filter=ModelExecutionLiveTest.* --run-live-tests
//
// The whole code is disabled because the tests cannot be tagged as MANUAL_
// tests, since they are also using the PRE_ browser test feature. The browser
// tests currently do not support both the wasy - PRE_ and MANUAL_. So the tests
// are just written to use PRE_, and commented out.
#if 0
class ModelExecutionLiveTest : public signin::test::LiveTest {
 public:
  ModelExecutionLiveTest() = default;
  ~ModelExecutionLiveTest() override = default;

  void SetUp() override {
    scoped_feature_list_.InitWithFeatures(
        {features::kOptimizationGuideModelExecution,
         features::internal::kTabOrganizationSettingsVisibility},
        {});
    LiveTest::SetUp();
    // Always disable animation for stability.
    ui::ScopedAnimationDurationScaleMode disable_animation(
        ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
  }

  OptimizationGuideKeyedService* GetOptGuideKeyedService() {
    return OptimizationGuideKeyedServiceFactory::GetForProfile(
        browser()->profile());
  }

  bool IsSettingVisible(optimization_guide::UserVisibleFeatureKey feature) {
    return GetOptGuideKeyedService()->IsSettingVisible(feature);
  }

  syncer::SyncService* sync_service() {
    return signin::test::sync_service(browser());
  }

 protected:
  base::test::ScopedFeatureList scoped_feature_list_;
  base::HistogramTester histogram_tester_;

  signin::test::SignInFunctions sign_in_functions =
      signin::test::SignInFunctions(
          base::BindLambdaForTesting(
              [this]() -> Browser* { return this->browser(); }),
          base::BindLambdaForTesting(
              [this](int index,
                     const GURL& url,
                     ui::PageTransition transition) -> bool {
                return this->AddTabAtIndex(index, url, transition);
              }));
};

IN_PROC_BROWSER_TEST_F(ModelExecutionLiveTest, PRE_SimpleSyncFlow) {
  signin::test::TestAccount ta;
  CHECK(GetTestAccountsUtil()->GetAccount("TEST_ACCOUNT_1", ta));
  sign_in_functions.TurnOnSync(ta, 0);

  EXPECT_TRUE(sync_service()->IsSyncFeatureEnabled());
  EXPECT_TRUE(IsSettingVisible(
      UserVisibleFeatureKey::kTabOrganization));
  histogram_tester_.ExpectBucketCount(
      "OptimizationGuide.ModelExecution.SettingsVisibilityResult."
      "TabOrganization",
      ModelExecutionFeaturesController::SettingsVisibilityResult::
          kVisibleFieldTrialEnabled,
      1);
}

IN_PROC_BROWSER_TEST_F(ModelExecutionLiveTest, SimpleSyncFlow) {
  signin::test::TestAccount ta;
  CHECK(GetTestAccountsUtil()->GetAccount("TEST_ACCOUNT_1", ta));

  EXPECT_TRUE(sync_service()->IsSyncFeatureEnabled());
  EXPECT_TRUE(IsSettingVisible(
      UserVisibleFeatureKey::kTabOrganization));
  histogram_tester_.ExpectBucketCount(
      "OptimizationGuide.ModelExecution.SettingsVisibilityResult."
      "TabOrganization",
      ModelExecutionFeaturesController::SettingsVisibilityResult::
          kVisibleFieldTrialEnabled,
      1);
}

IN_PROC_BROWSER_TEST_F(ModelExecutionLiveTest,
                       PRE_SimpleSyncFlowForMinorAccount) {
  signin::test::TestAccount ta;
  CHECK(GetTestAccountsUtil()->GetAccount("TEST_ACCOUNT_MINOR", ta));
  sign_in_functions.TurnOnSync(ta, 0);

  EXPECT_TRUE(sync_service()->IsSyncFeatureEnabled());
  EXPECT_FALSE(IsSettingVisible(
      UserVisibleFeatureKey::kTabOrganization));
  histogram_tester_.ExpectBucketCount(
      "OptimizationGuide.ModelExecution.SettingsVisibilityResult."
      "TabOrganization",
      ModelExecutionFeaturesController::SettingsVisibilityResult::
          kNotVisibleModelExecutionCapability,
      1);
}

IN_PROC_BROWSER_TEST_F(ModelExecutionLiveTest,
                       SimpleSyncFlowForMinorAccount) {
  signin::test::TestAccount ta;
  CHECK(GetTestAccountsUtil()->GetAccount("TEST_ACCOUNT_MINOR", ta));

  EXPECT_TRUE(sync_service()->IsSyncFeatureEnabled());
  EXPECT_FALSE(IsSettingVisible(
      UserVisibleFeatureKey::kTabOrganization));
  histogram_tester_.ExpectBucketCount(
      "OptimizationGuide.ModelExecution.SettingsVisibilityResult."
      "TabOrganization",
      ModelExecutionFeaturesController::SettingsVisibilityResult::
          kNotVisibleModelExecutionCapability,
      1);
}

#endif

}  // namespace optimization_guide