forked from mirror/chromium
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ozone] Add clipboard testing support.
Mock out clipboard delegate and provide a simple mocked system clipboard implementation to test clipboard_ozone Change-Id: I4d65e1496930cb14a32396be974e8f84353288d0
- Loading branch information
Showing
3 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef UI_BASE_CLIPBOARD_MOCK_CLIPBOARD_DELEGATE_ | ||
#define UI_BASE_CLIPBOARD_MOCK_CLIPBOARD_DELEGATE_ | ||
|
||
#include "base/callback.h" | ||
#include "ui/ozone/public/clipboard_delegate.h" | ||
|
||
namespace ui { | ||
|
||
// Delegate class, which mocks out system clipboard. | ||
// TODO(msisov): move the declaration details to .cc file. | ||
class MockClipboardDelegate : public ClipboardDelegate { | ||
public: | ||
MockClipboardDelegate() = default; | ||
~MockClipboardDelegate() = default; | ||
|
||
void OfferClipboardData(const DataMap& data_map, | ||
OfferDataClosure callback) override { | ||
offered_data_map_ = data_map; | ||
std::move(callback).Run(); | ||
} | ||
|
||
void RequestClipboardData(const std::string& mime_type, | ||
DataMap* data_map, | ||
RequestDataClosure callback) override { | ||
auto it = offered_data_map_.find(mime_type); | ||
DCHECK(it != offered_data_map_.end()); | ||
*data_map = offered_data_map_; | ||
std::move(callback).Run(std::move(it->second)); | ||
} | ||
|
||
void GetAvailableMimeTypes(GetMimeTypesClosure callback) override { | ||
std::vector<std::string> mime_types; | ||
for (const auto& item : offered_data_map_) { | ||
mime_types.push_back(item.first); | ||
} | ||
std::move(callback).Run(std::move(mime_types)); | ||
} | ||
|
||
bool IsSelectionOwner() override { | ||
return !offered_data_map_.empty(); | ||
} | ||
private: | ||
ClipboardDelegate::DataMap offered_data_map_; | ||
}; | ||
|
||
} // namespace ui | ||
|
||
#endif // UI_OZONE_PUBLIC_CLIPBOARD_DELEGATE_H_ |