File: sharing_browsertest.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 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 (103 lines) | stat: -rw-r--r-- 3,632 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
95
96
97
98
99
100
101
102
103
// 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_BROWSER_UI_VIEWS_SHARING_SHARING_BROWSERTEST_H_
#define CHROME_BROWSER_UI_VIEWS_SHARING_SHARING_BROWSERTEST_H_

#include <memory>
#include <string>
#include <string_view>

#include "base/memory/raw_ptr.h"
#include "chrome/browser/gcm/gcm_profile_service_factory.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/ui/page_action/page_action_icon_type.h"
#include "components/sharing_message/sharing_message_bridge.h"
#include "components/sharing_message/sharing_service.h"
#include "components/sharing_message/sharing_target_device_info.h"
#include "components/sync_device_info/fake_device_info_tracker.h"
#include "url/gurl.h"

class PageActionIconView;

class FakeSharingMessageBridge : public SharingMessageBridge {
 public:
  FakeSharingMessageBridge() = default;

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

  ~FakeSharingMessageBridge() override = default;

  // SharingMessageBridge:
  void SendSharingMessage(
      std::unique_ptr<sync_pb::SharingMessageSpecifics> specifics,
      CommitFinishedCallback on_commit_callback) override;

  // SharingMessageBridge:
  base::WeakPtr<syncer::DataTypeControllerDelegate> GetControllerDelegate()
      override;

  const sync_pb::SharingMessageSpecifics& specifics() const {
    return specifics_;
  }

 private:
  sync_pb::SharingMessageSpecifics specifics_;
};

// Base test class for testing sharing features.
class SharingBrowserTest : public SyncTest {
 public:
  SharingBrowserTest();

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

  ~SharingBrowserTest() override;

  void SetUpOnMainThread() override;

  void Init(
      sync_pb::SharingSpecificFields_EnabledFeatures first_device_feature,
      sync_pb::SharingSpecificFields_EnabledFeatures second_device_feature);

  virtual std::string GetTestPageURL() const = 0;

  std::unique_ptr<TestRenderViewContextMenu> InitContextMenu(
      const GURL& url,
      std::string_view link_text,
      std::string_view selection_text);

  void CheckLastReceiver(const SharingTargetDeviceInfo& device) const;

  components_sharing_message::SharingMessage GetLastSharingMessageSent() const;

  SharingService* sharing_service() const;

  content::WebContents* web_contents() const;

  PageActionIconView* GetPageActionIconView(PageActionIconType type);

 private:
  void SetUpDevices(
      sync_pb::SharingSpecificFields_EnabledFeatures first_device_feature,
      sync_pb::SharingSpecificFields_EnabledFeatures second_device_feature);

  void RegisterDevice(int profile_index,
                      sync_pb::SharingSpecificFields_EnabledFeatures feature);
  void AddDeviceInfo(const syncer::DeviceInfo& original_device,
                     int fake_device_id);

  gcm::GCMProfileServiceFactory::ScopedTestingFactoryInstaller
      scoped_testing_factory_installer_;
  raw_ptr<content::WebContents, DanglingUntriaged> web_contents_;
  syncer::FakeDeviceInfoTracker fake_device_info_tracker_;
  std::vector<std::unique_ptr<syncer::DeviceInfo>> device_infos_;
  raw_ptr<SharingService, AcrossTasksDanglingUntriaged> sharing_service_;
  FakeSharingMessageBridge fake_sharing_message_bridge_;
};

#endif  // CHROME_BROWSER_UI_VIEWS_SHARING_SHARING_BROWSERTEST_H_