File: android_browser_test.h

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 (83 lines) | stat: -rw-r--r-- 3,494 bytes parent folder | download | duplicates (2)
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
// 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/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();

  // 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_;
};

#endif  // CHROME_TEST_BASE_ANDROID_ANDROID_BROWSER_TEST_H_