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_
|