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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
// Copyright 2016 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_ASH_ARC_EXTENSIONS_FAKE_ARC_SUPPORT_H_
#define CHROME_BROWSER_ASH_ARC_EXTENSIONS_FAKE_ARC_SUPPORT_H_
#include <memory>
#include <string>
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "chrome/browser/ash/arc/arc_support_host.h"
#include "extensions/browser/api/messaging/native_message_host.h"
namespace arc {
// Fake implementation of ARC support Chrome App for testing.
class FakeArcSupport : public extensions::NativeMessageHost::Client {
public:
// Observer to get arc support related notifications.
class Observer {
public:
// Called when ui_page() changes, with the new page as argument.
virtual void OnPageChanged(ArcSupportHost::UIPage page) {}
protected:
virtual ~Observer() = default;
};
explicit FakeArcSupport(ArcSupportHost* support_host);
FakeArcSupport(const FakeArcSupport&) = delete;
FakeArcSupport& operator=(const FakeArcSupport&) = delete;
~FakeArcSupport() override;
// Emulates to open ARC support Chrome app, and connect message host to
// ARC support host.
void Open(Profile* profile);
// Emulates clicking Close button.
void Close();
// Emulates clicking Agree button on the fake terms of service page.
void ClickAgreeButton();
// Emulates clicking Cancel button on the fake terms of service page.
void ClickCancelButton();
// Error page emulation.
void ClickRetryButton();
void ClickSendFeedbackButton();
void ClickRunNetworkTestsButton();
void TosLoadResult(bool success);
bool metrics_mode() const { return metrics_mode_; }
bool backup_and_restore_managed() const {
return backup_and_restore_managed_;
}
bool backup_and_restore_mode() const { return backup_and_restore_mode_; }
bool location_service_managed() const { return location_service_managed_; }
bool location_service_mode() const { return location_service_mode_; }
const std::string& tos_content() const { return tos_content_; }
bool tos_shown() const { return tos_shown_; }
// Emulates checking preference box.
void set_metrics_mode(bool mode) { metrics_mode_ = mode; }
void set_backup_and_restore_mode(bool mode) {
backup_and_restore_mode_ = mode;
}
void set_location_service_mode(bool mode) { location_service_mode_ = mode; }
// Allows control of whether some preferences are managed by policy.
void set_backup_and_restore_managed(bool managed) {
backup_and_restore_managed_ = managed;
}
void set_location_service_managed(bool managed) {
location_service_managed_ = managed;
}
// Allows emulation of the ToS display.
void set_tos_content(const std::string& tos_content) {
tos_content_ = tos_content;
}
void set_tos_shown(bool shown) { tos_shown_ = shown; }
// Returns the current page.
ArcSupportHost::UIPage ui_page() const { return ui_page_; }
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
bool HasObserver(Observer* observer);
private:
void UnsetMessageHost();
// extensions::NativeMessageHost::Client:
void PostMessageFromNativeHost(const std::string& message) override;
void CloseChannel(const std::string& error_message) override;
const raw_ptr<ArcSupportHost> support_host_;
std::unique_ptr<extensions::NativeMessageHost> native_message_host_;
ArcSupportHost::UIPage ui_page_ = ArcSupportHost::UIPage::NO_PAGE;
bool metrics_mode_ = false;
bool backup_and_restore_managed_ = false;
bool backup_and_restore_mode_ = false;
bool location_service_managed_ = false;
bool location_service_mode_ = false;
std::string tos_content_;
bool tos_shown_ = false;
base::ObserverList<Observer>::Unchecked observer_list_;
base::WeakPtrFactory<FakeArcSupport> weak_ptr_factory_{this};
};
} // namespace arc
#endif // CHROME_BROWSER_ASH_ARC_EXTENSIONS_FAKE_ARC_SUPPORT_H_
|