File: android_browser_test.h

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 (94 lines) | stat: -rw-r--r-- 3,981 bytes parent folder | download | duplicates (3)
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
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_TEST_BASE_ANDROID_ANDROID_BROWSER_TEST_H_
#define CHROME_TEST_BASE_ANDROID_ANDROID_BROWSER_TEST_H_

#include "base/callback_list.h"
#include "base/files/scoped_temp_dir.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/test/browser_test_base.h"

class PrefService;

// A base class for browser tests run on Android. It exposes very little API
// since the majority of the Android UI is accessed through static methods,
// such as TabModelList.
//
// Do *not* extend this class to attempt to mirror APIs on InProcessBrowserTest
// which is the base class for desktop platforms.
// Shared abstractions around Desktop-vs-Android should be implemented as
// topical helper classes or functions independent of the BrowserTestBase class
// hierarchy. Helpers may take a PlatformBrowserTest* in their APIs in order to
// support both types of browser tests, such as in the chrome_test_utils
// namespace.
//
// Further details and methodology can be found in the design doc:
// https://docs.google.com/document/d/1jT3W6VnVI4b0FuiNbYzgGZPxIOUZmppUZZwi3OebvVE/preview
class AndroidBrowserTest : public content::BrowserTestBase {
 public:
  AndroidBrowserTest();

  AndroidBrowserTest(const AndroidBrowserTest&) = delete;
  AndroidBrowserTest& operator=(const AndroidBrowserTest&) = delete;

  ~AndroidBrowserTest() override;

  // Returns the currently running AndroidBrowserTest.
  static AndroidBrowserTest* GetCurrent();

  // Sets up default command line that will be visible to the code under test.
  // Called by SetUp() after SetUpCommandLine() to add default command line
  // switches. A default implementation is provided in this class. If a test
  // does not want to use the default implementation, it should override this
  // method.
  virtual void SetUpDefaultCommandLine(base::CommandLine* command_line);

  // Initializes the contents of the user data directory. Called by SetUp()
  // after creating the user data directory, but before any browser is launched.
  // If a test wishes to set up some initial non-empty state in the user data
  // directory before the browser starts up, it can do so here. Returns true if
  // successful. To set initial prefs, see SetUpLocalStatePrefService.
  [[nodiscard]] virtual bool SetUpUserDataDirectory();

  // Called just before BrowserContextKeyedService creation is started
  // for each Profile creation.
  // Test fixtures inheriting AndroidBrowserTest can inject some fake/test
  // BrowserContextKeyedService as necessary for testing.
  virtual void SetUpBrowserContextKeyedServices(
      content::BrowserContext* context) {}

  // Tests can override this to customize the initial local_state.
  virtual void SetUpLocalStatePrefService(PrefService* local_state) {}

  // content::BrowserTestBase implementation.
  void SetUp() override;
  void PreRunTestOnMainThread() override;
  void PostRunTestOnMainThread() override;

  // Counts the number of "PRE_" prefixes in the test name. This is used to
  // differentiate between different PRE tests in browser test constructors
  // and setup functions.
  static size_t GetTestPreCount();

  // Returns the test data path used by the embedded test server.
  base::FilePath GetChromeTestDataDir() const;

  // Returns the profile. If there are multiple profiles, it's not determined
  // what profile is returned.
  Profile* GetProfile() const;

 private:
  // Temporary user data directory. Used only when a user data directory is not
  // specified in the command line.
  base::ScopedTempDir temp_user_data_dir_;

  base::test::ScopedFeatureList feature_list_;

  // Used to set up test factories for each browser context.
  base::CallbackListSubscription create_services_subscription_;
};

#endif  // CHROME_TEST_BASE_ANDROID_ANDROID_BROWSER_TEST_H_