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

#ifndef COMPONENTS_OMNIBOX_BROWSER_TEST_LOCATION_BAR_MODEL_H_
#define COMPONENTS_OMNIBOX_BROWSER_TEST_LOCATION_BAR_MODEL_H_

#include <stddef.h>
#include <memory>
#include <string>

#include "base/compiler_specific.h"
#include "base/memory/raw_ptr.h"
#include "components/omnibox/browser/location_bar_model.h"

namespace gfx {
struct VectorIcon;
}

// A LocationBarModel that is backed by instance variables, which are
// initialized with some basic values that can be changed with the provided
// setters. This should be used only for testing.
class TestLocationBarModel : public LocationBarModel {
 public:
  TestLocationBarModel();
  ~TestLocationBarModel() override;
  TestLocationBarModel(const TestLocationBarModel&) = delete;
  TestLocationBarModel& operator=(const TestLocationBarModel&) = delete;
  std::u16string GetFormattedFullURL() const override;
  std::u16string GetURLForDisplay() const override;
  GURL GetURL() const override;
  security_state::SecurityLevel GetSecurityLevel() const override;
  net::CertStatus GetCertStatus() const override;
  metrics::OmniboxEventProto::PageClassification GetPageClassification(
      bool is_prefetch = false) const override;
  const gfx::VectorIcon& GetVectorIcon() const override;
  std::u16string GetSecureDisplayText() const override;
  std::u16string GetSecureAccessibilityText() const override;
  bool ShouldDisplayURL() const override;
  bool IsOfflinePage() const override;
  bool ShouldPreventElision() const override;

  void set_formatted_full_url(const std::u16string& url) {
    formatted_full_url_ = std::make_unique<std::u16string>(url);
  }
  void set_url_for_display(const std::u16string& url) {
    url_for_display_ = std::make_unique<std::u16string>(url);
  }
  void set_url(const GURL& url) { url_ = url; }
  void set_security_level(security_state::SecurityLevel security_level) {
    security_level_ = security_level;
  }
  void set_cert_status(net::CertStatus cert_status) {
    cert_status_ = cert_status;
  }
  void set_icon(const gfx::VectorIcon& icon) { icon_ = &icon; }
  void set_should_display_url(bool should_display_url) {
    should_display_url_ = should_display_url;
  }
  void set_offline_page(bool offline_page) { offline_page_ = offline_page; }
  void set_secure_display_text(std::u16string secure_display_text) {
    secure_display_text_ = secure_display_text;
  }
  void set_should_prevent_elision(bool should_prevent_elision) {
    should_prevent_elision_ = should_prevent_elision;
  }

 private:
  // If either of these is not explicitly set, the test class will return
  // |url_.spec()| for the URL for display or fully formatted URL.
  std::unique_ptr<std::u16string> formatted_full_url_;
  std::unique_ptr<std::u16string> url_for_display_;

  GURL url_;
  security_state::SecurityLevel security_level_ = security_state::NONE;
  net::CertStatus cert_status_ = 0;
  raw_ptr<const gfx::VectorIcon> icon_ = nullptr;
  bool should_display_url_ = false;
  bool offline_page_ = false;
  std::u16string secure_display_text_ = std::u16string();
  bool should_prevent_elision_ = false;
};

#endif  // COMPONENTS_OMNIBOX_BROWSER_TEST_LOCATION_BAR_MODEL_H_