This is a black box testing suite to verify the crosapi behavior, named Crosapi Test. Crosapi Test can be used to check if Ash returns the expected value when a crosapi function is called.
The key points that make Crosapi Test different from other tests are:
See Ash Crosapi Testing Framework for more details.
You can write tests by creating a class that inherits CrosapiTestBase, and the new class has remote instance(s). You can use individual interfaces by calling CrosapiTestBase::BindCrosapiInterface() with bind functions (e.g. BindNetworkChange or BindFileManager).
This is an example code for FileManager.
// Inherit CrosapiTestBase to use the test suite.
class FileManagerCrosapiTest : public CrosapiTestBase {
protected:
void SetUp() override {
// You need to call the parent's SetUp() to check crosapi connection is set up.
CrosapiTestBase::SetUp();
// Pass bind function, then you can use crosapi function.
file_manager_ = BindCrosapiInterface(&mojom::Crosapi::BindFileManger);
}
mojo::Remote<mojom::FileManager> file_manager_;
};
TEST_F(FileManagerCrosapiTest, ShowItemInFolder) {
base::test::TestFuture<mojom::OpenResult> future;
file_manager_->ShowItemInFolder(kNonExistingPath, future.GetCallback());
EXPECT_EQ(future.Get(), mojom::OpenResult::kFailedPathNotFound);
}
Note : You cannot modify Ash states directly because the test process is separated from Ash process. Instead, you can use TestController to manipulate Ash if the test target is test_ash_chrome.