blob: c6f56bb7b4de42486292d16dd6dc228fca792ba6 [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include <sstream>
#include <string>
#include <fuchsia/modular/cpp/fidl.h>
#include <fuchsia/ui/viewsv1token/cpp/fidl.h>
#include <lib/component/cpp/startup_context.h>
#include <lib/context/cpp/formatting.h>
#include <lib/fidl/cpp/binding.h>
#include <lib/fsl/vmo/strings.h>
#include <lib/fxl/logging.h>
#include <lib/fxl/macros.h>
#include "peridot/lib/fidl/array_to_string.h"
#include "peridot/lib/rapidjson/rapidjson.h"
#include "peridot/lib/testing/component_main.h"
#include "peridot/lib/testing/session_shell_base.h"
#include "peridot/public/lib/integration_testing/cpp/reporting.h"
#include "peridot/public/lib/integration_testing/cpp/testing.h"
#include "peridot/tests/chain/defs.h"
#include "peridot/tests/common/defs.h"
using modular::testing::Put;
using modular::testing::TestPoint;
namespace {
const char kStoryName[] = "story";
// Cf. README.md for what this test does and how.
class TestApp : public modular::testing::SessionShellBase {
public:
TestApp(component::StartupContext* const startup_context)
: SessionShellBase(startup_context) {
TestInit(__FILE__);
startup_context->ConnectToEnvironmentService(puppet_master_.NewRequest());
CreateStory();
}
~TestApp() override = default;
private:
TestPoint create_story_{"CreateStory()"};
void CreateStory() {
puppet_master_->ControlStory("story", story_puppet_master_.NewRequest());
fidl::VectorPtr<fuchsia::modular::StoryCommand> commands;
fuchsia::modular::AddMod add_mod;
add_mod.mod_name.push_back("root");
add_mod.intent.action = "action";
add_mod.intent.handler = kModuleUrl;
fuchsia::modular::IntentParameterData data;
fsl::SizedVmo vmo;
FXL_CHECK(fsl::VmoFromString(R"("initial data for the story")", &vmo));
data.set_json(std::move(vmo).ToTransport());
fuchsia::modular::IntentParameter intent_parameter;
intent_parameter.name = "rootModuleParam1";
intent_parameter.data = std::move(data);
add_mod.intent.parameters.push_back(std::move(intent_parameter));
fuchsia::modular::StoryCommand command;
command.set_add_mod(std::move(add_mod));
commands.push_back(std::move(command));
story_puppet_master_->Enqueue(std::move(commands));
story_puppet_master_->Execute(
[this](fuchsia::modular::ExecuteResult result) {
create_story_.Pass();
StartStory();
});
}
void StartStory() {
// Request start of the new story.
story_provider()->GetController(kStoryName, story_controller_.NewRequest());
story_controller_->RequestStart();
}
fuchsia::modular::PuppetMasterPtr puppet_master_;
fuchsia::modular::StoryPuppetMasterPtr story_puppet_master_;
fidl::StringPtr story_id_;
fuchsia::modular::StoryControllerPtr story_controller_;
FXL_DISALLOW_COPY_AND_ASSIGN(TestApp);
};
} // namespace
int main(int /*argc*/, const char** /*argv*/) {
modular::testing::ComponentMain<TestApp>();
return 0;
}