Integrate dialog export and Apple service teams
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "platform_api/network_tls_policy.h"
|
||||
#include "platform_api/platform_policy.h"
|
||||
#include "platform_api/platform_services.h"
|
||||
#include "platform_apple/apple_platform_services.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
@@ -495,6 +496,56 @@ private:
|
||||
std::string clipboard_value_;
|
||||
};
|
||||
|
||||
class FakeAppleDocumentPickerBridge final {
|
||||
public:
|
||||
[[nodiscard]] pp::platform::apple::AppleDocumentPickerBridge bridge()
|
||||
{
|
||||
pp::platform::apple::AppleDocumentPickerBridge result;
|
||||
result.pick_image = [this](pp::platform::PickedPathCallback callback) {
|
||||
++pick_image_requests;
|
||||
callback(image_path);
|
||||
};
|
||||
result.pick_file = [this](
|
||||
std::vector<std::string> file_types,
|
||||
pp::platform::PickedPathCallback callback) {
|
||||
++pick_file_requests;
|
||||
picked_file_types = std::move(file_types);
|
||||
callback(file_path);
|
||||
};
|
||||
result.pick_save_file = [this](
|
||||
std::vector<std::string> file_types,
|
||||
pp::platform::PickedPathCallback callback) {
|
||||
++pick_save_file_requests;
|
||||
save_file_types = std::move(file_types);
|
||||
callback(save_path);
|
||||
};
|
||||
result.pick_directory = [this](pp::platform::PickedPathCallback callback) {
|
||||
++pick_directory_requests;
|
||||
callback(directory_path);
|
||||
};
|
||||
result.format_working_directory_path = [this](std::string_view path) {
|
||||
++format_requests;
|
||||
last_format_path.assign(path);
|
||||
return formatted_path;
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
int pick_image_requests = 0;
|
||||
int pick_file_requests = 0;
|
||||
int pick_save_file_requests = 0;
|
||||
int pick_directory_requests = 0;
|
||||
int format_requests = 0;
|
||||
std::string image_path = "D:/Paint/import.png";
|
||||
std::string file_path = "D:/Paint/demo.ppi";
|
||||
std::string save_path = "D:/Paint/export.ppi";
|
||||
std::string directory_path = "D:/Paint/work";
|
||||
std::string formatted_path = "D:/Paint/Resolved";
|
||||
std::string last_format_path;
|
||||
std::vector<std::string> picked_file_types;
|
||||
std::vector<std::string> save_file_types;
|
||||
};
|
||||
|
||||
void platform_services_dispatch_clipboard_reads_and_writes(pp::tests::Harness& harness)
|
||||
{
|
||||
FakePlatformServices fake("#112233");
|
||||
@@ -776,6 +827,117 @@ void platform_services_dispatch_prepared_file_save(pp::tests::Harness& harness)
|
||||
PP_EXPECT(harness, saved);
|
||||
}
|
||||
|
||||
void apple_document_platform_services_preserve_browse_root_policy(pp::tests::Harness& harness)
|
||||
{
|
||||
pp::platform::apple::AppleDocumentPlatformServices ios_services(pp::platform::PlatformFamily::ios);
|
||||
pp::platform::apple::AppleDocumentPlatformServices macos_services(pp::platform::PlatformFamily::macos);
|
||||
|
||||
const auto ios_roots = ios_services.document_browse_roots("D:/Paint/work", "D:/Paint");
|
||||
const auto macos_roots = macos_services.document_browse_roots("D:/Paint/work", "D:/Paint");
|
||||
|
||||
PP_EXPECT(harness, ios_roots.size() == 2);
|
||||
PP_EXPECT(harness, ios_roots[0] == "D:/Paint/work");
|
||||
PP_EXPECT(harness, ios_roots[1] == "D:/Paint/Inbox");
|
||||
PP_EXPECT(harness, macos_roots.size() == 1);
|
||||
PP_EXPECT(harness, macos_roots[0] == "D:/Paint/work");
|
||||
}
|
||||
|
||||
void apple_document_platform_services_dispatch_ios_picker_callbacks(pp::tests::Harness& harness)
|
||||
{
|
||||
FakeAppleDocumentPickerBridge fake;
|
||||
pp::platform::apple::AppleDocumentPlatformServices services(
|
||||
pp::platform::PlatformFamily::ios,
|
||||
fake.bridge());
|
||||
std::string image_path;
|
||||
std::string file_path;
|
||||
std::string save_path = "unchanged";
|
||||
std::string directory_path = "unchanged";
|
||||
|
||||
services.pick_image([&](std::string path) { image_path = std::move(path); });
|
||||
services.pick_file({ "ppi", "ppbr" }, [&](std::string path) { file_path = std::move(path); });
|
||||
services.pick_save_file({ "ppi" }, [&](std::string path) { save_path = std::move(path); });
|
||||
services.pick_directory([&](std::string path) { directory_path = std::move(path); });
|
||||
|
||||
PP_EXPECT(harness, fake.pick_image_requests == 1);
|
||||
PP_EXPECT(harness, fake.pick_file_requests == 1);
|
||||
PP_EXPECT(harness, fake.pick_save_file_requests == 0);
|
||||
PP_EXPECT(harness, fake.pick_directory_requests == 0);
|
||||
PP_EXPECT(harness, image_path == "D:/Paint/import.png");
|
||||
PP_EXPECT(harness, file_path == "D:/Paint/demo.ppi");
|
||||
PP_EXPECT(harness, fake.picked_file_types.size() == 2);
|
||||
PP_EXPECT(harness, fake.picked_file_types[0] == "ppi");
|
||||
PP_EXPECT(harness, fake.picked_file_types[1] == "ppbr");
|
||||
PP_EXPECT(harness, save_path == "unchanged");
|
||||
PP_EXPECT(harness, directory_path == "unchanged");
|
||||
}
|
||||
|
||||
void apple_document_platform_services_filter_macos_picker_paths(pp::tests::Harness& harness)
|
||||
{
|
||||
FakeAppleDocumentPickerBridge fake;
|
||||
pp::platform::apple::AppleDocumentPlatformServices services(
|
||||
pp::platform::PlatformFamily::macos,
|
||||
fake.bridge());
|
||||
std::string image_path = "unchanged";
|
||||
std::string file_path = "unchanged";
|
||||
std::string save_path = "unchanged";
|
||||
std::string directory_path = "unchanged";
|
||||
|
||||
fake.file_path.clear();
|
||||
services.pick_image([&](std::string path) { image_path = std::move(path); });
|
||||
PP_EXPECT(harness, fake.pick_image_requests == 0);
|
||||
PP_EXPECT(harness, fake.pick_file_requests == 1);
|
||||
PP_EXPECT(harness, fake.picked_file_types.size() == 5);
|
||||
PP_EXPECT(harness, fake.picked_file_types[0] == "png");
|
||||
PP_EXPECT(harness, fake.picked_file_types[1] == "PNG");
|
||||
PP_EXPECT(harness, fake.picked_file_types[2] == "jpg");
|
||||
PP_EXPECT(harness, fake.picked_file_types[3] == "JPG");
|
||||
PP_EXPECT(harness, fake.picked_file_types[4] == "jpeg");
|
||||
PP_EXPECT(harness, image_path == "unchanged");
|
||||
|
||||
fake.file_path = "D:/Paint/demo.ppi";
|
||||
services.pick_file({ "ppi" }, [&](std::string path) { file_path = std::move(path); });
|
||||
PP_EXPECT(harness, fake.pick_file_requests == 2);
|
||||
PP_EXPECT(harness, file_path == "D:/Paint/demo.ppi");
|
||||
|
||||
fake.save_path.clear();
|
||||
services.pick_save_file({ "ppi" }, [&](std::string path) { save_path = std::move(path); });
|
||||
PP_EXPECT(harness, fake.pick_save_file_requests == 1);
|
||||
PP_EXPECT(harness, save_path == "unchanged");
|
||||
|
||||
fake.save_path = "D:/Paint/export.ppi";
|
||||
services.pick_save_file({ "ppi" }, [&](std::string path) { save_path = std::move(path); });
|
||||
PP_EXPECT(harness, fake.pick_save_file_requests == 2);
|
||||
PP_EXPECT(harness, save_path == "D:/Paint/export.ppi");
|
||||
|
||||
fake.directory_path.clear();
|
||||
services.pick_directory([&](std::string path) { directory_path = std::move(path); });
|
||||
PP_EXPECT(harness, fake.pick_directory_requests == 1);
|
||||
PP_EXPECT(harness, directory_path == "unchanged");
|
||||
|
||||
fake.directory_path = "D:/Paint/work";
|
||||
services.pick_directory([&](std::string path) { directory_path = std::move(path); });
|
||||
PP_EXPECT(harness, fake.pick_directory_requests == 2);
|
||||
PP_EXPECT(harness, directory_path == "D:/Paint/work");
|
||||
}
|
||||
|
||||
void apple_document_platform_services_preserve_working_directory_picker_policy(pp::tests::Harness& harness)
|
||||
{
|
||||
FakeAppleDocumentPickerBridge fake;
|
||||
pp::platform::apple::AppleDocumentPlatformServices ios_services(
|
||||
pp::platform::PlatformFamily::ios,
|
||||
fake.bridge());
|
||||
pp::platform::apple::AppleDocumentPlatformServices macos_services(
|
||||
pp::platform::PlatformFamily::macos,
|
||||
fake.bridge());
|
||||
|
||||
PP_EXPECT(harness, !ios_services.supports_working_directory_picker());
|
||||
PP_EXPECT(harness, macos_services.supports_working_directory_picker());
|
||||
PP_EXPECT(harness, ios_services.format_working_directory_path("D:/Paint/.") == "D:/Paint/.");
|
||||
PP_EXPECT(harness, macos_services.format_working_directory_path("D:/Paint/.") == "D:/Paint/Resolved");
|
||||
PP_EXPECT(harness, fake.format_requests == 1);
|
||||
PP_EXPECT(harness, fake.last_format_path == "D:/Paint/.");
|
||||
}
|
||||
|
||||
void web_platform_services_preserve_default_web_policy(pp::tests::Harness& harness)
|
||||
{
|
||||
ScopedInjectedWebPlatformServices scoped(nullptr);
|
||||
@@ -1209,6 +1371,18 @@ int main()
|
||||
"platform services dispatch working directory picker policy",
|
||||
platform_services_dispatch_working_directory_picker_policy);
|
||||
harness.run("platform services dispatch prepared file save", platform_services_dispatch_prepared_file_save);
|
||||
harness.run(
|
||||
"apple document platform services preserve browse root policy",
|
||||
apple_document_platform_services_preserve_browse_root_policy);
|
||||
harness.run(
|
||||
"apple document platform services dispatch ios picker callbacks",
|
||||
apple_document_platform_services_dispatch_ios_picker_callbacks);
|
||||
harness.run(
|
||||
"apple document platform services filter macos picker paths",
|
||||
apple_document_platform_services_filter_macos_picker_paths);
|
||||
harness.run(
|
||||
"apple document platform services preserve working directory picker policy",
|
||||
apple_document_platform_services_preserve_working_directory_picker_policy);
|
||||
harness.run("web platform services preserve default web policy", web_platform_services_preserve_default_web_policy);
|
||||
harness.run("web platform services resolve injected services", web_platform_services_resolve_injected_services);
|
||||
harness.run("platform services dispatch writable file target", platform_services_dispatch_writable_file_target);
|
||||
|
||||
Reference in New Issue
Block a user