[go: nahoru, domu]

blob: 92c89696d10db74fc92c610f39465269dad637d1 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2019 The Chromium Authors
Michael van Ouwerkerk89a6f772019-10-03 11:30:442// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Himanshu Jaju825b9882019-11-21 15:28:255#ifndef CHROME_BROWSER_UI_VIEWS_SHARING_SHARING_BROWSERTEST_H_
6#define CHROME_BROWSER_UI_VIEWS_SHARING_SHARING_BROWSERTEST_H_
Michael van Ouwerkerk89a6f772019-10-03 11:30:447
8#include <memory>
9#include <string>
10
Keishi Hattori0e45c022021-11-27 09:25:5211#include "base/memory/raw_ptr.h"
Michael van Ouwerkerk7914f972019-10-18 10:48:4312#include "base/strings/string_piece_forward.h"
Michael van Ouwerkerk89a6f772019-10-03 11:30:4413#include "chrome/browser/gcm/gcm_profile_service_factory.h"
14#include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
Alex Chau328eeb932020-04-22 11:06:3515#include "chrome/browser/sharing/sharing_message_bridge.h"
Michael van Ouwerkerk89a6f772019-10-03 11:30:4416#include "chrome/browser/sharing/sharing_service.h"
Marc Treib4131d032023-02-07 13:36:1017#include "chrome/browser/sharing/web_push/web_push_sender.h"
Michael van Ouwerkerk89a6f772019-10-03 11:30:4418#include "chrome/browser/sync/test/integration/sync_test.h"
Himanshu Jaju243b0fe2019-11-22 15:25:4719#include "chrome/browser/ui/page_action/page_action_icon_type.h"
Michael van Ouwerkerk89a6f772019-10-03 11:30:4420#include "components/sync_device_info/device_info_sync_service.h"
21#include "components/sync_device_info/fake_device_info_tracker.h"
22#include "url/gurl.h"
23
Alex Chau328eeb932020-04-22 11:06:3524namespace syncer {
25class DeviceInfo;
26} // namespace syncer
27
Himanshu Jaju243b0fe2019-11-22 15:25:4728class PageActionIconView;
29
Marc Treib4131d032023-02-07 13:36:1030class FakeWebPushSender : public WebPushSender {
31 public:
32 FakeWebPushSender() : WebPushSender(/*url_loader_factory=*/nullptr) {}
33
34 FakeWebPushSender(const FakeWebPushSender&) = delete;
35 FakeWebPushSender& operator=(const FakeWebPushSender&) = delete;
36
37 ~FakeWebPushSender() override = default;
38
39 void SendMessage(const std::string& fcm_token,
40 crypto::ECPrivateKey* vapid_key,
41 WebPushMessage message,
42 WebPushCallback callback) override;
43
44 const std::string& fcm_token() { return fcm_token_; }
45 const WebPushMessage& message() { return message_; }
46
47 private:
48 std::string fcm_token_;
49 WebPushMessage message_;
50};
51
Alex Chau328eeb932020-04-22 11:06:3552class FakeSharingMessageBridge : public SharingMessageBridge {
53 public:
54 FakeSharingMessageBridge() = default;
Peter Boström53c6c5952021-09-17 09:41:2655
56 FakeSharingMessageBridge(const FakeSharingMessageBridge&) = delete;
57 FakeSharingMessageBridge& operator=(const FakeSharingMessageBridge&) = delete;
58
Alex Chau328eeb932020-04-22 11:06:3559 ~FakeSharingMessageBridge() override = default;
60
61 // SharingMessageBridge:
62 void SendSharingMessage(
63 std::unique_ptr<sync_pb::SharingMessageSpecifics> specifics,
64 CommitFinishedCallback on_commit_callback) override;
65
66 // SharingMessageBridge:
67 base::WeakPtr<syncer::ModelTypeControllerDelegate> GetControllerDelegate()
68 override;
69
70 const sync_pb::SharingMessageSpecifics& specifics() const {
71 return specifics_;
72 }
73
74 private:
75 sync_pb::SharingMessageSpecifics specifics_;
Alex Chau328eeb932020-04-22 11:06:3576};
77
Michael van Ouwerkerk89a6f772019-10-03 11:30:4478// Base test class for testing sharing features.
79class SharingBrowserTest : public SyncTest {
80 public:
81 SharingBrowserTest();
82
Peter Boström53c6c5952021-09-17 09:41:2683 SharingBrowserTest(const SharingBrowserTest&) = delete;
84 SharingBrowserTest& operator=(const SharingBrowserTest&) = delete;
85
Michael van Ouwerkerk89a6f772019-10-03 11:30:4486 ~SharingBrowserTest() override;
87
88 void SetUpOnMainThread() override;
89
Michael van Ouwerkerk7914f972019-10-18 10:48:4390 void Init(
91 sync_pb::SharingSpecificFields_EnabledFeatures first_device_feature,
92 sync_pb::SharingSpecificFields_EnabledFeatures second_device_feature);
Michael van Ouwerkerk89a6f772019-10-03 11:30:4493
94 virtual std::string GetTestPageURL() const = 0;
95
Michael van Ouwerkerk7914f972019-10-18 10:48:4396 std::unique_ptr<TestRenderViewContextMenu> InitContextMenu(
Michael van Ouwerkerk89a6f772019-10-03 11:30:4497 const GURL& url,
Michael van Ouwerkerk7914f972019-10-18 10:48:4398 base::StringPiece link_text,
99 base::StringPiece selection_text);
Michael van Ouwerkerk89a6f772019-10-03 11:30:44100
Alex Chau328eeb932020-04-22 11:06:35101 void CheckLastReceiver(const syncer::DeviceInfo& device) const;
Michael van Ouwerkerk89a6f772019-10-03 11:30:44102
103 chrome_browser_sharing::SharingMessage GetLastSharingMessageSent() const;
104
105 SharingService* sharing_service() const;
106
107 content::WebContents* web_contents() const;
108
Himanshu Jaju243b0fe2019-11-22 15:25:47109 PageActionIconView* GetPageActionIconView(PageActionIconType type);
110
Michael van Ouwerkerk89a6f772019-10-03 11:30:44111 private:
Michael van Ouwerkerk7914f972019-10-18 10:48:43112 void SetUpDevices(
113 sync_pb::SharingSpecificFields_EnabledFeatures first_device_feature,
114 sync_pb::SharingSpecificFields_EnabledFeatures second_device_feature);
115
116 void RegisterDevice(int profile_index,
117 sync_pb::SharingSpecificFields_EnabledFeatures feature);
118 void AddDeviceInfo(const syncer::DeviceInfo& original_device,
119 int fake_device_id);
120
Michael van Ouwerkerk89a6f772019-10-03 11:30:44121 gcm::GCMProfileServiceFactory::ScopedTestingFactoryInstaller
122 scoped_testing_factory_installer_;
Ali Hijazi654b0662022-10-22 21:26:32123 raw_ptr<content::WebContents, DanglingUntriaged> web_contents_;
Michael van Ouwerkerk89a6f772019-10-03 11:30:44124 syncer::FakeDeviceInfoTracker fake_device_info_tracker_;
125 std::vector<std::unique_ptr<syncer::DeviceInfo>> device_infos_;
Pâris508dce92023-06-29 18:23:48126 raw_ptr<SharingService, DanglingAcrossTasks> sharing_service_;
127 raw_ptr<FakeWebPushSender, DanglingAcrossTasks> fake_web_push_sender_;
Alex Chau328eeb932020-04-22 11:06:35128 FakeSharingMessageBridge fake_sharing_message_bridge_;
Michael van Ouwerkerk89a6f772019-10-03 11:30:44129};
130
Himanshu Jaju825b9882019-11-21 15:28:25131#endif // CHROME_BROWSER_UI_VIEWS_SHARING_SHARING_BROWSERTEST_H_