| Index: chrome/test/chromedriver/commands_unittest.cc
|
| diff --git a/chrome/test/chromedriver/commands_unittest.cc b/chrome/test/chromedriver/commands_unittest.cc
|
| index 44571863054bbd1a38e1ca25808019295033843a..5a5a1180d7eb2ae21a74ac6ddd2c2e09e7d348ad 100644
|
| --- a/chrome/test/chromedriver/commands_unittest.cc
|
| +++ b/chrome/test/chromedriver/commands_unittest.cc
|
| @@ -546,3 +546,124 @@ TEST(CommandsTest, ErrorFindChildElement) {
|
| ExecuteFindChildElements(
|
| 1, &session, &web_view, element_id, params, &result).code());
|
| }
|
| +
|
| +namespace {
|
| +
|
| +class MockCommandListener : public CommandListener {
|
| + public:
|
| + MockCommandListener() : called_(false) {}
|
| + virtual ~MockCommandListener() {}
|
| +
|
| + virtual Status BeforeCommand(const std::string& command_name) OVERRIDE {
|
| + called_ = true;
|
| + EXPECT_STREQ("cmd", command_name.c_str());
|
| + return Status(kOk);
|
| + }
|
| +
|
| + void VerifyCalled() {
|
| + EXPECT_TRUE(called_);
|
| + }
|
| +
|
| + void VerifyNotCalled() {
|
| + EXPECT_FALSE(called_);
|
| + }
|
| +
|
| + private:
|
| + bool called_;
|
| +};
|
| +
|
| +Status ExecuteAddListenerToSession(
|
| + MockCommandListener* listener,
|
| + Session* session,
|
| + const base::DictionaryValue& params,
|
| + scoped_ptr<base::Value>* return_value) {
|
| + session->AddListener(listener);
|
| + listener->VerifyNotCalled();
|
| + return Status(kOk);
|
| +}
|
| +
|
| +Status ExecuteTestListener(
|
| + Session* session,
|
| + const base::DictionaryValue& params,
|
| + scoped_ptr<base::Value>* return_value) {
|
| + session->quit = true;
|
| + return Status(kOk);
|
| +}
|
| +
|
| +void VerifyListenerNotNotifiedAfterCommandRun(
|
| + MockCommandListener* listener,
|
| + base::RunLoop* run_loop,
|
| + const Status& status,
|
| + scoped_ptr<base::Value> value,
|
| + const std::string& session_id) {
|
| + ASSERT_EQ(kOk, status.code());
|
| + listener->VerifyNotCalled();
|
| + run_loop->Quit();
|
| +}
|
| +
|
| +
|
| +void VerifyListenerNotifiedBeforeCommandRun(
|
| + MockCommandListener* listener,
|
| + base::RunLoop* run_loop,
|
| + const Status& status,
|
| + scoped_ptr<base::Value> value,
|
| + const std::string& session_id) {
|
| + ASSERT_EQ(kOk, status.code());
|
| + listener->VerifyCalled();
|
| + run_loop->Quit();
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +TEST(CommandsTest, SessionNotifiedOfCommand) {
|
| + SessionThreadMap map;
|
| + linked_ptr<base::Thread> thread(new base::Thread("1"));
|
| + ASSERT_TRUE(thread->Start());
|
| + std::string id("id");
|
| + thread->message_loop()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&internal::CreateSessionOnSessionThreadForTesting, id));
|
| + map[id] = thread;
|
| +
|
| + base::DictionaryValue params;
|
| + // Listener is owned by and will be destroyed by session
|
| + MockCommandListener* listener = new MockCommandListener();
|
| + SessionCommand cmd = base::Bind(
|
| + &ExecuteAddListenerToSession, listener);
|
| +
|
| + base::MessageLoop loop;
|
| + base::RunLoop run_loop_addlistener;
|
| +
|
| + // Listeners are notified immediately before commands are run.
|
| + // Here, the command adds the listener to the session, so the listener
|
| + // should not be notified since it will not have been added yet.
|
| + ExecuteSessionCommand(
|
| + &map,
|
| + "cmd",
|
| + cmd,
|
| + false,
|
| + params,
|
| + id,
|
| + base::Bind(&VerifyListenerNotNotifiedAfterCommandRun, listener,
|
| + &run_loop_addlistener));
|
| +
|
| + run_loop_addlistener.Run();
|
| +
|
| + base::RunLoop run_loop_testlistener;
|
| + cmd = base::Bind(
|
| + &ExecuteTestListener);
|
| +
|
| + // The listener has been added to the session and should be notified of
|
| + // the ExecuteTestListener command.
|
| + ExecuteSessionCommand(
|
| + &map,
|
| + "cmd",
|
| + cmd,
|
| + false,
|
| + params,
|
| + id,
|
| + base::Bind(&VerifyListenerNotifiedBeforeCommandRun, listener,
|
| + &run_loop_testlistener));
|
| +
|
| + run_loop_testlistener.Run();
|
| +}
|
|
|