Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Michael van Ouwerkerk | 89a6f77 | 2019-10-03 11:30:44 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Himanshu Jaju | 825b988 | 2019-11-21 15:28:25 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_UI_VIEWS_SHARING_SHARING_BROWSERTEST_H_ |
| 6 | #define CHROME_BROWSER_UI_VIEWS_SHARING_SHARING_BROWSERTEST_H_ |
Michael van Ouwerkerk | 89a6f77 | 2019-10-03 11:30:44 | [diff] [blame] | 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 11 | #include "base/memory/raw_ptr.h" |
Michael van Ouwerkerk | 7914f97 | 2019-10-18 10:48:43 | [diff] [blame] | 12 | #include "base/strings/string_piece_forward.h" |
Michael van Ouwerkerk | 89a6f77 | 2019-10-03 11:30:44 | [diff] [blame] | 13 | #include "chrome/browser/gcm/gcm_profile_service_factory.h" |
| 14 | #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h" |
Alex Chau | 328eeb93 | 2020-04-22 11:06:35 | [diff] [blame] | 15 | #include "chrome/browser/sharing/sharing_message_bridge.h" |
Michael van Ouwerkerk | 89a6f77 | 2019-10-03 11:30:44 | [diff] [blame] | 16 | #include "chrome/browser/sharing/sharing_service.h" |
Marc Treib | 4131d03 | 2023-02-07 13:36:10 | [diff] [blame] | 17 | #include "chrome/browser/sharing/web_push/web_push_sender.h" |
Michael van Ouwerkerk | 89a6f77 | 2019-10-03 11:30:44 | [diff] [blame] | 18 | #include "chrome/browser/sync/test/integration/sync_test.h" |
Himanshu Jaju | 243b0fe | 2019-11-22 15:25:47 | [diff] [blame] | 19 | #include "chrome/browser/ui/page_action/page_action_icon_type.h" |
Michael van Ouwerkerk | 89a6f77 | 2019-10-03 11:30:44 | [diff] [blame] | 20 | #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 Chau | 328eeb93 | 2020-04-22 11:06:35 | [diff] [blame] | 24 | namespace syncer { |
| 25 | class DeviceInfo; |
| 26 | } // namespace syncer |
| 27 | |
Himanshu Jaju | 243b0fe | 2019-11-22 15:25:47 | [diff] [blame] | 28 | class PageActionIconView; |
| 29 | |
Marc Treib | 4131d03 | 2023-02-07 13:36:10 | [diff] [blame] | 30 | class 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 Chau | 328eeb93 | 2020-04-22 11:06:35 | [diff] [blame] | 52 | class FakeSharingMessageBridge : public SharingMessageBridge { |
| 53 | public: |
| 54 | FakeSharingMessageBridge() = default; |
Peter Boström | 53c6c595 | 2021-09-17 09:41:26 | [diff] [blame] | 55 | |
| 56 | FakeSharingMessageBridge(const FakeSharingMessageBridge&) = delete; |
| 57 | FakeSharingMessageBridge& operator=(const FakeSharingMessageBridge&) = delete; |
| 58 | |
Alex Chau | 328eeb93 | 2020-04-22 11:06:35 | [diff] [blame] | 59 | ~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 Chau | 328eeb93 | 2020-04-22 11:06:35 | [diff] [blame] | 76 | }; |
| 77 | |
Michael van Ouwerkerk | 89a6f77 | 2019-10-03 11:30:44 | [diff] [blame] | 78 | // Base test class for testing sharing features. |
| 79 | class SharingBrowserTest : public SyncTest { |
| 80 | public: |
| 81 | SharingBrowserTest(); |
| 82 | |
Peter Boström | 53c6c595 | 2021-09-17 09:41:26 | [diff] [blame] | 83 | SharingBrowserTest(const SharingBrowserTest&) = delete; |
| 84 | SharingBrowserTest& operator=(const SharingBrowserTest&) = delete; |
| 85 | |
Michael van Ouwerkerk | 89a6f77 | 2019-10-03 11:30:44 | [diff] [blame] | 86 | ~SharingBrowserTest() override; |
| 87 | |
| 88 | void SetUpOnMainThread() override; |
| 89 | |
Michael van Ouwerkerk | 7914f97 | 2019-10-18 10:48:43 | [diff] [blame] | 90 | void Init( |
| 91 | sync_pb::SharingSpecificFields_EnabledFeatures first_device_feature, |
| 92 | sync_pb::SharingSpecificFields_EnabledFeatures second_device_feature); |
Michael van Ouwerkerk | 89a6f77 | 2019-10-03 11:30:44 | [diff] [blame] | 93 | |
| 94 | virtual std::string GetTestPageURL() const = 0; |
| 95 | |
Michael van Ouwerkerk | 7914f97 | 2019-10-18 10:48:43 | [diff] [blame] | 96 | std::unique_ptr<TestRenderViewContextMenu> InitContextMenu( |
Michael van Ouwerkerk | 89a6f77 | 2019-10-03 11:30:44 | [diff] [blame] | 97 | const GURL& url, |
Michael van Ouwerkerk | 7914f97 | 2019-10-18 10:48:43 | [diff] [blame] | 98 | base::StringPiece link_text, |
| 99 | base::StringPiece selection_text); |
Michael van Ouwerkerk | 89a6f77 | 2019-10-03 11:30:44 | [diff] [blame] | 100 | |
Alex Chau | 328eeb93 | 2020-04-22 11:06:35 | [diff] [blame] | 101 | void CheckLastReceiver(const syncer::DeviceInfo& device) const; |
Michael van Ouwerkerk | 89a6f77 | 2019-10-03 11:30:44 | [diff] [blame] | 102 | |
| 103 | chrome_browser_sharing::SharingMessage GetLastSharingMessageSent() const; |
| 104 | |
| 105 | SharingService* sharing_service() const; |
| 106 | |
| 107 | content::WebContents* web_contents() const; |
| 108 | |
Himanshu Jaju | 243b0fe | 2019-11-22 15:25:47 | [diff] [blame] | 109 | PageActionIconView* GetPageActionIconView(PageActionIconType type); |
| 110 | |
Michael van Ouwerkerk | 89a6f77 | 2019-10-03 11:30:44 | [diff] [blame] | 111 | private: |
Michael van Ouwerkerk | 7914f97 | 2019-10-18 10:48:43 | [diff] [blame] | 112 | 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 Ouwerkerk | 89a6f77 | 2019-10-03 11:30:44 | [diff] [blame] | 121 | gcm::GCMProfileServiceFactory::ScopedTestingFactoryInstaller |
| 122 | scoped_testing_factory_installer_; |
Ali Hijazi | 654b066 | 2022-10-22 21:26:32 | [diff] [blame] | 123 | raw_ptr<content::WebContents, DanglingUntriaged> web_contents_; |
Michael van Ouwerkerk | 89a6f77 | 2019-10-03 11:30:44 | [diff] [blame] | 124 | syncer::FakeDeviceInfoTracker fake_device_info_tracker_; |
| 125 | std::vector<std::unique_ptr<syncer::DeviceInfo>> device_infos_; |
Pâris | 508dce9 | 2023-06-29 18:23:48 | [diff] [blame] | 126 | raw_ptr<SharingService, DanglingAcrossTasks> sharing_service_; |
| 127 | raw_ptr<FakeWebPushSender, DanglingAcrossTasks> fake_web_push_sender_; |
Alex Chau | 328eeb93 | 2020-04-22 11:06:35 | [diff] [blame] | 128 | FakeSharingMessageBridge fake_sharing_message_bridge_; |
Michael van Ouwerkerk | 89a6f77 | 2019-10-03 11:30:44 | [diff] [blame] | 129 | }; |
| 130 | |
Himanshu Jaju | 825b988 | 2019-11-21 15:28:25 | [diff] [blame] | 131 | #endif // CHROME_BROWSER_UI_VIEWS_SHARING_SHARING_BROWSERTEST_H_ |