tree: 4bcd0355ff53248602dd869509dd2725262dcb73 [path history] [tgz]
  1. ash_crosapi_tests_env.cc
  2. ash_crosapi_tests_env.h
  3. ash_crosapi_tests_main.cc
  4. crosapi_test_base.cc
  5. crosapi_test_base.h
  6. DEPS
  7. file_manager_ash_crosapitest.cc
  8. network_change_ash_crosapitest.cc
  9. README.md
chrome/browser/ash/crosapi/test/README.md

Ash Crosapi Test

Overview

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:

  • This test suite focuses on Ash and runs without Lacros.
  • This test suite checks the crosapi behavior from outside of Ash.

See Ash Crosapi Testing Framework for more details.

How To Write

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.

Example tests