Route picker callbacks through platform services
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -51,16 +52,51 @@ public:
|
||||
shared_path.assign(path);
|
||||
}
|
||||
|
||||
void pick_image(pp::platform::PickedPathCallback callback) override
|
||||
{
|
||||
++pick_image_requests;
|
||||
callback(picker_path);
|
||||
}
|
||||
|
||||
void pick_file(std::vector<std::string> file_types, pp::platform::PickedPathCallback callback) override
|
||||
{
|
||||
++pick_file_requests;
|
||||
picked_file_types = std::move(file_types);
|
||||
callback(picker_path);
|
||||
}
|
||||
|
||||
void pick_save_file(std::vector<std::string> file_types, pp::platform::PickedPathCallback callback) override
|
||||
{
|
||||
++pick_save_file_requests;
|
||||
save_file_types = std::move(file_types);
|
||||
callback(save_path);
|
||||
}
|
||||
|
||||
void pick_directory(pp::platform::PickedPathCallback callback) override
|
||||
{
|
||||
++pick_directory_requests;
|
||||
callback(directory_path);
|
||||
}
|
||||
|
||||
int clipboard_reads = 0;
|
||||
int clipboard_writes = 0;
|
||||
int cursor_updates = 0;
|
||||
int keyboard_updates = 0;
|
||||
int display_file_requests = 0;
|
||||
int share_file_requests = 0;
|
||||
int pick_image_requests = 0;
|
||||
int pick_file_requests = 0;
|
||||
int pick_save_file_requests = 0;
|
||||
int pick_directory_requests = 0;
|
||||
bool cursor_visible = false;
|
||||
bool keyboard_visible = false;
|
||||
std::string displayed_path;
|
||||
std::string shared_path;
|
||||
std::string picker_path = "D:/Paint/import.png";
|
||||
std::string save_path = "D:/Paint/export.ppi";
|
||||
std::string directory_path = "D:/Paint";
|
||||
std::vector<std::string> picked_file_types;
|
||||
std::vector<std::string> save_file_types;
|
||||
|
||||
private:
|
||||
std::string clipboard_value_;
|
||||
@@ -118,6 +154,32 @@ void platform_services_dispatch_file_actions(pp::tests::Harness& harness)
|
||||
PP_EXPECT(harness, fake.shared_path == "D:/Paint/demo.ppi");
|
||||
}
|
||||
|
||||
void platform_services_dispatch_picker_callbacks(pp::tests::Harness& harness)
|
||||
{
|
||||
FakePlatformServices fake("unused");
|
||||
pp::platform::PlatformServices& services = fake;
|
||||
std::string image_path;
|
||||
std::string file_path;
|
||||
std::string save_path;
|
||||
std::string directory_path;
|
||||
|
||||
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 == 1);
|
||||
PP_EXPECT(harness, fake.pick_directory_requests == 1);
|
||||
PP_EXPECT(harness, image_path == "D:/Paint/import.png");
|
||||
PP_EXPECT(harness, file_path == "D:/Paint/import.png");
|
||||
PP_EXPECT(harness, save_path == "D:/Paint/export.ppi");
|
||||
PP_EXPECT(harness, directory_path == "D:/Paint");
|
||||
PP_EXPECT(harness, fake.picked_file_types.size() == 2);
|
||||
PP_EXPECT(harness, fake.save_file_types.size() == 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -127,5 +189,6 @@ int main()
|
||||
harness.run("platform services preserve empty clipboard writes", platform_services_preserve_empty_clipboard_writes);
|
||||
harness.run("platform services dispatch visibility updates", platform_services_dispatch_visibility_updates);
|
||||
harness.run("platform services dispatch file actions", platform_services_dispatch_file_actions);
|
||||
harness.run("platform services dispatch picker callbacks", platform_services_dispatch_picker_callbacks);
|
||||
return harness.finish();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user